From 9eb75a0c07f2f847caa1cae80ef162e8b99d29d4 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 3 Mar 2022 18:42:20 +1300 Subject: [PATCH] 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 --- CHANGES.current | 12 ++++++---- Doc/Manual/Typemaps.html | 2 +- .../errors/swig_typemap_missing_value.i | 3 ++- .../errors/swig_typemap_missing_value.stderr | 3 ++- Source/CParse/parser.y | 22 +++++-------------- Source/Include/swigwarn.h | 2 +- 6 files changed, 20 insertions(+), 24 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index a715b7e5d..257565587 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -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 diff --git a/Doc/Manual/Typemaps.html b/Doc/Manual/Typemaps.html index 4842641dd..2d6e5d190 100644 --- a/Doc/Manual/Typemaps.html +++ b/Doc/Manual/Typemaps.html @@ -3298,7 +3298,7 @@ The example above also shows a common approach of issuing a warning for an as ye

-Compatibility note: In SWIG-1.1 different languages could be distinguished with the language name being put within the %typemap directive, for example,
+Compatibility note: In SWIG-1.1 different languages could be distinguished with the language name being put within the %typemap 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,
%typemap(ruby, in) int "$1 = NUM2INT($input);".

diff --git a/Examples/test-suite/errors/swig_typemap_missing_value.i b/Examples/test-suite/errors/swig_typemap_missing_value.i index ec9ed1ede..b9937af1a 100644 --- a/Examples/test-suite/errors/swig_typemap_missing_value.i +++ b/Examples/test-suite/errors/swig_typemap_missing_value.i @@ -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); diff --git a/Examples/test-suite/errors/swig_typemap_missing_value.stderr b/Examples/test-suite/errors/swig_typemap_missing_value.stderr index b30a412c3..26bc8cdb9 100644 --- a/Examples/test-suite/errors/swig_typemap_missing_value.stderr +++ b/Examples/test-suite/errors/swig_typemap_missing_value.stderr @@ -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 instead. +swig_typemap_missing_value.i:4: Error: %typemap method shouldn't have a value specified. diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 176719697..70bd3ef20 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -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 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 instead.\n", + Getattr(p, "name")); /* Set to empty value to avoid segfaults later. */ Setattr(p, "value", NewStringEmpty()); } diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h index 7528c4331..267b69c90 100644 --- a/Source/Include/swigwarn.h +++ b/Source/Include/swigwarn.h @@ -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