Handle typemap argument without a value

This now gives an error, previously SWIG segfaulted.

Fixes #891
This commit is contained in:
Olly Betts 2022-03-02 15:53:51 +13:00
commit aa24e6b22b
4 changed files with 29 additions and 10 deletions

View file

@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.1.0 (in progress)
===========================
2022-03-02: olly
#891 Give error for typemap argument without a value. Previously
SWIG segfaulted.
2022-02-27: wsfulton
[Python] #735 #1561 Function annotations containing C/C++ types are no longer
generated when using the -py3 option. Function annotations support has been

View file

@ -0,0 +1,6 @@
%module xxx
%typemap(in, numinputs=1, foo) int ""
/* SWIG segfaulted trying to use the above typemap in SWIG < 4.1.0. */
void func(int arg);

View file

@ -0,0 +1 @@
swig_typemap_missing_value.i:3: Error: %typemap argument 'foo' is missing value

View file

@ -2723,26 +2723,34 @@ typemap_directive : TYPEMAP LPAREN typemap_type RPAREN tm_list stringbrace {
/* typemap method type (lang,method) or (method) */
typemap_type : kwargs {
Hash *p;
String *name;
p = nextSibling($1);
String *name = Getattr($1, "name");
Hash *p = nextSibling($1);
if (p && (!Getattr(p,"value"))) {
/* this is the deprecated two argument typemap form */
Swig_warning(WARN_DEPRECATED_TYPEMAP_LANG,cparse_file, cparse_line,
"Specifying the language name in %%typemap is deprecated - use #ifdef SWIG<LANG> instead.\n");
/* two argument typemap form */
name = Getattr($1,"name");
Printf(stdout, "name=%s typemap_lang=%s\n", name, typemap_lang);
if (!name || (Strcmp(name,typemap_lang))) {
$$.method = 0;
$$.kwargs = 0;
name = 0;
p = 0;
} else {
$$.method = Getattr(p,"name");
$$.kwargs = nextSibling(p);
name = Getattr(p,"name");
p = nextSibling(p);
}
} else {
/* one-argument typemap-form */
$$.method = Getattr($1,"name");
$$.kwargs = p;
}
$$.method = name;
$$.kwargs = p;
while (p) {
if (!Getattr(p, "value")) {
Swig_error(cparse_file, cparse_line,
"%%typemap argument '%s' is missing value\n", Getattr(p, "name"));
/* Set to empty value to avoid segfaults later. */
Setattr(p, "value", NewStringEmpty());
}
p = nextSibling(p);
}
}
;