From 54ddefe4103d9adc7b64adf2ab2dab3fe13a400d Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 27 Jul 2022 13:45:08 +1200 Subject: [PATCH] Revert "Modify fix for << in array size" This reverts commit 0ff9a0959ab0fc537c7db53fb94efb7534b45925. The modified fix breaks Java and C#, where C constant expressions get used in the generated target language code in some cases. Revert this fix for now. --- Lib/swiglabels.swg | 5 ----- Source/CParse/parser.y | 6 +----- Source/Swig/typesys.c | 4 +++- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/Lib/swiglabels.swg b/Lib/swiglabels.swg index 43b2f6edc..b3855665e 100644 --- a/Lib/swiglabels.swg +++ b/Lib/swiglabels.swg @@ -121,8 +121,3 @@ #ifdef __INTEL_COMPILER # pragma warning disable 592 #endif - -/* We replace `<<` with `SWIG_LSHIFT` in constant expressions to avoid - * confusing SWIG's type system into thinking there's a template. - */ -#define SWIG_LSHIFT << diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index ce0602f3b..816264de6 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -6803,11 +6803,7 @@ exprcompound : expr PLUS expr { $$.type = promote($1.type,$3.type); } | expr LSHIFT expr { - /* To avoid confusing SWIG's type system, we replace `<<` with - * `SWIG_LSHIFT` here, then define the latter as a macro in - * the generated wrapper file. - */ - $$.val = NewStringf("%s SWIG_LSHIFT %s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); + $$.val = NewStringf("%s << %s",COMPOUND_EXPR_VAL($1),COMPOUND_EXPR_VAL($3)); $$.type = promote_type($1.type); } | expr RSHIFT expr { diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c index 710688a0f..464b89f28 100644 --- a/Source/Swig/typesys.c +++ b/Source/Swig/typesys.c @@ -1702,7 +1702,9 @@ void SwigType_remember_clientdata(const SwigType *t, const_String_or_char_ptr cl if (t) { char *ct = Char(t); - if (strchr(ct, '<') && !(strstr(ct, "<("))) { + const char *lt = strchr(ct, '<'); + /* Allow for `<<` operator in constant expression for array size. */ + if (lt && lt[1] != '(' && lt[1] != '<') { Printf(stdout, "Bad template type passed to SwigType_remember: %s\n", t); assert(0); }