Improve typemap method and attribute checking

Specifying a value on the typemap method now gives an error, e.g.:

%typemap(argout=123) char * ""

The old way of specifying a language name in the typemap attributes
is no longer supported (it has been deprecated for 16 years).

Closes #891
This commit is contained in:
Olly Betts 2022-03-03 18:42:20 +13:00
commit 9eb75a0c07
6 changed files with 20 additions and 24 deletions

View file

@ -7,6 +7,14 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.1.0 (in progress)
===========================
2022-03-03: olly
#891 Report errors for typemap attributes without a value
(previously SWIG segfaulted) and for typemap types with a value
(previously the value was quietly ignored).
The old way of specifying a language name in the typemap attributes
is no longer supported (it has been deprecated for 16 years).
2022-03-02: geographika, wsfulton
[Python] #1951 Add Python variable annotations support.
@ -38,10 +46,6 @@ Version 4.1.0 (in progress)
*** POTENTIAL INCOMPATIBILITY ***
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

@ -3298,7 +3298,7 @@ The example above also shows a common approach of issuing a warning for an as ye
</p>
<p>
<b>Compatibility note: </b> In SWIG-1.1 different languages could be distinguished with the language name being put within the <tt>%typemap</tt> directive, for example, <br>
<b>Compatibility note: </b> In SWIG-1.1 different languages could be distinguished with the language name being put within the <tt>%typemap</tt> directive, but this was deprecated in SWIG 1.3.28 and support finally dropped completely in SWIG 4.1.0 so you'll need to update any remaining uses to use the approach above. For example, <br>
<tt>%typemap(ruby, in) int "$1 = NUM2INT($input);"</tt>.
</p>

View file

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

View file

@ -1 +1,2 @@
swig_typemap_missing_value.i:3: Error: %typemap argument 'foo' is missing value
swig_typemap_missing_value.i:3: Error: %typemap attribute 'foo' is missing its value. If this is specifying the target language, that's no longer supported: use #ifdef SWIG<LANG> instead.
swig_typemap_missing_value.i:4: Error: %typemap method shouldn't have a value specified.

View file

@ -2725,27 +2725,17 @@ typemap_directive : TYPEMAP LPAREN typemap_type RPAREN tm_list stringbrace {
typemap_type : kwargs {
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 */
if (!name || (Strcmp(name,typemap_lang))) {
name = 0;
p = 0;
} else {
name = Getattr(p,"name");
p = nextSibling(p);
}
} else {
/* one-argument typemap-form */
}
$$.method = name;
$$.kwargs = p;
if (Getattr($1, "value")) {
Swig_error(cparse_file, cparse_line,
"%%typemap method shouldn't have a value specified.\n");
}
while (p) {
if (!Getattr(p, "value")) {
Swig_error(cparse_file, cparse_line,
"%%typemap argument '%s' is missing value\n", Getattr(p, "name"));
"%%typemap attribute '%s' is missing its value. If this is specifying the target language, that's no longer supported: use #ifdef SWIG<LANG> instead.\n",
Getattr(p, "name"));
/* Set to empty value to avoid segfaults later. */
Setattr(p, "value", NewStringEmpty());
}

View file

@ -52,7 +52,7 @@
#define WARN_DEPRECATED_NAME 121
#define WARN_DEPRECATED_NOEXTERN 122
#define WARN_DEPRECATED_NODEFAULT 123
#define WARN_DEPRECATED_TYPEMAP_LANG 124
/* Unused since 4.1.0: #define WARN_DEPRECATED_TYPEMAP_LANG 124 */
#define WARN_DEPRECATED_INPUT_FILE 125
#define WARN_DEPRECATED_NESTED_WORKAROUND 126