From c1258323b113033988240d3838f0001608163876 Mon Sep 17 00:00:00 2001 From: Seth R Johnson Date: Tue, 9 May 2017 14:36:14 -0400 Subject: [PATCH 001/262] Fix missing include in SWIG typemap --- Lib/carrays.i | 6 ++++++ Lib/cdata.i | 4 +++- Lib/cpointer.i | 6 ++++++ Lib/swig.swg | 36 ++++++++++++++++++++---------------- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/Lib/carrays.i b/Lib/carrays.i index 3a9c3cfee..0aa3eee89 100644 --- a/Lib/carrays.i +++ b/Lib/carrays.i @@ -5,6 +5,12 @@ * pointers as arrays. * ----------------------------------------------------------------------------- */ +#ifndef __cplusplus +// C uses free/calloc/malloc +%include "swigfragments.swg" +%fragment(""); +#endif + /* ----------------------------------------------------------------------------- * %array_functions(TYPE,NAME) * diff --git a/Lib/cdata.i b/Lib/cdata.i index 23b7211e7..e058fe28b 100644 --- a/Lib/cdata.i +++ b/Lib/cdata.i @@ -68,7 +68,7 @@ static jbyteArray SWIG_JavaArrayOutCDATA(JNIEnv *jenv, char *result, jsize sz) { /* ----------------------------------------------------------------------------- - * %cdata(TYPE [, NAME]) + * %cdata(TYPE [, NAME]) * * Convert raw C data to a binary string. * ----------------------------------------------------------------------------- */ @@ -107,6 +107,8 @@ SWIGCDATA cdata_##NAME(TYPE *ptr, int nelements); %cdata(void); +%fragment(""); + /* Memory move function. Due to multi-argument typemaps this appears to be wrapped as void memmove(void *data, const char *s); */ void memmove(void *data, const void *indata, int inlen); diff --git a/Lib/cpointer.i b/Lib/cpointer.i index 881c511fc..5eca6fae1 100644 --- a/Lib/cpointer.i +++ b/Lib/cpointer.i @@ -5,6 +5,12 @@ * pointer objects. * ----------------------------------------------------------------------------- */ +#ifndef __cplusplus +// C uses free/calloc/malloc +%include "swigfragments.swg" +%fragment(""); +#endif + /* ----------------------------------------------------------------------------- * %pointer_class(type,name) * diff --git a/Lib/swig.swg b/Lib/swig.swg index 6dc215dcf..c215e8d89 100644 --- a/Lib/swig.swg +++ b/Lib/swig.swg @@ -442,6 +442,10 @@ namespace std { * Default char * and C array typemaps * ----------------------------------------------------------------------------- */ +%fragment("", "runtime") %{ +#include +%} + /* Set up the typemap for handling new return strings */ #ifdef __cplusplus @@ -453,7 +457,7 @@ namespace std { /* Default typemap for handling char * members */ #ifdef __cplusplus -%typemap(memberin) char * { +%typemap(memberin,fragment="") char * { delete [] $1; if ($input) { $1 = ($1_type) (new char[strlen((const char *)$input)+1]); @@ -462,7 +466,7 @@ namespace std { $1 = 0; } } -%typemap(memberin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * { +%typemap(memberin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG,fragment="") const char * { if ($input) { $1 = ($1_type) (new char[strlen((const char *)$input)+1]); strcpy((char *)$1, (const char *)$input); @@ -470,7 +474,7 @@ namespace std { $1 = 0; } } -%typemap(globalin) char * { +%typemap(globalin,fragment="") char * { delete [] $1; if ($input) { $1 = ($1_type) (new char[strlen((const char *)$input)+1]); @@ -479,7 +483,7 @@ namespace std { $1 = 0; } } -%typemap(globalin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * { +%typemap(globalin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG,fragment="") const char * { if ($input) { $1 = ($1_type) (new char[strlen((const char *)$input)+1]); strcpy((char *)$1, (const char *)$input); @@ -488,7 +492,7 @@ namespace std { } } #else -%typemap(memberin) char * { +%typemap(memberin,fragment="") char * { free($1); if ($input) { $1 = ($1_type) malloc(strlen((const char *)$input)+1); @@ -497,7 +501,7 @@ namespace std { $1 = 0; } } -%typemap(memberin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * { +%typemap(memberin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG,fragment="") const char * { if ($input) { $1 = ($1_type) malloc(strlen((const char *)$input)+1); strcpy((char *)$1, (const char *)$input); @@ -505,7 +509,7 @@ namespace std { $1 = 0; } } -%typemap(globalin) char * { +%typemap(globalin,fragment="") char * { free($1); if ($input) { $1 = ($1_type) malloc(strlen((const char *)$input)+1); @@ -514,7 +518,7 @@ namespace std { $1 = 0; } } -%typemap(globalin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * { +%typemap(globalin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG,fragment="") const char * { if ($input) { $1 = ($1_type) malloc(strlen((const char *)$input)+1); strcpy((char *)$1, (const char *)$input); @@ -527,7 +531,7 @@ namespace std { /* Character array handling */ -%typemap(memberin) char [ANY] { +%typemap(memberin,fragment="") char [ANY] { if($input) { strncpy((char*)$1, (const char *)$input, $1_dim0-1); $1[$1_dim0-1] = 0; @@ -536,7 +540,7 @@ namespace std { } } -%typemap(globalin) char [ANY] { +%typemap(globalin,fragment="") char [ANY] { if($input) { strncpy((char*)$1, (const char *)$input, $1_dim0-1); $1[$1_dim0-1] = 0; @@ -545,25 +549,25 @@ namespace std { } } -%typemap(memberin) char [] { +%typemap(memberin,fragment="") char [] { if ($input) strcpy((char *)$1, (const char *)$input); else $1[0] = 0; } -%typemap(globalin) char [] { +%typemap(globalin,fragment="") char [] { if ($input) strcpy((char *)$1, (const char *)$input); else $1[0] = 0; } /* memberin/globalin typemap for arrays. */ -%typemap(memberin) SWIGTYPE [ANY] { +%typemap(memberin,fragment="") SWIGTYPE [ANY] { size_t ii; $1_basetype *b = ($1_basetype *) $1; for (ii = 0; ii < (size_t)$1_size; ii++) b[ii] = *(($1_basetype *) $input + ii); } -%typemap(globalin) SWIGTYPE [ANY] { +%typemap(globalin,fragment="") SWIGTYPE [ANY] { size_t ii; $1_basetype *b = ($1_basetype *) $1; for (ii = 0; ii < (size_t)$1_size; ii++) b[ii] = *(($1_basetype *) $input + ii); @@ -571,7 +575,7 @@ namespace std { /* memberin/globalin typemap for double arrays. */ -%typemap(memberin) SWIGTYPE [ANY][ANY] { +%typemap(memberin,fragment="") SWIGTYPE [ANY][ANY] { $basetype (*inp)[$1_dim1] = ($basetype (*)[$1_dim1])($input); $basetype (*dest)[$1_dim1] = ($basetype (*)[$1_dim1])($1); size_t ii = 0; @@ -583,7 +587,7 @@ namespace std { } } -%typemap(globalin) SWIGTYPE [ANY][ANY] { +%typemap(globalin,fragment="") SWIGTYPE [ANY][ANY] { $basetype (*inp)[$1_dim1] = ($basetype (*)[$1_dim1])($input); $basetype (*dest)[$1_dim1] = ($basetype (*)[$1_dim1])($1); size_t ii = 0; From feeb2516aedfc19fdc1eefe233dec9bc5593fe2b Mon Sep 17 00:00:00 2001 From: Seth R Johnson Date: Tue, 7 Nov 2017 18:35:00 -0500 Subject: [PATCH 002/262] "Include what you use" for tests Many of these tests implicitly required the target language library files to include the headers upstream. --- Examples/test-suite/default_args.i | 59 ++++++++++--------- Examples/test-suite/director_thread.i | 2 +- Examples/test-suite/li_cdata.i | 4 ++ Examples/test-suite/li_cdata_cpp.i | 4 ++ Examples/test-suite/li_std_except.i | 2 + Examples/test-suite/memberin_extend.i | 1 + Examples/test-suite/mod.h | 2 +- Examples/test-suite/namespace_typemap.i | 1 + Examples/test-suite/nested_extend_c.i | 4 ++ Examples/test-suite/operator_overload_break.i | 1 + Examples/test-suite/operator_pointer_ref.i | 2 + .../test-suite/smart_pointer_const_overload.i | 4 ++ Examples/test-suite/special_variable_macros.i | 2 + Examples/test-suite/string_simple.i | 1 + .../testdir/inctest/subdir2/hello.i | 1 + Examples/test-suite/threads.i | 1 + Examples/test-suite/typedef_struct.i | 1 + 17 files changed, 61 insertions(+), 31 deletions(-) diff --git a/Examples/test-suite/default_args.i b/Examples/test-suite/default_args.i index 6b680f561..2f8fdbbd2 100644 --- a/Examples/test-suite/default_args.i +++ b/Examples/test-suite/default_args.i @@ -18,6 +18,7 @@ %{ #define TESTCASE_THROW1(T1) #define TESTCASE_THROW2(T1, T2) +#include %} %include @@ -71,7 +72,7 @@ class EnumClass { public: enum speed { FAST, SLOW }; - // Note: default values should be EnumClass::FAST and SWEET + // Note: default values should be EnumClass::FAST and SWEET bool blah(speed s = FAST, flavor f = SWEET) { return (s == FAST && f == SWEET); }; }; @@ -83,16 +84,16 @@ // casts const char * casts1(const char *m = (const char *) NULL) { - char *ret = NULL; - if (m) { + char *ret = NULL; + if (m) { ret = new char[strlen(m)+1]; strcpy(ret, m); } return ret; } const char * casts2(const char *m = (const char *) "Hello") { - char *ret = NULL; - if (m) { + char *ret = NULL; + if (m) { ret = new char[strlen(m)+1]; strcpy(ret, m); } @@ -108,16 +109,16 @@ char chartest6(char c = '\x43') { return c; } // 'C' // namespaces - namespace AType { - enum AType { NoType }; - } + namespace AType { + enum AType { NoType }; + } void dummy(AType::AType aType = AType::NoType) {} - namespace A { - namespace B { - int CONST_NUM = 10; - } + namespace A { + namespace B { + int CONST_NUM = 10; + } int afunction(int i = B::CONST_NUM) { return i; } - } + } // references int reftest1(const int &x = 42) { return x; } @@ -131,7 +132,7 @@ void test(int x = Oak + Fir + Cedar) {} }; enum Tree::types chops(enum Tree::types type) { return type; } - + %} // Rename a class member @@ -155,11 +156,11 @@ static int spam; Foo(){} - + Foo(int x, int y = 0, int z = 0){} void meth(int x, int y = 0, int z = 0){} - + // Use a renamed member as a default argument. SWIG has to resolve // bar to Foo::bar and not Foo::spam. SWIG-1.3.11 got this wrong. // (Different default parameter wrapping in SWIG-1.3.23 ensures SWIG doesn't have to resolve these symbols). @@ -189,20 +190,20 @@ // tests valuewrapper %feature("compactdefaultargs") MyClass2::set; %inline %{ - enum MyType { Val1, Val2 }; + enum MyType { Val1, Val2 }; - class MyClass1 - { - public: + class MyClass1 + { + public: MyClass1(MyType myType) {} - }; + }; - class MyClass2 - { - public : + class MyClass2 + { + public : void set(MyClass1 cl1 = Val1) {} - // This could have been written : set(MyClass1 cl1 = MyClass1(Val1)) - // But it works in C++ since there is a "conversion" constructor in MyClass1. + // This could have been written : set(MyClass1 cl1 = MyClass1(Val1)) + // But it works in C++ since there is a "conversion" constructor in MyClass1. void set2(MyClass1 cl1 = Val1) {} }; %} @@ -281,7 +282,7 @@ struct ConstMethods { }; %} -// const methods +// const methods // runtime test needed to check that the const method is called struct ConstMethods { int coo(double d = 0.0) const; @@ -305,8 +306,8 @@ struct ConstMethods { return(x+p); } - typedef struct Pointf { - double x,y; + typedef struct Pointf { + double x,y; } Pointf; } %} diff --git a/Examples/test-suite/director_thread.i b/Examples/test-suite/director_thread.i index c4564737f..649ab2538 100644 --- a/Examples/test-suite/director_thread.i +++ b/Examples/test-suite/director_thread.i @@ -20,7 +20,6 @@ #ifdef _WIN32 #include #include -#include #else #include #include @@ -30,6 +29,7 @@ #endif #include +#include #include "swig_examples_lock.h" class Foo; diff --git a/Examples/test-suite/li_cdata.i b/Examples/test-suite/li_cdata.i index 2180af96e..4e1a01e4e 100644 --- a/Examples/test-suite/li_cdata.i +++ b/Examples/test-suite/li_cdata.i @@ -5,4 +5,8 @@ %cdata(int); %cdata(double); +%{ +#include +%} + void *malloc(size_t size); diff --git a/Examples/test-suite/li_cdata_cpp.i b/Examples/test-suite/li_cdata_cpp.i index 2d7d300e4..80ff2932b 100644 --- a/Examples/test-suite/li_cdata_cpp.i +++ b/Examples/test-suite/li_cdata_cpp.i @@ -5,4 +5,8 @@ %cdata(int); %cdata(double); +%{ +#include +%} + void *malloc(size_t size); diff --git a/Examples/test-suite/li_std_except.i b/Examples/test-suite/li_std_except.i index 60bce999d..9bf70cd3f 100644 --- a/Examples/test-suite/li_std_except.i +++ b/Examples/test-suite/li_std_except.i @@ -9,6 +9,8 @@ %} %inline %{ + #include + #include struct E1 : public std::exception { }; diff --git a/Examples/test-suite/memberin_extend.i b/Examples/test-suite/memberin_extend.i index c6eb10526..43251973f 100644 --- a/Examples/test-suite/memberin_extend.i +++ b/Examples/test-suite/memberin_extend.i @@ -11,6 +11,7 @@ struct ExtendMe { %{ #include +#include std::map ExtendMeStringMap; void ExtendMe_thing_set(ExtendMe *self, const char *val) { char *old_val = ExtendMeStringMap[self]; diff --git a/Examples/test-suite/mod.h b/Examples/test-suite/mod.h index aae629850..60eb36b77 100644 --- a/Examples/test-suite/mod.h +++ b/Examples/test-suite/mod.h @@ -1,4 +1,4 @@ - +#include class C; diff --git a/Examples/test-suite/namespace_typemap.i b/Examples/test-suite/namespace_typemap.i index 9c74715f0..e7b91b9d4 100644 --- a/Examples/test-suite/namespace_typemap.i +++ b/Examples/test-suite/namespace_typemap.i @@ -2,6 +2,7 @@ %module namespace_typemap %{ +#include namespace test { /* A minimalistic string class */ class string_class { diff --git a/Examples/test-suite/nested_extend_c.i b/Examples/test-suite/nested_extend_c.i index f1d7ff2c8..67ca86578 100644 --- a/Examples/test-suite/nested_extend_c.i +++ b/Examples/test-suite/nested_extend_c.i @@ -12,6 +12,10 @@ #endif +%{ +#include "stdlib.h" +%} + #if !defined(SWIGOCTAVE) && !defined(SWIG_JAVASCRIPT_V8) %extend hiA { hiA() { diff --git a/Examples/test-suite/operator_overload_break.i b/Examples/test-suite/operator_overload_break.i index a948f2d49..809498fa7 100644 --- a/Examples/test-suite/operator_overload_break.i +++ b/Examples/test-suite/operator_overload_break.i @@ -18,6 +18,7 @@ %{ #include +#include using namespace std; %} diff --git a/Examples/test-suite/operator_pointer_ref.i b/Examples/test-suite/operator_pointer_ref.i index 84182da0d..cd4ed2db0 100644 --- a/Examples/test-suite/operator_pointer_ref.i +++ b/Examples/test-suite/operator_pointer_ref.i @@ -4,6 +4,8 @@ #if defined(_MSC_VER) #pragma warning(disable: 4996) // 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help for details. #endif +#include +#include %} %rename(AsCharStarRef) operator char*&; diff --git a/Examples/test-suite/smart_pointer_const_overload.i b/Examples/test-suite/smart_pointer_const_overload.i index 75a137b73..526bcc9bd 100644 --- a/Examples/test-suite/smart_pointer_const_overload.i +++ b/Examples/test-suite/smart_pointer_const_overload.i @@ -3,6 +3,10 @@ %warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED) Bar::operator->; // Overloaded method Bar::operator ->() ignored %warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED) Bar2::operator->; // Overloaded method Bar2::operator ->() ignored +%{ +#include +%} + %inline %{ int CONST_ACCESS = 1; int MUTABLE_ACCESS = 2; diff --git a/Examples/test-suite/special_variable_macros.i b/Examples/test-suite/special_variable_macros.i index ca2edaa98..98d108b6b 100644 --- a/Examples/test-suite/special_variable_macros.i +++ b/Examples/test-suite/special_variable_macros.i @@ -9,6 +9,8 @@ #if defined(_MSC_VER) #pragma warning(disable: 4996) // 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help for details. #endif +#include +#include %} %ignore Name::operator=; diff --git a/Examples/test-suite/string_simple.i b/Examples/test-suite/string_simple.i index c319aa1ef..839d56d9b 100644 --- a/Examples/test-suite/string_simple.i +++ b/Examples/test-suite/string_simple.i @@ -3,6 +3,7 @@ %newobject copy_string; %inline %{ +#include #include const char* copy_string(const char* str) { size_t len = strlen(str); diff --git a/Examples/test-suite/testdir/inctest/subdir2/hello.i b/Examples/test-suite/testdir/inctest/subdir2/hello.i index ed172b1fd..e87b43759 100644 --- a/Examples/test-suite/testdir/inctest/subdir2/hello.i +++ b/Examples/test-suite/testdir/inctest/subdir2/hello.i @@ -3,6 +3,7 @@ %{ typedef char * TypedefString; +#include %} diff --git a/Examples/test-suite/threads.i b/Examples/test-suite/threads.i index 7c6b09be0..28c55945e 100644 --- a/Examples/test-suite/threads.i +++ b/Examples/test-suite/threads.i @@ -9,6 +9,7 @@ %inline %{ #include + #include struct Kerfuffle { std::string StdString(std::string str) { return str; diff --git a/Examples/test-suite/typedef_struct.i b/Examples/test-suite/typedef_struct.i index 185e81105..b9a670cf5 100644 --- a/Examples/test-suite/typedef_struct.i +++ b/Examples/test-suite/typedef_struct.i @@ -31,6 +31,7 @@ #define MS_NOOVERRIDE -1111 +#include %} From c041ac6d1cda407baa338bd016c0a68f2f0c6834 Mon Sep 17 00:00:00 2001 From: Seth R Johnson Date: Fri, 23 Mar 2018 15:04:00 -0400 Subject: [PATCH 003/262] Move fragment to swigfragments --- Examples/test-suite/char_strings.i | 5 +++-- Examples/test-suite/threads_exception.i | 1 + Examples/test-suite/varargs.i | 4 ++++ Lib/cdata.i | 2 ++ Lib/swig.swg | 4 ---- Lib/swigfragments.swg | 4 ++++ 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Examples/test-suite/char_strings.i b/Examples/test-suite/char_strings.i index 9a87df4e3..aa3b125ce 100644 --- a/Examples/test-suite/char_strings.i +++ b/Examples/test-suite/char_strings.i @@ -11,6 +11,7 @@ below. %{ #include +#include #define OTHERLAND_MSG "Little message from the safe world." #define CPLUSPLUS_MSG "A message from the deep dark world of C++, where anything is possible." @@ -150,11 +151,11 @@ const char global_const_char_array2[sizeof(CPLUSPLUS_MSG)+1] = CPLUSPLUS_MSG; %inline { struct Formatpos; struct OBFormat; - + static int GetNextFormat(Formatpos& itr, const char*& str,OBFormat*& pFormat) { return 0; } - + } diff --git a/Examples/test-suite/threads_exception.i b/Examples/test-suite/threads_exception.i index 4708633db..776e84231 100644 --- a/Examples/test-suite/threads_exception.i +++ b/Examples/test-suite/threads_exception.i @@ -13,6 +13,7 @@ %} %{ +#include struct A {}; %} diff --git a/Examples/test-suite/varargs.i b/Examples/test-suite/varargs.i index dd56cb073..b4143da7c 100644 --- a/Examples/test-suite/varargs.i +++ b/Examples/test-suite/varargs.i @@ -7,6 +7,10 @@ %varargs(int mode = 0) Foo::statictest(const char*fmt, ...); %varargs(2, int mode = 0) test_plenty(const char*fmt, ...); +%{ +#include +%} + %inline %{ char *test(const char *fmt, ...) { return (char *) fmt; diff --git a/Lib/cdata.i b/Lib/cdata.i index e058fe28b..e82843b3a 100644 --- a/Lib/cdata.i +++ b/Lib/cdata.i @@ -4,6 +4,8 @@ * SWIG library file containing macros for manipulating raw C data as strings. * ----------------------------------------------------------------------------- */ +%include + %{ typedef struct SWIGCDATA { char *data; diff --git a/Lib/swig.swg b/Lib/swig.swg index c215e8d89..d719a139c 100644 --- a/Lib/swig.swg +++ b/Lib/swig.swg @@ -442,10 +442,6 @@ namespace std { * Default char * and C array typemaps * ----------------------------------------------------------------------------- */ -%fragment("", "runtime") %{ -#include -%} - /* Set up the typemap for handling new return strings */ #ifdef __cplusplus diff --git a/Lib/swigfragments.swg b/Lib/swigfragments.swg index 63bb6c8f4..a2b467bce 100644 --- a/Lib/swigfragments.swg +++ b/Lib/swigfragments.swg @@ -29,6 +29,10 @@ #include %} +%fragment("", "header") %{ +#include +%} + %fragment("", "header") %{ #include %} From 3fe47b4b46562d96c45d8d2ea9a9dca7bd0d143e Mon Sep 17 00:00:00 2001 From: Hirokazu MORIKAWA Date: Sat, 1 May 2021 09:25:03 +0900 Subject: [PATCH 004/262] [javascript][v8] SWIG_V8_VERSION generation method corrected. "SWIG_V8_VERSION" generation method was incorrectly fixed. Signed-off-by: Hirokazu MORIKAWA --- Lib/javascript/v8/javascriptruntime.swg | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/javascript/v8/javascriptruntime.swg b/Lib/javascript/v8/javascriptruntime.swg index 115554a5a..59909389e 100644 --- a/Lib/javascript/v8/javascriptruntime.swg +++ b/Lib/javascript/v8/javascriptruntime.swg @@ -58,7 +58,10 @@ #if defined(V8_MAJOR_VERSION) && defined(V8_MINOR_VERSION) #undef SWIG_V8_VERSION -#define SWIG_V8_VERSION (V8_MAJOR_VERSION * 256 + V8_MINOR_VERSION) +#define SWIG_V8_VERSION ((V8_MAJOR_VERSION / 10) * 4096 + \ + (V8_MAJOR_VERSION % 10) * 256 + \ + (V8_MINOR_VERSION / 10) * 16 + \ + (V8_MINOR_VERSION % 10)) #endif #include From a2fc5ecaff561b4e3c6c8edc84d46a20eebae731 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 6 Jul 2021 10:56:48 +1200 Subject: [PATCH 005/262] Fix "dobule" typos in docs Fixes #2043. --- Doc/Manual/SWIGPlus.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/Manual/SWIGPlus.html b/Doc/Manual/SWIGPlus.html index 0c259e393..2244a0508 100644 --- a/Doc/Manual/SWIGPlus.html +++ b/Doc/Manual/SWIGPlus.html @@ -3632,7 +3632,7 @@ Alternatively, you could expand the constructor template in selected instantiati // Create default and conversion constructors %extend pair<double, double> { - %template(paird) pair<double, dobule>; // Default constructor + %template(paird) pair<double, double>; // Default constructor %template(pairc) pair<int, int>; // Conversion constructor }; @@ -3647,7 +3647,7 @@ instead:
 // Create default and conversion constructors 
 %extend pair<double, double> {
-  %template(pair) pair<double, dobule>;   // Default constructor
+  %template(pair) pair<double, double>;   // Default constructor
   %template(pair) pair<int, int>;         // Conversion constructor
 };
 
From 901f399f8c60bf1a05e14c3b1a9de5c0e601d4dc Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Sun, 1 Aug 2021 16:49:08 +0100 Subject: [PATCH 006/262] [CI] generalise travis-linux-install.sh - move content to CI-linux-install.sh which is independent of Travis - create equivalent for Github Actions (GHA) --- Tools/CI-linux-install.sh | 120 +++++++++++++++++++++++++++++++++ Tools/GHA-linux-install.sh | 9 +++ Tools/travis-linux-install.sh | 123 ++-------------------------------- 3 files changed, 134 insertions(+), 118 deletions(-) create mode 100644 Tools/CI-linux-install.sh create mode 100644 Tools/GHA-linux-install.sh diff --git a/Tools/CI-linux-install.sh b/Tools/CI-linux-install.sh new file mode 100644 index 000000000..9f3f93804 --- /dev/null +++ b/Tools/CI-linux-install.sh @@ -0,0 +1,120 @@ +#!/bin/bash +# expected to be called from elsewhere with certain variables set +# e.g. RETRY=travis-retry SWIGLANG=python GCC=7 +set -e # exit on failure (same as -o errexit) + +if [[ -n "$GCC" ]]; then + $RETRY sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test + $RETRY sudo apt-get -qq update + $RETRY sudo apt-get install -qq g++-$GCC +fi + +$RETRY sudo apt-get -qq install libboost-dev libpcre3-dev + +WITHLANG=$SWIGLANG + +case "$SWIGLANG" in + "") ;; + "csharp") + $RETRY sudo apt-get -qq install mono-devel + ;; + "d") + $RETRY wget http://downloads.dlang.org/releases/2.x/${VER}/dmd_${VER}-0_amd64.deb + $RETRY sudo dpkg -i dmd_${VER}-0_amd64.deb + ;; + "go") + if [[ "$VER" ]]; then + eval "$(gimme ${VER}.x)" + fi + ;; + "javascript") + case "$ENGINE" in + "node") + $RETRY wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.10/install.sh | bash + export NVM_DIR="$HOME/.nvm" + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + $RETRY nvm install ${VER} + nvm use ${VER} + if [ "$VER" == "0.10" ] || [ "$VER" == "0.12" ] || [ "$VER" == "4" ] || [ "$VER" == "6" ] ; then +# $RETRY sudo apt-get install -qq nodejs node-gyp + $RETRY npm install -g node-gyp@$VER + elif [ "$VER" == "8" ] ; then + $RETRY npm install -g node-gyp@6 + elif [ "$VER" == "10" ] || [ "$VER" == "12" ] || [ "$VER" == "14" ] || [ "$VER" == "16" ]; then + $RETRY npm install -g node-gyp@7 + else + $RETRY npm install -g node-gyp + fi + ;; + "jsc") + $RETRY sudo apt-get install -qq libwebkitgtk-dev + ;; + "v8") + $RETRY sudo apt-get install -qq libv8-dev + ;; + esac + ;; + "guile") + $RETRY sudo apt-get -qq install guile-2.0-dev + ;; + "lua") + if [[ -z "$VER" ]]; then + $RETRY sudo apt-get -qq install lua5.2 liblua5.2-dev + else + $RETRY sudo apt-get -qq install lua${VER} liblua${VER}-dev + fi + ;; + "mzscheme") + $RETRY sudo apt-get -qq install racket + ;; + "ocaml") + $RETRY sudo apt-get -qq install ocaml camlp4 + ;; + "octave") + $RETRY sudo apt-get -qq install liboctave-dev + ;; + "php") + $RETRY sudo add-apt-repository -y ppa:ondrej/php + $RETRY sudo apt-get -qq update + $RETRY sudo apt-get -qq install php$VER-cli php$VER-dev + ;; + "python") + pip install --user pycodestyle + if [[ "$PY3" ]]; then + $RETRY sudo apt-get install -qq python3-dev + fi + WITHLANG=$SWIGLANG$PY3 + if [[ "$VER" ]]; then + $RETRY sudo add-apt-repository -y ppa:deadsnakes/ppa + $RETRY sudo apt-get -qq update + $RETRY sudo apt-get -qq install python${VER}-dev + WITHLANG=$SWIGLANG$PY3=$SWIGLANG$VER + fi + ;; + "r") + $RETRY sudo apt-get -qq install r-base + ;; + "ruby") + if [[ "$VER" == "2.7" || "$VER" == "3.0" ]]; then + # Ruby 2.7+ support is currently only rvm master (30 Dec 2019) + $RETRY rvm get master + rvm reload + rvm list known + fi + if [[ "$VER" ]]; then + $RETRY rvm install $VER + fi + ;; + "scilab") + # Travis has the wrong version of Java pre-installed resulting in error using scilab: + # /usr/bin/scilab-bin: error while loading shared libraries: libjava.so: cannot open shared object file: No such file or directory + echo "JAVA_HOME was set to $JAVA_HOME" + unset JAVA_HOME + $RETRY sudo apt-get -qq install scilab + ;; + "tcl") + $RETRY sudo apt-get -qq install tcl-dev + ;; +esac + +set +e # turn off exit on failure (same as +o errexit) diff --git a/Tools/GHA-linux-install.sh b/Tools/GHA-linux-install.sh new file mode 100644 index 000000000..ea2108fce --- /dev/null +++ b/Tools/GHA-linux-install.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +#lsb_release -a +# find location of current script (only works in bash) +script_dir="$( dirname "${BASH_SOURCE[0]}")" + +# run generic script +RETRY= +source "$script_dir"/CI-linux-install.sh diff --git a/Tools/travis-linux-install.sh b/Tools/travis-linux-install.sh index cb7d9d298..cda834112 100755 --- a/Tools/travis-linux-install.sh +++ b/Tools/travis-linux-install.sh @@ -2,123 +2,10 @@ # Install Linux packages where the version has been overidden in .travis.yml -set -e # exit on failure (same as -o errexit) - lsb_release -a -travis_retry sudo apt-get -qq update +# find location of current script (only works in bash) +script_dir="$( dirname "${BASH_SOURCE[0]}")" -if [[ -n "$GCC" ]]; then - travis_retry sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test - travis_retry sudo apt-get -qq update - travis_retry sudo apt-get install -qq g++-$GCC -fi - -travis_retry sudo apt-get -qq install libboost-dev libpcre3-dev - -WITHLANG=$SWIGLANG - -case "$SWIGLANG" in - "") ;; - "csharp") - travis_retry sudo apt-get -qq install mono-devel - ;; - "d") - travis_retry wget http://downloads.dlang.org/releases/2.x/${VER}/dmd_${VER}-0_amd64.deb - travis_retry sudo dpkg -i dmd_${VER}-0_amd64.deb - ;; - "go") - if [[ "$VER" ]]; then - eval "$(gimme ${VER}.x)" - fi - ;; - "javascript") - case "$ENGINE" in - "node") - travis_retry wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.10/install.sh | bash - export NVM_DIR="$HOME/.nvm" - [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" - travis_retry nvm install ${VER} - nvm use ${VER} - if [ "$VER" == "0.10" ] || [ "$VER" == "0.12" ] || [ "$VER" == "4" ] || [ "$VER" == "6" ] ; then -# travis_retry sudo apt-get install -qq nodejs node-gyp - travis_retry npm install -g node-gyp@$VER - elif [ "$VER" == "8" ] ; then - travis_retry npm install -g node-gyp@6 - elif [ "$VER" == "10" ] || [ "$VER" == "12" ] || [ "$VER" == "14" ] || [ "$VER" == "16" ]; then - travis_retry npm install -g node-gyp@7 - else - travis_retry npm install -g node-gyp - fi - ;; - "jsc") - travis_retry sudo apt-get install -qq libwebkitgtk-dev - ;; - "v8") - travis_retry sudo apt-get install -qq libv8-dev - ;; - esac - ;; - "guile") - travis_retry sudo apt-get -qq install guile-2.0-dev - ;; - "lua") - if [[ -z "$VER" ]]; then - travis_retry sudo apt-get -qq install lua5.2 liblua5.2-dev - else - travis_retry sudo apt-get -qq install lua${VER} liblua${VER}-dev - fi - ;; - "mzscheme") - travis_retry sudo apt-get -qq install racket - ;; - "ocaml") - travis_retry sudo apt-get -qq install ocaml camlp4 - ;; - "octave") - travis_retry sudo apt-get -qq install liboctave-dev - ;; - "php") - travis_retry sudo add-apt-repository -y ppa:ondrej/php - travis_retry sudo apt-get -qq update - travis_retry sudo apt-get -qq install php$VER-cli php$VER-dev - ;; - "python") - pip install --user pycodestyle - if [[ "$PY3" ]]; then - travis_retry sudo apt-get install -qq python3-dev - fi - WITHLANG=$SWIGLANG$PY3 - if [[ "$VER" ]]; then - travis_retry sudo add-apt-repository -y ppa:deadsnakes/ppa - travis_retry sudo apt-get -qq update - travis_retry sudo apt-get -qq install python${VER}-dev - WITHLANG=$SWIGLANG$PY3=$SWIGLANG$VER - fi - ;; - "r") - travis_retry sudo apt-get -qq install r-base - ;; - "ruby") - if [[ "$VER" == "2.7" || "$VER" == "3.0" ]]; then - # Ruby 2.7+ support is currently only rvm master (30 Dec 2019) - travis_retry rvm get master - rvm reload - rvm list known - fi - if [[ "$VER" ]]; then - travis_retry rvm install $VER - fi - ;; - "scilab") - # Travis has the wrong version of Java pre-installed resulting in error using scilab: - # /usr/bin/scilab-bin: error while loading shared libraries: libjava.so: cannot open shared object file: No such file or directory - echo "JAVA_HOME was set to $JAVA_HOME" - unset JAVA_HOME - travis_retry sudo apt-get -qq install scilab - ;; - "tcl") - travis_retry sudo apt-get -qq install tcl-dev - ;; -esac - -set +e # turn off exit on failure (same as +o errexit) +# run generic script +RETRY=travis-retry +source "$script_dir"/CI-linux-install.sh From 333e2daa132d71e6533c37ed4031f9081abab17b Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Mon, 2 Aug 2021 09:42:54 +0100 Subject: [PATCH 007/262] [CI] change python install --- Tools/CI-linux-install.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Tools/CI-linux-install.sh b/Tools/CI-linux-install.sh index 9f3f93804..0ce8f1203 100644 --- a/Tools/CI-linux-install.sh +++ b/Tools/CI-linux-install.sh @@ -10,6 +10,8 @@ if [[ -n "$GCC" ]]; then fi $RETRY sudo apt-get -qq install libboost-dev libpcre3-dev +# testflags.py needs python +$RETRY sudo apt-get install -qq python WITHLANG=$SWIGLANG @@ -80,15 +82,14 @@ case "$SWIGLANG" in ;; "python") pip install --user pycodestyle - if [[ "$PY3" ]]; then - $RETRY sudo apt-get install -qq python3-dev - fi - WITHLANG=$SWIGLANG$PY3 if [[ "$VER" ]]; then $RETRY sudo add-apt-repository -y ppa:deadsnakes/ppa $RETRY sudo apt-get -qq update $RETRY sudo apt-get -qq install python${VER}-dev WITHLANG=$SWIGLANG$PY3=$SWIGLANG$VER + else + $RETRY sudo apt-get install -qq python${PY3}-dev + WITHLANG=$SWIGLANG$PY3 fi ;; "r") From b734d67dd39e13ee0bd972718e5485dd958ed3dd Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Mon, 2 Aug 2021 07:53:53 +0100 Subject: [PATCH 008/262] [GHA] first GitHub actions workflow --- .github/workflows/test.yml | 95 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..ffa3736f5 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,95 @@ +name: test SWIG CI + +on: + push: + #branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ${{ matrix.os }} + strategy: + matrix: + # the agent machine operating systems + os: [ubuntu-latest] + SWIGJOBS: ["-j2"] + CSTD: [""] + CC: ["gcc"] + CPP11: ["1"] + CPP14: [""] + CPP17: [""] + CONFIGOPTS: [""] + SWIGLANG: ["", "python"] + VER: [""] + SWIG_FEATURES: [""] + # let's run all of them, as opposed to aborting when one fails + fail-fast: false + + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + - name: ccache + uses: hendrikmuhs/ccache-action@v1 + with: + key: ${{ matrix.os }}-${{ matrix.SWIGLANG }} + - name: configure + shell: bash + env: + SWIGLANG: ${{ matrix.SWIGLANG }} + CONFIGOPTS: ${{ matrix.CONFIGOPTS }} + CC: ${{ matrix.CC }} + run: | + set -ex + export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" + source Tools/GHA-linux-install.sh + if test -n "$CPP11"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++11 $CXXFLAGS" "CFLAGS=-std=c11 $CFLAGS") && export CSTD=c11 && export CPPSTD=c++11; fi + if test -n "$CPP14"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++14 $CXXFLAGS" "CFLAGS=-std=c11 $CFLAGS") && export CSTD=c11 && export CPPSTD=c++14; fi + if test -n "$CPP17"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++17 $CXXFLAGS" "CFLAGS=-std=c17 $CFLAGS") && export CSTD=c17 && export CPPSTD=c++17; fi + if test -n "$SWIGLANG"; then CONFIGOPTS+=(--without-alllang --with-$WITHLANG); fi + echo "${CONFIGOPTS[@]}" + ./autogen.sh && mkdir -p build/build && cd build/build && ../../configure "${CONFIGOPTS[@]}" + + - name: build + shell: bash + env: + SWIGLANG: ${{ matrix.SWIGLANG }} + SWIGJOBS: ${{ matrix.SWIGJOBS }} + run: | + set -ex + cd ${GITHUB_WORKSPACE}/build/build; + make -s $SWIGJOBS + ./swig -version && ./swig -pcreversion + if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-ccache; fi + if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-errors-test-suite; fi + echo 'Installing...' + if test -z "$SWIGLANG"; then sudo make -s install && swig -version && ccache-swig -V; fi + - name: tests + shell: bash + env: + SWIGLANG: ${{ matrix.SWIGLANG }} + SWIGJOBS: ${{ matrix.SWIGJOBS }} + SWIG_FEATURES: ${{ matrix.SWIG_FEATURES }} + CC: ${{ matrix.CC }} + CSTD: ${{ matrix.CSTD }} + CPP11: ${{ matrix.CPP11 }} + CPP14: ${{ matrix.CPP14 }} + CPP17: ${{ matrix.CPP17 }} + run: | + set -ex + cd ${GITHUB_WORKSPACE}/build/build; + if test -n "$CPP11"; then export CPPSTD=c++11; fi + if test -n "$CPP14"; then export CPPSTD=c++14; fi + if test -n "$CPP17"; then export CPPSTD=c++17; fi + # Stricter compile flags for examples. Various headers and SWIG generated code prevents full use of -pedantic. + if test -n "$SWIGLANG"; then cflags=$($GITHUB_WORKSPACE/Tools/testflags.py --language $SWIGLANG --cflags --std=$CSTD --compiler=$CC) && echo $cflags; fi + if test -n "$SWIGLANG"; then cxxflags=$($GITHUB_WORKSPACE/Tools/testflags.py --language $SWIGLANG --cxxflags --std=$CPPSTD --compiler=$CC) && echo $cxxflags; fi + if test -n "$SWIGLANG"; then make -s check-$SWIGLANG-version; fi + if test -n "$SWIGLANG"; then make check-$SWIGLANG-enabled; fi + if test -n "$SWIGLANG"; then make $SWIGJOBS check-$SWIGLANG-examples CFLAGS="$cflags" CXXFLAGS="$cxxflags"; fi + if test -n "$SWIGLANG"; then make $SWIGJOBS check-$SWIGLANG-test-suite CFLAGS="$cflags" CXXFLAGS="$cxxflags"; fi + #echo 'Cleaning...' + # Skip on osx as often fails with: rm: Resource temporarily unavailable + #if test "$TRAVIS_OS_NAME" != "osx"; then make check-maintainer-clean && ../../configure $CONFIGOPTS; fi From fb09a5578a3b30abcdfd388610d9dedb614eb969 Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Mon, 2 Aug 2021 10:01:27 +0100 Subject: [PATCH 009/262] [GHA] convert matrix to use include --- .github/workflows/test.yml | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ffa3736f5..0e645cafd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,18 +12,28 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - # the agent machine operating systems - os: [ubuntu-latest] - SWIGJOBS: ["-j2"] - CSTD: [""] - CC: ["gcc"] - CPP11: ["1"] - CPP14: [""] - CPP17: [""] - CONFIGOPTS: [""] - SWIGLANG: ["", "python"] - VER: [""] - SWIG_FEATURES: [""] + #SWIGJOBS: ["-j2"] + # other variables to optionally set + # CC, GCC (used as suffix) + # CPP11, CPP14, CPP17 + # CONFIGOPTS + # SWIGLANG + # PY3,VER + # SWIG_FEATURES + include: + - os: ubuntu-latest + CPP11: 1 + SWIGLANG: "" + - os: ubuntu-latest + CPP11: 1 + SWIGLANG: python + - os: ubuntu-latest + CPP11: 1 + SWIGLANG: python + PY3: 3 + - os: ubuntu-latest + CPP11: 1 + SWIGLANG: tcl # let's run all of them, as opposed to aborting when one fails fail-fast: false From 0e45679aa745e046bcced66bb53495fa573f97b0 Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Mon, 2 Aug 2021 12:02:53 +0100 Subject: [PATCH 010/262] [GHA] only run on master and PRs --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0e645cafd..c6537bb06 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,8 +1,8 @@ -name: test SWIG CI +name: test SWIG via CI on: push: - #branches: [ master ] + branches: [ master ] pull_request: branches: [ master ] From 9d50ec97d0467093db0dd613f7520134c21729f4 Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Mon, 2 Aug 2021 12:12:40 +0100 Subject: [PATCH 011/262] [GHA] enable GHA branch for the moment [appveyor skip] [travis skip] --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c6537bb06..6e23c9242 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,7 +2,8 @@ name: test SWIG via CI on: push: - branches: [ master ] + # enable on master and GHA branches. The latter should be removed once merged to SWIG/master. + branches: [ master, GHA ] pull_request: branches: [ master ] From a2850397ba3eec5d4c58304cf8277ca535919760 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Thu, 5 Aug 2021 14:05:10 +0200 Subject: [PATCH 012/262] [Python] Fix overload_simple_cast test with 3.10 Closes #2044 --- Examples/test-suite/python/python_overload_simple_cast_runme.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Examples/test-suite/python/python_overload_simple_cast_runme.py b/Examples/test-suite/python/python_overload_simple_cast_runme.py index fc398ab29..7a0174af8 100644 --- a/Examples/test-suite/python/python_overload_simple_cast_runme.py +++ b/Examples/test-suite/python/python_overload_simple_cast_runme.py @@ -9,6 +9,8 @@ class Ai: def __int__(self): return self.x + def __index__(self): + return self.x class Ad: From 4e599ddbdba9b97c03605ef887717c86467cf2a3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 9 Aug 2021 13:17:08 +0200 Subject: [PATCH 013/262] Remove "GHA" branch from the workflow file Follow an existing comment saying that it should be removed before merging. --- .github/workflows/test.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6e23c9242..7c945c71d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,10 +2,9 @@ name: test SWIG via CI on: push: - # enable on master and GHA branches. The latter should be removed once merged to SWIG/master. - branches: [ master, GHA ] + branches: master pull_request: - branches: [ master ] + branches: master jobs: build: From d022a1507abfce0458fbfc972a01323cb7d94ea5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 9 Aug 2021 13:20:40 +0200 Subject: [PATCH 014/262] Rename workflow file to just ci.yml It doesn't seem appropriate to use test.yml for it. --- .github/workflows/{test.yml => ci.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{test.yml => ci.yml} (99%) diff --git a/.github/workflows/test.yml b/.github/workflows/ci.yml similarity index 99% rename from .github/workflows/test.yml rename to .github/workflows/ci.yml index 7c945c71d..c6e6519b7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: test SWIG via CI +name: CI on: push: From 4461c443cf86493851b25c5052dc01800371cef6 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 14 Sep 2021 13:59:21 -0700 Subject: [PATCH 015/262] remove Go -no-cgo option It only worked for Go versions before 1.5, which is more than five years ago and long-unsupported. --- Doc/Manual/Go.html | 65 +- Lib/go/goruntime.swg | 146 ---- Source/Modules/go.cxx | 1717 ++++------------------------------------- 3 files changed, 167 insertions(+), 1761 deletions(-) diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html index 1a5bb08c7..4e230c78b 100644 --- a/Doc/Manual/Go.html +++ b/Doc/Manual/Go.html @@ -71,6 +71,7 @@ code. SWIG fills this gap. There are (at least) two different Go compilers. The first is the gc compiler of the Go distribution, normally invoked via the go tool. +SWIG supports the gc compiler version 1.2 or later. The second Go compiler is the gccgo compiler, which is a frontend to the GCC compiler suite. The interface to C/C++ code is completely different for the two Go compilers. @@ -142,44 +143,6 @@ You will now have a Go package that you can import from other Go packages as usual.

-

-SWIG can be used without cgo, via the -no-cgo option, but -more steps are required. This only works with Go versions before 1.5. -When using Go version 1.2 or later, or when using gccgo, the code -generated by SWIG can be linked directly into the Go program. A -typical command sequence when using the Go compiler of the Go -distribution would look like this: -

- -
-% swig -go -no-cgo example.i
-% gcc -c code.c    # The C library being wrapped.
-% gcc -c example_wrap.c
-% go tool 6g example.go
-% go tool 6c example_gc.c
-% go tool pack grc example.a example.6 example_gc.6 code.o example_wrap.o
-% go tool 6g main.go
-% go tool 6l main.6
-
- -

-You can also put the wrapped code into a shared library, and when using the Go -versions before 1.2 this is the only supported option. A typical command -sequence for this approach would look like this: -

- -
-% swig -go -no-cgo -use-shlib example.i
-% gcc -c -fpic example.c
-% gcc -c -fpic example_wrap.c
-% gcc -shared example.o example_wrap.o -o example.so
-% go tool 6g example.go
-% go tool 6c example_gc.c
-% go tool pack grc example.a example.6 example_gc.6
-% go tool 6g main.go  # your code, not generated by SWIG
-% go tool 6l main.6
-
-

25.3.1 Go-specific Commandline Options

@@ -206,9 +169,7 @@ swig -go -help -no-cgo -Generate files that can be used directly, rather than via the Go - cgo tool. This option does not work with Go 1.5 or later. It is - required for versions of Go before 1.2. +This option is no longer supported. @@ -279,13 +240,10 @@ swig -go -help

25.3.2 Generated Wrapper Files

-

There are two different approaches to generating wrapper files, - controlled by SWIG's -no-cgo option. The -no-cgo - option only works with version of Go before 1.5. It is required - when using versions of Go before 1.2.

- -

With or without the -no-cgo option, SWIG will generate the - following files when generating wrapper code:

+

+SWIG will generate the following files when generating wrapper +code: +

  • @@ -308,17 +266,6 @@ or C++ compiler.
-

When the -no-cgo option is used, and the -gccgo - option is not used, SWIG will also generate an additional file:

- -
    -
  • -MODULE_gc.c will contain C code which should be compiled with the C -compiler distributed as part of the gc compiler. It should then be -combined with the compiled MODULE.go using go tool pack. -
  • -
-

25.4 A tour of basic C/C++ wrapping

diff --git a/Lib/go/goruntime.swg b/Lib/go/goruntime.swg index 269a4eefd..667cc35ca 100644 --- a/Lib/go/goruntime.swg +++ b/Lib/go/goruntime.swg @@ -23,46 +23,38 @@ static void* Swig_malloc(int c) { %} -#if SWIGGO_CGO %insert(cgo_comment_typedefs) %{ #include %} -#endif #if SWIGGO_INTGO_SIZE == 32 %insert(runtime) %{ typedef int intgo; typedef unsigned int uintgo; %} -#if SWIGGO_CGO %insert(cgo_comment_typedefs) %{ typedef int intgo; typedef unsigned int uintgo; %} -#endif #elif SWIGGO_INTGO_SIZE == 64 %insert(runtime) %{ typedef long long intgo; typedef unsigned long long uintgo; %} -#if SWIGGO_CGO %insert(cgo_comment_typedefs) %{ typedef long long intgo; typedef unsigned long long uintgo; %} -#endif #else %insert(runtime) %{ typedef ptrdiff_t intgo; typedef size_t uintgo; %} -#if SWIGGO_CGO %insert(cgo_comment_typedefs) %{ typedef ptrdiff_t intgo; typedef size_t uintgo; %} #endif -#endif #ifndef SWIGGO_GCCGO // Set the host compiler struct attribute that will be @@ -89,8 +81,6 @@ typedef struct { void* array; intgo len; intgo cap; } _goslice_; %} -#ifdef SWIGGO_CGO - %insert(cgo_comment_typedefs) %{ typedef struct { char *p; intgo n; } _gostring_; @@ -98,8 +88,6 @@ typedef struct { void* array; intgo len; intgo cap; } _goslice_; %} -#endif - #ifndef SWIGGO_GCCGO /* Boilerplate for C/C++ code when using 6g/8g. This code is compiled with gcc. */ @@ -145,43 +133,6 @@ static void _swig_gopanic(const char *p) { %} -#if !SWIGGO_CGO - -/* This is here for backward compatibility, but it will not work - with Go 1.5 or later. Do not use it in new code. */ -%insert(runtime) %{ - -static void *_swig_goallocate(size_t len) { - struct { - size_t len; - void *ret; - } SWIGSTRUCTPACKED a; - a.len = len; - crosscall2(_cgo_allocate, &a, (int) sizeof a); - return a.ret; -} - -%} - -#endif - -#if !SWIGGO_CGO - -/* Boilerplate for C code when using 6g/8g. This code is compiled - with 6c/8c. */ -%insert(gc_header) %{ -#include "runtime.h" -#include "cgocall.h" - -#pragma dataflag 16 -static void *cgocall = runtime·cgocall; -#pragma dataflag 16 -void *·_cgo_runtime_cgocall = &cgocall; - -%} - -#endif - #else /* Boilerplate for C/C++ code when using gccgo. */ @@ -201,97 +152,6 @@ extern void _cgo_panic(const char *); #define _swig_gopanic _cgo_panic %} -#if !SWIGGO_CGO - -%insert(runtime) %{ - -/* Implementations of SwigCgocall and friends for different versions - of gccgo. The Go code will call these functions using C names with - a prefix of the module name. The implementations here call the - routine in libgo. The routines to call vary depending on the gccgo - version. We assume that the version of gcc used to compile this - file is the same as the version of gccgo. */ - -#ifdef __cplusplus -extern "C" { -#endif - -#define SWIG_GCC_VERSION \ - (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) - -#if SWIG_GCC_VERSION < 40700 -#define SwigDoCgocall() -#define SwigDoCgocallDone() -#define SwigDoCgocallBack() -#define SwigDoCgocallBackDone() -#elif SWIG_GCC_VERSION == 40700 -void SwigDoCgocall(void) __asm__("libgo_syscall.syscall.Entersyscall"); -void SwigDoCgocallDone(void) __asm__("libgo_syscall.syscall.Exitsyscall"); -void SwigDoCgocallBack(void) __asm__("libgo_syscall.syscall.Exitsyscall"); -void SwigDoCgocallBackDone(void) __asm__("libgo_syscall.syscall.Entersyscall"); -#else -void SwigDoCgocall(void) __asm__("syscall.Cgocall"); -void SwigDoCgocallDone(void) __asm__("syscall.CgocallDone"); -void SwigDoCgocallBack(void) __asm__("syscall.CgocallBack"); -void SwigDoCgocallBackDone(void) __asm__("syscall.CgocallBackDone"); -#endif - -#define SWIGSTRINGIFY2(s) #s -#define SWIGSTRINGIFY(s) SWIGSTRINGIFY2(s) - -void SwigCgocall() - __asm__(SWIGSTRINGIFY(SWIGGO_PREFIX) ".SwigCgocall"); -void SwigCgocall() { - SwigDoCgocall(); -} - -void SwigCgocallDone() - __asm__(SWIGSTRINGIFY(SWIGGO_PREFIX) ".SwigCgocallDone"); -void SwigCgocallDone() { - SwigDoCgocallDone(); -} - -void SwigCgocallBack() - __asm__(SWIGSTRINGIFY(SWIGGO_PREFIX) ".SwigCgocallBack"); -void SwigCgocallBack() { - SwigDoCgocallBack(); -} - -void SwigCgocallBackDone() - __asm__(SWIGSTRINGIFY(SWIGGO_PREFIX) ".SwigCgocallBackDone"); -void SwigCgocallBackDone() { - SwigDoCgocallBackDone(); -} - -#undef SWIGSTRINGIFY -#undef SWIGSTRINGIFY2 - -#ifdef __cplusplus -} -#endif - -%} - -#endif - -#endif - -#if !SWIGGO_CGO - -%insert(runtime) %{ - -/* This is here for backward compatibility, but it will not work - with Go 1.5 or later. Do not use it in new code. */ -static _gostring_ _swig_makegostring(const char *p, size_t l) { - _gostring_ ret; - ret.p = (char*)_swig_goallocate(l + 1); - memcpy(ret.p, p, l); - ret.n = l; - return ret; -} - -%} - #endif %insert(runtime) %{ @@ -304,12 +164,6 @@ static _gostring_ _swig_makegostring(const char *p, size_t l) { %go_import("unsafe", _ "runtime/cgo") -#if !SWIGGO_CGO -%insert(go_header) %{ -var _cgo_runtime_cgocall func(unsafe.Pointer, uintptr) -%} -#endif - #else %go_import("syscall", "unsafe") diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index f9092134a..2b5261f14 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -115,8 +115,6 @@ class GO:public Language { String *package; // SWIG module name. String *module; - // Flag for generating cgo input files. - bool cgo_flag; // Flag for generating gccgo output. bool gccgo_flag; // Prefix to use with gccgo. @@ -137,7 +135,6 @@ class GO:public Language { /* Output files */ File *f_c_begin; File *f_go_begin; - File *f_gc_begin; /* Output fragments */ File *f_c_runtime; @@ -151,9 +148,6 @@ class GO:public Language { File *f_go_header; File *f_go_wrappers; File *f_go_directors; - File *f_gc_runtime; - File *f_gc_header; - File *f_gc_wrappers; File *f_cgo_comment; File *f_cgo_comment_typedefs; @@ -201,7 +195,6 @@ class GO:public Language { public: GO():package(NULL), module(NULL), - cgo_flag(true), gccgo_flag(false), go_prefix(NULL), prefix_option(NULL), @@ -212,7 +205,6 @@ public: intgo_type_size(0), f_c_begin(NULL), f_go_begin(NULL), - f_gc_begin(NULL), f_c_runtime(NULL), f_c_header(NULL), f_c_wrappers(NULL), @@ -224,9 +216,6 @@ public: f_go_header(NULL), f_go_wrappers(NULL), f_go_directors(NULL), - f_gc_runtime(NULL), - f_gc_header(NULL), - f_gc_wrappers(NULL), f_cgo_comment(NULL), f_cgo_comment_typedefs(NULL), saw_import(false), @@ -256,6 +245,7 @@ private: SWIG_library_directory("go"); bool display_help = false; + bool saw_nocgo_flag = false; // Process command line options. for (int i = 1; i < argc; i++) { @@ -271,10 +261,9 @@ private: } } else if (strcmp(argv[i], "-cgo") == 0) { Swig_mark_arg(i); - cgo_flag = true; } else if (strcmp(argv[i], "-no-cgo") == 0) { Swig_mark_arg(i); - cgo_flag = false; + saw_nocgo_flag = true; } else if (strcmp(argv[i], "-gccgo") == 0) { Swig_mark_arg(i); gccgo_flag = true; @@ -346,6 +335,11 @@ private: } } + if (saw_nocgo_flag) { + Printf(stderr, "SWIG -go: -no-cgo option is no longer supported\n"); + SWIG_exit(EXIT_FAILURE); + } + if (gccgo_flag && !pkgpath_option && !prefix_option) { prefix_option = NewString("go"); } @@ -353,10 +347,6 @@ private: // Add preprocessor symbol to parser. Preprocessor_define("SWIGGO 1", 0); - if (cgo_flag) { - Preprocessor_define("SWIGGO_CGO 1", 0); - } - if (gccgo_flag) { Preprocessor_define("SWIGGO_GCCGO 1", 0); } @@ -458,12 +448,6 @@ private: String *go_filename = NewString(""); Printf(go_filename, "%s%s.go", SWIG_output_directory(), module); - String *gc_filename = NULL; - if (!gccgo_flag) { - gc_filename = NewString(""); - Printf(gc_filename, "%s%s_gc.c", SWIG_output_directory(), module); - } - // Generate a unique ID based on a hash of the SWIG input. swig_uint64 hash = {0, 0}; FILE *swig_input = Swig_open(swig_filename); @@ -504,14 +488,6 @@ private: SWIG_exit(EXIT_FAILURE); } - if (!gccgo_flag && !cgo_flag) { - f_gc_begin = NewFile(gc_filename, "w", SWIG_output_files()); - if (!f_gc_begin) { - FileErrorDisplay(gc_filename); - SWIG_exit(EXIT_FAILURE); - } - } - f_c_runtime = NewString(""); f_c_header = NewString(""); f_c_wrappers = NewString(""); @@ -522,15 +498,8 @@ private: f_go_header = NewString(""); f_go_wrappers = NewString(""); f_go_directors = NewString(""); - if (!gccgo_flag && !cgo_flag) { - f_gc_runtime = NewString(""); - f_gc_header = NewString(""); - f_gc_wrappers = NewString(""); - } - if (cgo_flag) { - f_cgo_comment = NewString(""); - f_cgo_comment_typedefs = NewString(""); - } + f_cgo_comment = NewString(""); + f_cgo_comment_typedefs = NewString(""); Swig_register_filebyname("begin", f_c_begin); Swig_register_filebyname("runtime", f_c_runtime); @@ -545,16 +514,8 @@ private: Swig_register_filebyname("go_header", f_go_header); Swig_register_filebyname("go_wrapper", f_go_wrappers); Swig_register_filebyname("go_director", f_go_directors); - if (!gccgo_flag && !cgo_flag) { - Swig_register_filebyname("gc_begin", f_gc_begin); - Swig_register_filebyname("gc_runtime", f_gc_runtime); - Swig_register_filebyname("gc_header", f_gc_header); - Swig_register_filebyname("gc_wrapper", f_gc_wrappers); - } - if (cgo_flag) { - Swig_register_filebyname("cgo_comment", f_cgo_comment); - Swig_register_filebyname("cgo_comment_typedefs", f_cgo_comment_typedefs); - } + Swig_register_filebyname("cgo_comment", f_cgo_comment); + Swig_register_filebyname("cgo_comment_typedefs", f_cgo_comment_typedefs); Swig_banner(f_c_begin); if (CPlusPlus) { @@ -587,34 +548,18 @@ private: Swig_banner(f_go_begin); Printf(f_go_begin, "\n// source: %s\n", swig_filename); - if (!gccgo_flag && !cgo_flag && soname) { - Swig_banner(f_gc_begin); - Printf(f_gc_begin, "\n/* source: %s */\n\n", swig_filename); - Printf(f_gc_begin, "\n/* This file should be compiled with 6c/8c. */\n"); - Printf(f_gc_begin, "#pragma dynimport _ _ \"%s\"\n", soname); - } + Printv(f_cgo_comment_typedefs, "/*\n", NULL); - if (cgo_flag) { - Printv(f_cgo_comment_typedefs, "/*\n", NULL); - - // The cgo program defines the intgo type after our function - // definitions, but we want those definitions to be able to use - // intgo also. - Printv(f_cgo_comment_typedefs, "#define intgo swig_intgo\n", NULL); - Printv(f_cgo_comment_typedefs, "typedef void *swig_voidp;\n", NULL); - } + // The cgo program defines the intgo type after our function + // definitions, but we want those definitions to be able to use + // intgo also. + Printv(f_cgo_comment_typedefs, "#define intgo swig_intgo\n", NULL); + Printv(f_cgo_comment_typedefs, "typedef void *swig_voidp;\n", NULL); // Output module initialization code. Printf(f_go_begin, "\npackage %s\n\n", getModuleName(package)); - if (gccgo_flag && !cgo_flag) { - Printf(f_go_runtime, "func SwigCgocall()\n"); - Printf(f_go_runtime, "func SwigCgocallDone()\n"); - Printf(f_go_runtime, "func SwigCgocallBack()\n"); - Printf(f_go_runtime, "func SwigCgocallBackDone()\n\n"); - } - // All the C++ wrappers should be extern "C". Printv(f_c_wrappers, "#ifdef __cplusplus\n", "extern \"C\" {\n", "#endif\n\n", NULL); @@ -686,21 +631,17 @@ private: // End the extern "C". Printv(f_c_wrappers, "#ifdef __cplusplus\n", "}\n", "#endif\n\n", NULL); - if (cgo_flag) { - // End the cgo comment. - Printv(f_cgo_comment, "#undef intgo\n", NULL); - Printv(f_cgo_comment, "*/\n", NULL); - Printv(f_cgo_comment, "import \"C\"\n", NULL); - Printv(f_cgo_comment, "\n", NULL); - } + // End the cgo comment. + Printv(f_cgo_comment, "#undef intgo\n", NULL); + Printv(f_cgo_comment, "*/\n", NULL); + Printv(f_cgo_comment, "import \"C\"\n", NULL); + Printv(f_cgo_comment, "\n", NULL); Dump(f_c_runtime, f_c_begin); Dump(f_c_wrappers, f_c_begin); Dump(f_c_init, f_c_begin); - if (cgo_flag) { - Dump(f_cgo_comment_typedefs, f_go_begin); - Dump(f_cgo_comment, f_go_begin); - } + Dump(f_cgo_comment_typedefs, f_go_begin); + Dump(f_cgo_comment, f_go_begin); Dump(f_go_imports, f_go_begin); Dump(f_go_header, f_go_begin); Dump(f_go_runtime, f_go_begin); @@ -708,12 +649,6 @@ private: if (directorsEnabled()) { Dump(f_go_directors, f_go_begin); } - if (!gccgo_flag && !cgo_flag) { - Dump(f_gc_header, f_gc_begin); - Dump(f_gc_runtime, f_gc_begin); - Dump(f_gc_wrappers, f_gc_begin); - } - Delete(f_c_runtime); Delete(f_c_header); Delete(f_c_wrappers); @@ -723,21 +658,10 @@ private: Delete(f_go_header); Delete(f_go_wrappers); Delete(f_go_directors); - if (!gccgo_flag && !cgo_flag) { - Delete(f_gc_runtime); - Delete(f_gc_header); - Delete(f_gc_wrappers); - } - if (cgo_flag) { - Delete(f_cgo_comment); - Delete(f_cgo_comment_typedefs); - } - + Delete(f_cgo_comment); + Delete(f_cgo_comment_typedefs); Delete(f_c_begin); Delete(f_go_begin); - if (!gccgo_flag && !cgo_flag) { - Delete(f_gc_begin); - } return SWIG_OK; } @@ -952,7 +876,7 @@ private: ParmList *parms = Getattr(n, "parms"); Setattr(n, "wrap:parms", parms); - int r = makeWrappers(n, name, go_name, overname, wname, NULL, parms, result, is_static); + int r = makeWrappers(n, go_name, overname, wname, NULL, parms, result, is_static); if (r != SWIG_OK) { return r; } @@ -1010,7 +934,6 @@ private: * * Write out the various function wrappers. * n: The function we are emitting. - * name: The function name. * go_name: The name of the function in Go. * overname: The overload string for overloaded function. * wname: The SWIG wrapped name--the name of the C function. @@ -1021,38 +944,15 @@ private: * is_static: Whether this is a static method or member. * ---------------------------------------------------------------------- */ - int makeWrappers(Node *n, String *name, String *go_name, String *overname, String *wname, List *base, ParmList *parms, SwigType *result, bool is_static) { + int makeWrappers(Node *n, String *go_name, String *overname, String *wname, List *base, ParmList *parms, SwigType *result, bool is_static) { assert(result); int ret = SWIG_OK; - if (cgo_flag) { - int r = makeCgoWrappers(n, go_name, overname, wname, base, parms, result, is_static); - if (r != SWIG_OK) { - ret = r; - } - } else { - int r = goFunctionWrapper(n, name, go_name, overname, wname, base, parms, result, is_static); - if (r != SWIG_OK) { - ret = r; - } - - if (!gccgo_flag) { - r = gcFunctionWrapper(wname); - if (r != SWIG_OK) { - ret = r; - } - r = gccFunctionWrapper(n, base, wname, parms, result); - if (r != SWIG_OK) { - ret = r; - } - } else { - r = gccgoFunctionWrapper(n, base, wname, parms, result); - if (r != SWIG_OK) { - ret = r; - } - } + int r = makeCgoWrappers(n, go_name, overname, wname, base, parms, result, is_static); + if (r != SWIG_OK) { + ret = r; } if (class_methods) { @@ -1618,415 +1518,6 @@ private: return SWIG_OK; } - /* ---------------------------------------------------------------------- - * goFunctionWrapper() - * - * Write out a function wrapper in Go. When not implementing a - * method, the actual code is all in C; here we just declare the C - * function. When implementing a method, we have to call the C - * function, because it will have a different name. If base is not - * NULL, then we are being called to forward a virtual method to a - * base class. - * ---------------------------------------------------------------------- */ - - int goFunctionWrapper(Node *n, String *name, String *go_name, String *overname, String *wname, List *base, ParmList *parms, SwigType *result, bool is_static) { - Wrapper *dummy = initGoTypemaps(parms); - - int parm_count = emit_num_arguments(parms); - int required_count = emit_num_required(parms); - - String *receiver = class_receiver; - if (receiver && is_static) { - receiver = NULL; - } - - String *nodetype = Getattr(n, "nodeType"); - bool is_constructor = Cmp(nodetype, "constructor") == 0; - bool is_destructor = Cmp(nodetype, "destructor") == 0; - if (is_constructor || is_destructor) { - assert(class_receiver); - assert(!base); - receiver = NULL; - } - - Swig_save("cgoGoWrapper", n, "type", "tmap:goout", NULL); - Setattr(n, "type", result); - - String *goout = goTypemapLookup("goout", n, "swig_r"); - - Swig_restore(n); - - bool add_to_interface = (interfaces && !is_constructor && !is_destructor && !is_static && !overname && checkFunctionVisibility(n, NULL)); - - bool needs_wrapper = (gccgo_flag || receiver || is_constructor || is_destructor || parm_count > required_count); - - bool has_goout = false; - if (goout) { - has_goout = true; - } - - // See whether any of the function parameters are represented by - // interface values. When calling the C++ code, we need to convert - // back to a uintptr. - Parm *p = parms; - for (int i = 0; i < parm_count; ++i) { - p = getParm(p); - String *ty = Getattr(p, "type"); - if (goGetattr(p, "tmap:goargout")) { - has_goout = true; - needs_wrapper = true; - } else if (goTypeIsInterface(p, ty) || goGetattr(p, "tmap:goin")) { - needs_wrapper = true; - } - - if (paramNeedsEscape(p)) { - needs_wrapper = true; - } - - p = nextParm(p); - } - if (goTypeIsInterface(n, result) || goout != NULL) { - needs_wrapper = true; - } - - if (!gccgo_flag) { - Printv(f_go_wrappers, "var ", wname, " unsafe.Pointer\n\n", NULL); - } - - // If this is a method, first declare the C function we will call. - // If we do not need a wrapper, then we will only be writing a - // declaration. - String *wrapper_name = NULL; - if (needs_wrapper) { - wrapper_name = buildGoWrapperName(name, overname); - - if (gccgo_flag) { - Printv(f_go_wrappers, "//extern ", go_prefix, "_", wname, "\n", NULL); - } - - bool arg = false; - Printv(f_go_wrappers, "func ", wrapper_name, "(", NULL); - if (parm_count > required_count) { - Printv(f_go_wrappers, argName(&arg), " int", NULL); - } - Parm *p = getParm(parms); - int i = 0; - if (is_destructor) { - if (parm_count > required_count) { - Printv(f_go_wrappers, ", ", NULL); - } - Printv(f_go_wrappers, argName(&arg), " uintptr", NULL); - ++i; - p = nextParm(p); - } else if (receiver && (base || !is_constructor)) { - if (parm_count > required_count) { - Printv(f_go_wrappers, ", ", NULL); - } - Printv(f_go_wrappers, argName(&arg), " ", receiver, NULL); - if (!base) { - ++i; - p = nextParm(p); - } - } - for (; i < parm_count; ++i) { - p = getParm(p); - if (i > 0 || (base && receiver) || parm_count > required_count) { - Printv(f_go_wrappers, ", ", NULL); - } - String *tm = goWrapperType(p, Getattr(p, "type"), false); - Printv(f_go_wrappers, argName(&arg), " ", tm, NULL); - Delete(tm); - p = nextParm(p); - } - Printv(f_go_wrappers, ")", NULL); - if (is_constructor) { - Printv(f_go_wrappers, " (", argName(&arg), " ", class_receiver, ")", NULL); - } else { - if (SwigType_type(result) != T_VOID) { - String *tm = goWrapperType(n, result, true); - Printv(f_go_wrappers, " (", argName(&arg), " ", tm, ")", NULL); - Delete(tm); - } - } - - if (!gccgo_flag) { - Printv(f_go_wrappers, " {\n", NULL); - if (arg) { - Printv(f_go_wrappers, "\t_swig_p := uintptr(unsafe.Pointer(&base))\n", NULL); - } else { - Printv(f_go_wrappers, "\tvar _swig_p uintptr\n", NULL); - } - Printv(f_go_wrappers, "\t_cgo_runtime_cgocall(", wname, ", _swig_p)\n", NULL); - Printv(f_go_wrappers, "\treturn\n", NULL); - Printv(f_go_wrappers, "}", NULL); - } - - Printv(f_go_wrappers, "\n\n", NULL); - } - - // Start defining the Go function. - - if (!needs_wrapper && gccgo_flag) { - Printv(f_go_wrappers, "//extern ", go_prefix, "_", wname, "\n", NULL); - } - - Printv(f_go_wrappers, "func ", NULL); - - p = parms; - int pi = 0; - - // Add the receiver if this is a method. - String *first = NULL; - if (receiver) { - Printv(f_go_wrappers, "(", NULL); - if (base && receiver) { - Printv(f_go_wrappers, "_swig_base", NULL); - if (first == NULL) { - first = NewString("_swig_base"); - } - } else { - Printv(f_go_wrappers, Getattr(p, "lname"), NULL); - if (first == NULL) { - first = Copy(Getattr(p, "lname")); - } - p = nextParm(p); - ++pi; - } - Printv(f_go_wrappers, " ", receiver, ") ", NULL); - } - - Printv(f_go_wrappers, go_name, NULL); - if (overname) { - Printv(f_go_wrappers, overname, NULL); - } - Printv(f_go_wrappers, "(", NULL); - - // If we are doing methods, add this function to the interface. - if (add_to_interface) { - Printv(interfaces, "\t", go_name, "(", NULL); - } - - // Write out the parameters to both the function definition and - // the interface. - - String *parm_print = NewString(""); - - for (; pi < parm_count; ++pi) { - p = getParm(p); - if (pi == 0 && is_destructor) { - String *cl = exportedName(class_name); - Printv(parm_print, Getattr(p, "lname"), " ", cl, NULL); - if (first == NULL) { - first = Copy(Getattr(p, "lname")); - } - Delete(cl); - } else { - if (pi > (receiver && !base ? 1 : 0)) { - Printv(parm_print, ", ", NULL); - } - if (pi >= required_count) { - Printv(parm_print, "_swig_args ...interface{}", NULL); - if (first == NULL) { - first = NewString("_swig_args"); - } - break; - } - Printv(parm_print, Getattr(p, "lname"), " ", NULL); - if (first == NULL) { - first = Copy(Getattr(p, "lname")); - } - String *tm = goType(p, Getattr(p, "type")); - Printv(parm_print, tm, NULL); - Delete(tm); - } - p = nextParm(p); - } - - Printv(parm_print, ")", NULL); - - // Write out the result type. - if (is_constructor) { - String *cl = exportedName(class_name); - Printv(parm_print, " (_swig_ret ", cl, ")", NULL); - if (first == NULL) { - first = NewString("_swig_ret"); - } - Delete(cl); - } else { - if (SwigType_type(result) != T_VOID) { - String *tm = goType(n, result); - Printv(parm_print, " (_swig_ret ", tm, ")", NULL); - if (first == NULL) { - first = NewString("_swig_ret"); - } - Delete(tm); - } - } - - Printv(f_go_wrappers, parm_print, NULL); - if (add_to_interface) { - Printv(interfaces, parm_print, "\n", NULL); - } - - // If this is a wrapper, we need to actually call the C function. - if (needs_wrapper) { - Printv(f_go_wrappers, " {\n", NULL); - - if (parm_count > required_count) { - Parm *p = parms; - int i; - for (i = 0; i < required_count; ++i) { - p = getParm(p); - p = nextParm(p); - } - for (; i < parm_count; ++i) { - p = getParm(p); - String *tm = goType(p, Getattr(p, "type")); - Printv(f_go_wrappers, "\tvar ", Getattr(p, "lname"), " ", tm, "\n", NULL); - Printf(f_go_wrappers, "\tif len(_swig_args) > %d {\n", i - required_count); - Printf(f_go_wrappers, "\t\t%s = _swig_args[%d].(%s)\n", Getattr(p, "lname"), i - required_count, tm); - Printv(f_go_wrappers, "\t}\n", NULL); - Delete(tm); - p = nextParm(p); - } - } - - String *call = NewString(""); - - bool need_return_var = SwigType_type(result) != T_VOID && ((gccgo_flag && is_constructor) || has_goout); - if (need_return_var) { - Printv(f_go_wrappers, "\tvar swig_r ", NULL); - if (is_constructor) { - String *cl = exportedName(class_name); - Printv(f_go_wrappers, cl, NULL); - Delete(cl); - } else { - Printv(f_go_wrappers, goImType(n, result), NULL); - } - Printv(f_go_wrappers, "\n", NULL); - } - - if (gccgo_flag) { - if (has_goout || is_constructor) { - Printv(call, "\tfunc() {\n", NULL); - } - Printv(call, "\tdefer SwigCgocallDone()\n", NULL); - Printv(call, "\tSwigCgocall()\n", NULL); - } - - Printv(call, "\t", NULL); - if (SwigType_type(result) != T_VOID) { - if (need_return_var) { - Printv(call, "swig_r = ", NULL); - } else { - Printv(call, "return ", NULL); - } - } - - Printv(call, wrapper_name, "(", NULL); - - if (parm_count > required_count) { - Printv(call, "len(_swig_args)", NULL); - } - - if (base && receiver) { - if (parm_count > required_count) { - Printv(call, ", ", NULL); - } - Printv(call, "_swig_base", NULL); - } - - Parm *p = parms; - for (int i = 0; i < parm_count; ++i) { - p = getParm(p); - if (i > 0 || (base && receiver) - || parm_count > required_count) { - Printv(call, ", ", NULL); - } - - SwigType *pt = Getattr(p, "type"); - String *ln = Getattr(p, "lname"); - - String *goin = goGetattr(p, "tmap:goin"); - if (goin == NULL) { - Printv(call, ln, NULL); - if ((i == 0 && is_destructor) || ((i > 0 || !receiver || base || is_constructor) && goTypeIsInterface(p, pt))) { - Printv(call, ".Swigcptr()", NULL); - } - Setattr(p, "emit:goinput", ln); - } else { - String *ivar = NewString(""); - Printf(ivar, "_swig_i_%d", i); - String *itm = goImType(p, pt); - Printv(f_go_wrappers, "\tvar ", ivar, " ", itm, "\n", NULL); - goin = Copy(goin); - Replaceall(goin, "$input", ln); - Replaceall(goin, "$result", ivar); - Printv(f_go_wrappers, goin, "\n", NULL); - Delete(goin); - Printv(call, ivar, NULL); - Setattr(p, "emit:goinput", ivar); - } - - // If the parameter has an argout or freearg typemap, make - // sure that it escapes. - if (paramNeedsEscape(p)) { - Printv(f_go_wrappers, "\tif Swig_escape_always_false {\n", NULL); - Printv(f_go_wrappers, "\t\tSwig_escape_val = ", Getattr(p, "emit:goinput"), "\n", NULL); - Printv(f_go_wrappers, "\t}\n", NULL); - } - - p = nextParm(p); - } - Printv(call, ")\n", NULL); - - if (gccgo_flag && (has_goout || is_constructor)) { - Printv(call, "\t}()\n", NULL); - } - - Printv(f_go_wrappers, call, NULL); - Delete(call); - - goargout(parms); - - if (need_return_var) { - if (goout == NULL) { - Printv(f_go_wrappers, "\treturn swig_r\n", NULL); - } else { - String *tm = goType(n, result); - Printv(f_go_wrappers, "\tvar swig_r_1 ", tm, "\n", NULL); - Replaceall(goout, "$input", "swig_r"); - Replaceall(goout, "$result", "swig_r_1"); - Printv(f_go_wrappers, goout, "\n", NULL); - Printv(f_go_wrappers, "\treturn swig_r_1\n", NULL); - } - } - - Printv(f_go_wrappers, "}\n", NULL); - } else if (!gccgo_flag) { - // We don't need a wrapper. If we're using gccgo, the function - // declaration is all we need--it has a //extern comment to - // GCC-compiled wrapper. If we're not using gccgo, we need to - // call the GCC-compiled wrapper here. - Printv(f_go_wrappers, " {\n", NULL); - if (first == NULL) { - Printv(f_go_wrappers, "\tvar _swig_p uintptr\n", NULL); - } else { - Printv(f_go_wrappers, "\t_swig_p := uintptr(unsafe.Pointer(&", first, "))\n", NULL); - } - Printv(f_go_wrappers, "\t_cgo_runtime_cgocall(", wname, ", _swig_p)\n", NULL); - Printv(f_go_wrappers, "\treturn\n", NULL); - Printv(f_go_wrappers, "}", NULL); - } - - Printv(f_go_wrappers, "\n", NULL); - - Delete(wrapper_name); - DelWrapper(dummy); - - return SWIG_OK; - } - /* ---------------------------------------------------------------------- * initGoTypemaps() * @@ -2055,362 +1546,6 @@ private: return dummy; } - /* ---------------------------------------------------------------------- - * argName() - * - * A helper for goFunctionWrapper to output the first argument name - * as "base" and all others as "_". - * ---------------------------------------------------------------------- */ - - const char *argName(bool *arg) { - if (*arg) { - return "_"; - } - *arg = true; - return "base"; - } - - /* ---------------------------------------------------------------------- - * paramNeedsEscape() - * - * A helper for goFunctionWrapper that returns whether a parameter - * needs to explicitly escape. This is true if the parameter has a - * non-empty argout or freearg typemap, because in those cases the - * Go argument might be or contain a pointer. We need to ensure - * that that pointer does not point into the stack, which means that - * it needs to escape. - * ---------------------------------------------------------------------- */ - bool paramNeedsEscape(Parm *p) { - String *argout = Getattr(p, "tmap:argout"); - String *freearg = Getattr(p, "tmap:freearg"); - if ((!argout || Len(argout) == 0) && (!freearg || Len(freearg) == 0)) { - return false; - } - // If a C++ type is represented as an interface type in Go, then - // we don't care whether it escapes, because we know that the - // pointer is a C++ pointer. - if (goTypeIsInterface(p, Getattr(p, "type"))) { - return false; - } - return true; - } - - /* ---------------------------------------------------------------------- - * gcFunctionWrapper() - * - * This is used for 6g/8g, not for gccgo. Write out the function - * redirector that will be compiled with 6c/8c. This used to write - * out a real function wrapper, but that has moved into Go code. - * ---------------------------------------------------------------------- */ - - int gcFunctionWrapper(String *wname) { - Wrapper *f = NewWrapper(); - - Printv(f->def, "#pragma dynimport ", wname, " ", wname, " \"\"\n", NULL); - Printv(f->def, "#pragma cgo_import_static ", wname, "\n", NULL); - Printv(f->def, "extern void ", wname, "(void*);\n", NULL); - // Declare this as a uintptr, since it is not a pointer into the - // Go heap. - // \xc2\xb7 is UTF-8 for U+00B7 which is Unicode 'Middle Dot' - Printv(f->def, "uintptr \xc2\xb7", wname, " = (uintptr)", wname, ";\n", NULL); - - Wrapper_print(f, f_gc_wrappers); - - DelWrapper(f); - - return SWIG_OK; - } - - /* ---------------------------------------------------------------------- - * gccFunctionWrapper() - * - * This is used for 6g/8g, not for gccgo. Write out the function - * wrapper which will be compiled with gcc. If the base parameter - * is not NULL, this is calls the base class method rather than - * executing the SWIG wrapper code. - * ---------------------------------------------------------------------- */ - - int gccFunctionWrapper(Node *n, List *base, String *wname, ParmList *parms, SwigType *result) { - Wrapper *f = NewWrapper(); - - Swig_save("gccFunctionWrapper", n, "parms", NULL); - - Parm *base_parm = NULL; - if (base && !isStatic(n)) { - SwigType *base_type = Copy(getClassType()); - SwigType_add_pointer(base_type); - base_parm = NewParm(base_type, NewString("arg1"), n); - set_nextSibling(base_parm, parms); - parms = base_parm; - } - - emit_parameter_variables(parms, f); - emit_attach_parmmaps(parms, f); - int parm_count = emit_num_arguments(parms); - int required_count = emit_num_required(parms); - bool needs_swigargs = false; - - emit_return_variable(n, result, f); - - // Start the function definition. - - Printv(f->def, "void\n", wname, "(void *swig_v)\n", "{\n", NULL); - - // The single function parameter is a pointer to the real argument - // values. Define the structure that it points to. - - String *swigargs = NewString("\tstruct swigargs {\n"); - - if (parm_count > required_count) { - needs_swigargs = true; - Printv(swigargs, "\t\tintgo _swig_optargc;\n", NULL); - } - - Parm *p = parms; - for (int i = 0; i < parm_count; ++i) { - p = getParm(p); - - String *ln = Getattr(p, "lname"); - SwigType *pt = Getattr(p, "type"); - String *ct = gcCTypeForGoValue(p, pt, ln); - Printv(swigargs, "\t\t\t", ct, ";\n", NULL); - needs_swigargs = true; - Delete(ct); - - String *gn = NewStringf("_swig_go_%d", i); - ct = gcCTypeForGoValue(p, pt, gn); - Setattr(p, "emit:input", gn); - Wrapper_add_local(f, gn, ct); - Delete(ct); - - p = nextParm(p); - } - if (SwigType_type(result) != T_VOID) { - Printv(swigargs, "\t\tlong : 0;\n", NULL); - String *ln = NewString(Swig_cresult_name()); - String *ct = gcCTypeForGoValue(n, result, ln); - Delete(ln); - Printv(swigargs, "\t\t", ct, ";\n", NULL); - needs_swigargs = true; - Delete(ct); - - ln = NewString("_swig_go_result"); - ct = gcCTypeForGoValue(n, result, ln); - Wrapper_add_local(f, "_swig_go_result", ct); - Delete(ct); - Delete(ln); - } - Printv(swigargs, "\t} SWIGSTRUCTPACKED *swig_a = (struct swigargs *) swig_v;\n", NULL); - - // Copy the input arguments out of the structure into the Go local - // variables. - p = parms; - for (int i = 0; i < parm_count; ++i) { - p = getParm(p); - String *ln = Getattr(p, "lname"); - String *gn = Getattr(p, "emit:input"); - Printv(f->code, "\t", gn, " = swig_a->", ln, ";\n", NULL); - p = nextParm(p); - } - - // Apply the in typemaps. - p = parms; - for (int i = 0; i < parm_count; ++i) { - p = getParm(p); - String *tm = Getattr(p, "tmap:in"); - if (!tm) { - Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument\n", SwigType_str(Getattr(p, "type"), 0)); - } else { - tm = Copy(tm); - String *gn = Getattr(p, "emit:input"); - Replaceall(tm, "$input", gn); - if (i < required_count) { - Printv(f->code, "\t", tm, "\n", NULL); - } else { - Printf(f->code, "\tif (swig_a->_swig_optargc > %d) {\n", i - required_count); - Printv(f->code, "\t\t", tm, "\n", NULL); - Printv(f->code, "\t}\n", NULL); - } - Delete(tm); - } - p = nextParm(p); - } - - Printv(f->code, "\n", NULL); - - // Do the real work of the function. - - checkConstraints(parms, f); - - emitGoAction(n, base, parms, result, f); - - argout(parms, f); - - cleanupFunction(n, f, parms); - - if (needs_swigargs) - { - Printv(f->locals, swigargs, NULL); - } - - Printv(f->code, "}\n", NULL); - - Wrapper_print(f, f_c_wrappers); - - Swig_restore(n); - - Delete(swigargs); - DelWrapper(f); - Delete(base_parm); - - return SWIG_OK; - } - - /* ---------------------------------------------------------------------- - * gccgoFunctionWrapper() - * - * This is used for gccgo, not 6g/8g. Write out the function - * wrapper which will be compiled with gcc. If the base parameter - * is not NULL, this is calls the base class method rather than - * executing the SWIG wrapper code. - * ---------------------------------------------------------------------- */ - - int gccgoFunctionWrapper(Node *n, List *base, String *wname, ParmList *parms, SwigType *result) { - Wrapper *f = NewWrapper(); - - Swig_save("gccgoFunctionWrapper", n, "parms", NULL); - - Parm *base_parm = NULL; - if (base && !isStatic(n)) { - SwigType *base_type = Copy(getClassType()); - SwigType_add_pointer(base_type); - base_parm = NewParm(base_type, NewString("arg1"), n); - set_nextSibling(base_parm, parms); - parms = base_parm; - } - - emit_parameter_variables(parms, f); - emit_attach_parmmaps(parms, f); - int parm_count = emit_num_arguments(parms); - int required_count = emit_num_required(parms); - - emit_return_variable(n, result, f); - - // Start the function definition. - - String *fnname = NewString(""); - Printv(fnname, "go_", wname, "(", NULL); - - if (parm_count > required_count) { - Printv(fnname, "intgo _swig_optargc", NULL); - } - - Parm *p = parms; - for (int i = 0; i < parm_count; ++i) { - p = getParm(p); - SwigType *pt = Copy(Getattr(p, "type")); - if (SwigType_isarray(pt)) { - SwigType_del_array(pt); - SwigType_add_pointer(pt); - } - String *pn = NewString("g"); - Append(pn, Getattr(p, "lname")); - String *ct = gccgoCTypeForGoValue(p, pt, pn); - if (i > 0 || parm_count > required_count) { - Printv(fnname, ", ", NULL); - } - Printv(fnname, ct, NULL); - Delete(ct); - Delete(pn); - Delete(pt); - p = nextParm(p); - } - - Printv(fnname, ")", NULL); - - String *fndef = NewString(""); - if (SwigType_type(result) == T_VOID) { - Printv(fndef, "void ", fnname, NULL); - } else { - String *ct = gccgoCTypeForGoValue(n, result, fnname); - Printv(fndef, ct, NULL); - Delete(ct); - } - - Printv(f->def, fndef, " __asm__(\"", go_prefix, "_", wname, "\");\n", NULL); - - Printv(f->def, fndef, " {\n", NULL); - - Delete(fnname); - Delete(fndef); - - if (SwigType_type(result) != T_VOID) { - String *ln = NewString("_swig_go_result"); - String *ct = gccgoCTypeForGoValue(n, result, ln); - Wrapper_add_local(f, "_swig_go_result", ct); - Delete(ct); - Delete(ln); - } - - // Copy the parameters into the variables which hold their values, - // applying appropriate transformations. - - p = parms; - for (int i = 0; i < parm_count; ++i) { - p = getParm(p); - - String *tm = Getattr(p, "tmap:in"); - if (!tm) { - Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, - "Unable to use type %s as a function argument\n", SwigType_str(Getattr(p, "type"), 0)); - } else { - String *ln = Getattr(p, "lname"); - String *pn = NewString("g"); - Append(pn, ln); - tm = Copy(tm); - Replaceall(tm, "$input", pn); - Setattr(p, "emit:input", pn); - if (i < required_count) { - Printv(f->code, " ", tm, "\n", NULL); - } else { - Printf(f->code, " if (_swig_optargc > %d) {\n", i - required_count); - Printv(f->code, " ", tm, "\n", NULL); - Printv(f->code, " }\n", NULL); - } - Delete(tm); - } - - p = nextParm(p); - } - - Printv(f->code, "\n", NULL); - - // Do the real work of the function. - - checkConstraints(parms, f); - - emitGoAction(n, base, parms, result, f); - - argout(parms, f); - - cleanupFunction(n, f, parms); - - if (SwigType_type(result) != T_VOID) { - Printv(f->code, " return _swig_go_result;\n", NULL); - } - - Printv(f->code, "}\n", NULL); - - Wrapper_print(f, f_c_wrappers); - - Swig_restore(n); - - DelWrapper(f); - Delete(base_parm); - - return SWIG_OK; - } - /* ----------------------------------------------------------------------- * checkConstraints() * @@ -2442,10 +1577,6 @@ private: * ----------------------------------------------------------------------- */ void emitGoAction(Node *n, List *base, ParmList *parms, SwigType *result, Wrapper *f) { - if (!gccgo_flag && !cgo_flag && SwigType_type(result) != T_VOID) { - Wrapper_add_local(f, "swig_stktop", "char *swig_stktop"); - Printv(f->code, "\tswig_stktop = _swig_topofstack();\n", NULL); - } String *actioncode; if (!base || isStatic(n)) { Swig_director_emit_dynamic_cast(n, f); @@ -2455,9 +1586,6 @@ private: actioncode = NewString(""); String *current = NewString(""); - if (!gccgo_flag && !cgo_flag) { - Printv(current, "swig_a->", NULL); - } Printv(current, Getattr(parms, "lname"), NULL); int vc = 0; @@ -2493,14 +1621,6 @@ private: Delete(tm); } - if (!gccgo_flag && !cgo_flag && SwigType_type(result) != T_VOID) { - // If the function called back into the Go code, the stack might - // have been copied. We need to adjust swig_a accordingly here. - // This is what cgo does. - Printv(f->code, "\tswig_a = (struct swigargs*)((char*)swig_a + (_swig_topofstack() - swig_stktop));\n", NULL); - Printv(f->code, "\tswig_a->", Swig_cresult_name(), " = ", "_swig_go_result;\n", NULL); - } - Swig_restore(n); } @@ -2553,26 +1673,23 @@ private: } } - // When using cgo, if we need to memcpy a parameter to pass it to - // the C code, the compiler may think that the parameter is not - // live during the function call. If the garbage collector runs - // while the C/C++ function is running, the parameter may be - // freed. Force the compiler to see the parameter as live across - // the C/C++ function. - if (cgo_flag) { - int parm_count = emit_num_arguments(parms); - p = parms; - for (int i = 0; i < parm_count; ++i) { - p = getParm(p); - bool c_struct_type; - Delete(cgoTypeForGoValue(p, Getattr(p, "type"), &c_struct_type)); - if (c_struct_type) { - Printv(f_go_wrappers, "\tif Swig_escape_always_false {\n", NULL); - Printv(f_go_wrappers, "\t\tSwig_escape_val = ", Getattr(p, "emit:goinput"), "\n", NULL); - Printv(f_go_wrappers, "\t}\n", NULL); - } - p = nextParm(p); + // If we need to memcpy a parameter to pass it to the C code, the + // compiler may think that the parameter is not live during the + // function call. If the garbage collector runs while the C/C++ + // function is running, the parameter may be freed. Force the + // compiler to see the parameter as live across the C/C++ function. + int parm_count = emit_num_arguments(parms); + p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + bool c_struct_type; + Delete(cgoTypeForGoValue(p, Getattr(p, "type"), &c_struct_type)); + if (c_struct_type) { + Printv(f_go_wrappers, "\tif Swig_escape_always_false {\n", NULL); + Printv(f_go_wrappers, "\t\tSwig_escape_val = ", Getattr(p, "emit:goinput"), "\n", NULL); + Printv(f_go_wrappers, "\t}\n", NULL); } + p = nextParm(p); } } @@ -2893,7 +2010,7 @@ private: Append(wname, unique_id); Setattr(n, "wrap:name", wname); - int r = makeWrappers(n, sname, go_name, NULL, wname, NULL, NULL, type, true); + int r = makeWrappers(n, go_name, NULL, wname, NULL, NULL, type, true); if (r != SWIG_OK) { return r; @@ -3206,7 +2323,7 @@ private: } } - int r = makeWrappers(method, name, go_name, overname, wname, bases, Getattr(method, "parms"), result, is_static); + int r = makeWrappers(method, go_name, overname, wname, bases, Getattr(method, "parms"), result, is_static); Swig_restore(method); @@ -3281,7 +2398,7 @@ private: Append(wname, unique_id); ParmList *parms = NewParm(vt, var_name, var); String *result = NewString("void"); - int r = makeWrappers(var, mname_set, go_name, NULL, wname, bases, parms, result, false); + int r = makeWrappers(var, go_name, NULL, wname, bases, parms, result, false); if (r != SWIG_OK) { return r; } @@ -3310,7 +2427,7 @@ private: String *wname = Swig_name_wrapper(mname_get); Append(wname, unique_id); - int r = makeWrappers(var, mname_get, go_name, NULL, wname, bases, NULL, vt, false); + int r = makeWrappers(var, go_name, NULL, wname, bases, NULL, vt, false); if (r != SWIG_OK) { return r; } @@ -3426,8 +2543,7 @@ private: SwigType *result = Copy(Getattr(b.item, "classtypeobj")); SwigType_add_pointer(result); - int r = makeWrappers(n, name, go_name, NULL, wname, NULL, parm, result, - false); + int r = makeWrappers(n, go_name, NULL, wname, NULL, parm, result, false); if (r != SWIG_OK) { return r; } @@ -3675,50 +2791,17 @@ private: } if (!is_ignored) { - if (cgo_flag) { - Printv(f_cgo_comment, "extern uintptr_t ", wname, "(int", NULL); + Printv(f_cgo_comment, "extern uintptr_t ", wname, "(int", NULL); - p = parms; - for (int i = 0; i < parm_count; ++i) { - p = getParm(p); - bool c_struct_type; - String *ct = cgoTypeForGoValue(p, Getattr(p, "type"), &c_struct_type); - Printv(f_cgo_comment, ", ", ct, " ", Getattr(p, "lname"), NULL); - p = nextParm(p); - } - Printv(f_cgo_comment, ");\n", NULL); - } else { - // Declare the C++ wrapper. - - if (!gccgo_flag) { - Printv(f_go_wrappers, "var ", wname, " unsafe.Pointer\n\n", NULL); - } else { - Printv(f_go_wrappers, "//extern ", go_prefix, "_", wname, "\n", NULL); - } - - Printv(f_go_wrappers, "func ", fn_with_over_name, "(_swig_director int", NULL); - - p = parms; - for (int i = 0; i < parm_count; ++i) { - p = getParm(p); - String *tm = goWrapperType(p, Getattr(p, "type"), false); - Printv(f_go_wrappers, ", _ ", tm, NULL); - Delete(tm); - p = nextParm(p); - } - - Printv(f_go_wrappers, ") (_swig_ret ", go_type_name, ")", NULL); - - if (!gccgo_flag) { - Printv(f_go_wrappers, " {\n", NULL); - Printv(f_go_wrappers, "\t_swig_p := uintptr(unsafe.Pointer(&_swig_director))\n", NULL); - Printv(f_go_wrappers, "\t_cgo_runtime_cgocall(", wname, ", _swig_p)\n", NULL); - Printv(f_go_wrappers, "\treturn\n", NULL); - Printv(f_go_wrappers, "}", NULL); - } - - Printv(f_go_wrappers, "\n\n", NULL); + p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + bool c_struct_type; + String *ct = cgoTypeForGoValue(p, Getattr(p, "type"), &c_struct_type); + Printv(f_cgo_comment, ", ", ct, " ", Getattr(p, "lname"), NULL); + p = nextParm(p); } + Printv(f_cgo_comment, ");\n", NULL); // Write out the Go function that calls the wrapper. @@ -3738,19 +2821,10 @@ private: Printv(f_go_wrappers, "\tp := &", director_struct_name, "{0, v}\n", NULL); - if (gccgo_flag && !cgo_flag) { - Printv(f_go_wrappers, "\tdefer SwigCgocallDone()\n", NULL); - Printv(f_go_wrappers, "\tSwigCgocall()\n", NULL); - } - String *call = NewString(""); Printv(call, "\tp.", class_receiver, " = ", NULL); - if (cgo_flag) { - Printv(call, go_type_name, "(C.", wname, "(C.int(swigDirectorAdd(p))", NULL); - } else { - Printv(call, fn_with_over_name, "(swigDirectorAdd(p)", NULL); - } + Printv(call, go_type_name, "(C.", wname, "(C.int(swigDirectorAdd(p))", NULL); p = parms; for (int i = 0; i < parm_count; ++i) { @@ -3781,25 +2855,19 @@ private: Setattr(p, "emit:goinput", ivar); - if (cgo_flag) { - bool c_struct_type; - String *ct = cgoTypeForGoValue(p, pt, &c_struct_type); - if (c_struct_type) { - Printv(call, "*(*C.", ct, ")(unsafe.Pointer(&", ivar, "))", NULL); - } else { - Printv(call, "C.", ct, "(", ivar, ")", NULL); - } - Delete(ct); + bool c_struct_type; + String *ct = cgoTypeForGoValue(p, pt, &c_struct_type); + if (c_struct_type) { + Printv(call, "*(*C.", ct, ")(unsafe.Pointer(&", ivar, "))", NULL); } else { - Printv(call, ivar, NULL); + Printv(call, "C.", ct, "(", ivar, ")", NULL); } + Delete(ct); + p = nextParm(p); } - Printv(call, ")", NULL); - if (cgo_flag) { - Printv(call, ")", NULL); - } + Printv(call, "))", NULL); Printv(f_go_wrappers, call, "\n", NULL); @@ -3837,39 +2905,23 @@ private: Printv(action, ");", NULL); Setattr(n, "wrap:action", action); - if (cgo_flag) { - cgoWrapperInfo info; + cgoWrapperInfo info; - info.n = n; - info.go_name = func_name; - info.overname = overname; - info.wname = wname; - info.base = NULL; - info.parms = first_parm; - info.result = result; - info.is_static = false; - info.receiver = NULL; - info.is_constructor = true; - info.is_destructor = false; + info.n = n; + info.go_name = func_name; + info.overname = overname; + info.wname = wname; + info.base = NULL; + info.parms = first_parm; + info.result = result; + info.is_static = false; + info.receiver = NULL; + info.is_constructor = true; + info.is_destructor = false; - int r = cgoGccWrapper(&info); - if (r != SWIG_OK) { - return r; - } - } else if (!gccgo_flag) { - int r = gcFunctionWrapper(wname); - if (r != SWIG_OK) { - return r; - } - r = gccFunctionWrapper(n, NULL, wname, first_parm, result); - if (r != SWIG_OK) { - return r; - } - } else { - int r = gccgoFunctionWrapper(n, NULL, wname, first_parm, result); - if (r != SWIG_OK) { - return r; - } + int r = cgoGccWrapper(&info); + if (r != SWIG_OK) { + return r; } Swig_restore(n); @@ -3958,7 +3010,7 @@ private: Setattr(n, "wrap:parms", parms); String *result = NewString("void"); - int r = makeWrappers(n, fnname, fnname, NULL, wname, NULL, parms, result, isStatic(n)); + int r = makeWrappers(n, fnname, NULL, wname, NULL, parms, result, isStatic(n)); if (r != SWIG_OK) { return r; } @@ -4023,65 +3075,9 @@ private: * makeDirectorDestructorWrapper * * Emit the function wrapper for the destructor of a director class. - * This writes director_sig to f_c_directors and leaves the function - * unfinished. * ------------------------------------------------------------ */ void makeDirectorDestructorWrapper(String *go_name, String *director_struct_name, String *director_sig) { - if (cgo_flag) { - makeCgoDirectorDestructorWrapper(go_name, director_struct_name, director_sig); - return; - } - - Printv(f_go_wrappers, "func ", go_name, "(c int) {\n", NULL); - if (gccgo_flag) { - Printv(f_go_wrappers, "\tSwigCgocallBack()\n", NULL); - Printv(f_go_wrappers, "\tdefer SwigCgocallBackDone()\n", NULL); - } - Printv(f_go_wrappers, "\tswigDirectorLookup(c).(*", director_struct_name, ").", class_receiver, " = 0\n", NULL); - Printv(f_go_wrappers, "\tswigDirectorDelete(c)\n", NULL); - Printv(f_go_wrappers, "}\n\n", NULL); - - String *wname = NewString("_swiggo_wrap_DeleteDirector_"); - Append(wname, class_name); - - if (!gccgo_flag) { - Printv(f_c_directors, "extern \"C\" void ", wname, "(void*, int);\n", NULL); - } else { - Printv(f_c_directors, "extern \"C\" void ", wname, "(intgo) __asm__(\"", go_prefix, ".", go_name, "\");\n", NULL); - } - - Printv(f_c_directors, director_sig, NULL); - - if (!gccgo_flag) { - Printv(f_c_directors, " struct { intgo p; } SWIGSTRUCTPACKED a;\n", NULL); - Printv(f_c_directors, " a.p = go_val;\n", NULL); - Printv(f_c_directors, " crosscall2(", wname, ", &a, (int) sizeof a);\n", NULL); - - Printv(f_gc_wrappers, "#pragma dynexport ", wname, " ", wname, "\n", NULL); - Printv(f_gc_wrappers, "#pragma cgo_export_static ", wname, " ", wname, "\n", NULL); - Printv(f_gc_wrappers, "#pragma textflag 7\n", NULL); - Printv(f_gc_wrappers, "extern void \xc2\xb7", go_name, "();\n", NULL); - Printv(f_gc_wrappers, "void\n", NULL); - Printv(f_gc_wrappers, wname, "(void *a, int32 n)\n", NULL); - Printv(f_gc_wrappers, "{\n", NULL); - Printv(f_gc_wrappers, "\truntime\xc2\xb7" "cgocallback(\xc2\xb7", go_name, ", a, n);\n", NULL); - Printv(f_gc_wrappers, "}\n\n", NULL); - } else { - Printv(f_c_directors, " ", wname, "(go_val);\n", NULL); - } - - Delete(wname); - } - - /* ------------------------------------------------------------ - * makeCgoDirectorDestructorWrapper - * - * When using cgo, emit the function wrapper for the destructor of a - * director class. - * ------------------------------------------------------------ */ - - void makeCgoDirectorDestructorWrapper(String *go_name, String *director_struct_name, String *director_sig) { String *wname = Copy(go_name); Append(wname, unique_id); @@ -4251,9 +3247,7 @@ private: if (overname) { Append(callback_name, overname); } - if (cgo_flag) { - Append(callback_name, unique_id); - } + Append(callback_name, unique_id); String *upcall_name = Copy(director_struct_name); Append(upcall_name, "_upcall_"); @@ -4314,68 +3308,28 @@ private: Printv(f_go_wrappers, "}\n\n", NULL); if (!GetFlag(n, "abstract")) { - if (cgo_flag) { - Printv(f_cgo_comment, "extern ", NULL); + Printv(f_cgo_comment, "extern ", NULL); - if (SwigType_type(result) == T_VOID) { - Printv(f_cgo_comment, "void", NULL); - } else { - bool c_struct_type; - String *ret_type = cgoTypeForGoValue(n, result, &c_struct_type); - Printv(f_cgo_comment, ret_type, NULL); - Delete(ret_type); - } - - Printv(f_cgo_comment, " ", upcall_wname, "(uintptr_t", NULL); - - p = parms; - for (int i = 0; i < parm_count; ++i) { - p = getParm(p); - bool c_struct_type; - String *ct = cgoTypeForGoValue(p, Getattr(p, "type"), &c_struct_type); - Printv(f_cgo_comment, ", ", ct, " ", Getattr(p, "lname"), NULL); - p = nextParm(p); - } - Printv(f_cgo_comment, ");\n", NULL); + if (SwigType_type(result) == T_VOID) { + Printv(f_cgo_comment, "void", NULL); } else { - // Declare the upcall function, which calls the method on - // the parent class. - - if (!gccgo_flag) { - Printv(f_go_wrappers, "var ", upcall_wname, " unsafe.Pointer\n\n", NULL); - } else { - Printv(f_go_wrappers, "//extern ", go_prefix, "_", upcall_wname, "\n", NULL); - } - - Printv(f_go_wrappers, "func ", upcall_gc_name, "(_swig_ptr ", go_type_name, NULL); - - p = parms; - for (int i = 0; i < parm_count; ++i) { - p = getParm(p); - String *tm = goWrapperType(p, Getattr(p, "type"), false); - Printv(f_go_wrappers, ", _ ", tm, NULL); - Delete(tm); - p = nextParm(p); - } - - Printv(f_go_wrappers, ")", NULL); - - if (SwigType_type(result) != T_VOID) { - String *tm = goWrapperType(n, result, true); - Printv(f_go_wrappers, " (_swig_ret ", tm, ")", NULL); - Delete(tm); - } - - if (!gccgo_flag) { - Printv(f_go_wrappers, " {\n", NULL); - Printv(f_go_wrappers, "\t_swig_p := uintptr(unsafe.Pointer(&_swig_ptr))\n", NULL); - Printv(f_go_wrappers, "\t_cgo_runtime_cgocall(", upcall_wname, ", _swig_p)\n", NULL); - Printv(f_go_wrappers, "\treturn\n", NULL); - Printv(f_go_wrappers, "}", NULL); - } - - Printv(f_go_wrappers, "\n\n", NULL); + bool c_struct_type; + String *ret_type = cgoTypeForGoValue(n, result, &c_struct_type); + Printv(f_cgo_comment, ret_type, NULL); + Delete(ret_type); } + + Printv(f_cgo_comment, " ", upcall_wname, "(uintptr_t", NULL); + + p = parms; + for (int i = 0; i < parm_count; ++i) { + p = getParm(p); + bool c_struct_type; + String *ct = cgoTypeForGoValue(p, Getattr(p, "type"), &c_struct_type); + Printv(f_cgo_comment, ", ", ct, " ", Getattr(p, "lname"), NULL); + p = nextParm(p); + } + Printv(f_cgo_comment, ");\n", NULL); } // Define the method on the director class in Go. @@ -4434,73 +3388,36 @@ private: String *ret_type = NULL; bool memcpy_ret = false; String *wt = NULL; - bool has_goout = false; String *goout = NULL; if (SwigType_type(result) != T_VOID) { ret_type = goImType(n, result); Printv(f_go_wrappers, "\tvar swig_r ", ret_type, "\n", NULL); goout = goTypemapLookup("goout", n, "swig_r"); - if (goout) { - has_goout = true; - } - if (cgo_flag) { - bool c_struct_type; - Delete(cgoTypeForGoValue(n, result, &c_struct_type)); - if (c_struct_type) { - memcpy_ret = true; - } + bool c_struct_type; + Delete(cgoTypeForGoValue(n, result, &c_struct_type)); + if (c_struct_type) { + memcpy_ret = true; } } - p = parms; - for (int i = 0; i < parm_count; ++i) { - p = getParm(p); - if (goGetattr(p, "tmap:goargout")) { - has_goout = true; - } - p = nextParm(p); - } - String *call = NewString(""); - if (gccgo_flag && !cgo_flag) { - if (has_goout) { - Printv(call, "\tfunc() {\n", NULL); - } - Printv(call, "\tdefer SwigCgocallDone()\n", NULL); - Printv(call, "\tSwigCgocall()\n", NULL); - } - Printv(call, "\t", NULL); if (SwigType_type(result) != T_VOID) { if (memcpy_ret) { Printv(call, "swig_r_p := ", NULL); } else { - Printv(call, "swig_r = ", NULL); - if (cgo_flag) { - Printv(call, "(", ret_type, ")(", NULL); - } + Printv(call, "swig_r = (", ret_type, ")(", NULL); } - if (cgo_flag && goTypeIsInterface(n, result)) { + if (goTypeIsInterface(n, result)) { wt = goWrapperType(n, result, true); Printv(call, "(", wt, ")(", NULL); } } - if (cgo_flag) { - Printv(call, "C.", upcall_wname, NULL); - } else { - Printv(call, upcall_gc_name, NULL); - } - Printv(call, "(", NULL); - if (cgo_flag) { - Printv(call, "C.uintptr_t(", NULL); - } - Printv(call, "swig_p.", go_type_name, NULL); - if (cgo_flag) { - Printv(call, ")", NULL); - } + Printv(call, "C.", upcall_wname, "(C.uintptr_t(swig_p.", + go_type_name, ")", NULL); p = parms; for (int i = 0; i < parm_count; ++i) { @@ -4533,16 +3450,12 @@ private: Setattr(p, "emit:goinput", ivar); - if (cgo_flag) { - bool c_struct_type; - String *ct = cgoTypeForGoValue(p, pt, &c_struct_type); - if (c_struct_type) { - Printv(call, "*(*C.", ct, ")(unsafe.Pointer(&", ivar, "))", NULL); - } else { - Printv(call, "C.", ct, "(", ivar, ")", NULL); - } + bool c_struct_type; + String *ct = cgoTypeForGoValue(p, pt, &c_struct_type); + if (c_struct_type) { + Printv(call, "*(*C.", ct, ")(unsafe.Pointer(&", ivar, "))", NULL); } else { - Printv(call, ivar, NULL); + Printv(call, "C.", ct, "(", ivar, ")", NULL); } p = nextParm(p); @@ -4550,19 +3463,13 @@ private: Printv(call, ")", NULL); - if (gccgo_flag && !cgo_flag && has_goout) { - Printv(call, "\n\t}()", NULL); + if (wt) { + // Close the type conversion to the wrapper type. + Printv(call, ")", NULL); } - - if (cgo_flag) { - if (wt) { - // Close the type conversion to the wrapper type. - Printv(call, ")", NULL); - } - if (SwigType_type(result) != T_VOID && !memcpy_ret) { - // Close the type conversion of the return value. - Printv(call, ")", NULL); - } + if (SwigType_type(result) != T_VOID && !memcpy_ret) { + // Close the type conversion of the return value. + Printv(call, ")", NULL); } Printv(call, "\n", NULL); @@ -4676,41 +3583,23 @@ private: Printv(action, ");", NULL); Setattr(n, "wrap:action", action); - if (cgo_flag) { - cgoWrapperInfo info; + cgoWrapperInfo info; - info.n = n; - info.go_name = go_name; - info.overname = overname; - info.wname = upcall_wname; - info.base = NULL; - info.parms = first_parm; - info.result = result; - info.is_static = is_static; - info.receiver = NULL; - info.is_constructor = false; - info.is_destructor = false; + info.n = n; + info.go_name = go_name; + info.overname = overname; + info.wname = upcall_wname; + info.base = NULL; + info.parms = first_parm; + info.result = result; + info.is_static = is_static; + info.receiver = NULL; + info.is_constructor = false; + info.is_destructor = false; - int r = cgoGccWrapper(&info); - if (r != SWIG_OK) { - return r; - } - } else if (!gccgo_flag) { - // Write the upcall wrapper function. This is compiled by gc - // and calls the C++ function. - int r = gcFunctionWrapper(upcall_wname); - if (r != SWIG_OK) { - return r; - } - r = gccFunctionWrapper(n, NULL, upcall_wname, first_parm, result); - if (r != SWIG_OK) { - return r; - } - } else { - int r = gccgoFunctionWrapper(n, NULL, upcall_wname, first_parm, result); - if (r != SWIG_OK) { - return r; - } + int r = cgoGccWrapper(&info); + if (r != SWIG_OK) { + return r; } Delete(first_type); @@ -4755,54 +3644,30 @@ private: Printv(f_go_wrappers, "\tvar swig_r ", ret_type, "\n", NULL); goout = goTypemapLookup("goout", n, "swig_r"); - if (cgo_flag) { - bool c_struct_type; - Delete(cgoTypeForGoValue(n, result, &c_struct_type)); - if (c_struct_type) { - memcpy_ret = true; - } + bool c_struct_type; + Delete(cgoTypeForGoValue(n, result, &c_struct_type)); + if (c_struct_type) { + memcpy_ret = true; } } String *call = NewString(""); - if (gccgo_flag && !cgo_flag) { - if (goout != NULL) { - Printv(call, "\tfunc() {\n", NULL); - } - Printv(call, "\tdefer SwigCgocallDone()\n", NULL); - Printv(call, "\tSwigCgocall()\n", NULL); - } - Printv(call, "\t", NULL); if (SwigType_type(result) != T_VOID) { if (memcpy_ret) { Printv(call, "swig_r_p := ", NULL); } else { - Printv(call, "swig_r = ", NULL); - if (cgo_flag) { - Printv(call, "(", ret_type, ")(", NULL); - } + Printv(call, "swig_r = (", ret_type, ")(", NULL); } - if (cgo_flag && goTypeIsInterface(n, result)) { + if (goTypeIsInterface(n, result)) { wt = goWrapperType(n, result, true); Printv(call, "(", wt, ")(", NULL); } } - if (cgo_flag) { - Printv(call, "C.", upcall_wname, NULL); - } else { - Printv(call, upcall_gc_name, NULL); - } - Printv(call, "(", NULL); - if (cgo_flag) { - Printv(call, "C.uintptr_t(", NULL); - } - Printv(call, "p.(*", director_struct_name, ").", go_type_name, NULL); - if (cgo_flag) { - Printv(call, ")", NULL); - } + Printv(call, "C.", upcall_wname, "(C.uintptr_t(p.(*", + director_struct_name, ").", go_type_name, ")", NULL); p = parms; for (int i = 0; i < parm_count; ++i) { @@ -4833,16 +3698,12 @@ private: Setattr(p, "emit:goinput", ivar); - if (cgo_flag) { - bool c_struct_type; - String *ct = cgoTypeForGoValue(p, pt, &c_struct_type); - if (c_struct_type) { - Printv(call, "*(*C.", ct, ")(unsafe.Pointer(&", ivar, "))", NULL); - } else { - Printv(call, "C.", ct, "(", ivar, ")", NULL); - } + bool c_struct_type; + String *ct = cgoTypeForGoValue(p, pt, &c_struct_type); + if (c_struct_type) { + Printv(call, "*(*C.", ct, ")(unsafe.Pointer(&", ivar, "))", NULL); } else { - Printv(call, ivar, NULL); + Printv(call, "C.", ct, "(", ivar, ")", NULL); } Delete(ln); @@ -4852,19 +3713,13 @@ private: Printv(call, ")", NULL); - if (gccgo_flag && !cgo_flag && goout != NULL) { - Printv(call, "\n\t}()", NULL); + if (wt) { + // Close the type conversion to the wrapper type. + Printv(call, ")", NULL); } - - if (cgo_flag) { - if (wt) { - // Close the type conversion to the wrapper type. - Printv(call, ")", NULL); - } - if (SwigType_type(result) != T_VOID && !memcpy_ret) { - // Close the type conversion of the return value. - Printv(call, ")", NULL); - } + if (SwigType_type(result) != T_VOID && !memcpy_ret) { + // Close the type conversion of the return value. + Printv(call, ")", NULL); } Printv(call, "\n", NULL); @@ -4904,11 +3759,8 @@ private: // The Go function which invokes the method. This is called by // the C++ method on the director class. - if (cgo_flag) { - Printv(f_go_wrappers, "//export ", callback_name, "\n", NULL); - } - - Printv(f_go_wrappers, "func ", callback_name, "(swig_c int", NULL); + Printv(f_go_wrappers, "//export ", callback_name, "\n", + "func ", callback_name, "(swig_c int", NULL); p = parms; for (int i = 0; i < parm_count; ++i) { @@ -5014,23 +3866,11 @@ private: } Printv(call, "\n", NULL); - if (gccgo_flag && !cgo_flag) { - if (goout != NULL) { - Printv(f_go_wrappers, "\tfunc() {\n", NULL); - } - Printv(f_go_wrappers, "\tSwigCgocallBack()\n", NULL); - Printv(f_go_wrappers, "\tdefer SwigCgocallBackDone()\n", NULL); - } - Printv(f_go_wrappers, "\tswig_p := swigDirectorLookup(swig_c).(*", director_struct_name, ")\n", NULL); Printv(f_go_wrappers, goincode, NULL); Printv(f_go_wrappers, call, NULL); Delete(call); - if (gccgo_flag && !cgo_flag && goout != NULL) { - Printv(f_go_wrappers, "\t}()\n", NULL); - } - if (SwigType_type(result) != T_VOID) { if (goout == NULL) { Printv(f_go_wrappers, "\treturn swig_r\n", NULL); @@ -5132,241 +3972,6 @@ private: * Emit the function wrapper for a director method. * ------------------------------------------------------------ */ void makeDirectorMethodWrapper(Node *n, Wrapper *w, String *callback_name) { - if (cgo_flag) { - makeCgoDirectorMethodWrapper(n, w, callback_name); - return; - } - - ParmList *parms = Getattr(n, "wrap:parms"); - SwigType *result = Getattr(n, "type"); - - String *callback_wname = Swig_name_wrapper(callback_name); - Append(callback_wname, unique_id); - - if (!gccgo_flag) { - Printv(f_c_directors, "extern \"C\" void ", callback_wname, "(void*, int);\n", NULL); - } else { - Printv(f_c_directors, "extern \"C\" ", NULL); - - String *fnname = NewString(""); - Printv(fnname, callback_wname, "(int", NULL); - - Parm *p = parms; - while (p) { - while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { - p = Getattr(p, "tmap:directorin:next"); - } - String *cg = gccgoCTypeForGoValue(p, Getattr(p, "type"), - Getattr(p, "lname")); - Printv(fnname, ", ", cg, NULL); - Delete(cg); - p = Getattr(p, "tmap:directorin:next"); - } - - Printv(fnname, ")", NULL); - - if (SwigType_type(result) == T_VOID) { - Printv(f_c_directors, "void ", fnname, NULL); - } else { - String *tm = gccgoCTypeForGoValue(n, result, fnname); - Printv(f_c_directors, tm, NULL); - Delete(tm); - } - - Delete(fnname); - - Printv(f_c_directors, " __asm__(\"", go_prefix, ".", callback_name, "\");\n", NULL); - } - - if (!gccgo_flag) { - Printv(w->code, " struct {\n", NULL); - Printv(w->code, " intgo go_val;\n", NULL); - - Parm *p = parms; - while (p) { - while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { - p = Getattr(p, "tmap:directorin:next"); - } - String *ln = Getattr(p, "lname"); - String *cg = gcCTypeForGoValue(p, Getattr(p, "type"), ln); - Printv(w->code, " ", cg, ";\n", NULL); - Delete(cg); - p = Getattr(p, "tmap:directorin:next"); - } - if (SwigType_type(result) != T_VOID) { - Printv(w->code, " long : 0;\n", NULL); - String *rname = NewString(Swig_cresult_name()); - String *cg = gcCTypeForGoValue(n, result, rname); - Printv(w->code, " ", cg, ";\n", NULL); - Delete(cg); - Delete(rname); - } - - Printv(w->code, " } SWIGSTRUCTPACKED swig_a;\n", NULL); - Printv(w->code, " swig_a.go_val = go_val;\n", NULL); - - p = parms; - while (p) { - while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { - p = Getattr(p, "tmap:directorin:next"); - } - String *tm = Getattr(p, "tmap:directorin"); - if (!tm) { - Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, - line_number, "Unable to use type %s as director method argument\n", SwigType_str(Getattr(p, "type"), 0)); - } else { - tm = Copy(tm); - String *ln = Getattr(p, "lname"); - String *input = NewString(""); - Printv(input, "swig_a.", ln, NULL); - Setattr(p, "emit:directorinput", input); - Replaceall(tm, "$input", input); - Replaceall(tm, "$owner", "0"); - Delete(input); - Printv(w->code, "\t", tm, "\n", NULL); - Delete(tm); - } - p = Getattr(p, "tmap:directorin:next"); - } - - Printv(w->code, " crosscall2(", callback_wname, ", &swig_a, (int) sizeof swig_a);\n", NULL); - - /* Marshal outputs */ - for (p = parms; p;) { - String *tm; - if ((tm = Getattr(p, "tmap:directorargout"))) { - tm = Copy(tm); - Replaceall(tm, "$result", "jresult"); - Replaceall(tm, "$input", Getattr(p, "emit:directorinput")); - Printv(w->code, tm, "\n", NIL); - Delete(tm); - p = Getattr(p, "tmap:directorargout:next"); - } else { - p = nextSibling(p); - } - } - - if (SwigType_type(result) != T_VOID) { - String *result_str = NewString("c_result"); - String *tm = Swig_typemap_lookup("directorout", n, result_str, NULL); - if (!tm) { - Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, - "Unable to use type %s as director method result\n", SwigType_str(result, 0)); - } else { - static const String *swig_a_result = NewStringf("swig_a.%s", Swig_cresult_name()); - Replaceall(tm, "$input", swig_a_result); - Replaceall(tm, "$result", "c_result"); - Printv(w->code, " ", tm, "\n", NULL); - String *retstr = SwigType_rcaststr(result, "c_result"); - Printv(w->code, " return ", retstr, ";\n", NULL); - Delete(retstr); - Delete(tm); - } - Delete(result_str); - } - - // The C wrapper code which calls the Go function. - Printv(f_gc_wrappers, "#pragma dynexport ", callback_wname, " ", callback_wname, "\n", NULL); - Printv(f_gc_wrappers, "#pragma cgo_export_static ", callback_wname, " ", callback_wname, "\n", NULL); - Printv(f_gc_wrappers, "#pragma textflag 7\n", NULL); - Printv(f_gc_wrappers, "extern void \xc2\xb7", callback_name, "();\n", NULL); - Printv(f_gc_wrappers, "void\n", NULL); - Printv(f_gc_wrappers, callback_wname, "(void *a, int32 n)\n", NULL); - Printv(f_gc_wrappers, "{\n", NULL); - Printv(f_gc_wrappers, "\truntime\xc2\xb7" "cgocallback(\xc2\xb7", callback_name, ", a, n);\n", NULL); - Printv(f_gc_wrappers, "}\n\n", NULL); - } else { - if (SwigType_type(result) != T_VOID) { - String *r = NewString(Swig_cresult_name()); - String *tm = gccgoCTypeForGoValue(n, result, r); - Wrapper_add_local(w, r, tm); - Delete(tm); - Delete(r); - } - - String *args = NewString(""); - - Parm *p = parms; - while (p) { - while (checkAttribute(p, "tmap:directorin:numinputs", "0")) { - p = Getattr(p, "tmap:directorin:next"); - } - - String *pn = NewString("g"); - Append(pn, Getattr(p, "lname")); - Setattr(p, "emit:directorinput", pn); - - String *tm = gccgoCTypeForGoValue(n, Getattr(p, "type"), pn); - Wrapper_add_local(w, pn, tm); - Delete(tm); - - tm = Getattr(p, "tmap:directorin"); - if (!tm) { - Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, - line_number, "Unable to use type %s as director method argument\n", SwigType_str(Getattr(p, "type"), 0)); - } else { - tm = Copy(tm); - Replaceall(tm, "$input", pn); - Replaceall(tm, "$owner", 0); - Printv(w->code, " ", tm, "\n", NULL); - Delete(tm); - - Printv(args, ", ", pn, NULL); - } - - p = Getattr(p, "tmap:directorin:next"); - } - - Printv(w->code, " ", NULL); - if (SwigType_type(result) != T_VOID) { - Printv(w->code, Swig_cresult_name(), " = ", NULL); - } - Printv(w->code, callback_wname, "(go_val", args, ");\n", NULL); - - /* Marshal outputs */ - for (p = parms; p;) { - String *tm; - if ((tm = Getattr(p, "tmap:directorargout"))) { - tm = Copy(tm); - Replaceall(tm, "$result", "jresult"); - Replaceall(tm, "$input", Getattr(p, "emit:directorinput")); - Printv(w->code, tm, "\n", NIL); - Delete(tm); - p = Getattr(p, "tmap:directorargout:next"); - } else { - p = nextSibling(p); - } - } - - if (SwigType_type(result) != T_VOID) { - String *result_str = NewString("c_result"); - String *tm = Swig_typemap_lookup("directorout", n, result_str, NULL); - if (!tm) { - Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, - "Unable to use type %s as director method result\n", SwigType_str(result, 0)); - } else { - Replaceall(tm, "$input", Swig_cresult_name()); - Replaceall(tm, "$result", "c_result"); - Printv(w->code, " ", tm, "\n", NULL); - String *retstr = SwigType_rcaststr(result, "c_result"); - Printv(w->code, " return ", retstr, ";\n", NULL); - Delete(retstr); - Delete(tm); - } - Delete(result_str); - } - } - - Delete(callback_wname); - } - - /* ------------------------------------------------------------ - * makeDirectorMethodWrapper - * - * Emit the function wrapper for a director method for cgo. - * ------------------------------------------------------------ */ - - void makeCgoDirectorMethodWrapper(Node *n, Wrapper *w, String *callback_name) { ParmList *parms = Getattr(n, "wrap:parms"); SwigType *result = Getattr(n, "type"); From 6ca5d5d722b07977cd2865337d4a9e6cf6d75d5f Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 15 Sep 2021 17:56:01 -0700 Subject: [PATCH 016/262] swig -go: don't use crosscall2 for panicking Instead rely only on documented and exported interfaces. --- Lib/go/goruntime.swg | 53 +------------------------------------------ Source/Modules/go.cxx | 31 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 52 deletions(-) diff --git a/Lib/go/goruntime.swg b/Lib/go/goruntime.swg index 667cc35ca..c3401b1a8 100644 --- a/Lib/go/goruntime.swg +++ b/Lib/go/goruntime.swg @@ -88,52 +88,7 @@ typedef struct { void* array; intgo len; intgo cap; } _goslice_; %} -#ifndef SWIGGO_GCCGO -/* Boilerplate for C/C++ code when using 6g/8g. This code is compiled - with gcc. */ -%insert(runtime) %{ - -#define swiggo_size_assert_eq(x, y, name) typedef char name[(x-y)*(x-y)*-2+1]; -#define swiggo_size_assert(t, n) swiggo_size_assert_eq(sizeof(t), n, swiggo_sizeof_##t##_is_not_##n) - -swiggo_size_assert(char, 1) -swiggo_size_assert(short, 2) -swiggo_size_assert(int, 4) -typedef long long swiggo_long_long; -swiggo_size_assert(swiggo_long_long, 8) -swiggo_size_assert(float, 4) -swiggo_size_assert(double, 8) - -#ifdef __cplusplus -extern "C" { -#endif -extern void crosscall2(void (*fn)(void *, int), void *, int); -extern char* _cgo_topofstack(void) __attribute__ ((weak)); -extern void _cgo_allocate(void *, int); -extern void _cgo_panic(void *, int); -#ifdef __cplusplus -} -#endif - -static char *_swig_topofstack() { - if (_cgo_topofstack) { - return _cgo_topofstack(); - } else { - return 0; - } -} - -static void _swig_gopanic(const char *p) { - struct { - const char *p; - } SWIGSTRUCTPACKED a; - a.p = p; - crosscall2(_cgo_panic, &a, (int) sizeof a); -} - -%} - -#else +#ifdef SWIGGO_GCCGO /* Boilerplate for C/C++ code when using gccgo. */ %insert(runtime) %{ @@ -154,12 +109,6 @@ extern void _cgo_panic(const char *); #endif -%insert(runtime) %{ - -#define SWIG_contract_assert(expr, msg) \ - if (!(expr)) { _swig_gopanic(msg); } else -%} - #ifndef SWIGGO_GCCGO %go_import("unsafe", _ "runtime/cgo") diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 2b5261f14..7c6c7d3ff 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -637,6 +637,37 @@ private: Printv(f_cgo_comment, "import \"C\"\n", NULL); Printv(f_cgo_comment, "\n", NULL); + bool need_panic = false; + if (Strstr(f_c_runtime, "SWIG_contract_assert(") != 0 || Strstr(f_c_wrappers, "SWIG_contract_assert(") != 0) { + Printv(f_c_begin, "\n#define SWIG_contract_assert(expr, msg) if (!(expr)) { _swig_gopanic(msg); } else\n\n", NULL); + need_panic = true; + } + + if (!gccgo_flag && (need_panic || Strstr(f_c_runtime, "_swig_gopanic") != 0 || Strstr(f_c_wrappers, "_swig_gopanic") != 0)) { + Printv(f_go_header, "//export cgo_panic_", unique_id, "\n", NULL); + Printv(f_go_header, "func cgo_panic_", unique_id, "(p *byte) {\n", NULL); + Printv(f_go_header, "\ts := (*[1024]byte)(unsafe.Pointer(p))[:]\n", NULL); + Printv(f_go_header, "\tvar i int\n", NULL); + Printv(f_go_header, "\tvar b byte\n", NULL); + Printv(f_go_header, "\tfor i, b = range s {\n", NULL); + Printv(f_go_header, "\t\tif b == 0 {\n", NULL); + Printv(f_go_header, "\t\t\ti--\n", NULL); + Printv(f_go_header, "\t\t\tbreak\n", NULL); + Printv(f_go_header, "\t\t}\n", NULL); + Printv(f_go_header, "\t}\n", NULL); + Printv(f_go_header, "\tpanic(string(s[:i+1]))\n", NULL); + Printv(f_go_header, "}\n\n", NULL); + + Printv(f_c_begin, "\nextern\n", NULL); + Printv(f_c_begin, "#ifdef __cplusplus\n", NULL); + Printv(f_c_begin, " \"C\"\n", NULL); + Printv(f_c_begin, "#endif\n", NULL); + Printv(f_c_begin, " void cgo_panic_", unique_id, "(const char*);\n", NULL); + Printv(f_c_begin, "static void _swig_gopanic(const char *p) {\n", NULL); + Printv(f_c_begin, " cgo_panic_", unique_id, "(p);\n", NULL); + Printv(f_c_begin, "}\n\n", NULL); + } + Dump(f_c_runtime, f_c_begin); Dump(f_c_wrappers, f_c_begin); Dump(f_c_init, f_c_begin); From 45ebd33698e79c7b0bfb9448b1cbb13f1a425a80 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 16 Sep 2021 10:29:48 -0700 Subject: [PATCH 017/262] swig -go: improve _cgo_panic implementation --- Source/Modules/go.cxx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 7c6c7d3ff..c4d61e583 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -647,15 +647,12 @@ private: Printv(f_go_header, "//export cgo_panic_", unique_id, "\n", NULL); Printv(f_go_header, "func cgo_panic_", unique_id, "(p *byte) {\n", NULL); Printv(f_go_header, "\ts := (*[1024]byte)(unsafe.Pointer(p))[:]\n", NULL); - Printv(f_go_header, "\tvar i int\n", NULL); - Printv(f_go_header, "\tvar b byte\n", NULL); - Printv(f_go_header, "\tfor i, b = range s {\n", NULL); + Printv(f_go_header, "\tfor i, b := range s {\n", NULL); Printv(f_go_header, "\t\tif b == 0 {\n", NULL); - Printv(f_go_header, "\t\t\ti--\n", NULL); - Printv(f_go_header, "\t\t\tbreak\n", NULL); + Printv(f_go_header, "\t\t\tpanic(string(s[:i]))\n", NULL); Printv(f_go_header, "\t\t}\n", NULL); Printv(f_go_header, "\t}\n", NULL); - Printv(f_go_header, "\tpanic(string(s[:i+1]))\n", NULL); + Printv(f_go_header, "\tpanic(string(s))\n", NULL); Printv(f_go_header, "}\n\n", NULL); Printv(f_c_begin, "\nextern\n", NULL); From 561a1d843d5877ec06265a6dbc96eefef5d0a945 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 20 Sep 2021 15:04:51 +1200 Subject: [PATCH 018/262] Fix ODR violations Detected by compiling with GCC flags `-flto -Wodr`. --- Source/Modules/overload.cxx | 2 ++ Source/Modules/python.cxx | 3 ++- Source/Modules/r.cxx | 3 ++- Source/Modules/ruby.cxx | 2 ++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Source/Modules/overload.cxx b/Source/Modules/overload.cxx index 512c5da39..8a4ce48f7 100644 --- a/Source/Modules/overload.cxx +++ b/Source/Modules/overload.cxx @@ -21,6 +21,7 @@ String *argv_template_string; String *argc_template_string; +namespace { struct Overloaded { Node *n; /* Node */ int argc; /* Argument count */ @@ -28,6 +29,7 @@ struct Overloaded { int error; /* Ambiguity error */ bool implicitconv_function; /* For ordering implicitconv functions*/ }; +} static int fast_dispatch_mode = 0; static int cast_dispatch_mode = 0; diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 6bc7ef737..7d618635e 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -93,6 +93,7 @@ static int nortti = 0; static int relativeimport = 0; /* flags for the make_autodoc function */ +namespace { enum autodoc_t { AUTODOC_CLASS, AUTODOC_CTOR, @@ -103,7 +104,7 @@ enum autodoc_t { AUTODOC_CONST, AUTODOC_VAR }; - +} static const char *usage1 = "\ Python Options (available with -python)\n\ diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index b3f109fc0..99db2275f 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -1301,13 +1301,14 @@ void R::addAccessor(String *memberName, Wrapper *wrapper, String *name, #define MAX_OVERLOAD 256 +namespace { struct Overloaded { Node *n; /* Node */ int argc; /* Argument count */ ParmList *parms; /* Parameters used for overload check */ int error; /* Ambiguity error */ }; - +} List * R::Swig_overload_rank(Node *n, bool script_lang_wrapping) { diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index bb4d19d91..ec4a75dbd 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -116,6 +116,7 @@ public: /* flags for the make_autodoc function */ +namespace { enum autodoc_t { AUTODOC_CLASS, AUTODOC_CTOR, @@ -127,6 +128,7 @@ enum autodoc_t { AUTODOC_SETTER, AUTODOC_NONE }; +} static const char *usage = "\ Ruby Options (available with -ruby)\n\ From acc41e3ffff48da356acf64484ba05fce0ba5605 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 24 Sep 2021 15:16:09 +0100 Subject: [PATCH 019/262] Add missing Go improvements to changes file --- CHANGES.current | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 9ab912b15..a118132f8 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,16 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2021-09-16: ianlancetaylor + [Go] Improved _cgo_panic implementation. + +2021-09-16: ianlancetaylor + [Go] Don't use crosscall2 for panicking. Instead rely on documented + and exported interfaces. + +2021-09-14: ianlancetaylor + [Go] Remove -no-cgo option (long unsupported in Go) + 2021-05-04: olly [PHP] #2014 Throw PHP exceptions instead of using PHP errors From 067d927cb188bad8003a5d68b9a03d86f4b3b264 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Sep 2021 16:53:40 +0200 Subject: [PATCH 020/262] Skip running CI for the changes to the files not affecting it Note that if we decide to do something for the docs later (e.g. run a spell checker on them), it should be done in a separate workflow and not in this one. --- .github/workflows/ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6e6519b7..5d2ddbedd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,8 +3,14 @@ name: CI on: push: branches: master + paths-ignore: + - 'CHANGES*' + - 'Doc/**' pull_request: branches: master + paths-ignore: + - 'CHANGES*' + - 'Doc/**' jobs: build: From 5d9bbea51041b9a70a8fc9d91f1faeb5d58b0772 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Sep 2021 17:00:24 +0200 Subject: [PATCH 021/262] Default to Ubuntu 20.04 if OS is not specified This makes the matrix more compact, as we don't need to specify the OS for the majority of the field (all of them now, but we'll add builds using "macos-N" later, so it will still be necessary for some of them), and the builds more stable than using which the current latest Ubuntu version is. --- .github/workflows/ci.yml | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d2ddbedd..562023f8e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,8 @@ on: jobs: build: - runs-on: ${{ matrix.os }} + runs-on: ${{ matrix.os || 'ubuntu-20.04' }} + strategy: matrix: #SWIGJOBS: ["-j2"] @@ -27,18 +28,14 @@ jobs: # PY3,VER # SWIG_FEATURES include: - - os: ubuntu-latest - CPP11: 1 + - CPP11: 1 SWIGLANG: "" - - os: ubuntu-latest - CPP11: 1 + - CPP11: 1 SWIGLANG: python - - os: ubuntu-latest - CPP11: 1 + - CPP11: 1 SWIGLANG: python PY3: 3 - - os: ubuntu-latest - CPP11: 1 + - CPP11: 1 SWIGLANG: tcl # let's run all of them, as opposed to aborting when one fails fail-fast: false @@ -50,7 +47,7 @@ jobs: - name: ccache uses: hendrikmuhs/ccache-action@v1 with: - key: ${{ matrix.os }}-${{ matrix.SWIGLANG }} + key: ${{ matrix.os || 'ubuntu-20.04' }}-${{ matrix.SWIGLANG }} - name: configure shell: bash env: From a2ff01a910665004948301feb5b0d05b41fad1a8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Sep 2021 17:07:52 +0200 Subject: [PATCH 022/262] Use better names for the CI builds Don't rely on the auto-generated names which are not very useful: e.g. currently something like "build (1, python, 3)" is shown, while this commit changes it to just "python3" which is both shorter and more readable. --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 562023f8e..c21dc3fe1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,11 @@ jobs: runs-on: ${{ matrix.os || 'ubuntu-20.04' }} + # By default, the name of the build is just the language used, but matrix + # entries can define the additional "desc" field with any additional + # information to include in the name. + name: ${{ matrix.SWIGLANG || 'none' }}${{ matrix.PY3 }} ${{ matrix.desc }} + strategy: matrix: #SWIGJOBS: ["-j2"] From bbfdedc18b85ddd5507a4d22f107219a384835ee Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Sep 2021 17:13:33 +0200 Subject: [PATCH 023/262] Define all environment variables at job level There doesn't seem to be any reason to make them step-specific, so simplify the workflow by doing it once and only once at the job level. No real changes. --- .github/workflows/ci.yml | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c21dc3fe1..943d6745f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,17 @@ jobs: # let's run all of them, as opposed to aborting when one fails fail-fast: false + env: + SWIGLANG: ${{ matrix.SWIGLANG }} + SWIGJOBS: ${{ matrix.SWIGJOBS }} + SWIG_FEATURES: ${{ matrix.SWIG_FEATURES }} + CONFIGOPTS: ${{ matrix.CONFIGOPTS }} + CC: ${{ matrix.CC }} + CSTD: ${{ matrix.CSTD }} + CPP11: ${{ matrix.CPP11 }} + CPP14: ${{ matrix.CPP14 }} + CPP17: ${{ matrix.CPP17 }} + steps: - uses: actions/checkout@v2 with: @@ -55,10 +66,6 @@ jobs: key: ${{ matrix.os || 'ubuntu-20.04' }}-${{ matrix.SWIGLANG }} - name: configure shell: bash - env: - SWIGLANG: ${{ matrix.SWIGLANG }} - CONFIGOPTS: ${{ matrix.CONFIGOPTS }} - CC: ${{ matrix.CC }} run: | set -ex export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" @@ -72,9 +79,6 @@ jobs: - name: build shell: bash - env: - SWIGLANG: ${{ matrix.SWIGLANG }} - SWIGJOBS: ${{ matrix.SWIGJOBS }} run: | set -ex cd ${GITHUB_WORKSPACE}/build/build; @@ -86,15 +90,6 @@ jobs: if test -z "$SWIGLANG"; then sudo make -s install && swig -version && ccache-swig -V; fi - name: tests shell: bash - env: - SWIGLANG: ${{ matrix.SWIGLANG }} - SWIGJOBS: ${{ matrix.SWIGJOBS }} - SWIG_FEATURES: ${{ matrix.SWIG_FEATURES }} - CC: ${{ matrix.CC }} - CSTD: ${{ matrix.CSTD }} - CPP11: ${{ matrix.CPP11 }} - CPP14: ${{ matrix.CPP14 }} - CPP17: ${{ matrix.CPP17 }} run: | set -ex cd ${GITHUB_WORKSPACE}/build/build; From 7692d5f9ecc0c051ea7c0201572f8c4c71955c0c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Sep 2021 17:17:10 +0200 Subject: [PATCH 024/262] Set SWIGJOBS environment variable automatically Use the number of available CPUs + 1 which seems to work best with the number of actually available CPUs in the GitHub Actions environment. --- .github/workflows/ci.yml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 943d6745f..df9746c61 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,6 @@ jobs: strategy: matrix: - #SWIGJOBS: ["-j2"] # other variables to optionally set # CC, GCC (used as suffix) # CPP11, CPP14, CPP17 @@ -47,7 +46,6 @@ jobs: env: SWIGLANG: ${{ matrix.SWIGLANG }} - SWIGJOBS: ${{ matrix.SWIGJOBS }} SWIG_FEATURES: ${{ matrix.SWIG_FEATURES }} CONFIGOPTS: ${{ matrix.CONFIGOPTS }} CC: ${{ matrix.CC }} @@ -77,6 +75,22 @@ jobs: echo "${CONFIGOPTS[@]}" ./autogen.sh && mkdir -p build/build && cd build/build && ../../configure "${CONFIGOPTS[@]}" + case $(uname) in + Linux) + cpu_count=$(nproc) + ;; + + Darwin) + cpu_count=$(sysctl -n hw.ncpu) + ;; + + *) + cpu_count=0 + ;; + esac + ((cpu_count++)) + echo SWIGJOBS=-j$cpu_count >> $GITHUB_ENV + - name: build shell: bash run: | From 9156f390ae0137806cacab4bac345805f727976e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Sep 2021 17:18:05 +0200 Subject: [PATCH 025/262] Don't set shell explicitly for the build steps Bash is used by default under all platforms we're going to support here, so there is no need to specify it explicitly. Moreover, by default the appropriate shell options (such as "pipefail", as well as "e") are used, and there is no need to override them. --- .github/workflows/ci.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index df9746c61..d0c7d0041 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,9 +63,8 @@ jobs: with: key: ${{ matrix.os || 'ubuntu-20.04' }}-${{ matrix.SWIGLANG }} - name: configure - shell: bash run: | - set -ex + set -x export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" source Tools/GHA-linux-install.sh if test -n "$CPP11"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++11 $CXXFLAGS" "CFLAGS=-std=c11 $CFLAGS") && export CSTD=c11 && export CPPSTD=c++11; fi @@ -92,9 +91,8 @@ jobs: echo SWIGJOBS=-j$cpu_count >> $GITHUB_ENV - name: build - shell: bash run: | - set -ex + set -x cd ${GITHUB_WORKSPACE}/build/build; make -s $SWIGJOBS ./swig -version && ./swig -pcreversion @@ -103,9 +101,8 @@ jobs: echo 'Installing...' if test -z "$SWIGLANG"; then sudo make -s install && swig -version && ccache-swig -V; fi - name: tests - shell: bash run: | - set -ex + set -x cd ${GITHUB_WORKSPACE}/build/build; if test -n "$CPP11"; then export CPPSTD=c++11; fi if test -n "$CPP14"; then export CPPSTD=c++14; fi From 542bc18b0f9ac6ebd3641247693ab91021343f43 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Sep 2021 17:24:54 +0200 Subject: [PATCH 026/262] Use working directory step option instead of explicit "cd" This seems simpler and more explicit ("cd" is easy to miss or forget). --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d0c7d0041..e0042d0d2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -91,9 +91,9 @@ jobs: echo SWIGJOBS=-j$cpu_count >> $GITHUB_ENV - name: build + working-directory: build/build run: | set -x - cd ${GITHUB_WORKSPACE}/build/build; make -s $SWIGJOBS ./swig -version && ./swig -pcreversion if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-ccache; fi @@ -101,9 +101,9 @@ jobs: echo 'Installing...' if test -z "$SWIGLANG"; then sudo make -s install && swig -version && ccache-swig -V; fi - name: tests + working-directory: build/build run: | set -x - cd ${GITHUB_WORKSPACE}/build/build; if test -n "$CPP11"; then export CPPSTD=c++11; fi if test -n "$CPP14"; then export CPPSTD=c++14; fi if test -n "$CPP17"; then export CPPSTD=c++17; fi From 1395b902bef2cfbdda03f01616e94503ba792b84 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Sep 2021 17:25:25 +0200 Subject: [PATCH 027/262] Re-add "clean" step of the build This was used with Travis CI, so there doesn't seem to be any reason not to use it with GitHub Actions too. --- .github/workflows/ci.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e0042d0d2..c9d4a8078 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -114,6 +114,9 @@ jobs: if test -n "$SWIGLANG"; then make check-$SWIGLANG-enabled; fi if test -n "$SWIGLANG"; then make $SWIGJOBS check-$SWIGLANG-examples CFLAGS="$cflags" CXXFLAGS="$cxxflags"; fi if test -n "$SWIGLANG"; then make $SWIGJOBS check-$SWIGLANG-test-suite CFLAGS="$cflags" CXXFLAGS="$cxxflags"; fi - #echo 'Cleaning...' - # Skip on osx as often fails with: rm: Resource temporarily unavailable - #if test "$TRAVIS_OS_NAME" != "osx"; then make check-maintainer-clean && ../../configure $CONFIGOPTS; fi + + - name: clean + working-directory: build/build + run: | + set -x + make check-maintainer-clean && ../../configure $CONFIGOPTS From 0c46a3024954f6f4b84e6ed8619a993fd3d448f0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Sep 2021 17:27:40 +0200 Subject: [PATCH 028/262] Use consistent names for the build steps Follow the convention of the GitHub built-in steps, such as the first "Set up job" one and use capitalized verbs in imperative mood rather than a mix of non-capitalized verbs and nouns. This is a purely cosmetic change. --- .github/workflows/ci.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c9d4a8078..c4f379dfd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,14 +55,17 @@ jobs: CPP17: ${{ matrix.CPP17 }} steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 with: submodules: recursive - - name: ccache + + - name: Install CCache uses: hendrikmuhs/ccache-action@v1 with: key: ${{ matrix.os || 'ubuntu-20.04' }}-${{ matrix.SWIGLANG }} - - name: configure + + - name: Configure run: | set -x export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" @@ -90,7 +93,7 @@ jobs: ((cpu_count++)) echo SWIGJOBS=-j$cpu_count >> $GITHUB_ENV - - name: build + - name: Build working-directory: build/build run: | set -x @@ -100,7 +103,8 @@ jobs: if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-errors-test-suite; fi echo 'Installing...' if test -z "$SWIGLANG"; then sudo make -s install && swig -version && ccache-swig -V; fi - - name: tests + + - name: Test working-directory: build/build run: | set -x @@ -115,7 +119,7 @@ jobs: if test -n "$SWIGLANG"; then make $SWIGJOBS check-$SWIGLANG-examples CFLAGS="$cflags" CXXFLAGS="$cxxflags"; fi if test -n "$SWIGLANG"; then make $SWIGJOBS check-$SWIGLANG-test-suite CFLAGS="$cflags" CXXFLAGS="$cxxflags"; fi - - name: clean + - name: Clean working-directory: build/build run: | set -x From 84b1b3f8b5724859142585e5a4a5f50ea01a2fbd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Sep 2021 17:29:38 +0200 Subject: [PATCH 029/262] Do not use "make -s" in the CI builds We want to have as much information as possible in case of the build failure, so don't use the "--silent" make option. --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c4f379dfd..b24c0c912 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -97,12 +97,12 @@ jobs: working-directory: build/build run: | set -x - make -s $SWIGJOBS + make $SWIGJOBS ./swig -version && ./swig -pcreversion - if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-ccache; fi - if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-errors-test-suite; fi + if test -z "$SWIGLANG"; then make $SWIGJOBS check-ccache; fi + if test -z "$SWIGLANG"; then make $SWIGJOBS check-errors-test-suite; fi echo 'Installing...' - if test -z "$SWIGLANG"; then sudo make -s install && swig -version && ccache-swig -V; fi + if test -z "$SWIGLANG"; then sudo make install && swig -version && ccache-swig -V; fi - name: Test working-directory: build/build @@ -114,7 +114,7 @@ jobs: # Stricter compile flags for examples. Various headers and SWIG generated code prevents full use of -pedantic. if test -n "$SWIGLANG"; then cflags=$($GITHUB_WORKSPACE/Tools/testflags.py --language $SWIGLANG --cflags --std=$CSTD --compiler=$CC) && echo $cflags; fi if test -n "$SWIGLANG"; then cxxflags=$($GITHUB_WORKSPACE/Tools/testflags.py --language $SWIGLANG --cxxflags --std=$CPPSTD --compiler=$CC) && echo $cxxflags; fi - if test -n "$SWIGLANG"; then make -s check-$SWIGLANG-version; fi + if test -n "$SWIGLANG"; then make check-$SWIGLANG-version; fi if test -n "$SWIGLANG"; then make check-$SWIGLANG-enabled; fi if test -n "$SWIGLANG"; then make $SWIGJOBS check-$SWIGLANG-examples CFLAGS="$cflags" CXXFLAGS="$cxxflags"; fi if test -n "$SWIGLANG"; then make $SWIGJOBS check-$SWIGLANG-test-suite CFLAGS="$cflags" CXXFLAGS="$cxxflags"; fi From 6088323e1431cc7b3fe7623cfe0e888f5a383137 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Sep 2021 17:38:24 +0200 Subject: [PATCH 030/262] Use ccache for building, not just configuring Set the PATH to include the ccache directory for the subsequent steps, including the "build" one, rather than only setting it locally for configure, as this didn't have much effect at all. --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b24c0c912..705c753fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,6 +69,8 @@ jobs: run: | set -x export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" + echo PATH="$PATH" >> $GITHUB_ENV + source Tools/GHA-linux-install.sh if test -n "$CPP11"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++11 $CXXFLAGS" "CFLAGS=-std=c11 $CFLAGS") && export CSTD=c11 && export CPPSTD=c++11; fi if test -n "$CPP14"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++14 $CXXFLAGS" "CFLAGS=-std=c11 $CFLAGS") && export CSTD=c11 && export CPPSTD=c++14; fi From dbb85de9cd73b4ae9df786264228cdc31f507de3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Sep 2021 17:39:23 +0200 Subject: [PATCH 031/262] Use the same ccache cache key for all languages but not compilers There doesn't seem to be any good reason to use per-language caches, as there are files that are common to all languages. But we do want to use different keys for the different compilers and even different compiler versions, as they yield different results when compiling the same code. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 705c753fb..32267499d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,7 +63,7 @@ jobs: - name: Install CCache uses: hendrikmuhs/ccache-action@v1 with: - key: ${{ matrix.os || 'ubuntu-20.04' }}-${{ matrix.SWIGLANG }} + key: ${{ matrix.os || 'ubuntu-20.04' }}-${{ matrix.CC || 'gcc' }}${{ matrix.GCC }} - name: Configure run: | From a6300299bf44a5482939c2b5746ab725c9c96a63 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Sep 2021 17:56:02 +0200 Subject: [PATCH 032/262] Add builds with other gcc versions and clang Also remove a not really useful comment mentioning the variables already used in the matrix mixed up with those not used yet. --- .github/workflows/ci.yml | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 32267499d..3e4d16162 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,16 +24,24 @@ jobs: strategy: matrix: - # other variables to optionally set - # CC, GCC (used as suffix) - # CPP11, CPP14, CPP17 - # CONFIGOPTS - # SWIGLANG - # PY3,VER - # SWIG_FEATURES include: - - CPP11: 1 - SWIGLANG: "" + - SWIGLANG: "" + desc: gcc + - SWIGLANG: "" + GCC: 7 + desc: gcc7 + - SWIGLANG: "" + GCC: 8 + desc: gcc8 + - SWIGLANG: "" + GCC: 9 + desc: gcc9 + - SWIGLANG: "" + GCC: 10 + desc: gcc10 + - SWIGLANG: "" + CC: clang + desc: clang - CPP11: 1 SWIGLANG: python - CPP11: 1 From 55dfa99e4926efaba8bbdb9bb9ea085b3f75114b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Sep 2021 18:11:44 +0200 Subject: [PATCH 033/262] Define CC and CXX environment variables correctly They are supposed to be set to gcc-$GCC and g++-$GCC respectively, if the suffix is defined, so do it. Also use "compiler", rather than "CC", in the matrix for consistency with .travis.yml and to avoid confusion between this property, which may be empty, and CC environment variable, which is supposed to be always defined. Finally, show the path and the version of the compiler being used: this was also done under Travis CI and there doesn't seem to be any reason not to do it here. --- .github/workflows/ci.yml | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3e4d16162..7db336f53 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,7 +40,7 @@ jobs: GCC: 10 desc: gcc10 - SWIGLANG: "" - CC: clang + compiler: clang desc: clang - CPP11: 1 SWIGLANG: python @@ -56,7 +56,6 @@ jobs: SWIGLANG: ${{ matrix.SWIGLANG }} SWIG_FEATURES: ${{ matrix.SWIG_FEATURES }} CONFIGOPTS: ${{ matrix.CONFIGOPTS }} - CC: ${{ matrix.CC }} CSTD: ${{ matrix.CSTD }} CPP11: ${{ matrix.CPP11 }} CPP14: ${{ matrix.CPP14 }} @@ -71,7 +70,7 @@ jobs: - name: Install CCache uses: hendrikmuhs/ccache-action@v1 with: - key: ${{ matrix.os || 'ubuntu-20.04' }}-${{ matrix.CC || 'gcc' }}${{ matrix.GCC }} + key: ${{ matrix.os || 'ubuntu-20.04' }}-${{ matrix.compiler || 'gcc' }}${{ matrix.GCC }} - name: Configure run: | @@ -80,6 +79,28 @@ jobs: echo PATH="$PATH" >> $GITHUB_ENV source Tools/GHA-linux-install.sh + + if test '${{ matrix.compiler }}' = 'clang'; then + CC="clang" + CXX="clang++" + elif test -n "$GCC"; then + CC="gcc-$GCC" + CXX="g++-$GCC" + else + CC="gcc" + CXX="g++" + fi + + export CC CXX + + echo CC="$CC" >> $GITHUB_ENV + echo CXX="$CXX" >> $GITHUB_ENV + + echo "Compiler used:" + ls -la $(which $CC) $(which $CXX) + $CC --version + $CXX --version + if test -n "$CPP11"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++11 $CXXFLAGS" "CFLAGS=-std=c11 $CFLAGS") && export CSTD=c11 && export CPPSTD=c++11; fi if test -n "$CPP14"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++14 $CXXFLAGS" "CFLAGS=-std=c11 $CFLAGS") && export CSTD=c11 && export CPPSTD=c++14; fi if test -n "$CPP17"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++17 $CXXFLAGS" "CFLAGS=-std=c17 $CFLAGS") && export CSTD=c17 && export CPPSTD=c++17; fi From 6c2a4607f0d0b20875ae586a56821107b3b40340 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Sep 2021 18:12:50 +0200 Subject: [PATCH 034/262] Use -fPIE for clang builds Executables can't be produced without this option using clang available under Ubuntu 20.04, as linking fails with a lot of errors of the form /usr/bin/ld: Swig/wrapfunc.o: relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIE --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7db336f53..1403c149f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,6 +83,9 @@ jobs: if test '${{ matrix.compiler }}' = 'clang'; then CC="clang" CXX="clang++" + + CFLAGS="$CFLAGS -fPIE" + CXXFLAGS="$CXXFLAGS -fPIE" elif test -n "$GCC"; then CC="gcc-$GCC" CXX="g++-$GCC" From 07d1ababcc61bc1869203b37498aa0f7d1211013 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Sep 2021 20:01:15 +0200 Subject: [PATCH 035/262] Remove explicit CPP11 from matrix entries not needing it This actually decreases the C++ version used by the default Ubuntu 20.04 compilers, so it's not clear why should we be using it. --- .github/workflows/ci.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1403c149f..8815de117 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,13 +42,10 @@ jobs: - SWIGLANG: "" compiler: clang desc: clang - - CPP11: 1 - SWIGLANG: python - - CPP11: 1 - SWIGLANG: python + - SWIGLANG: python + - SWIGLANG: python PY3: 3 - - CPP11: 1 - SWIGLANG: tcl + - SWIGLANG: tcl # let's run all of them, as opposed to aborting when one fails fail-fast: false From b77b90da889088ff5e9bfa783315ba350ee93e94 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Sep 2021 20:04:49 +0200 Subject: [PATCH 036/262] Define PY3 environment variable if necessary This fixes handling Python 2 and 3 builds in the same way. --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8815de117..b9a5c4c81 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,6 +51,7 @@ jobs: env: SWIGLANG: ${{ matrix.SWIGLANG }} + PY3: ${{ matrix.PY3 }} SWIG_FEATURES: ${{ matrix.SWIG_FEATURES }} CONFIGOPTS: ${{ matrix.CONFIGOPTS }} CSTD: ${{ matrix.CSTD }} From 576e8317ff9f9530a79e6254355538dbe24cc294 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Sep 2021 20:33:47 +0200 Subject: [PATCH 037/262] Don't set CONFIGOPTS to empty string initially This results in passing empty argument to configure which, in turn, triggers "WARNING: you should use --build, --host, --target" from it as this argument is apparently misinterpreted as the host name. --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b9a5c4c81..cc9263912 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,7 +53,6 @@ jobs: SWIGLANG: ${{ matrix.SWIGLANG }} PY3: ${{ matrix.PY3 }} SWIG_FEATURES: ${{ matrix.SWIG_FEATURES }} - CONFIGOPTS: ${{ matrix.CONFIGOPTS }} CSTD: ${{ matrix.CSTD }} CPP11: ${{ matrix.CPP11 }} CPP14: ${{ matrix.CPP14 }} @@ -102,6 +101,9 @@ jobs: $CC --version $CXX --version + if test -n '${{ matrix.CONFIGOPTS }}'; then + CONFIGOPTS=${{ matrix.CONFIGOPTS }} + fi if test -n "$CPP11"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++11 $CXXFLAGS" "CFLAGS=-std=c11 $CFLAGS") && export CSTD=c11 && export CPPSTD=c++11; fi if test -n "$CPP14"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++14 $CXXFLAGS" "CFLAGS=-std=c11 $CFLAGS") && export CSTD=c11 && export CPPSTD=c++14; fi if test -n "$CPP17"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++17 $CXXFLAGS" "CFLAGS=-std=c17 $CFLAGS") && export CSTD=c17 && export CPPSTD=c++17; fi From 1f7cd009c950a5ab1291834217eb5daa838c0624 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 1 Oct 2021 01:01:29 +0200 Subject: [PATCH 038/262] Remove unnecessary warning triggering copy ctors from the test Defining a copy ctor results in -Werror=deprecated-copy when using implicitly-generated assignment operator with recent gcc versions, so simply remove this copy ctor, which was apparently never needed anyhow, to avoid it and rely on the compiler generating both the copy ctor and assignment operator implicitly. --- Examples/test-suite/director_nspace.i | 2 -- 1 file changed, 2 deletions(-) diff --git a/Examples/test-suite/director_nspace.i b/Examples/test-suite/director_nspace.i index f24227c68..016f61ddf 100644 --- a/Examples/test-suite/director_nspace.i +++ b/Examples/test-suite/director_nspace.i @@ -15,7 +15,6 @@ namespace TopLevel class FooBar { public: FooBar() {} - FooBar(const FooBar&) {} virtual ~FooBar() {} std::string FooBarDo() { return "Bar::Foo2::Foo2Bar()"; } @@ -56,7 +55,6 @@ namespace TopLevel class FooBar { public: FooBar(); - FooBar(const FooBar&); virtual ~FooBar(); std::string FooBarDo(); From f0b301044013b3764a378bcd0b5e63ac1f42bcc1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 1 Oct 2021 01:06:01 +0200 Subject: [PATCH 039/262] Avoid another warning about deprecated implicit copy ctor This is similar to the previous commit, but in the other direction, with the warning being generated for the implicitly-declared copy ctor due to having an explicitly-declared assignment operator. And the fix is different too because we need to have an assignment operator in this test, so define the copy ctor explicitly too. --- Examples/test-suite/private_assign.i | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Examples/test-suite/private_assign.i b/Examples/test-suite/private_assign.i index acc4d0bc9..d9ba70cf4 100644 --- a/Examples/test-suite/private_assign.i +++ b/Examples/test-suite/private_assign.i @@ -14,6 +14,8 @@ return *this; } public: + Foo() { } + Foo(const Foo &f) { } // copy ctor can still be public, however. void bar() { } }; From 58a49bac66cf52b6015bf835d820c45a6c45ac25 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 1 Oct 2021 01:13:28 +0200 Subject: [PATCH 040/262] Suppress more -Wignored-qualifiers in JavaScript tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is probably not the greatest idea, and it would be better to change the generated code to avoid these tests instead, but it was already done like this for several tests, so just add two more of them that generate warnings such as ../../member_funcptr_galore_wrap.cxx: In function ‘SwigV8ReturnValue _wrap_MemberFuncPtrs_aaa6(const SwigV8Arguments&)’: ../../member_funcptr_galore_wrap.cxx:3495:90: error: type qualifiers ignored on cast result type [-Werror=ignored-qualifiers] 3495 | result = (int)((MemberFuncPtrs const *)arg1)->aaa6((short (Funcs::*const )(bool) const)arg2); | ^~~~ when using gcc 9. --- Examples/test-suite/javascript/Makefile.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Examples/test-suite/javascript/Makefile.in b/Examples/test-suite/javascript/Makefile.in index 93602a434..9de151087 100644 --- a/Examples/test-suite/javascript/Makefile.in +++ b/Examples/test-suite/javascript/Makefile.in @@ -57,8 +57,10 @@ ifeq (node,$(JSENGINE)) # dunno... ignoring generously apply_signed_char.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\" constant_pointers.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\" + cpp11_ref_qualifiers.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\" director_basic.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\" enum_thorough.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\" + member_funcptr_galore.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\" setup_node = \ test -d $* || mkdir $* && \ From 4b05d8d9473cb8e1fd3a6af6c80aead157c6a9ee Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 1 Oct 2021 01:55:25 +0200 Subject: [PATCH 041/262] Don't run ccomplextest as part of JavaScript test suite This test currently fails due to "I" being undefined, so disable it to let the rest of the tests to pass and add it later when this can be fixed. --- Examples/test-suite/javascript/Makefile.in | 3 --- 1 file changed, 3 deletions(-) diff --git a/Examples/test-suite/javascript/Makefile.in b/Examples/test-suite/javascript/Makefile.in index 9de151087..0e11f3d9d 100644 --- a/Examples/test-suite/javascript/Makefile.in +++ b/Examples/test-suite/javascript/Makefile.in @@ -13,9 +13,6 @@ srcdir = @srcdir@ top_srcdir = @top_srcdir@ top_builddir = @top_builddir@ -C_TEST_CASES += \ - ccomplextest \ - CPP_TEST_CASES += \ javascript_lib_arrays \ From 11c876063926b8998cf6b8fafc0a4a5932b4a189 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Sep 2021 20:55:07 +0200 Subject: [PATCH 042/262] Install rvm in CI setup script if it's not available It is not available out of the box in GitHub environment, unlike under Travis CI, so install it ourselves. Note that we do it manually because installing the rael-gc/rvm PPA doesn't seem to work with weird failures in GitHub Actions environment. We also can't use gpg2 --recv-keys in this environment as it doesn't work, apparently due to a firewall. --- Tools/CI-linux-install.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Tools/CI-linux-install.sh b/Tools/CI-linux-install.sh index 0ce8f1203..ab5b10ddb 100644 --- a/Tools/CI-linux-install.sh +++ b/Tools/CI-linux-install.sh @@ -96,6 +96,20 @@ case "$SWIGLANG" in $RETRY sudo apt-get -qq install r-base ;; "ruby") + if ! command -v rvm; then + case "$VER" in + 1.9 | 2.0 | 2.1 | 2.2 | 2.3 ) + $RETRY sudo apt-get -qq install libgdbm-dev libncurses5-dev libyaml-dev libssl1.0-dev + ;; + esac + # YOLO + curl -sSL https://rvm.io/mpapis.asc | gpg --import - + curl -sSL https://rvm.io/pkuczynski.asc | gpg --import - + curl -sSL https://get.rvm.io | bash -s stable + set +x + source $HOME/.rvm/scripts/rvm + set -x + fi if [[ "$VER" == "2.7" || "$VER" == "3.0" ]]; then # Ruby 2.7+ support is currently only rvm master (30 Dec 2019) $RETRY rvm get master From 51cb07711f02e95f45ace5e580a75e5846f96881 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 30 Sep 2021 20:20:46 +0200 Subject: [PATCH 043/262] Add most of Linux builds from Travis CI Don't add the builds known/allowed to fail and don't add all the variations of Python builds, there are just too many of those, but do add mostly all the rest, with the exceptions below: Builds using JavaScript backend with node <= 10 had to be disabled as well, as they just seem to be broken and there is no real motivation in supporting these ancient versions. Builds using D can't be run currently due to incompatibility between the ancient dmd version being used and the earliest support Ubuntu version (18.04) on GitHub Actions and not supporting newer versions in SWIG. Builds using Scilab had to be disabled as running the test suite reliably hangs. This would need to be debugged by somebody motivated in doing it. Note that some builds need to be run under Ubuntu 18.04 (Bionic) and not the default 20.04 (Focal) as they use old dependencies that don't exist in Focal any longer. In the future we ought to switch to using newer versions of these dependencies. --- .github/workflows/ci.yml | 139 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 138 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc9263912..beab2b08a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: # By default, the name of the build is just the language used, but matrix # entries can define the additional "desc" field with any additional # information to include in the name. - name: ${{ matrix.SWIGLANG || 'none' }}${{ matrix.PY3 }} ${{ matrix.desc }} + name: ${{ matrix.SWIGLANG || 'none' }}${{ matrix.PY3 }} ${{ matrix.ENGINE}} ${{ matrix.VER }} ${{ matrix.desc }} strategy: matrix: @@ -42,9 +42,128 @@ jobs: - SWIGLANG: "" compiler: clang desc: clang + - SWIGLANG: csharp + # D support can't be enabled because dmd 2.066 fails to build anything + # under Ubuntu 18.04 due to its standard library (libphobos2.a) not + # being compiled with -FPIC, but system gcc using -fpie by default, + # resulting in linking errors for any output. And later versions, such + # as 2.086.1, are not supported and result in errors in SWIG test suite. + # + # - SWIGLANG: d + # VER: '2.066.0' + # os: ubuntu-18.04 # This dlang version doesn't work under 20.04. + - SWIGLANG: go + VER: '1.3' + - SWIGLANG: go + VER: '1.6' + - SWIGLANG: go + VER: '1.8' + - SWIGLANG: go + VER: '1.12' + CSTD: gnu99 + - SWIGLANG: go + VER: '1.16' + CSTD: gnu99 + - SWIGLANG: guile + - SWIGLANG: java + - SWIGLANG: javascript + ENGINE: node + VER: '12' + CPP11: 1 + - SWIGLANG: javascript + ENGINE: node + VER: '14' + CPP11: 1 + - SWIGLANG: javascript + ENGINE: node + VER: '16' + CPP14: 1 + - SWIGLANG: javascript + ENGINE: jsc + os: ubuntu-18.04 # libwebkitgtk-dev dependency not available in 20.04. + - SWIGLANG: javascript + ENGINE: v8 + os: ubuntu-18.04 # libv8-dev only actually provides v8 in 18.04. + - SWIGLANG: lua + - SWIGLANG: lua + VER: '5.3' + - SWIGLANG: octave + CPP11: 1 + - SWIGLANG: perl5 + - SWIGLANG: php + VER: '7.4' + - SWIGLANG: php + VER: '8.0' - SWIGLANG: python - SWIGLANG: python PY3: 3 + VER: '3.2' + os: ubuntu-18.04 # Python < 3.5 not available for 20.04. + - SWIGLANG: python + PY3: 3 + VER: '3.3' + os: ubuntu-18.04 # Python < 3.5 not available for 20.04. + - SWIGLANG: python + PY3: 3 + VER: '3.4' + os: ubuntu-18.04 # Python < 3.5 not available for 20.04. + - SWIGLANG: python + PY3: 3 + VER: '3.5' + - SWIGLANG: python + PY3: 3 + VER: '3.6' + - SWIGLANG: python + PY3: 3 + VER: '3.7' + - SWIGLANG: python + PY3: 3 + VER: '3.8' + - SWIGLANG: python + PY3: 3 + VER: '3.9' + - SWIGLANG: python + SWIG_FEATURES: -builtin + desc: builtin + - SWIGLANG: python + SWIG_FEATURES: -builtin -O + desc: builtin optimized + - SWIGLANG: python + PY3: 3 + SWIG_FEATURES: -builtin + desc: builtin + - SWIGLANG: python + PY3: 3 + SWIG_FEATURES: -builtin -O + desc: builtin optimized + - SWIGLANG: r + - SWIGLANG: ruby + VER: '1.9' + os: ubuntu-18.04 + - SWIGLANG: ruby + VER: '2.0' + os: ubuntu-18.04 + - SWIGLANG: ruby + VER: '2.1' + os: ubuntu-18.04 + - SWIGLANG: ruby + VER: '2.2' + os: ubuntu-18.04 + - SWIGLANG: ruby + VER: '2.3' + os: ubuntu-18.04 + - SWIGLANG: ruby + VER: '2.4' + - SWIGLANG: ruby + VER: '2.5' + - SWIGLANG: ruby + VER: '2.6' + - SWIGLANG: ruby + VER: '2.7' + - SWIGLANG: ruby + VER: '3.0' + CSTD: c99 + CPP11: 1 - SWIGLANG: tcl # let's run all of them, as opposed to aborting when one fails fail-fast: false @@ -52,6 +171,8 @@ jobs: env: SWIGLANG: ${{ matrix.SWIGLANG }} PY3: ${{ matrix.PY3 }} + VER: ${{ matrix.VER }} + ENGINE: ${{ matrix.ENGINE }} SWIG_FEATURES: ${{ matrix.SWIG_FEATURES }} CSTD: ${{ matrix.CSTD }} CPP11: ${{ matrix.CPP11 }} @@ -141,6 +262,22 @@ jobs: - name: Test working-directory: build/build run: | + case "$SWIGLANG" in + javascript) + case "$ENGINE" in + node) + export NVM_DIR="$HOME/.nvm" + [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" + nvm use ${VER} + ;; + esac + ;; + + ruby) + source $HOME/.rvm/scripts/rvm + ;; + esac + set -x if test -n "$CPP11"; then export CPPSTD=c++11; fi if test -n "$CPP14"; then export CPPSTD=c++14; fi From f038fcb44d0c1c9ed20f038544ed66320573b99c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 1 Oct 2021 04:26:15 +0200 Subject: [PATCH 044/262] Do nothing in li_std_functors test when using Ruby 2.6 This test sporadically crashes when run in GitHub Actions environment, so skip it for now when using the Ruby 2.6 version installed by rvm. --- Examples/test-suite/ruby/li_std_functors_runme.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Examples/test-suite/ruby/li_std_functors_runme.rb b/Examples/test-suite/ruby/li_std_functors_runme.rb index 5623d49f0..a2a7c6f3d 100644 --- a/Examples/test-suite/ruby/li_std_functors_runme.rb +++ b/Examples/test-suite/ruby/li_std_functors_runme.rb @@ -63,7 +63,9 @@ def test yield method(:_map), Li_std_functors::Map end -# these should fail and not segfault +# these should fail and not segfault but currently do segfault with Ruby 2.6 +# in GitHub Actions environment +if RUBY_VERSION != '2.6.6' begin Li_std_functors::Set.new('sd') rescue @@ -72,5 +74,4 @@ end test do |proc, container| proc.call(container) end - - +end From 3b7e46dd19850c83833c23db5ae231eef4d23b39 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 1 Oct 2021 04:28:11 +0200 Subject: [PATCH 045/262] Try using one less make job to see its effect on total time Check if using -j2, rather than -j3, may help with speeding up Octave unit tests run which takes ~25 minutes currently. --- .github/workflows/ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index beab2b08a..076c322a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -242,11 +242,12 @@ jobs: ;; *) - cpu_count=0 + cpu_count=1 ;; esac - ((cpu_count++)) - echo SWIGJOBS=-j$cpu_count >> $GITHUB_ENV + if [[ $cpu_count != 1 ]]; then + echo SWIGJOBS=-j$cpu_count >> $GITHUB_ENV + fi - name: Build working-directory: build/build From 2c86dd193b9daeb85b2a9abd2e49d5369e659fdd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 3 Oct 2021 16:13:12 +0200 Subject: [PATCH 046/262] Ignore changes to appveyor.yml in GitHub Actions CI workflow Don't bother rerunning GitHub CI builds when only AppVeyor configuration changes. --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 076c322a7..4bc141e41 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,11 +6,13 @@ on: paths-ignore: - 'CHANGES*' - 'Doc/**' + - 'appveyor.yml' pull_request: branches: master paths-ignore: - 'CHANGES*' - 'Doc/**' + - 'appveyor.yml' jobs: build: From 7744425c219a3affff00166ad15a178bcef13178 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 3 Oct 2021 16:14:21 +0200 Subject: [PATCH 047/262] Ignore change to files not affecting the build in appveyor.yml There is no need to rerun the CI builds if only the docs, changelog or anything GitHub-related changes. --- appveyor.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index fad8f0bc0..1df9f8f2f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,6 +2,12 @@ platform: - x86 - x64 +skip_commits: + files: + - 'CHANGES*' + - 'Doc/**' + - '.github/**' + environment: global: MAKEJOBS: 2 From 1f33118077bb768c77e5a8d138d49dad274d240f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 3 Oct 2021 16:17:33 +0200 Subject: [PATCH 048/262] Don't bother building out of date PR versions on AppVeyor Exit early if there is version of the PR newer than the one that we are about to start building, to avoid wasting 3.5 hours of AppVeyor build time on the outdated PR versions. The snippet doing this was copied from https://github.com/appveyor/ci/issues/38#issuecomment-70628826 (thanks to Tony Kelman). An alternative to doing this could be enabling the "Rolling builds" option in the AppVeyor UI, see https://www.appveyor.com/docs/build-configuration/#rolling-builds but this method seems to work well in practice and is more explicit. --- appveyor.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 1df9f8f2f..10bee7ee5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -51,6 +51,13 @@ matrix: - SWIGLANG: python OSVARIANT: cygwin +init: +- ps: | + if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod ` + https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | ` + Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { ` + throw "There are newer queued builds for this pull request, failing early." } + install: - date /T & time /T - ps: >- From 42ed181e0816e32e0145bc02bdd4cc0141519de3 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Thu, 5 Aug 2021 15:27:00 +0200 Subject: [PATCH 049/262] [CMake] Add option to enable pcre Closes #2031, #2065. --- CHANGES.current | 3 +++ CMakeLists.txt | 6 +++--- Doc/Manual/Windows.html | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index a118132f8..3492e6df6 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2021-10-03: jschueller + [CMake] #2065: Add option to enable or disable PCRE support. + 2021-09-16: ianlancetaylor [Go] Improved _cgo_panic implementation. diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b6743471..8a195de54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,9 +73,9 @@ if (MSVC) set (CMAKE_CXX_FLAGS "/EHsc ${CMAKE_CXX_FLAGS}") endif () -set (PCRE_REQUIRED_ARG "REQUIRED" CACHE STRING "required arg") -find_package (PCRE ${PCRE_REQUIRED_ARG}) -if (PCRE_FOUND) +option (WITH_PCRE "Enable pcre" ON) +if (WITH_PCRE) + find_package (PCRE REQUIRED) set (HAVE_PCRE 1) include_directories (${PCRE_INCLUDE_DIRS}) endif() diff --git a/Doc/Manual/Windows.html b/Doc/Manual/Windows.html index 9365070e9..eae9ffb84 100644 --- a/Doc/Manual/Windows.html +++ b/Doc/Manual/Windows.html @@ -251,7 +251,8 @@ For fully working build steps always check the Continuous Integration setups cur and save to a folder e.g. C:\Tools\Bison
  • - Install PCRE using Nuget using the following command:
    C:\Tools\nuget install pcre -Version 8.33.0.1 -OutputDirectory C:\Tools\pcre
    + Install PCRE using Nuget using the following command:
    C:\Tools\nuget install pcre -Version 8.33.0.1 -OutputDirectory C:\Tools\pcre
    . + Alternatively, use WITH_PCRE option to disable PCRE support if you are sure not to need it.
  • We will also need the SWIG source code. Either download a zipped archive from GitHub, or if git is installed clone the latest codebase From 6c59cae7996f83e0340145ed989b72c7eee68246 Mon Sep 17 00:00:00 2001 From: Anthony Heading Date: Mon, 30 Aug 2021 20:40:12 -0400 Subject: [PATCH 050/262] Avoid gcc 11 misleading indentation warning in generated code Closes https://github.com/swig/swig/pull/2074 --- CHANGES.current | 4 ++++ Lib/perl5/perltypemaps.swg | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 3492e6df6..6bafec31c 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -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) =========================== +2021-10-03: ajrh1 + [Perl] #2074: Avoid -Wmisleading-indentation in generated code + when using gcc11. + 2021-10-03: jschueller [CMake] #2065: Add option to enable or disable PCRE support. diff --git a/Lib/perl5/perltypemaps.swg b/Lib/perl5/perltypemaps.swg index bab3d7acd..42f8887be 100644 --- a/Lib/perl5/perltypemaps.swg +++ b/Lib/perl5/perltypemaps.swg @@ -56,7 +56,9 @@ %define %set_output(obj) $result = obj; argvi++ %enddef /* append output */ -%define %append_output(obj) if (argvi >= items) EXTEND(sp, argvi+1); %set_output(obj) %enddef +%define %append_output(obj) +if (argvi >= items) EXTEND(sp, argvi+1); +%set_output(obj) %enddef /* variable output */ %define %set_varoutput(obj) sv_setsv($result,obj) %enddef From 8a0ec051db5dd638e55d0a636d31e8a70dabcdd1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 3 Oct 2021 17:19:29 +0200 Subject: [PATCH 051/262] Don't run non-node JS tests in parallel in the CI builds This seems to be broken and sporadically results in "Text file busy" errors when the tests are run actually in parallel, as is the case in GitHub CI environment. --- .github/workflows/ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 076c322a7..9c5a967f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -271,6 +271,12 @@ jobs: [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" nvm use ${VER} ;; + *) + # Running tests using v8 or jsc involves creating a custom + # interpreter in Tools/javascript, which is currently broken + # for parallel builds (we attempt to update this interpreter + # while running, resulting in "Text file busy" error). + unset SWIGJOBS esac ;; From b1fe12182bc28a3c5c63597f5fdd9ded819c461c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 13 Oct 2021 11:54:25 +0100 Subject: [PATCH 052/262] GHA workflow break up It's useful to see the configure step by itself, so split it out from the installation of prerequisites. The make install is verbose, put it in it's own step Move checking of the errors test-suite and ccache checks from the Build to Test step. --- .github/workflows/ci.yml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b46500560..f0bf68377 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -192,7 +192,7 @@ jobs: with: key: ${{ matrix.os || 'ubuntu-20.04' }}-${{ matrix.compiler || 'gcc' }}${{ matrix.GCC }} - - name: Configure + - name: Install Dependencies run: | set -x export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" @@ -224,6 +224,9 @@ jobs: $CC --version $CXX --version + - name: Configure + run: | + set -x if test -n '${{ matrix.CONFIGOPTS }}'; then CONFIGOPTS=${{ matrix.CONFIGOPTS }} fi @@ -257,10 +260,6 @@ jobs: set -x make $SWIGJOBS ./swig -version && ./swig -pcreversion - if test -z "$SWIGLANG"; then make $SWIGJOBS check-ccache; fi - if test -z "$SWIGLANG"; then make $SWIGJOBS check-errors-test-suite; fi - echo 'Installing...' - if test -z "$SWIGLANG"; then sudo make install && swig -version && ccache-swig -V; fi - name: Test working-directory: build/build @@ -291,6 +290,10 @@ jobs: if test -n "$CPP11"; then export CPPSTD=c++11; fi if test -n "$CPP14"; then export CPPSTD=c++14; fi if test -n "$CPP17"; then export CPPSTD=c++17; fi + + if test -z "$SWIGLANG"; then make $SWIGJOBS check-ccache; fi + if test -z "$SWIGLANG"; then make $SWIGJOBS check-errors-test-suite; fi + # Stricter compile flags for examples. Various headers and SWIG generated code prevents full use of -pedantic. if test -n "$SWIGLANG"; then cflags=$($GITHUB_WORKSPACE/Tools/testflags.py --language $SWIGLANG --cflags --std=$CSTD --compiler=$CC) && echo $cflags; fi if test -n "$SWIGLANG"; then cxxflags=$($GITHUB_WORKSPACE/Tools/testflags.py --language $SWIGLANG --cxxflags --std=$CPPSTD --compiler=$CC) && echo $cxxflags; fi @@ -299,6 +302,12 @@ jobs: if test -n "$SWIGLANG"; then make $SWIGJOBS check-$SWIGLANG-examples CFLAGS="$cflags" CXXFLAGS="$cxxflags"; fi if test -n "$SWIGLANG"; then make $SWIGJOBS check-$SWIGLANG-test-suite CFLAGS="$cflags" CXXFLAGS="$cxxflags"; fi + - name: Test Installation + run: | + working-directory: build/build + set -x + if test -z "$SWIGLANG"; then sudo make install && swig -version && ccache-swig -V; fi + - name: Clean working-directory: build/build run: | From af68e7f61808cddf5ca55c4fe4138f6a8cf0fe37 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 13 Oct 2021 12:03:20 +0100 Subject: [PATCH 053/262] GHA: Restore silent flag to building SWIG There is too much cruft to wade through to find compiler warnings. I check these once in a while for all compilers. We could alternatively use -Werr, but at the risk of more broken builds. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f0bf68377..4b4a03673 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -258,7 +258,7 @@ jobs: working-directory: build/build run: | set -x - make $SWIGJOBS + make -s $SWIGJOBS ./swig -version && ./swig -pcreversion - name: Test From b17416c1873b8a1f20a47b6cfd908a7989c8d7c7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 13 Oct 2021 12:10:53 +0100 Subject: [PATCH 054/262] GHA: remove useless diagnostics This echo is out of sync with the script for some reason and is rather pointless subsequent to the breaking up of the steps --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4b4a03673..a35133d8f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -219,7 +219,6 @@ jobs: echo CC="$CC" >> $GITHUB_ENV echo CXX="$CXX" >> $GITHUB_ENV - echo "Compiler used:" ls -la $(which $CC) $(which $CXX) $CC --version $CXX --version From 7e9726945244c25c445fa76506d8345def2b887f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 13 Oct 2021 12:19:34 +0100 Subject: [PATCH 055/262] Fix Install step --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a35133d8f..5f0c70d46 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -301,9 +301,9 @@ jobs: if test -n "$SWIGLANG"; then make $SWIGJOBS check-$SWIGLANG-examples CFLAGS="$cflags" CXXFLAGS="$cxxflags"; fi if test -n "$SWIGLANG"; then make $SWIGJOBS check-$SWIGLANG-test-suite CFLAGS="$cflags" CXXFLAGS="$cxxflags"; fi - - name: Test Installation - run: | + - name: Install working-directory: build/build + run: | set -x if test -z "$SWIGLANG"; then sudo make install && swig -version && ccache-swig -V; fi From d7c2cbec38d44c1d76dd63e9433bc4db82c304a9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 13 Oct 2021 12:27:31 +0100 Subject: [PATCH 056/262] GHA: clean up Configure step Setup Javascript before running configure - may fix broken Javascript testing. Configure step just configures now. --- .github/workflows/ci.yml | 78 ++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5f0c70d46..c74ee45cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -200,6 +200,45 @@ jobs: source Tools/GHA-linux-install.sh + case $(uname) in + Linux) + cpu_count=$(nproc) + ;; + + Darwin) + cpu_count=$(sysctl -n hw.ncpu) + ;; + + *) + cpu_count=1 + ;; + esac + if [[ $cpu_count != 1 ]]; then + echo SWIGJOBS=-j$cpu_count >> $GITHUB_ENV + fi + + case "$SWIGLANG" in + javascript) + case "$ENGINE" in + node) + export NVM_DIR="$HOME/.nvm" + [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" + nvm use ${VER} + ;; + *) + # Running tests using v8 or jsc involves creating a custom + # interpreter in Tools/javascript, which is currently broken + # for parallel builds (we attempt to update this interpreter + # while running, resulting in "Text file busy" error). + unset SWIGJOBS + esac + ;; + + ruby) + source $HOME/.rvm/scripts/rvm + ;; + esac + if test '${{ matrix.compiler }}' = 'clang'; then CC="clang" CXX="clang++" @@ -236,23 +275,6 @@ jobs: echo "${CONFIGOPTS[@]}" ./autogen.sh && mkdir -p build/build && cd build/build && ../../configure "${CONFIGOPTS[@]}" - case $(uname) in - Linux) - cpu_count=$(nproc) - ;; - - Darwin) - cpu_count=$(sysctl -n hw.ncpu) - ;; - - *) - cpu_count=1 - ;; - esac - if [[ $cpu_count != 1 ]]; then - echo SWIGJOBS=-j$cpu_count >> $GITHUB_ENV - fi - - name: Build working-directory: build/build run: | @@ -263,28 +285,6 @@ jobs: - name: Test working-directory: build/build run: | - case "$SWIGLANG" in - javascript) - case "$ENGINE" in - node) - export NVM_DIR="$HOME/.nvm" - [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" - nvm use ${VER} - ;; - *) - # Running tests using v8 or jsc involves creating a custom - # interpreter in Tools/javascript, which is currently broken - # for parallel builds (we attempt to update this interpreter - # while running, resulting in "Text file busy" error). - unset SWIGJOBS - esac - ;; - - ruby) - source $HOME/.rvm/scripts/rvm - ;; - esac - set -x if test -n "$CPP11"; then export CPPSTD=c++11; fi if test -n "$CPP14"; then export CPPSTD=c++14; fi From 61983e04b078efde6a4c218b009e2653039a0feb Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 13 Oct 2021 12:43:24 +0100 Subject: [PATCH 057/262] Try save WITHLANG --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c74ee45cc..d0ca72692 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -199,6 +199,7 @@ jobs: echo PATH="$PATH" >> $GITHUB_ENV source Tools/GHA-linux-install.sh + echo WITHLANG="$WITHLANG" >> $GITHUB_ENV case $(uname) in Linux) From aaf19fbf93e08d3ae0584096a66b0bad3a08aa59 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 13 Oct 2021 18:26:08 +0100 Subject: [PATCH 058/262] GHA: Fix regressions The environment variables are not kept between runs, arg. Temp hack to try and get export env working for Configure and Test steps. --- .github/workflows/ci.yml | 56 ++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d0ca72692..c31ea2568 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -214,19 +214,11 @@ jobs: cpu_count=1 ;; esac - if [[ $cpu_count != 1 ]]; then - echo SWIGJOBS=-j$cpu_count >> $GITHUB_ENV - fi case "$SWIGLANG" in javascript) case "$ENGINE" in - node) - export NVM_DIR="$HOME/.nvm" - [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" - nvm use ${VER} - ;; - *) + v8 | jsc) # Running tests using v8 or jsc involves creating a custom # interpreter in Tools/javascript, which is currently broken # for parallel builds (we attempt to update this interpreter @@ -234,12 +226,12 @@ jobs: unset SWIGJOBS esac ;; - - ruby) - source $HOME/.rvm/scripts/rvm - ;; esac + if [[ $cpu_count != 1 ]]; then + echo SWIGJOBS=-j$cpu_count >> $GITHUB_ENV + fi + if test '${{ matrix.compiler }}' = 'clang'; then CC="clang" CXX="clang++" @@ -266,6 +258,25 @@ jobs: - name: Configure run: | set -x + + # Repeat language specific environment setup + case "$SWIGLANG" in + javascript) + case "$ENGINE" in + node) + export NVM_DIR="$HOME/.nvm" + [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" + nvm use ${VER} + ;; + *) + esac + ;; + + ruby) + source $HOME/.rvm/scripts/rvm + ;; + esac + if test -n '${{ matrix.CONFIGOPTS }}'; then CONFIGOPTS=${{ matrix.CONFIGOPTS }} fi @@ -287,6 +298,25 @@ jobs: working-directory: build/build run: | set -x + + # Repeat language specific environment setup + case "$SWIGLANG" in + javascript) + case "$ENGINE" in + node) + export NVM_DIR="$HOME/.nvm" + [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" + nvm use ${VER} + ;; + *) + esac + ;; + + ruby) + source $HOME/.rvm/scripts/rvm + ;; + esac + if test -n "$CPP11"; then export CPPSTD=c++11; fi if test -n "$CPP14"; then export CPPSTD=c++14; fi if test -n "$CPP17"; then export CPPSTD=c++17; fi From d0b6cfeca44d8a09e0cbfd3e754b4796fa429dd0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 14 Oct 2021 11:40:55 +0100 Subject: [PATCH 059/262] Factor out common environment setup GHA steps --- .github/workflows/ci.yml | 38 ++--------------------------------- Tools/CI-linux-environment.sh | 27 +++++++++++++++++++++++++ Tools/CI-linux-install.sh | 2 +- 3 files changed, 30 insertions(+), 37 deletions(-) create mode 100644 Tools/CI-linux-environment.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c31ea2568..d1abbc404 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -258,24 +258,7 @@ jobs: - name: Configure run: | set -x - - # Repeat language specific environment setup - case "$SWIGLANG" in - javascript) - case "$ENGINE" in - node) - export NVM_DIR="$HOME/.nvm" - [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" - nvm use ${VER} - ;; - *) - esac - ;; - - ruby) - source $HOME/.rvm/scripts/rvm - ;; - esac + source Tools/CI-linux-environment.sh if test -n '${{ matrix.CONFIGOPTS }}'; then CONFIGOPTS=${{ matrix.CONFIGOPTS }} @@ -298,24 +281,7 @@ jobs: working-directory: build/build run: | set -x - - # Repeat language specific environment setup - case "$SWIGLANG" in - javascript) - case "$ENGINE" in - node) - export NVM_DIR="$HOME/.nvm" - [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" - nvm use ${VER} - ;; - *) - esac - ;; - - ruby) - source $HOME/.rvm/scripts/rvm - ;; - esac + source Tools/CI-linux-environment.sh if test -n "$CPP11"; then export CPPSTD=c++11; fi if test -n "$CPP14"; then export CPPSTD=c++14; fi diff --git a/Tools/CI-linux-environment.sh b/Tools/CI-linux-environment.sh new file mode 100644 index 000000000..d530f37a8 --- /dev/null +++ b/Tools/CI-linux-environment.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# Expected to be called from elsewhere with same variables set as CI-linux-install.sh +# e.g. RETRY=travis-retry SWIGLANG=python +# Sets up environment for using various target languages +# For Github Actions where the environment is not preserved between steps +set -e # exit on failure (same as -o errexit) + +case "$SWIGLANG" in + "javascript") + case "$ENGINE" in + "node") + export NVM_DIR="$HOME/.nvm" + [ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh" + nvm use ${VER} + ;; + *) ;; + esac + ;; + "ruby") + if ! command -v rvm; then + set +x + source $HOME/.rvm/scripts/rvm + set -x + fi + ;; + *) ;; +esac diff --git a/Tools/CI-linux-install.sh b/Tools/CI-linux-install.sh index ab5b10ddb..7daa55e3e 100644 --- a/Tools/CI-linux-install.sh +++ b/Tools/CI-linux-install.sh @@ -1,5 +1,5 @@ #!/bin/bash -# expected to be called from elsewhere with certain variables set +# Expected to be called from elsewhere with certain variables set # e.g. RETRY=travis-retry SWIGLANG=python GCC=7 set -e # exit on failure (same as -o errexit) From 4df45013d5c56fe940f9bdeb138bc6dff1a1e60c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 14 Oct 2021 12:26:04 +0100 Subject: [PATCH 060/262] Fix to find scripts in Tools --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d1abbc404..32d5b53dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -198,7 +198,7 @@ jobs: export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" echo PATH="$PATH" >> $GITHUB_ENV - source Tools/GHA-linux-install.sh + source $GITHUB_WORKSPACE/Tools/GHA-linux-install.sh echo WITHLANG="$WITHLANG" >> $GITHUB_ENV case $(uname) in @@ -258,7 +258,7 @@ jobs: - name: Configure run: | set -x - source Tools/CI-linux-environment.sh + source $GITHUB_WORKSPACE/Tools/CI-linux-environment.sh if test -n '${{ matrix.CONFIGOPTS }}'; then CONFIGOPTS=${{ matrix.CONFIGOPTS }} @@ -281,7 +281,7 @@ jobs: working-directory: build/build run: | set -x - source Tools/CI-linux-environment.sh + source $GITHUB_WORKSPACE/Tools/CI-linux-environment.sh if test -n "$CPP11"; then export CPPSTD=c++11; fi if test -n "$CPP14"; then export CPPSTD=c++14; fi From 206105bc3f9ebd96c82cd51a8ee40d0518a125b6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 14 Oct 2021 19:56:30 +0100 Subject: [PATCH 061/262] GHA: Correctly unset SWIGJOBS for broken parallel language checks --- .github/workflows/ci.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 32d5b53dc..4e3eb7f45 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -215,19 +215,6 @@ jobs: ;; esac - case "$SWIGLANG" in - javascript) - case "$ENGINE" in - v8 | jsc) - # Running tests using v8 or jsc involves creating a custom - # interpreter in Tools/javascript, which is currently broken - # for parallel builds (we attempt to update this interpreter - # while running, resulting in "Text file busy" error). - unset SWIGJOBS - esac - ;; - esac - if [[ $cpu_count != 1 ]]; then echo SWIGJOBS=-j$cpu_count >> $GITHUB_ENV fi @@ -290,6 +277,19 @@ jobs: if test -z "$SWIGLANG"; then make $SWIGJOBS check-ccache; fi if test -z "$SWIGLANG"; then make $SWIGJOBS check-errors-test-suite; fi + case "$SWIGLANG" in + javascript) + case "$ENGINE" in + v8 | jsc) + # Running tests using v8 or jsc involves creating a custom + # interpreter in Tools/javascript, which is currently broken + # for parallel builds (we attempt to update this interpreter + # while running, resulting in "Text file busy" error). + unset SWIGJOBS + esac + ;; + esac + # Stricter compile flags for examples. Various headers and SWIG generated code prevents full use of -pedantic. if test -n "$SWIGLANG"; then cflags=$($GITHUB_WORKSPACE/Tools/testflags.py --language $SWIGLANG --cflags --std=$CSTD --compiler=$CC) && echo $cflags; fi if test -n "$SWIGLANG"; then cxxflags=$($GITHUB_WORKSPACE/Tools/testflags.py --language $SWIGLANG --cxxflags --std=$CPPSTD --compiler=$CC) && echo $cxxflags; fi From fc31b9ab0489cca0ead4f700233e7342f6449fb2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 15 Oct 2021 08:15:14 +0100 Subject: [PATCH 062/262] Add gcc11 testing --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4e3eb7f45..be949a136 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,6 +41,9 @@ jobs: - SWIGLANG: "" GCC: 10 desc: gcc10 + - SWIGLANG: "" + GCC: 11 + desc: gcc11 - SWIGLANG: "" compiler: clang desc: clang From 6c4125db0c24c8ef79da58fe24d4a9362e758df4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 18 Oct 2021 08:10:36 +0100 Subject: [PATCH 063/262] GHA: apt-get update for Octave To fix: Failed to fetch http://azure.archive.ubuntu.com/ubuntu/pool/main/m/mesa/libgl1-mesa-dev_21.0.3-0ubuntu0.3~20.04.2_amd64.deb 404 Not Found --- Tools/CI-linux-install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/Tools/CI-linux-install.sh b/Tools/CI-linux-install.sh index 7daa55e3e..80e7c1fb9 100644 --- a/Tools/CI-linux-install.sh +++ b/Tools/CI-linux-install.sh @@ -73,6 +73,7 @@ case "$SWIGLANG" in $RETRY sudo apt-get -qq install ocaml camlp4 ;; "octave") + $RETRY sudo apt-get -qq update $RETRY sudo apt-get -qq install liboctave-dev ;; "php") From 7a65f028f88da6d5ba66602ddcccbce58b1a57ce Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 20 Oct 2021 11:51:17 +0100 Subject: [PATCH 064/262] Update docs - python static members access [skip-ci] --- Doc/Manual/Python.html | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index c132afc8a..1bd7b1e3c 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -1608,7 +1608,7 @@ public:

    -In Python, the static member can be access in three different ways: +In Python, the static member can be accessed in three different ways:

    @@ -1616,7 +1616,7 @@ In Python, the static member can be access in three different ways: >>> example.Spam_foo() # Spam::foo() >>> s = example.Spam() >>> s.foo() # Spam::foo() via an instance ->>> example.Spam.foo() # Spam::foo(). Python-2.2 only +>>> example.Spam.foo() # Spam::foo() using Python-2.2 and later
    @@ -1627,16 +1627,31 @@ last technique is only available in Python-2.2 and later versions.

    Static member variables are currently accessed as global variables. This means, -they are accessed through cvar like this: +they are accessed through cvar or via an instance property:

    ->>> print example.cvar.Spam_bar
    +>>> example.cvar.Spam_bar # Spam::bar
    +7
    +>>> s = example.Spam()
    +>>> s.bar                 # Spam::bar via an instance property
     7
     
    +

    +The -builtin option uses a metaclass to additionally provide access as follows: +

    + +
    +
    +>>> example.Spam.bar      # Spam::bar using -builtin option only
    +7
    +
    +
    + +

    33.3.8 C++ inheritance

    From c280d63a4da24eaf97e025f48371171daf3af8e9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 20 Oct 2021 21:05:20 +0100 Subject: [PATCH 065/262] GHA: Add python 3.10 testing --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be949a136..6a9e86d73 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -127,6 +127,9 @@ jobs: - SWIGLANG: python PY3: 3 VER: '3.9' + - SWIGLANG: python + PY3: 3 + VER: '3.10' - SWIGLANG: python SWIG_FEATURES: -builtin desc: builtin From 04a6ad3bb582c15d7dc13c86b9657038adeb07ce Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 21 Oct 2021 07:45:05 +0100 Subject: [PATCH 066/262] Add SWIG_FEATURES into GHA name --- .github/workflows/ci.yml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a9e86d73..d054656a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,10 +19,9 @@ jobs: runs-on: ${{ matrix.os || 'ubuntu-20.04' }} - # By default, the name of the build is just the language used, but matrix - # entries can define the additional "desc" field with any additional - # information to include in the name. - name: ${{ matrix.SWIGLANG || 'none' }}${{ matrix.PY3 }} ${{ matrix.ENGINE}} ${{ matrix.VER }} ${{ matrix.desc }} + # By default, the name of the build is the language used and SWIG options, but matrix entries + # can define the additional "desc" field with any additional information to include in the name. + name: ${{ matrix.SWIGLANG || 'none' }}${{ matrix.PY3 }} ${{ matrix.ENGINE}} ${{ matrix.VER }} ${{ matrix.SWIG_FEATURES }} ${{ matrix.desc }} strategy: matrix: @@ -132,18 +131,14 @@ jobs: VER: '3.10' - SWIGLANG: python SWIG_FEATURES: -builtin - desc: builtin - SWIGLANG: python SWIG_FEATURES: -builtin -O - desc: builtin optimized - SWIGLANG: python PY3: 3 SWIG_FEATURES: -builtin - desc: builtin - SWIGLANG: python PY3: 3 SWIG_FEATURES: -builtin -O - desc: builtin optimized - SWIGLANG: r - SWIGLANG: ruby VER: '1.9' From 090b884481be45b29b44539bff83306954e6f7a9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 21 Oct 2021 09:32:10 +0100 Subject: [PATCH 067/262] Use source instead of . --- Tools/CI-linux-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/CI-linux-install.sh b/Tools/CI-linux-install.sh index 80e7c1fb9..5f6b1462e 100644 --- a/Tools/CI-linux-install.sh +++ b/Tools/CI-linux-install.sh @@ -34,7 +34,7 @@ case "$SWIGLANG" in "node") $RETRY wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.10/install.sh | bash export NVM_DIR="$HOME/.nvm" - [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + [ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh" $RETRY nvm install ${VER} nvm use ${VER} if [ "$VER" == "0.10" ] || [ "$VER" == "0.12" ] || [ "$VER" == "4" ] || [ "$VER" == "6" ] ; then From 87c50d811d69765b0c431632e0484059af54020d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 22 Oct 2021 14:57:58 +0100 Subject: [PATCH 068/262] Fix installation of Go from gimme GHA does not have gimme pre-installed --- Tools/CI-linux-environment.sh | 6 ++++++ Tools/CI-linux-install.sh | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Tools/CI-linux-environment.sh b/Tools/CI-linux-environment.sh index d530f37a8..e854c5b0e 100644 --- a/Tools/CI-linux-environment.sh +++ b/Tools/CI-linux-environment.sh @@ -6,6 +6,12 @@ set -e # exit on failure (same as -o errexit) case "$SWIGLANG" in + "go") + if [[ "$VER" ]]; then + eval "$($HOME/bin/gimme ${VER}.x)" + $HOME/bin/gimme --list + fi + ;; "javascript") case "$ENGINE" in "node") diff --git a/Tools/CI-linux-install.sh b/Tools/CI-linux-install.sh index 5f6b1462e..04dd5127f 100644 --- a/Tools/CI-linux-install.sh +++ b/Tools/CI-linux-install.sh @@ -26,7 +26,11 @@ case "$SWIGLANG" in ;; "go") if [[ "$VER" ]]; then - eval "$(gimme ${VER}.x)" + mkdir -p $HOME/bin + curl -sL -o $HOME/bin/gimme https://raw.githubusercontent.com/travis-ci/gimme/master/gimme + chmod +x $HOME/bin/gimme + eval "$($HOME/bin/gimme ${VER}.x)" + $HOME/bin/gimme --list fi ;; "javascript") From cf8268d19e2a2d9bb30b37fdda7d11e93728be01 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 22 Oct 2021 15:03:49 +0100 Subject: [PATCH 069/262] GHA: Remove go-1.3 testing Results in error message: /usr/bin/ld: -r and -pie may not be used together Same problem on Ubuntu 18.04. Same with versions go-1.2 to go-1.5. --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d054656a4..3da720d7e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,10 +56,9 @@ jobs: # - SWIGLANG: d # VER: '2.066.0' # os: ubuntu-18.04 # This dlang version doesn't work under 20.04. - - SWIGLANG: go - VER: '1.3' - SWIGLANG: go VER: '1.6' + CSTD: gnu99 - SWIGLANG: go VER: '1.8' - SWIGLANG: go From cbbeb4298a30023ff9be33dd93e2a88f6ac46be8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 22 Oct 2021 09:16:21 +0100 Subject: [PATCH 070/262] GHA: Fix CSTD and CPPSTD usage --- .github/workflows/ci.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3da720d7e..e28e344b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -247,12 +247,18 @@ jobs: set -x source $GITHUB_WORKSPACE/Tools/CI-linux-environment.sh + if test -n "$CPP11"; then export CPPSTD=c++11 && export CSTD=c11; fi + if test -n "$CPP14"; then export CPPSTD=c++14 && export CSTD=c11; fi + if test -n "$CPP17"; then export CPPSTD=c++17 && export CSTD=c17; fi + echo CPPSTD="$CPPSTD" >> $GITHUB_ENV + echo CSTD="$CSTD" >> $GITHUB_ENV + if test -n '${{ matrix.CONFIGOPTS }}'; then CONFIGOPTS=${{ matrix.CONFIGOPTS }} fi - if test -n "$CPP11"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++11 $CXXFLAGS" "CFLAGS=-std=c11 $CFLAGS") && export CSTD=c11 && export CPPSTD=c++11; fi - if test -n "$CPP14"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++14 $CXXFLAGS" "CFLAGS=-std=c11 $CFLAGS") && export CSTD=c11 && export CPPSTD=c++14; fi - if test -n "$CPP17"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++17 $CXXFLAGS" "CFLAGS=-std=c17 $CFLAGS") && export CSTD=c17 && export CPPSTD=c++17; fi + if test -n "$CPP11"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++11 $CXXFLAGS" "CFLAGS=-std=c11 $CFLAGS"); fi + if test -n "$CPP14"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++14 $CXXFLAGS" "CFLAGS=-std=c11 $CFLAGS"); fi + if test -n "$CPP17"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++17 $CXXFLAGS" "CFLAGS=-std=c17 $CFLAGS"); fi if test -n "$SWIGLANG"; then CONFIGOPTS+=(--without-alllang --with-$WITHLANG); fi echo "${CONFIGOPTS[@]}" ./autogen.sh && mkdir -p build/build && cd build/build && ../../configure "${CONFIGOPTS[@]}" @@ -270,10 +276,6 @@ jobs: set -x source $GITHUB_WORKSPACE/Tools/CI-linux-environment.sh - if test -n "$CPP11"; then export CPPSTD=c++11; fi - if test -n "$CPP14"; then export CPPSTD=c++14; fi - if test -n "$CPP17"; then export CPPSTD=c++17; fi - if test -z "$SWIGLANG"; then make $SWIGJOBS check-ccache; fi if test -z "$SWIGLANG"; then make $SWIGJOBS check-errors-test-suite; fi From 8b5cd5f9063aba702ba2af54c62ac2fde769d819 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 22 Oct 2021 09:16:41 +0100 Subject: [PATCH 071/262] GHA: cleaner output --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e28e344b5..0e08a5f06 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -244,8 +244,8 @@ jobs: - name: Configure run: | - set -x source $GITHUB_WORKSPACE/Tools/CI-linux-environment.sh + set -x if test -n "$CPP11"; then export CPPSTD=c++11 && export CSTD=c11; fi if test -n "$CPP14"; then export CPPSTD=c++14 && export CSTD=c11; fi @@ -273,8 +273,8 @@ jobs: - name: Test working-directory: build/build run: | - set -x source $GITHUB_WORKSPACE/Tools/CI-linux-environment.sh + set -x if test -z "$SWIGLANG"; then make $SWIGJOBS check-ccache; fi if test -z "$SWIGLANG"; then make $SWIGJOBS check-errors-test-suite; fi From 7ddd9da1306b7f394c25db8080d9de14ae8b9c58 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 2 Nov 2021 19:48:53 +0100 Subject: [PATCH 072/262] Update the apt sources before trying to install anything We need to refresh the information about the available packages before trying to install them. --- Tools/CI-linux-install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tools/CI-linux-install.sh b/Tools/CI-linux-install.sh index 04dd5127f..b18206e64 100644 --- a/Tools/CI-linux-install.sh +++ b/Tools/CI-linux-install.sh @@ -7,6 +7,8 @@ if [[ -n "$GCC" ]]; then $RETRY sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test $RETRY sudo apt-get -qq update $RETRY sudo apt-get install -qq g++-$GCC +else + $RETRY sudo apt-get -qq update fi $RETRY sudo apt-get -qq install libboost-dev libpcre3-dev From 119222be770546ee7fdc19c1b603d66a23c1c302 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 9 Nov 2021 23:20:31 +0100 Subject: [PATCH 073/262] Refactor code in Language::staticmemberfunctionHandler() No real changes, just move the test for "code" to the outer scope to facilitate the upcoming changes. This commit is best viewed ignoring whitespace-only changes. --- Source/Modules/lang.cxx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 66aebdea1..3064d22f9 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -1320,16 +1320,18 @@ int Language::staticmemberfunctionHandler(Node *n) { Delete(mrename); mrename = mangled; - if (Getattr(n, "sym:overloaded") && code) { - Append(cname, Getattr(defaultargs ? defaultargs : n, "sym:overname")); - } + if (code) { + if (Getattr(n, "sym:overloaded")) { + Append(cname, Getattr(defaultargs ? defaultargs : n, "sym:overname")); + } - if (!defaultargs && code) { - /* Hmmm. An added static member. We have to create a little wrapper for this */ - String *mangled_cname = Swig_name_mangle(cname); - Swig_add_extension_code(n, mangled_cname, parms, type, code, CPlusPlus, 0); - Setattr(n, "extendname", mangled_cname); - Delete(mangled_cname); + if (!defaultargs) { + /* Hmmm. An added static member. We have to create a little wrapper for this */ + String *mangled_cname = Swig_name_mangle(cname); + Swig_add_extension_code(n, mangled_cname, parms, type, code, CPlusPlus, 0); + Setattr(n, "extendname", mangled_cname); + Delete(mangled_cname); + } } } From 26bf86322b18040e2f2156c34a47b44c927d1399 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 9 Nov 2021 23:33:31 +0100 Subject: [PATCH 074/262] Use SWIG-specific for non-overloaded synthesized functions too This avoids conflicts between such functions, which are generated when using %extend to add static methods to an existing class, and the actual wrapper functions generated by the backend. This shouldn't result in any user-visible changes. --- Source/Modules/lang.cxx | 3 +++ Source/Swig/cwrap.c | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 3064d22f9..196ff47a9 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -1321,8 +1321,11 @@ int Language::staticmemberfunctionHandler(Node *n) { mrename = mangled; if (code) { + // See Swig_MethodToFunction() for the explanation of this code. if (Getattr(n, "sym:overloaded")) { Append(cname, Getattr(defaultargs ? defaultargs : n, "sym:overname")); + } else { + Append(cname, "__SWIG"); } if (!defaultargs) { diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index d6e5e0cdc..0d8008ef0 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -1076,9 +1076,18 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas /* Check if the method is overloaded. If so, and it has code attached, we append an extra suffix to avoid a name-clash in the generated wrappers. This allows overloaded methods to be defined - in C. */ - if (Getattr(n, "sym:overloaded") && code) { - Append(mangled, Getattr(defaultargs ? defaultargs : n, "sym:overname")); + in C. + + But when not using the suffix used for overloaded functions, we still need to ensure that the + wrapper name doesn't conflict with any wrapper functions, so make it sufficiently unique by + appending a suffix similar to the one used for overloaded functions to it. + */ + if (code) { + if (Getattr(n, "sym:overloaded")) { + Append(mangled, Getattr(defaultargs ? defaultargs : n, "sym:overname")); + } else { + Append(mangled, "__SWIG"); + } } /* See if there is any code that we need to emit */ From 1c34be2d249c661b69d54cf1060278c40301ee79 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 1 Nov 2021 19:24:07 +0000 Subject: [PATCH 075/262] Fix nspace warning message --- Source/Modules/java.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 958da8ed1..444fe02d1 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -196,7 +196,7 @@ public: String *name = Getattr(n, "name") ? Getattr(n, "name") : NewString(""); Swig_warning(WARN_JAVA_NSPACE_WITHOUT_PACKAGE, Getfile(n), Getline(n), "The nspace feature is used on '%s' without -package. " - "The generated code may not compile as Java does not support types declared in a named package accessing types declared in an unnamed package.\n", name); + "The generated code may not compile as Java does not support types declared in a named package accessing types declared in an unnamed package.\n", SwigType_namestr(name)); } } From 1bd3e771a08ab9b4240b410904cdea9188ef77f3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 23 Oct 2021 16:11:59 +0100 Subject: [PATCH 076/262] Fix C tests for Javascript and c++17 --- Examples/test-suite/register_par.i | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Examples/test-suite/register_par.i b/Examples/test-suite/register_par.i index 643841455..3be1c7ea0 100644 --- a/Examples/test-suite/register_par.i +++ b/Examples/test-suite/register_par.i @@ -4,6 +4,18 @@ struct swig_tree; %} +%{ +#if defined(__cplusplus) +#if __cplusplus >= 201703L +/* +Fix for languages that compile C tests as C++: + error: ISO C++17 does not allow ‘register’ storage class specifier [-Werror=register] +*/ +#define register +#endif +#endif +%} + // bug # 924413 %inline { void clear_tree_flags(register struct swig_tree *tp, register int i) {} From 95c76a6fa60ce846826a8bd4b2dc41e7f56cf294 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 10 Nov 2021 14:10:52 +0000 Subject: [PATCH 077/262] Simpler Test code for handling SWIGLANG --- .github/workflows/ci.yml | 46 +++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0e08a5f06..0e1ebbe25 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -276,29 +276,31 @@ jobs: source $GITHUB_WORKSPACE/Tools/CI-linux-environment.sh set -x - if test -z "$SWIGLANG"; then make $SWIGJOBS check-ccache; fi - if test -z "$SWIGLANG"; then make $SWIGJOBS check-errors-test-suite; fi + if test -z "$SWIGLANG"; then + make $SWIGJOBS check-ccache + make $SWIGJOBS check-errors-test-suite + else + case "$SWIGLANG" in + javascript) + case "$ENGINE" in + v8 | jsc) + # Running tests using v8 or jsc involves creating a custom + # interpreter in Tools/javascript, which is currently broken + # for parallel builds (we attempt to update this interpreter + # while running, resulting in "Text file busy" error). + unset SWIGJOBS + esac + ;; + esac - case "$SWIGLANG" in - javascript) - case "$ENGINE" in - v8 | jsc) - # Running tests using v8 or jsc involves creating a custom - # interpreter in Tools/javascript, which is currently broken - # for parallel builds (we attempt to update this interpreter - # while running, resulting in "Text file busy" error). - unset SWIGJOBS - esac - ;; - esac - - # Stricter compile flags for examples. Various headers and SWIG generated code prevents full use of -pedantic. - if test -n "$SWIGLANG"; then cflags=$($GITHUB_WORKSPACE/Tools/testflags.py --language $SWIGLANG --cflags --std=$CSTD --compiler=$CC) && echo $cflags; fi - if test -n "$SWIGLANG"; then cxxflags=$($GITHUB_WORKSPACE/Tools/testflags.py --language $SWIGLANG --cxxflags --std=$CPPSTD --compiler=$CC) && echo $cxxflags; fi - if test -n "$SWIGLANG"; then make check-$SWIGLANG-version; fi - if test -n "$SWIGLANG"; then make check-$SWIGLANG-enabled; fi - if test -n "$SWIGLANG"; then make $SWIGJOBS check-$SWIGLANG-examples CFLAGS="$cflags" CXXFLAGS="$cxxflags"; fi - if test -n "$SWIGLANG"; then make $SWIGJOBS check-$SWIGLANG-test-suite CFLAGS="$cflags" CXXFLAGS="$cxxflags"; fi + # Stricter compile flags for examples. Various headers and SWIG generated code prevents full use of -pedantic. + cflags=$($GITHUB_WORKSPACE/Tools/testflags.py --language $SWIGLANG --cflags --std=$CSTD --compiler=$CC) && echo $cflags + cxxflags=$($GITHUB_WORKSPACE/Tools/testflags.py --language $SWIGLANG --cxxflags --std=$CPPSTD --compiler=$CC) && echo $cxxflags + make check-$SWIGLANG-version + make check-$SWIGLANG-enabled + make $SWIGJOBS check-$SWIGLANG-examples CFLAGS="$cflags" CXXFLAGS="$cxxflags" + make $SWIGJOBS check-$SWIGLANG-test-suite CFLAGS="$cflags" CXXFLAGS="$cxxflags" + fi - name: Install working-directory: build/build From b69b5888a81fb605e94ddaa1fa5df7c26de2838e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 11 Nov 2021 20:13:13 +0000 Subject: [PATCH 078/262] GHA: Fix testing of php versions The ubuntu-20.04 machine has php 7.4 and 8.0 installed. configure.ac always looks for newer versions over older versions of php. To prevent always testing 8.0, remove all versions and just install the required version. --- .github/workflows/ci.yml | 1 - Tools/CI-linux-install.sh | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0e1ebbe25..2c21212f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -96,7 +96,6 @@ jobs: - SWIGLANG: php VER: '7.4' - SWIGLANG: php - VER: '8.0' - SWIGLANG: python - SWIGLANG: python PY3: 3 diff --git a/Tools/CI-linux-install.sh b/Tools/CI-linux-install.sh index b18206e64..6edce572b 100644 --- a/Tools/CI-linux-install.sh +++ b/Tools/CI-linux-install.sh @@ -83,9 +83,12 @@ case "$SWIGLANG" in $RETRY sudo apt-get -qq install liboctave-dev ;; "php") - $RETRY sudo add-apt-repository -y ppa:ondrej/php - $RETRY sudo apt-get -qq update - $RETRY sudo apt-get -qq install php$VER-cli php$VER-dev + if [[ "$VER" ]]; then + $RETRY sudo apt-get -qq remove "php*-cli" "php*-dev" # Multiple versions are pre-installed + $RETRY sudo add-apt-repository -y ppa:ondrej/php + $RETRY sudo apt-get -qq update + $RETRY sudo apt-get -qq install php$VER-cli php$VER-dev + fi ;; "python") pip install --user pycodestyle From e74b9830bbb0a3f32d044e56b671b7685cd253bf Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 11 Nov 2021 20:32:54 +0000 Subject: [PATCH 079/262] GHA: C++11 testing and compiler name Show compiler name (directly from inputs rather than from 'desc'. Fix testing of C++11, C++14. Allow for CSTD override to override with -std=gnu11 for languages whose headers are not -std=c11 compatible. Show c/c++ std being tested from github yaml file in the name. --- .github/workflows/ci.yml | 46 ++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2c21212f1..7f97a15f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,31 +21,24 @@ jobs: # By default, the name of the build is the language used and SWIG options, but matrix entries # can define the additional "desc" field with any additional information to include in the name. - name: ${{ matrix.SWIGLANG || 'none' }}${{ matrix.PY3 }} ${{ matrix.ENGINE}} ${{ matrix.VER }} ${{ matrix.SWIG_FEATURES }} ${{ matrix.desc }} + name: ${{ matrix.SWIGLANG || 'none' }}${{ matrix.PY3 }} ${{ matrix.ENGINE}} ${{ matrix.VER }} ${{ matrix.SWIG_FEATURES }} ${{ (matrix.compiler || 'gcc') }}${{ matrix.GCC }} ${{ matrix.CPPSTD }} ${{ matrix.CSTD }} ${{ matrix.desc }} strategy: matrix: include: - SWIGLANG: "" - desc: gcc - SWIGLANG: "" GCC: 7 - desc: gcc7 - SWIGLANG: "" GCC: 8 - desc: gcc8 - SWIGLANG: "" GCC: 9 - desc: gcc9 - SWIGLANG: "" GCC: 10 - desc: gcc10 - SWIGLANG: "" GCC: 11 - desc: gcc11 - SWIGLANG: "" compiler: clang - desc: clang - SWIGLANG: csharp # D support can't be enabled because dmd 2.066 fails to build anything # under Ubuntu 18.04 due to its standard library (libphobos2.a) not @@ -72,15 +65,15 @@ jobs: - SWIGLANG: javascript ENGINE: node VER: '12' - CPP11: 1 + CPPSTD: c++11 - SWIGLANG: javascript ENGINE: node VER: '14' - CPP11: 1 + CPPSTD: c++11 - SWIGLANG: javascript ENGINE: node VER: '16' - CPP14: 1 + CPPSTD: c++14 - SWIGLANG: javascript ENGINE: jsc os: ubuntu-18.04 # libwebkitgtk-dev dependency not available in 20.04. @@ -91,7 +84,7 @@ jobs: - SWIGLANG: lua VER: '5.3' - SWIGLANG: octave - CPP11: 1 + CPPSTD: c++11 - SWIGLANG: perl5 - SWIGLANG: php VER: '7.4' @@ -164,7 +157,7 @@ jobs: - SWIGLANG: ruby VER: '3.0' CSTD: c99 - CPP11: 1 + CPPSTD: c++11 - SWIGLANG: tcl # let's run all of them, as opposed to aborting when one fails fail-fast: false @@ -176,9 +169,8 @@ jobs: ENGINE: ${{ matrix.ENGINE }} SWIG_FEATURES: ${{ matrix.SWIG_FEATURES }} CSTD: ${{ matrix.CSTD }} - CPP11: ${{ matrix.CPP11 }} - CPP14: ${{ matrix.CPP14 }} - CPP17: ${{ matrix.CPP17 }} + CPPSTD: ${{ matrix.CPPSTD }} + GCC: ${{ matrix.GCC }} steps: - name: Checkout @@ -246,18 +238,16 @@ jobs: source $GITHUB_WORKSPACE/Tools/CI-linux-environment.sh set -x - if test -n "$CPP11"; then export CPPSTD=c++11 && export CSTD=c11; fi - if test -n "$CPP14"; then export CPPSTD=c++14 && export CSTD=c11; fi - if test -n "$CPP17"; then export CPPSTD=c++17 && export CSTD=c17; fi - echo CPPSTD="$CPPSTD" >> $GITHUB_ENV - echo CSTD="$CSTD" >> $GITHUB_ENV - - if test -n '${{ matrix.CONFIGOPTS }}'; then - CONFIGOPTS=${{ matrix.CONFIGOPTS }} + if [[ -z "$CSTD" ]]; then + case "$CPPSTD" in + c++11) export CSTD=c11 ;; + c++14) export CSTD=c11 ;; + c++17) export CSTD=c17 ;; + esac + echo CSTD="$CSTD" >> $GITHUB_ENV fi - if test -n "$CPP11"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++11 $CXXFLAGS" "CFLAGS=-std=c11 $CFLAGS"); fi - if test -n "$CPP14"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++14 $CXXFLAGS" "CFLAGS=-std=c11 $CFLAGS"); fi - if test -n "$CPP17"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++17 $CXXFLAGS" "CFLAGS=-std=c17 $CFLAGS"); fi + if test -n "$CPPSTD"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=$CPPSTD $CXXFLAGS"); fi + if test -n "$CSTD"; then CONFIGOPTS+=("CFLAGS=-std=$CSTD $CFLAGS"); fi if test -n "$SWIGLANG"; then CONFIGOPTS+=(--without-alllang --with-$WITHLANG); fi echo "${CONFIGOPTS[@]}" ./autogen.sh && mkdir -p build/build && cd build/build && ../../configure "${CONFIGOPTS[@]}" @@ -311,4 +301,4 @@ jobs: working-directory: build/build run: | set -x - make check-maintainer-clean && ../../configure $CONFIGOPTS + make check-maintainer-clean && ../../configure From d13c63dc8d3bd8357f3777623d791e2dddc82d0f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 11 Nov 2021 20:38:50 +0000 Subject: [PATCH 080/262] GHA: test go 1.17 (latest) version --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f97a15f2..8dee9715b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,7 +58,7 @@ jobs: VER: '1.12' CSTD: gnu99 - SWIGLANG: go - VER: '1.16' + VER: '1.17' CSTD: gnu99 - SWIGLANG: guile - SWIGLANG: java From c1d8852609d0e87afa9abe52dbba47db9359ae17 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 11 Nov 2021 21:08:46 +0000 Subject: [PATCH 081/262] GHA: Turn on full c++11, c++14, c++17 testing Like we had on Travis Note that Octave C++11 is already tested --- .github/workflows/ci.yml | 105 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 100 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8dee9715b..d670bd71d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,15 +51,14 @@ jobs: # os: ubuntu-18.04 # This dlang version doesn't work under 20.04. - SWIGLANG: go VER: '1.6' - CSTD: gnu99 + CSTD: gnu11 - SWIGLANG: go VER: '1.8' - SWIGLANG: go VER: '1.12' - CSTD: gnu99 + CSTD: gnu11 - SWIGLANG: go VER: '1.17' - CSTD: gnu99 - SWIGLANG: guile - SWIGLANG: java - SWIGLANG: javascript @@ -156,9 +155,105 @@ jobs: VER: '2.7' - SWIGLANG: ruby VER: '3.0' - CSTD: c99 + - SWIGLANG: tcl + # c++11 testing + - SWIGLANG: csharp + CPPSTD: c++11 + - SWIGLANG: go + VER: '1.17' + CPPSTD: c++11 + CSTD: gnu11 + - SWIGLANG: java + CPPSTD: c++11 + - SWIGLANG: javascript + ENGINE: node + VER: '14' + CPPSTD: c++11 + # - SWIGLANG: octave + # CPPSTD: c++11 + - SWIGLANG: perl5 + CPPSTD: c++11 + - SWIGLANG: php + CPPSTD: c++11 + CSTD: gnu11 + - SWIGLANG: python + CPPSTD: c++11 + PY3: 3 + - SWIGLANG: r + CPPSTD: c++11 + - SWIGLANG: ruby CPPSTD: c++11 - SWIGLANG: tcl + CPPSTD: c++11 + # c++14 testing + - SWIGLANG: csharp + CPPSTD: c++14 + - SWIGLANG: go + VER: '1.17' + CPPSTD: c++14 + CSTD: gnu11 + - SWIGLANG: java + CPPSTD: c++14 + - SWIGLANG: javascript + ENGINE: node + VER: '16' + CPPSTD: c++14 + - SWIGLANG: octave + CPPSTD: c++14 + - SWIGLANG: perl5 + CPPSTD: c++14 + - SWIGLANG: php + CPPSTD: c++14 + CSTD: gnu11 + - SWIGLANG: python + CPPSTD: c++14 + PY3: 3 + - SWIGLANG: r + CPPSTD: c++14 + - SWIGLANG: ruby + CPPSTD: c++14 + - SWIGLANG: tcl + CPPSTD: c++14 + # c++17 testing (using gcc11) + - SWIGLANG: csharp + CPPSTD: c++17 + GCC: 11 + - SWIGLANG: go + VER: '1.17' + CPPSTD: c++17 + GCC: 11 + CSTD: gnu17 + - SWIGLANG: java + CPPSTD: c++17 + GCC: 11 + - SWIGLANG: javascript + ENGINE: node + VER: '16' + CPPSTD: c++17 + GCC: 11 + - SWIGLANG: octave + CPPSTD: c++17 + GCC: 11 + - SWIGLANG: perl5 + CPPSTD: c++17 + GCC: 11 + - SWIGLANG: php + CPPSTD: c++17 + CSTD: gnu17 + GCC: 11 + - SWIGLANG: python + CPPSTD: c++17 + GCC: 11 + PY3: 3 + - SWIGLANG: r + CPPSTD: c++17 + GCC: 11 + - SWIGLANG: ruby + CPPSTD: c++17 + GCC: 11 + - SWIGLANG: tcl + CPPSTD: c++17 + GCC: 11 # let's run all of them, as opposed to aborting when one fails fail-fast: false @@ -168,9 +263,9 @@ jobs: VER: ${{ matrix.VER }} ENGINE: ${{ matrix.ENGINE }} SWIG_FEATURES: ${{ matrix.SWIG_FEATURES }} + GCC: ${{ matrix.GCC }} CSTD: ${{ matrix.CSTD }} CPPSTD: ${{ matrix.CPPSTD }} - GCC: ${{ matrix.GCC }} steps: - name: Checkout From aedcad5384e17aa00196117c1312a0cfbf911591 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 11 Nov 2021 22:03:38 +0000 Subject: [PATCH 082/262] Run GHA on all branches --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d670bd71d..7de1aa675 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,6 @@ name: CI on: push: - branches: master paths-ignore: - 'CHANGES*' - 'Doc/**' From 7da8ce722b07fcd437854a30d29b07b86fa57661 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 11 Nov 2021 22:51:31 +0000 Subject: [PATCH 083/262] Ruby 3.0 requires std::nullptr_t --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7de1aa675..79c27b7d0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -154,6 +154,7 @@ jobs: VER: '2.7' - SWIGLANG: ruby VER: '3.0' + CPPSTD: c++11 - SWIGLANG: tcl # c++11 testing - SWIGLANG: csharp From d15a3cb1d4bc537e55aaedb0239559bfd4bf77b2 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 11 Nov 2021 23:02:53 +0000 Subject: [PATCH 084/262] Fix testcase -Wstringop-truncation warning in gcc11 --- Examples/javascript/exception/example.h | 2 +- Examples/lua/exception/example.h | 2 +- Examples/python/exception/example.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Examples/javascript/exception/example.h b/Examples/javascript/exception/example.h index bc744cda7..c76c46a5d 100644 --- a/Examples/javascript/exception/example.h +++ b/Examples/javascript/exception/example.h @@ -10,7 +10,7 @@ class Exc { public: Exc(int c, const char *m) { code = c; - strncpy(msg,m,256); + strncpy(msg,m,255); } int code; char msg[256]; diff --git a/Examples/lua/exception/example.h b/Examples/lua/exception/example.h index bc744cda7..c76c46a5d 100644 --- a/Examples/lua/exception/example.h +++ b/Examples/lua/exception/example.h @@ -10,7 +10,7 @@ class Exc { public: Exc(int c, const char *m) { code = c; - strncpy(msg,m,256); + strncpy(msg,m,255); } int code; char msg[256]; diff --git a/Examples/python/exception/example.h b/Examples/python/exception/example.h index bc744cda7..c76c46a5d 100644 --- a/Examples/python/exception/example.h +++ b/Examples/python/exception/example.h @@ -10,7 +10,7 @@ class Exc { public: Exc(int c, const char *m) { code = c; - strncpy(msg,m,256); + strncpy(msg,m,255); } int code; char msg[256]; From 6cafc931352551340411fab7621e7c8e54d537c6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 12 Nov 2021 08:03:33 +0000 Subject: [PATCH 085/262] -Wfree-nonheap-object warning fix using gcc-11 --- Examples/test-suite/typemap_various.i | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/typemap_various.i b/Examples/test-suite/typemap_various.i index 3436bac1c..2caff97dc 100644 --- a/Examples/test-suite/typemap_various.i +++ b/Examples/test-suite/typemap_various.i @@ -61,7 +61,11 @@ void CheckRetTypemapUsed() { %inline { class FFoo { public: - char * Bar(bool b) const { return (char *)"x"; } + char * Bar(bool b) const { + char *ret = new char[2]; + strcpy(ret, b ? "1" : "0"); + return ret; + } }; } From ada739b4a8e71717f9438c0b6d7e34f1b18e3832 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 12 Nov 2021 09:09:14 +0000 Subject: [PATCH 086/262] Fix mismatched new char[] and free() - Javascript Javascript - v8 and node only. When wrapping C code char arrays. Now calloc is now used instead of new char[] in SWIG_AsCharPtrAndSize. Fixes gcc-11 warning -Wmismatched-new-delete in arrays and memberin_extend testcases. --- CHANGES.current | 5 +++++ Lib/javascript/v8/javascriptstrings.swg | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 6bafec31c..0abed204a 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,11 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2021-11-12: wsfulton + [Javascript] v8 and node only. Fix mismatched new char[] and free() + when wrapping C code char arrays. Now calloc is now used instead of + new char[] in SWIG_AsCharPtrAndSize. + 2021-10-03: ajrh1 [Perl] #2074: Avoid -Wmisleading-indentation in generated code when using gcc11. diff --git a/Lib/javascript/v8/javascriptstrings.swg b/Lib/javascript/v8/javascriptstrings.swg index 42d0b86b5..aaf1b9302 100644 --- a/Lib/javascript/v8/javascriptstrings.swg +++ b/Lib/javascript/v8/javascriptstrings.swg @@ -14,7 +14,7 @@ SWIG_AsCharPtrAndSize(SWIGV8_VALUE valRef, char** cptr, size_t* psize, int *allo %#endif size_t len = SWIGV8_UTF8_LENGTH(js_str) + 1; - char* cstr = new char[len]; + char* cstr = (char*) %new_array(len, char); SWIGV8_WRITE_UTF8(js_str, cstr, len); if(alloc) *alloc = SWIG_NEWOBJ; From 842ed6ca9dc5c8d6b46e31f34ed22556f025f61c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 12 Nov 2021 18:13:41 +0000 Subject: [PATCH 087/262] Testcase warning fix using gcc-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit warning: ‘this’ pointer is null [-Wnonnull] --- Examples/test-suite/smart_pointer_inherit.i | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/smart_pointer_inherit.i b/Examples/test-suite/smart_pointer_inherit.i index 52df5a92b..26987a5ac 100644 --- a/Examples/test-suite/smart_pointer_inherit.i +++ b/Examples/test-suite/smart_pointer_inherit.i @@ -70,7 +70,10 @@ class ItkVectorContainerUILSNUS2 : public std::vector< ItkLevelSetNodeUS2 > { class ItkVectorContainerUILSNUS2_Pointer { public: - ItkVectorContainerUILSNUS2 * operator->() const { return 0; } + ItkVectorContainerUILSNUS2 * operator->() const { + static ItkVectorContainerUILSNUS2 instance; + return &instance; + } }; %} From 01eb2e0aa99acaace2ebe406ef069cfb3f2420e1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 12 Nov 2021 19:30:53 +0000 Subject: [PATCH 088/262] Lua int ref typemap improvements Fixes complex typedefs to const int& and const unsigned int&. Fixes cpp11_type_aliasing testcase --- Lib/lua/luatypemaps.swg | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/lua/luatypemaps.swg b/Lib/lua/luatypemaps.swg index 6c92e3b59..3f531bd05 100644 --- a/Lib/lua/luatypemaps.swg +++ b/Lib/lua/luatypemaps.swg @@ -39,12 +39,12 @@ $1 = ($type)lua_tonumber(L, $input);%} // SWIG assumes that this code will need a pointer to int to be passed in // (this might be ok for objects by const ref, but not for numeric primitives) // therefore we add a set of typemaps to fix this (for both in & out) -%typemap(in,checkfn="lua_isnumber") const int&($basetype temp) -%{ temp=($basetype)lua_tonumber(L,$input); $1=&temp;%} +%typemap(in,checkfn="lua_isnumber") const int&($*1_ltype temp) +%{ temp=($*1_ltype)lua_tonumber(L,$input); $1=&temp;%} -%typemap(in,checkfn="lua_isnumber") const unsigned int&($basetype temp) +%typemap(in,checkfn="lua_isnumber") const unsigned int&($*1_ltype temp) %{SWIG_contract_assert((lua_tonumber(L,$input)>=0),"number must not be negative") -temp=($basetype)lua_tonumber(L,$input); $1=&temp;%} +temp=($*1_ltype)lua_tonumber(L,$input); $1=&temp;%} %typemap(out) const int&, const unsigned int& %{ lua_pushnumber(L, (lua_Number) *$1); SWIG_arg++;%} From 10af8fd921bebb88a9a739f0d6d3e9dceb07442b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 12 Nov 2021 19:45:25 +0000 Subject: [PATCH 089/262] Workaround Lua failing cpp11_raw_string_literals test --- Examples/test-suite/cpp11_raw_string_literals.i | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Examples/test-suite/cpp11_raw_string_literals.i b/Examples/test-suite/cpp11_raw_string_literals.i index b50b768b9..813374928 100644 --- a/Examples/test-suite/cpp11_raw_string_literals.i +++ b/Examples/test-suite/cpp11_raw_string_literals.i @@ -21,6 +21,11 @@ %include #endif +#if defined(SWIGLUA) +// Lua uses a parameter called L in every wrapper function +%ignore L; +#endif + %inline %{ #include #include From c83466af536ea4c5de5361aa93facbe70fed3079 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 12 Nov 2021 19:49:45 +0000 Subject: [PATCH 090/262] GHA: Add Lua to c++11,c++14,c++17 testing --- .github/workflows/ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 79c27b7d0..684cc69db 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -169,6 +169,8 @@ jobs: ENGINE: node VER: '14' CPPSTD: c++11 + - SWIGLANG: lua + CPPSTD: c++11 # - SWIGLANG: octave # CPPSTD: c++11 - SWIGLANG: perl5 @@ -198,6 +200,8 @@ jobs: ENGINE: node VER: '16' CPPSTD: c++14 + - SWIGLANG: lua + CPPSTD: c++14 - SWIGLANG: octave CPPSTD: c++14 - SWIGLANG: perl5 @@ -231,6 +235,9 @@ jobs: VER: '16' CPPSTD: c++17 GCC: 11 + - SWIGLANG: lua + CPPSTD: c++17 + GCC: 11 - SWIGLANG: octave CPPSTD: c++17 GCC: 11 From 54e2ad073fe2b9a29da48effea9ed83dd7773df7 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 15 Nov 2021 08:00:46 +0000 Subject: [PATCH 091/262] Fix cpp11_type_aliasing test Ordering fix for Guile wrappers to compile --- Examples/test-suite/cpp11_type_aliasing.i | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/cpp11_type_aliasing.i b/Examples/test-suite/cpp11_type_aliasing.i index abc1642c4..ea4048408 100644 --- a/Examples/test-suite/cpp11_type_aliasing.i +++ b/Examples/test-suite/cpp11_type_aliasing.i @@ -63,12 +63,14 @@ using IntArray = Int[]; // Test that SWIG understands these new types +%{ +Int mult2(Int x) { return x * 2; } +%} %callback("%s_cb"); Int mult2(Int x); %nocallback; %inline %{ -Int mult2(Int x) { return x * 2; } IntPtr allocate_int() { return new Int(12); } void free_int(int* ptr) { delete ptr; } void inplace_mult2(IntRef x) { x *= 2; } From 47d39ed3d8d3265b3be6ca2b5973acd0e715c16a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 15 Nov 2021 08:17:32 +0000 Subject: [PATCH 092/262] GHA: Add Guile to c++11,c++14,c++17 testing --- .github/workflows/ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 684cc69db..8a269f22f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -163,6 +163,8 @@ jobs: VER: '1.17' CPPSTD: c++11 CSTD: gnu11 + - SWIGLANG: guile + CPPSTD: c++11 - SWIGLANG: java CPPSTD: c++11 - SWIGLANG: javascript @@ -194,6 +196,8 @@ jobs: VER: '1.17' CPPSTD: c++14 CSTD: gnu11 + - SWIGLANG: guile + CPPSTD: c++14 - SWIGLANG: java CPPSTD: c++14 - SWIGLANG: javascript @@ -227,6 +231,9 @@ jobs: CPPSTD: c++17 GCC: 11 CSTD: gnu17 + - SWIGLANG: guile + CPPSTD: c++17 + GCC: 11 - SWIGLANG: java CPPSTD: c++17 GCC: 11 From e6b6fa93aa1ac92ee883079fe232ef7362643960 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 15 Nov 2021 19:25:41 +0000 Subject: [PATCH 093/262] Fix guile examples for C11 and later conformance --- Examples/guile/matrix/example.i | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Examples/guile/matrix/example.i b/Examples/guile/matrix/example.i index 3f801dcdf..6f8fa8859 100644 --- a/Examples/guile/matrix/example.i +++ b/Examples/guile/matrix/example.i @@ -14,4 +14,8 @@ %include math.i -extern double drand48(); +%{ +/* Add drand48 declaration as it is posix only and is not in stdlib.h when using strict c99 and later */ +extern double drand48(void); +%} +extern double drand48(void); From 75cacc1325ccb14c744603f68d49ba2f60874887 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 15 Nov 2021 19:55:26 +0000 Subject: [PATCH 094/262] CC and CXX override improvements in examples Use the overridden CC and CXX compiles when linking when overriding at make time. Previously the following would use CC and CXX specified at configure time when linking: make CC=gcc-11 CXX=g++-11 --- configure.ac | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/configure.ac b/configure.ac index 23d0a3731..c829723df 100644 --- a/configure.ac +++ b/configure.ac @@ -146,14 +146,14 @@ then *-*-aix*) LDSHARED="\$(srcdir)/ld_so_aix \$(CC)";; *-*-cygwin* | *-*-mingw*) if test "$GCC" = yes; then - LDSHARED="$CC -shared" + LDSHARED="\$(CC) -shared" else if test "cl" = $CC ; then # Microsoft Visual C++ (MSVC) - LDSHARED="$CC -nologo -LD" + LDSHARED="\$(CC) -nologo -LD" else # Unknown compiler try gcc approach - LDSHARED="$CC -shared" + LDSHARED="\$(CC) -shared" fi fi ;; *-*-irix5*) LDSHARED="ld -shared";; @@ -165,25 +165,25 @@ then *-sequent-sysv4) LDSHARED="ld -G";; *-*-next*) if test "$ns_dyld" - then LDSHARED='$(CC) $(LDFLAGS) -bundle -prebind' - else LDSHARED='$(CC) $(CFLAGS) -nostdlib -r' + then LDSHARED="\$(CC) \$(LDFLAGS) -bundle -prebind" + else LDSHARED="\$(CC) \$(CFLAGS) -nostdlib -r" fi if test "$with_next_framework" ; then LDSHARED="$LDSHARED \$(LDLIBRARY)" fi ;; - *-*-linux*) LDSHARED="$CC -shared";; + *-*-linux*) LDSHARED="\$(CC) -shared";; *-*-dgux*) LDSHARED="ld -G";; - *-*-freebsd3*) LDSHARED="$CC -shared";; + *-*-freebsd3*) LDSHARED="\$(CC) -shared";; *-*-freebsd* | *-*-openbsd*) LDSHARED="ld -Bshareable";; *-*-netbsd*) - if [[ "`$CC -dM -E - Date: Mon, 15 Nov 2021 20:19:12 +0000 Subject: [PATCH 095/262] Scilab compilation fix when wrapping C++11 enum classes --- Lib/scilab/scienum.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/scilab/scienum.swg b/Lib/scilab/scienum.swg index 54ec1f85c..cc1f7c977 100644 --- a/Lib/scilab/scienum.swg +++ b/Lib/scilab/scienum.swg @@ -18,7 +18,7 @@ SWIG_Int_AsEnum(void *pvApiCtx, int iVar, int *enumValue, char *fname) { } %fragment(SWIG_From_frag(Enum), "header", fragment="SWIG_Int_FromEnum") { -%#define SWIG_From_Enum(scilabValue) SWIG_Int_FromEnum(pvApiCtx, SWIG_Scilab_GetOutputPosition(), scilabValue, SWIG_Scilab_GetFuncName()) +%#define SWIG_From_Enum(scilabValue) SWIG_Int_FromEnum(pvApiCtx, SWIG_Scilab_GetOutputPosition(), (int)scilabValue, SWIG_Scilab_GetFuncName()) } %fragment("SWIG_Int_FromEnum", "header", fragment="SWIG_SciDouble_FromInt") { SWIGINTERN int From b53b2f1a27a2654b443db181199fe764e8a148ec Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 15 Nov 2021 22:13:27 +0000 Subject: [PATCH 096/262] Shorter names in cpp11_rvalue_reference3 testcase for Scilab --- Examples/test-suite/cpp11_rvalue_reference3.i | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/Examples/test-suite/cpp11_rvalue_reference3.i b/Examples/test-suite/cpp11_rvalue_reference3.i index 8ebf45366..55a55bac9 100644 --- a/Examples/test-suite/cpp11_rvalue_reference3.i +++ b/Examples/test-suite/cpp11_rvalue_reference3.i @@ -24,19 +24,19 @@ void takeit3(Thing const*&& t) {} void takeit4(Thing *const&& t) {} void takeit5(Thing const*const&& t) {} -struct Containing { - Thing && member_rvalue_ref; - Thing *&& member_rvalue_ref_ptr1; - Thing const*&& member_rvalue_ref_ptr2; - Thing *const&& member_rvalue_ref_ptr3; - Thing const*const &&member_rvalue_ref_ptr4; +struct Contain { + Thing && m_ref; + Thing *&& m_ref_ptr1; + Thing const*&& m_ref_ptr2; + Thing *const&& m_ref_ptr3; + Thing const*const &&m_ref_ptr4; - Containing(Thing&&r, Thing*&& r1, Thing const*&& r2, Thing *const&& r3, Thing const*const && r4) : - member_rvalue_ref(std::move(r)), - member_rvalue_ref_ptr1(std::move(r1)), - member_rvalue_ref_ptr2(std::move(r2)), - member_rvalue_ref_ptr3(std::move(r3)), - member_rvalue_ref_ptr4(std::move(r4)) + Contain(Thing&&r, Thing*&& r1, Thing const*&& r2, Thing *const&& r3, Thing const*const && r4) : + m_ref(std::move(r)), + m_ref_ptr1(std::move(r1)), + m_ref_ptr2(std::move(r2)), + m_ref_ptr3(std::move(r3)), + m_ref_ptr4(std::move(r4)) {} }; %} @@ -61,19 +61,19 @@ void int_takeit3(int const*&& t) {} void int_takeit4(int *const&& t) {} void int_takeit5(int const*const&& t) {} -struct IntContaining { - int && member_rvalue_ref; - int *&& member_rvalue_ref_ptr1; - int const*&& member_rvalue_ref_ptr2; - int *const&& member_rvalue_ref_ptr3; - int const*const &&member_rvalue_ref_ptr4; +struct IContain { + int && m_ref; + int *&& m_ref_ptr1; + int const*&& m_ref_ptr2; + int *const&& m_ref_ptr3; + int const*const &&m_ref_ptr4; - IntContaining(int&& r, int*&& r1, int const*&& r2, int *const&& r3, int const*const && r4) : - member_rvalue_ref(std::move(r)), - member_rvalue_ref_ptr1(std::move(r1)), - member_rvalue_ref_ptr2(std::move(r2)), - member_rvalue_ref_ptr3(std::move(r3)), - member_rvalue_ref_ptr4(std::move(r4)) + IContain(int&& r, int*&& r1, int const*&& r2, int *const&& r3, int const*const && r4) : + m_ref(std::move(r)), + m_ref_ptr1(std::move(r1)), + m_ref_ptr2(std::move(r2)), + m_ref_ptr3(std::move(r3)), + m_ref_ptr4(std::move(r4)) {} }; %} From 99954d6d4e45506c01c40cdfb1d20ef8dd1f7fd4 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 15 Nov 2021 22:45:56 +0000 Subject: [PATCH 097/262] Shorten testcase variable names for Scilab 6 to work --- .../test-suite/guile/overload_null_runme.scm | 14 +++++++------- .../javascript/overload_null_runme.js | 14 +++++++------- .../test-suite/lua/overload_null_runme.lua | 14 +++++++------- .../test-suite/octave/overload_null_runme.m | 14 +++++++------- Examples/test-suite/overload_null.i | 18 +++++++++--------- .../test-suite/perl5/overload_null_runme.pl | 14 +++++++------- .../test-suite/php/overload_null_runme.php | 14 +++++++------- .../test-suite/python/overload_null_runme.py | 14 +++++++------- Examples/test-suite/r/overload_null_runme.R | 14 +++++++------- .../test-suite/ruby/overload_null_runme.rb | 14 +++++++------- .../test-suite/scilab/overload_null_runme.sci | 14 +++++++------- .../test-suite/tcl/overload_null_runme.tcl | 14 +++++++------- 12 files changed, 86 insertions(+), 86 deletions(-) diff --git a/Examples/test-suite/guile/overload_null_runme.scm b/Examples/test-suite/guile/overload_null_runme.scm index f764d9c20..6824707d0 100644 --- a/Examples/test-suite/guile/overload_null_runme.scm +++ b/Examples/test-suite/guile/overload_null_runme.scm @@ -39,15 +39,15 @@ ;(check (=~ 15 (Overload-byval2cpr o #nil))) ;(check (=~ 16 (Overload-byval2cpr o x))) -; forward class declaration -(check (=~ 17 (Overload-byval1forwardptr o x))) -(check (=~ 18 (Overload-byval1forwardptr o #nil))) +; fwd class declaration +(check (=~ 17 (Overload-byval1fwdptr o x))) +(check (=~ 18 (Overload-byval1fwdptr o #nil))) -(check (=~ 19 (Overload-byval2forwardptr o #nil))) -(check (=~ 20 (Overload-byval2forwardptr o x))) +(check (=~ 19 (Overload-byval2fwdptr o #nil))) +(check (=~ 20 (Overload-byval2fwdptr o x))) -(check (=~ 21 (Overload-byval1forwardref o x))) +(check (=~ 21 (Overload-byval1fwdref o x))) -(check (=~ 22 (Overload-byval2forwardref o x))) +(check (=~ 22 (Overload-byval2fwdref o x))) (exit 0) diff --git a/Examples/test-suite/javascript/overload_null_runme.js b/Examples/test-suite/javascript/overload_null_runme.js index f1e35cac7..f6c31a436 100644 --- a/Examples/test-suite/javascript/overload_null_runme.js +++ b/Examples/test-suite/javascript/overload_null_runme.js @@ -37,13 +37,13 @@ check(13, o.byval1cpr(x)); // check(15, o.byval2cpr(null)); check(16, o.byval2cpr(x)); -// forward class declaration -check(17, o.byval1forwardptr(x)); -// check(18, o.byval1forwardptr(null)); +// fwd class declaration +check(17, o.byval1fwdptr(x)); +// check(18, o.byval1fwdptr(null)); -// check(19, o.byval2forwardptr(null)); -check(20, o.byval2forwardptr(x)); +// check(19, o.byval2fwdptr(null)); +check(20, o.byval2fwdptr(x)); -check(21, o.byval1forwardref(x)); +check(21, o.byval1fwdref(x)); -check(22, o.byval2forwardref(x)); +check(22, o.byval2fwdref(x)); diff --git a/Examples/test-suite/lua/overload_null_runme.lua b/Examples/test-suite/lua/overload_null_runme.lua index 69b7de2db..9b5ef5674 100644 --- a/Examples/test-suite/lua/overload_null_runme.lua +++ b/Examples/test-suite/lua/overload_null_runme.lua @@ -29,13 +29,13 @@ assert(14 == o:byval1cpr(nil)) assert(15 == o:byval2cpr(nil)) assert(16 == o:byval2cpr(x)) --- forward class declaration -assert(17 == o:byval1forwardptr(x)) -assert(18 == o:byval1forwardptr(nil)) +-- fwd class declaration +assert(17 == o:byval1fwdptr(x)) +assert(18 == o:byval1fwdptr(nil)) -assert(19 == o:byval2forwardptr(nil)) -assert(20 == o:byval2forwardptr(x)) +assert(19 == o:byval2fwdptr(nil)) +assert(20 == o:byval2fwdptr(x)) -assert(21 == o:byval1forwardref(x)) +assert(21 == o:byval1fwdref(x)) -assert(22 == o:byval2forwardref(x)) +assert(22 == o:byval2fwdref(x)) diff --git a/Examples/test-suite/octave/overload_null_runme.m b/Examples/test-suite/octave/overload_null_runme.m index a7c346c26..83c11a199 100644 --- a/Examples/test-suite/octave/overload_null_runme.m +++ b/Examples/test-suite/octave/overload_null_runme.m @@ -40,13 +40,13 @@ check(14, o.byval1cpr(null)); check(15, o.byval2cpr(null)); check(16, o.byval2cpr(x)); -# forward class declaration -check(17, o.byval1forwardptr(x)); -check(18, o.byval1forwardptr(null)); +# fwd class declaration +check(17, o.byval1fwdptr(x)); +check(18, o.byval1fwdptr(null)); -check(19, o.byval2forwardptr(null)); -check(20, o.byval2forwardptr(x)); +check(19, o.byval2fwdptr(null)); +check(20, o.byval2fwdptr(x)); -check(21, o.byval1forwardref(x)); +check(21, o.byval1fwdref(x)); -check(22, o.byval2forwardref(x)); +check(22, o.byval2fwdref(x)); diff --git a/Examples/test-suite/overload_null.i b/Examples/test-suite/overload_null.i index d4879fdb5..0ec970399 100644 --- a/Examples/test-suite/overload_null.i +++ b/Examples/test-suite/overload_null.i @@ -35,18 +35,18 @@ struct Overload { int byval2cpr(Y*const& y) { return 15; } int byval2cpr(X x) { return 16; } - // forward class declaration - int byval1forwardptr(X x) { return 17; } - int byval1forwardptr(F* f) { return 18; } + // fwd class declaration + int byval1fwdptr(X x) { return 17; } + int byval1fwdptr(F* f) { return 18; } - int byval2forwardptr(F* f) { return 19; } - int byval2forwardptr(X x) { return 20; } + int byval2fwdptr(F* f) { return 19; } + int byval2fwdptr(X x) { return 20; } - int byval1forwardref(X x) { return 21; } - int byval1forwardref(F& f) { return -21; } + int byval1fwdref(X x) { return 21; } + int byval1fwdref(F& f) { return -21; } - int byval2forwardref(F& f) { return -22; } - int byval2forwardref(X x) { return 22; } + int byval2fwdref(F& f) { return -22; } + int byval2fwdref(X x) { return 22; } }; %} diff --git a/Examples/test-suite/perl5/overload_null_runme.pl b/Examples/test-suite/perl5/overload_null_runme.pl index 7cc5090de..6c01b58a2 100644 --- a/Examples/test-suite/perl5/overload_null_runme.pl +++ b/Examples/test-suite/perl5/overload_null_runme.pl @@ -32,13 +32,13 @@ is(14, $o->byval1cpr(undef)); is(15, $o->byval2cpr(undef)); is(16, $o->byval2cpr($x)); -# forward class declaration -is(17, $o->byval1forwardptr($x)); -is(18, $o->byval1forwardptr(undef)); +# fwd class declaration +is(17, $o->byval1fwdptr($x)); +is(18, $o->byval1fwdptr(undef)); -is(19, $o->byval2forwardptr(undef)); -is(20, $o->byval2forwardptr($x)); +is(19, $o->byval2fwdptr(undef)); +is(20, $o->byval2fwdptr($x)); -is(21, $o->byval1forwardref($x)); +is(21, $o->byval1fwdref($x)); -is(22, $o->byval2forwardref($x)); +is(22, $o->byval2fwdref($x)); diff --git a/Examples/test-suite/php/overload_null_runme.php b/Examples/test-suite/php/overload_null_runme.php index b4b28e44f..7afafeacd 100644 --- a/Examples/test-suite/php/overload_null_runme.php +++ b/Examples/test-suite/php/overload_null_runme.php @@ -30,15 +30,15 @@ check::equal(14, $o->byval1cpr(null), "test 14"); check::equal(15, $o->byval2cpr(null), "test 15"); check::equal(16, $o->byval2cpr($x), "test 16"); -# forward class declaration -check::equal(17, $o->byval1forwardptr($x), "test 17"); -check::equal(18, $o->byval1forwardptr(null), "test 18"); +# fwd class declaration +check::equal(17, $o->byval1fwdptr($x), "test 17"); +check::equal(18, $o->byval1fwdptr(null), "test 18"); -check::equal(19, $o->byval2forwardptr(null), "test 19"); -check::equal(20, $o->byval2forwardptr($x), "test 20"); +check::equal(19, $o->byval2fwdptr(null), "test 19"); +check::equal(20, $o->byval2fwdptr($x), "test 20"); -check::equal(21, $o->byval1forwardref($x), "test 21"); +check::equal(21, $o->byval1fwdref($x), "test 21"); -check::equal(22, $o->byval2forwardref($x), "test 22"); +check::equal(22, $o->byval2fwdref($x), "test 22"); check::done(); diff --git a/Examples/test-suite/python/overload_null_runme.py b/Examples/test-suite/python/overload_null_runme.py index a34524255..4b69b5c8d 100644 --- a/Examples/test-suite/python/overload_null_runme.py +++ b/Examples/test-suite/python/overload_null_runme.py @@ -32,13 +32,13 @@ check(14, o.byval1cpr(None)) check(15, o.byval2cpr(None)) check(16, o.byval2cpr(x)) -# forward class declaration -check(17, o.byval1forwardptr(x)) -check(18, o.byval1forwardptr(None)) +# fwd class declaration +check(17, o.byval1fwdptr(x)) +check(18, o.byval1fwdptr(None)) -check(19, o.byval2forwardptr(None)) -check(20, o.byval2forwardptr(x)) +check(19, o.byval2fwdptr(None)) +check(20, o.byval2fwdptr(x)) -check(21, o.byval1forwardref(x)) +check(21, o.byval1fwdref(x)) -check(22, o.byval2forwardref(x)) +check(22, o.byval2fwdref(x)) diff --git a/Examples/test-suite/r/overload_null_runme.R b/Examples/test-suite/r/overload_null_runme.R index d187a1fbb..13dc0c609 100644 --- a/Examples/test-suite/r/overload_null_runme.R +++ b/Examples/test-suite/r/overload_null_runme.R @@ -34,16 +34,16 @@ unittest(12, o$byconstref2(x)) #unittest(15, o$byval2cpr(NULL)) #unittest(16, o$byval2cpr(x)) -# forward class declaration -unittest(17, o$byval1forwardptr(x)) -unittest(18, o$byval1forwardptr(NULL)) +# fwd class declaration +unittest(17, o$byval1fwdptr(x)) +unittest(18, o$byval1fwdptr(NULL)) -unittest(19, o$byval2forwardptr(NULL)) -unittest(20, o$byval2forwardptr(x)) +unittest(19, o$byval2fwdptr(NULL)) +unittest(20, o$byval2fwdptr(x)) -unittest(21, o$byval1forwardref(x)) +unittest(21, o$byval1fwdref(x)) -unittest(22, o$byval2forwardref(x)) +unittest(22, o$byval2fwdref(x)) q(save="no") diff --git a/Examples/test-suite/ruby/overload_null_runme.rb b/Examples/test-suite/ruby/overload_null_runme.rb index eabea5e40..e84851a88 100644 --- a/Examples/test-suite/ruby/overload_null_runme.rb +++ b/Examples/test-suite/ruby/overload_null_runme.rb @@ -40,13 +40,13 @@ swig_assert(14 == o.byval1cpr(nil)) swig_assert(15 == o.byval2cpr(nil)) swig_assert(16 == o.byval2cpr(x)) -# forward class declaration -swig_assert(17 == o.byval1forwardptr(x)) -swig_assert(18 == o.byval1forwardptr(nil)) +# fwd class declaration +swig_assert(17 == o.byval1fwdptr(x)) +swig_assert(18 == o.byval1fwdptr(nil)) -swig_assert(19 == o.byval2forwardptr(nil)) -swig_assert(20 == o.byval2forwardptr(x)) +swig_assert(19 == o.byval2fwdptr(nil)) +swig_assert(20 == o.byval2fwdptr(x)) -swig_assert(21 == o.byval1forwardref(x)) +swig_assert(21 == o.byval1fwdref(x)) -swig_assert(22 == o.byval2forwardref(x)) +swig_assert(22 == o.byval2fwdref(x)) diff --git a/Examples/test-suite/scilab/overload_null_runme.sci b/Examples/test-suite/scilab/overload_null_runme.sci index e3939ac5c..72a2b7ea6 100644 --- a/Examples/test-suite/scilab/overload_null_runme.sci +++ b/Examples/test-suite/scilab/overload_null_runme.sci @@ -30,16 +30,16 @@ checkequal(14, Overload_byval1cpr(o, NULL), "test 14"); checkequal(15, Overload_byval2cpr(o, NULL), "test 15"); checkequal(16, Overload_byval2cpr(o, x), "test 16"); -// forward class declaration -checkequal(17, Overload_byval1forwardptr(o, x), "test 17"); -checkequal(18, Overload_byval1forwardptr(o, NULL), "test 18"); +// fwd class declaration +checkequal(17, Overload_byval1fwdptr(o, x), "test 17"); +checkequal(18, Overload_byval1fwdptr(o, NULL), "test 18"); -checkequal(19, Overload_byval2forwardptr(o, NULL), "test 19"); -checkequal(20, Overload_byval2forwardptr(o, x), "test 20"); +checkequal(19, Overload_byval2fwdptr(o, NULL), "test 19"); +checkequal(20, Overload_byval2fwdptr(o, x), "test 20"); -checkequal(21, Overload_byval1forwardref(o, x), "test 21"); +checkequal(21, Overload_byval1fwdref(o, x), "test 21"); -checkequal(22, Overload_byval2forwardref(o, x), "test 22"); +checkequal(22, Overload_byval2fwdref(o, x), "test 22"); exec("swigtest.quit", -1); diff --git a/Examples/test-suite/tcl/overload_null_runme.tcl b/Examples/test-suite/tcl/overload_null_runme.tcl index 3716612ab..075d6046c 100644 --- a/Examples/test-suite/tcl/overload_null_runme.tcl +++ b/Examples/test-suite/tcl/overload_null_runme.tcl @@ -40,13 +40,13 @@ check "testX" 14 [$o byval1cpr "NULL"] check "testX" 15 [$o byval2cpr "NULL"] check "testX" 16 [$o byval2cpr $x] -# forward class declaration -check "testX" 17 [$o byval1forwardptr $x] -check "testX" 18 [$o byval1forwardptr "NULL"] +# fwd class declaration +check "testX" 17 [$o byval1fwdptr $x] +check "testX" 18 [$o byval1fwdptr "NULL"] -check "testX" 19 [$o byval2forwardptr "NULL"] -check "testX" 20 [$o byval2forwardptr $x] +check "testX" 19 [$o byval2fwdptr "NULL"] +check "testX" 20 [$o byval2fwdptr $x] -check "testX" 21 [$o byval1forwardref $x] +check "testX" 21 [$o byval1fwdref $x] -check "testX" 22 [$o byval2forwardref $x] +check "testX" 22 [$o byval2fwdref $x] From 63733a3b5cb435b5dbf456245e012d5f0e60a767 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 15 Nov 2021 22:56:29 +0000 Subject: [PATCH 098/262] Short struct name in cpp11_final_override for Scilab --- Examples/test-suite/cpp11_final_override.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/cpp11_final_override.i b/Examples/test-suite/cpp11_final_override.i index c31ae73b6..849655b16 100644 --- a/Examples/test-suite/cpp11_final_override.i +++ b/Examples/test-suite/cpp11_final_override.i @@ -90,7 +90,7 @@ struct FinalOverrideMethods { virtual void override(int) {} virtual ~FinalOverrideMethods() = default; }; -struct FinalOverrideVariables { +struct FinalOverrideVars { int final; double override; }; From 2582e3fc7535060926443fa60c39017ed42486d6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 15 Nov 2021 23:00:28 +0000 Subject: [PATCH 099/262] GHA: Add in Scilab testing --- .github/workflows/ci.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a269f22f..9c1e81b51 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -155,6 +155,7 @@ jobs: - SWIGLANG: ruby VER: '3.0' CPPSTD: c++11 + - SWIGLANG: scilab - SWIGLANG: tcl # c++11 testing - SWIGLANG: csharp @@ -187,6 +188,8 @@ jobs: CPPSTD: c++11 - SWIGLANG: ruby CPPSTD: c++11 + - SWIGLANG: scilab + CPPSTD: c++11 - SWIGLANG: tcl CPPSTD: c++11 # c++14 testing @@ -220,6 +223,8 @@ jobs: CPPSTD: c++14 - SWIGLANG: ruby CPPSTD: c++14 + - SWIGLANG: scilab + CPPSTD: c++14 - SWIGLANG: tcl CPPSTD: c++14 # c++17 testing (using gcc11) @@ -265,6 +270,9 @@ jobs: - SWIGLANG: ruby CPPSTD: c++17 GCC: 11 + - SWIGLANG: scilab + CPPSTD: c++17 + GCC: 11 - SWIGLANG: tcl CPPSTD: c++17 GCC: 11 From 9f5ad6debd26e05ee26c50a5d6db15e87e861c5b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 15 Nov 2021 23:24:07 +0000 Subject: [PATCH 100/262] Scilab JAVA_HOME environment fix This might be needed on Github Actions as well as Travis?? --- Tools/CI-linux-environment.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Tools/CI-linux-environment.sh b/Tools/CI-linux-environment.sh index e854c5b0e..0e9526dcf 100644 --- a/Tools/CI-linux-environment.sh +++ b/Tools/CI-linux-environment.sh @@ -29,5 +29,11 @@ case "$SWIGLANG" in set -x fi ;; + "scilab") + # Travis has the wrong version of Java pre-installed resulting in error using scilab: + # /usr/bin/scilab-bin: error while loading shared libraries: libjava.so: cannot open shared object file: No such file or directory + echo "JAVA_HOME was set to $JAVA_HOME" + unset JAVA_HOME + ;; *) ;; esac From dbab08ec2155d6e9800187007c71100168b5a989 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 16 Nov 2021 08:26:14 +0000 Subject: [PATCH 101/262] Scilab testing: don't hang on error --- configure.ac | 3 +++ 1 file changed, 3 insertions(+) diff --git a/configure.ac b/configure.ac index c829723df..9bf45c765 100644 --- a/configure.ac +++ b/configure.ac @@ -1251,6 +1251,9 @@ else if test $SCILAB_VERSION -ge 540; then SCILABOPT+=" -noatomsautoload" fi + if test $SCILAB_VERSION -ge 600; then + SCILABOPT+=" -quit" + fi AC_MSG_RESULT($SCILABOPT) # Check for Scilab header files From 0ec35cf24eb68be76184349895e39fa2bf156985 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 16 Nov 2021 19:43:24 +0000 Subject: [PATCH 102/262] GHA: Test Scilab 6.0 on ubuntu-18.04 6.1 on ubuntu-20.04 not yet working --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c1e81b51..2d4c2d9a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -156,6 +156,7 @@ jobs: VER: '3.0' CPPSTD: c++11 - SWIGLANG: scilab + os: ubuntu-18.04 # scilab-6.1 in ubuntu-20.04 not yet working - SWIGLANG: tcl # c++11 testing - SWIGLANG: csharp @@ -190,6 +191,7 @@ jobs: CPPSTD: c++11 - SWIGLANG: scilab CPPSTD: c++11 + os: ubuntu-18.04 # scilab-6.1 in ubuntu-20.04 not yet working - SWIGLANG: tcl CPPSTD: c++11 # c++14 testing @@ -225,6 +227,7 @@ jobs: CPPSTD: c++14 - SWIGLANG: scilab CPPSTD: c++14 + os: ubuntu-18.04 # scilab-6.1 in ubuntu-20.04 not yet working - SWIGLANG: tcl CPPSTD: c++14 # c++17 testing (using gcc11) @@ -273,6 +276,7 @@ jobs: - SWIGLANG: scilab CPPSTD: c++17 GCC: 11 + os: ubuntu-18.04 # scilab-6.1 in ubuntu-20.04 not yet working - SWIGLANG: tcl CPPSTD: c++17 GCC: 11 From ac9f819f6ed767f763320fc64c79025868b69a1c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 16 Nov 2021 19:45:20 +0000 Subject: [PATCH 103/262] Don't run appveyor when modifying Github Actions CI files --- appveyor.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 8538bfef1..07c4fac28 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,9 +4,10 @@ platform: skip_commits: files: + - '.github/**' - 'CHANGES*' - 'Doc/**' - - '.github/**' + - 'Tools/CI-*' environment: global: From f586d920f72aeedd8d4c9504415f4251005ef4bf Mon Sep 17 00:00:00 2001 From: Dimitris Apostolou Date: Sat, 13 Nov 2021 21:23:08 +0200 Subject: [PATCH 104/262] Fix typos --- CCache/README.swig | 2 +- CCache/execute.c | 2 +- CCache/snprintf.c | 4 ++-- CCache/web/index.html | 2 +- Doc/Manual/Doxygen.html | 2 +- Doc/Manual/Java.html | 2 +- Doc/Manual/R.html | 4 ++-- Examples/test-suite/cpp11_template_double_brackets.i | 2 +- Examples/test-suite/d/li_std_vector_runme.2.d | 2 +- Examples/test-suite/scilab/preproc_constants_runme.sci | 2 +- Examples/test-suite/scilab_identifier_name.i | 2 +- Examples/test-suite/tcl/imports_runme.tcl | 4 ++-- Lib/d/doperators.swg | 6 +++--- Lib/octave/octcomplex.swg | 2 +- Lib/ruby/rubyautodoc.swg | 4 ++-- Lib/tcl/mactkinit.c | 2 +- Source/Doxygen/doxytranslator.h | 4 ++-- Source/Doxygen/pydoc.h | 2 +- Source/Modules/javascript.cxx | 2 +- Source/Swig/cwrap.c | 2 +- Source/Swig/naming.c | 2 +- Tools/config/ax_boost_base.m4 | 2 +- Tools/travis-linux-install.sh | 2 +- Tools/travis-osx-install.sh | 2 +- 24 files changed, 31 insertions(+), 31 deletions(-) diff --git a/CCache/README.swig b/CCache/README.swig index aea0f3d82..82055d146 100644 --- a/CCache/README.swig +++ b/CCache/README.swig @@ -2,7 +2,7 @@ This directory contains a version of ccache. The initial version was based on cc debian patches 01-02, 04-14, see the debian/patches subdirectory. The ccache-win32-2.4 modifications to ccache-2.4 have also been merged in. -Changes have been made to support cacheing the output from SWIG. The ability to cache c/c++ compiler +Changes have been made to support caching the output from SWIG. The ability to cache c/c++ compiler output has been retained. Additional features added are the CCACHE_VERBOSE and CCACHE_SWIG environment variables, see docs. diff --git a/CCache/execute.c b/CCache/execute.c index 6df025e95..8c65e0ce0 100644 --- a/CCache/execute.c +++ b/CCache/execute.c @@ -137,7 +137,7 @@ int execute(char **argv, _dup2(fd, 2); _close(fd); - /* Spawn process (_exec* familly doesn't return) */ + /* Spawn process (_exec* family doesn't return) */ status = _spawnv(_P_WAIT, argv[0], (const char **)argv); /* Restore descriptors */ diff --git a/CCache/snprintf.c b/CCache/snprintf.c index 9bf8a817b..1a76c7d1b 100644 --- a/CCache/snprintf.c +++ b/CCache/snprintf.c @@ -16,7 +16,7 @@ * for string length. This covers a nasty loophole. * * The other functions are there to prevent NULL pointers from - * causing nast effects. + * causing nasty effects. * * More Recently: * Brandon Long 9/15/96 for mutt 0.43 @@ -30,7 +30,7 @@ * probably requires libm on most operating systems. Don't yet * support the exponent (e,E) and sigfig (g,G). Also, fmtint() * was pretty badly broken, it just wasn't being exercised in ways - * which showed it, so that's been fixed. Also, formated the code + * which showed it, so that's been fixed. Also, formatted the code * to mutt conventions, and removed dead code left over from the * original. Also, there is now a builtin-test, just compile with: * gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm diff --git a/CCache/web/index.html b/CCache/web/index.html index 4af839135..bc46916d2 100644 --- a/CCache/web/index.html +++ b/CCache/web/index.html @@ -34,7 +34,7 @@ on the new options.

    You can get this release from the download directory -

    NOTE! This release changes the hash input slighly, so you will +

    NOTE! This release changes the hash input slightly, so you will probably find that you will not get any hits against your existing cache when you upgrade. diff --git a/Doc/Manual/Doxygen.html b/Doc/Manual/Doxygen.html index 53238c24d..e7fd4c359 100644 --- a/Doc/Manual/Doxygen.html +++ b/Doc/Manual/Doxygen.html @@ -1354,7 +1354,7 @@ Here is the list of all Doxygen tags and the description of how they are transla \throws -replaced wih ':raises:' +replaced with ':raises:' \todo diff --git a/Doc/Manual/Java.html b/Doc/Manual/Java.html index dc403a98c..2591b27b5 100644 --- a/Doc/Manual/Java.html +++ b/Doc/Manual/Java.html @@ -9095,7 +9095,7 @@ This method normally calls the C++ destructor or free() for C code.

    The generated code can be debugged using both a Java debugger and a C++ debugger using the usual debugging techniques. Breakpoints can be set in either Java or C++ code and so both can be debugged simultaneously. -Most debuggers do not understand both Java and C++, with one noteable exception of Sun Studio, +Most debuggers do not understand both Java and C++, with one notable exception of Sun Studio, where it is possible to step from Java code into a JNI method within one environment.

    diff --git a/Doc/Manual/R.html b/Doc/Manual/R.html index e44fe432c..9b05922fd 100644 --- a/Doc/Manual/R.html +++ b/Doc/Manual/R.html @@ -196,7 +196,7 @@ slices)

    Wrapping of C++ classes for R works quite well. R has a special type, known as an external reference, that can be used as a pointer -to arbitary things, including C++ classes. The proxy layers generated +to arbitrary things, including C++ classes. The proxy layers generated for other classes are not required.

    @@ -265,7 +265,7 @@ v2$Axles [1] 4 v1$Available [1] FALSE -# Set availabilty +# Set availability v1$Available <- TRUE v1$Available [1] TRUE diff --git a/Examples/test-suite/cpp11_template_double_brackets.i b/Examples/test-suite/cpp11_template_double_brackets.i index ba5caa5c5..d7522c9f0 100644 --- a/Examples/test-suite/cpp11_template_double_brackets.i +++ b/Examples/test-suite/cpp11_template_double_brackets.i @@ -1,5 +1,5 @@ /* This interface checks whether SWIG supports the new double angled brackets - in the template syntax without having a space inbetween. This feature was + in the template syntax without having a space in between. This feature was introduced in new C++11 standard. */ %module cpp11_template_double_brackets diff --git a/Examples/test-suite/d/li_std_vector_runme.2.d b/Examples/test-suite/d/li_std_vector_runme.2.d index f4a666716..3f97062f1 100644 --- a/Examples/test-suite/d/li_std_vector_runme.2.d +++ b/Examples/test-suite/d/li_std_vector_runme.2.d @@ -47,7 +47,7 @@ void main() { enforce(countUntil(vector[], i * 10) == i, "indexOf test failed, i: " ~ to!string(i)); } - enforce(countUntil(vector[], 42) == -1, "non-existant item indexOf test failed"); + enforce(countUntil(vector[], 42) == -1, "non-existent item indexOf test failed"); vector.clear(); enforce(vector.length == 0, "clear test failed"); diff --git a/Examples/test-suite/scilab/preproc_constants_runme.sci b/Examples/test-suite/scilab/preproc_constants_runme.sci index d3d0a4b56..3dc1433af 100644 --- a/Examples/test-suite/scilab/preproc_constants_runme.sci +++ b/Examples/test-suite/scilab/preproc_constants_runme.sci @@ -24,7 +24,7 @@ endfunction test_global(); -// Test assignement in enums +// Test assignment in enums checkequal(kValue_get(), 4, "kValue"); exec("swigtest.quit", -1); diff --git a/Examples/test-suite/scilab_identifier_name.i b/Examples/test-suite/scilab_identifier_name.i index 94dde47e0..4e5a574e9 100644 --- a/Examples/test-suite/scilab_identifier_name.i +++ b/Examples/test-suite/scilab_identifier_name.i @@ -7,7 +7,7 @@ // Test truncating variables, constants, functions identifier names %inline %{ -// these identifier names wont be truncated +// these identifier names won't be truncated int gvar_identifier_name = -1; #define CONS_IDENTIFIER_NAME -11 int function_identifier_name() { return -21; }; diff --git a/Examples/test-suite/tcl/imports_runme.tcl b/Examples/test-suite/tcl/imports_runme.tcl index 6b2e77bde..bf2fc8cba 100644 --- a/Examples/test-suite/tcl/imports_runme.tcl +++ b/Examples/test-suite/tcl/imports_runme.tcl @@ -15,8 +15,8 @@ import set x [new_B] A_hello $x -if [ catch { $x nonexistant } ] { +if [ catch { $x nonexistent } ] { } else { - puts stderr "nonexistant method did not throw exception\n" + puts stderr "nonexistent method did not throw exception\n" exit 1 } diff --git a/Lib/d/doperators.swg b/Lib/d/doperators.swg index 0cb63533c..0a82a6cb4 100644 --- a/Lib/d/doperators.swg +++ b/Lib/d/doperators.swg @@ -58,7 +58,7 @@ template SwigOperatorDefinitions() { %rename(opCall) *::operator(); -// !a is not overrideable in D1. +// !a is not overridable in D1. %ignoreoperator(LNOT) operator!; // opCmp is used in D. @@ -71,7 +71,7 @@ template SwigOperatorDefinitions() { // a != b is rewritten as !a.opEquals(b) in D. %ignoreoperator(NOTEQUAL) operator!=; -// The logic operators are not overrideable in D. +// The logic operators are not overridable in D. %ignoreoperator(LAND) operator&&; %ignoreoperator(LOR) operator||; @@ -198,7 +198,7 @@ mixin template SwigOperatorDefinitions() { // a != b is rewritten as !a.opEquals(b) in D. %ignoreoperator(NOTEQUAL) operator!=; -// The logic operators are not overrideable in D. +// The logic operators are not overridable in D. %ignoreoperator(LAND) operator&&; %ignoreoperator(LOR) operator||; diff --git a/Lib/octave/octcomplex.swg b/Lib/octave/octcomplex.swg index 87e77a62e..553c25a3d 100644 --- a/Lib/octave/octcomplex.swg +++ b/Lib/octave/octcomplex.swg @@ -2,7 +2,7 @@ Defines the As/From conversors for double/float complex, you need to provide complex Type, the Name you want to use in the conversors, the complex Constructor method, and the Real and Imag complex - accesor methods. + accessor methods. See the std_complex.i and ccomplex.i for concrete examples. */ diff --git a/Lib/ruby/rubyautodoc.swg b/Lib/ruby/rubyautodoc.swg index 1e6b0d9dc..6b0472ce8 100644 --- a/Lib/ruby/rubyautodoc.swg +++ b/Lib/ruby/rubyautodoc.swg @@ -77,7 +77,7 @@ AUTODOC(operator>, "Higher than comparison operator"); AUTODOC(operator<<, "Left shifting or appending operator"); AUTODOC(operator>>, "Right shifting operator or extracting operator"); AUTODOC(operator+, "Add operator"); -AUTODOC(operator-, "Substraction operator"); +AUTODOC(operator-, "Subtraction operator"); AUTODOC(operator+(), "Positive operator"); AUTODOC(operator-(), "Negation operator"); AUTODOC(operator&, "AND operator"); @@ -93,7 +93,7 @@ AUTODOC(__gt__, "Higher than comparison operator"); AUTODOC(__lshift__, "Left shifting or appending operator"); AUTODOC(__rshift__, "Right shifting operator or extracting operator"); AUTODOC(__add___, "Add operator"); -AUTODOC(__sub__, "Substraction operator"); +AUTODOC(__sub__, "Subtraction operator"); AUTODOC(__pos__, "Positive operator"); AUTODOC(__neg__, "Negation operator"); AUTODOC(__and__, "AND operator"); diff --git a/Lib/tcl/mactkinit.c b/Lib/tcl/mactkinit.c index 8d1420088..18f1f0203 100644 --- a/Lib/tcl/mactkinit.c +++ b/Lib/tcl/mactkinit.c @@ -126,7 +126,7 @@ MacintoshInit() * * This procedure calls initialization routines require a Tcl * interp as an argument. This call effectively makes the passed - * iterpreter the "main" interpreter for the application. + * interpreter the "main" interpreter for the application. * * Results: * Returns TCL_OK if everything went fine. If it didn't the diff --git a/Source/Doxygen/doxytranslator.h b/Source/Doxygen/doxytranslator.h index f07b632a2..a72a31df6 100644 --- a/Source/Doxygen/doxytranslator.h +++ b/Source/Doxygen/doxytranslator.h @@ -53,13 +53,13 @@ public: virtual ~DoxygenTranslator(); /* - * Return the documentation for a given node formated for the correct + * Return the documentation for a given node formatted for the correct * documentation system. */ String *getDocumentation(Node *node, const_String_or_char_ptr indentationString); /* - * Returns truem is the specified node has comment attached. + * Returns true if the specified node has comment attached. */ bool hasDocumentation(Node *node); diff --git a/Source/Doxygen/pydoc.h b/Source/Doxygen/pydoc.h index 07c5ce51e..19885276f 100644 --- a/Source/Doxygen/pydoc.h +++ b/Source/Doxygen/pydoc.h @@ -195,7 +195,7 @@ private: typedef std::map >TagHandlersMap; static TagHandlersMap tagHandlers; - // this contains the sections tittles, like 'Arguments:' or 'Notes:', that are printed only once + // this contains the sections titles, like 'Arguments:' or 'Notes:', that are printed only once static std::map sectionTitles; // Helper functions for fillStaticTables(): make a new tag handler object. diff --git a/Source/Modules/javascript.cxx b/Source/Modules/javascript.cxx index d3ae3ce64..431dd4744 100644 --- a/Source/Modules/javascript.cxx +++ b/Source/Modules/javascript.cxx @@ -1255,7 +1255,7 @@ int JSEmitter::emitFunctionDispatcher(Node *n, bool /*is_member */ ) { // Note: this dispatcher function gets called after the last overloaded function has been created. // At this time, n.wrap:name contains the name of the last wrapper function. // To get a valid function name for the dispatcher function we take the last wrapper name and - // substract the extension "sym:overname", + // subtract the extension "sym:overname", String *wrap_name = NewString(Getattr(n, "wrap:name")); String *overname = Getattr(n, "sym:overname"); diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index d6e5e0cdc..7bf6641c8 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -632,7 +632,7 @@ String *Swig_cppconstructor_director_call(const_String_or_char_ptr name, ParmLis * If you define SWIG_FAST_REC_SEARCH, the method will set the found * 'attr' in the target class 'n'. If not, the method will set the * 'noattr' one. This prevents of having to navigate the entire - * hierarchy tree everytime, so, it is an O(1) method... or something + * hierarchy tree every time, so, it is an O(1) method... or something * like that. However, it populates all the parsed classes with the * 'attr' and/or 'noattr' attributes. * diff --git a/Source/Swig/naming.c b/Source/Swig/naming.c index 1d78e7a47..871a9e5bb 100644 --- a/Source/Swig/naming.c +++ b/Source/Swig/naming.c @@ -1514,7 +1514,7 @@ String *Swig_name_make(Node *n, String *prefix, const_String_or_char_ptr cname, if (n) { /* Parameter renaming is not fully implemented. Mainly because there is no C/C++ syntax to * for %rename to fully qualify a function's parameter name from outside the function. Hence it - * is not possible to implemented targetted warning suppression on one parameter in one function. */ + * is not possible to implemented targeted warning suppression on one parameter in one function. */ int suppress_parameter_rename_warning = Equal(nodeType(n), "parm"); if (!suppress_parameter_rename_warning) { SWIG_WARN_NODE_BEGIN(n); diff --git a/Tools/config/ax_boost_base.m4 b/Tools/config/ax_boost_base.m4 index f5a935cd6..94fb2a0d4 100644 --- a/Tools/config/ax_boost_base.m4 +++ b/Tools/config/ax_boost_base.m4 @@ -10,7 +10,7 @@ # # Test for the Boost C++ libraries of a particular version (or newer) # -# If no path to the installed boost library is given the macro searchs +# If no path to the installed boost library is given the macro searches # under /usr, /usr/local, /opt and /opt/local and evaluates the # $BOOST_ROOT environment variable. Further documentation is available at # . diff --git a/Tools/travis-linux-install.sh b/Tools/travis-linux-install.sh index cda834112..cb64d57d2 100755 --- a/Tools/travis-linux-install.sh +++ b/Tools/travis-linux-install.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Install Linux packages where the version has been overidden in .travis.yml +# Install Linux packages where the version has been overridden in .travis.yml lsb_release -a # find location of current script (only works in bash) diff --git a/Tools/travis-osx-install.sh b/Tools/travis-osx-install.sh index 71545ad5c..fc69c6654 100755 --- a/Tools/travis-osx-install.sh +++ b/Tools/travis-osx-install.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Install MacOS packages where the version has been overidden in .travis.yml +# Install MacOS packages where the version has been overridden in .travis.yml set -e # exit on failure (same as -o errexit) From 07f18bef368b2b8b0c8a93d0ced9b6e3567b490e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 17 Nov 2021 21:23:59 +0000 Subject: [PATCH 105/262] GHA: Test experimental languages - mzscheme and ocaml These are allowed to fail and they won't fail the overall build (like they did on Travis). Implemented via the continue-on-error flag that Github Actions provides. --- .github/workflows/ci.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d4c2d9a2..cd99957e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,11 +16,15 @@ on: jobs: build: + # When continue-on-error is true for an individual build, that build can fail (it'll show red), + # but it won't fail the overall build + continue-on-error: ${{ matrix.continue-on-error || false }} + runs-on: ${{ matrix.os || 'ubuntu-20.04' }} # By default, the name of the build is the language used and SWIG options, but matrix entries # can define the additional "desc" field with any additional information to include in the name. - name: ${{ matrix.SWIGLANG || 'none' }}${{ matrix.PY3 }} ${{ matrix.ENGINE}} ${{ matrix.VER }} ${{ matrix.SWIG_FEATURES }} ${{ (matrix.compiler || 'gcc') }}${{ matrix.GCC }} ${{ matrix.CPPSTD }} ${{ matrix.CSTD }} ${{ matrix.desc }} + name: ${{ matrix.SWIGLANG || 'none' }}${{ matrix.PY3 }} ${{ matrix.ENGINE}} ${{ matrix.VER }} ${{ matrix.SWIG_FEATURES }} ${{ (matrix.compiler || 'gcc') }}${{ matrix.GCC }} ${{ matrix.CPPSTD }} ${{ matrix.CSTD }} ${{ matrix.desc }} ${{ matrix.continue-on-error && '(can fail)' }} strategy: matrix: @@ -280,7 +284,12 @@ jobs: - SWIGLANG: tcl CPPSTD: c++17 GCC: 11 - # let's run all of them, as opposed to aborting when one fails + # Experimental languages (these are allowed to fail) + - SWIGLANG: mzscheme + continue-on-error: true + - SWIGLANG: ocaml + continue-on-error: true + # Run all of them, as opposed to aborting when one fails fail-fast: false env: From 9f8e9109be7202d4d05d08012262f9f189e31bcf Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 17 Nov 2021 22:18:06 +0000 Subject: [PATCH 106/262] Update CI system wrt experimental languages --- Doc/Manual/Extending.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html index 7c2a6c66c..5749f37ce 100644 --- a/Doc/Manual/Extending.html +++ b/Doc/Manual/Extending.html @@ -3613,7 +3613,7 @@ A target language is given the 'Supported' status when Examples must be available and run successfully.
  • - The examples and test-suite must be fully functioning on the Travis Continuous Integration platform. + The examples and test-suite must be fully functioning on the Github Actions Continuous Integration platform.
  • @@ -3660,9 +3660,9 @@ Some minimum requirements and notes about languages with the 'Experimental' stat The number of tests in these lists should be no greater than half of the number of tests in the full test-suite.
  • - The examples and test-suite must also be fully functioning on the Travis Continuous Integration platform. - However, experimental languages will be set as 'allow_failures'. - This means that pull requests and normal development commits will not break the entire Travis build should an experimental language fail. + The examples and test-suite must also be fully functioning on the Github Actions Continuous Integration platform. + However, experimental languages will be flagged as 'continue-on-error'. + This means that pull requests and normal development commits will not break the entire Github Actions build should an experimental language fail.
  • Any new failed tests will be fixed on a 'best effort' basis by core developers with no promises made. From 335434525594e7759556cc23c5e4b2fb0282dbf1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 17 Nov 2021 22:27:00 +0000 Subject: [PATCH 107/262] GHA: switch ocaml testing to ubuntu-18.04 --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cd99957e8..3bfa687a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -289,6 +289,7 @@ jobs: continue-on-error: true - SWIGLANG: ocaml continue-on-error: true + os: ubuntu-18.04 # ocaml-4.08 in ubuntu-20.04 not yet working # Run all of them, as opposed to aborting when one fails fail-fast: false From 6a56426f8f4887f649d06b83c0becbaa69bc6fe3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 2 Nov 2021 19:42:11 +0100 Subject: [PATCH 108/262] Use JSC version available in Ubuntu 20.04 in the CI builds Use the newer OS and JavaScript Core library versions for the CI build, we don't have to remain with the old version here, as the newer one works too. --- .github/workflows/ci.yml | 1 - Tools/CI-linux-install.sh | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3bfa687a2..d66a5f240 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,7 +78,6 @@ jobs: CPPSTD: c++14 - SWIGLANG: javascript ENGINE: jsc - os: ubuntu-18.04 # libwebkitgtk-dev dependency not available in 20.04. - SWIGLANG: javascript ENGINE: v8 os: ubuntu-18.04 # libv8-dev only actually provides v8 in 18.04. diff --git a/Tools/CI-linux-install.sh b/Tools/CI-linux-install.sh index 6edce572b..7bd141080 100644 --- a/Tools/CI-linux-install.sh +++ b/Tools/CI-linux-install.sh @@ -55,7 +55,7 @@ case "$SWIGLANG" in fi ;; "jsc") - $RETRY sudo apt-get install -qq libwebkitgtk-dev + $RETRY sudo apt-get install -qq libjavascriptcoregtk-4.0-dev ;; "v8") $RETRY sudo apt-get install -qq libv8-dev From 0304bdb82baaf5da94b6273c93e2623f1522a2a0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 27 Nov 2021 13:26:15 +0000 Subject: [PATCH 109/262] GHA: Add testing of node 17 Also remove duplicate test of node 14 --- .github/workflows/ci.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d66a5f240..ab8c68d1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,11 +70,7 @@ jobs: CPPSTD: c++11 - SWIGLANG: javascript ENGINE: node - VER: '14' - CPPSTD: c++11 - - SWIGLANG: javascript - ENGINE: node - VER: '16' + VER: '17' CPPSTD: c++14 - SWIGLANG: javascript ENGINE: jsc @@ -250,7 +246,7 @@ jobs: GCC: 11 - SWIGLANG: javascript ENGINE: node - VER: '16' + VER: '17' CPPSTD: c++17 GCC: 11 - SWIGLANG: lua From ebe14e6e2ae9ae59d7cbc32877b5e138c194cc5a Mon Sep 17 00:00:00 2001 From: John Senneker Date: Tue, 30 Nov 2021 16:13:17 -0500 Subject: [PATCH 110/262] Fixed crashes when using embedded Python interpreters. Fixes #2101. There are 3 related changes made here: 1. Move the SWIG_globals() singleton into pyrun from pyint so it is visible to SWIG_Python_DestroyModule(). The static globals varlink has been extracted out of the function so that it can be set to NULL in SWIG_Python_DestroyModule(), which fixes the issue described in #2101. (Now when the second interpreter starts up, the Swig_Globals_global pointer will be NULL, so it knows it has to create a new one.) 2. Remove a Py_DECREF on the globals varlink. The decrement is now performed by DestroyModule(), so there's no need to do it in SWIG_init(). 3. Fixed similar issue with SWIG_Python_TypeCache(). --- Lib/python/pyinit.swg | 214 ----------------------------------- Lib/python/pyrun.swg | 227 +++++++++++++++++++++++++++++++++++++- Source/Modules/python.cxx | 1 - 3 files changed, 225 insertions(+), 217 deletions(-) diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index a6d609d56..dfd3940ec 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -30,220 +30,6 @@ SWIGINTERN PyObject *SWIG_PyStaticMethod_New(PyObject *SWIGUNUSEDPARM(self), PyO extern "C" { #endif -/* Python-specific SWIG API */ -#define SWIG_newvarlink() SWIG_Python_newvarlink() -#define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr) -#define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants) - -/* ----------------------------------------------------------------------------- - * global variable support code. - * ----------------------------------------------------------------------------- */ - -typedef struct swig_globalvar { - char *name; /* Name of global variable */ - PyObject *(*get_attr)(void); /* Return the current value */ - int (*set_attr)(PyObject *); /* Set the value */ - struct swig_globalvar *next; -} swig_globalvar; - -typedef struct swig_varlinkobject { - PyObject_HEAD - swig_globalvar *vars; -} swig_varlinkobject; - -SWIGINTERN PyObject * -swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) { -#if PY_VERSION_HEX >= 0x03000000 - return PyUnicode_InternFromString(""); -#else - return PyString_FromString(""); -#endif -} - -SWIGINTERN PyObject * -swig_varlink_str(swig_varlinkobject *v) { -#if PY_VERSION_HEX >= 0x03000000 - PyObject *str = PyUnicode_InternFromString("("); - PyObject *tail; - PyObject *joined; - swig_globalvar *var; - for (var = v->vars; var; var=var->next) { - tail = PyUnicode_FromString(var->name); - joined = PyUnicode_Concat(str, tail); - Py_DecRef(str); - Py_DecRef(tail); - str = joined; - if (var->next) { - tail = PyUnicode_InternFromString(", "); - joined = PyUnicode_Concat(str, tail); - Py_DecRef(str); - Py_DecRef(tail); - str = joined; - } - } - tail = PyUnicode_InternFromString(")"); - joined = PyUnicode_Concat(str, tail); - Py_DecRef(str); - Py_DecRef(tail); - str = joined; -#else - PyObject *str = PyString_FromString("("); - swig_globalvar *var; - for (var = v->vars; var; var=var->next) { - PyString_ConcatAndDel(&str,PyString_FromString(var->name)); - if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", ")); - } - PyString_ConcatAndDel(&str,PyString_FromString(")")); -#endif - return str; -} - -SWIGINTERN void -swig_varlink_dealloc(swig_varlinkobject *v) { - swig_globalvar *var = v->vars; - while (var) { - swig_globalvar *n = var->next; - free(var->name); - free(var); - var = n; - } -} - -SWIGINTERN PyObject * -swig_varlink_getattr(swig_varlinkobject *v, char *n) { - PyObject *res = NULL; - swig_globalvar *var = v->vars; - while (var) { - if (strcmp(var->name,n) == 0) { - res = (*var->get_attr)(); - break; - } - var = var->next; - } - if (res == NULL && !PyErr_Occurred()) { - PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n); - } - return res; -} - -SWIGINTERN int -swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) { - int res = 1; - swig_globalvar *var = v->vars; - while (var) { - if (strcmp(var->name,n) == 0) { - res = (*var->set_attr)(p); - break; - } - var = var->next; - } - if (res == 1 && !PyErr_Occurred()) { - PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n); - } - return res; -} - -SWIGINTERN PyTypeObject* -swig_varlink_type(void) { - static char varlink__doc__[] = "Swig var link object"; - static PyTypeObject varlink_type; - static int type_init = 0; - if (!type_init) { - const PyTypeObject tmp = { -#if PY_VERSION_HEX >= 0x03000000 - PyVarObject_HEAD_INIT(NULL, 0) -#else - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ -#endif - "swigvarlink", /* tp_name */ - sizeof(swig_varlinkobject), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor) swig_varlink_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - (getattrfunc) swig_varlink_getattr, /* tp_getattr */ - (setattrfunc) swig_varlink_setattr, /* tp_setattr */ - 0, /* tp_compare */ - (reprfunc) swig_varlink_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - (reprfunc) swig_varlink_str, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - 0, /* tp_flags */ - varlink__doc__, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */ - 0, /* tp_del */ - 0, /* tp_version_tag */ -#if PY_VERSION_HEX >= 0x03040000 - 0, /* tp_finalize */ -#endif -#if PY_VERSION_HEX >= 0x03080000 - 0, /* tp_vectorcall */ -#endif -#if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000) - 0, /* tp_print */ -#endif -#ifdef COUNT_ALLOCS - 0, /* tp_allocs */ - 0, /* tp_frees */ - 0, /* tp_maxalloc */ - 0, /* tp_prev */ - 0 /* tp_next */ -#endif - }; - varlink_type = tmp; - type_init = 1; - if (PyType_Ready(&varlink_type) < 0) - return NULL; - } - return &varlink_type; -} - -/* Create a variable linking object for use later */ -SWIGINTERN PyObject * -SWIG_Python_newvarlink(void) { - swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type()); - if (result) { - result->vars = 0; - } - return ((PyObject*) result); -} - -SWIGINTERN void -SWIG_Python_addvarlink(PyObject *p, const char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) { - swig_varlinkobject *v = (swig_varlinkobject *) p; - swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar)); - if (gv) { - size_t size = strlen(name)+1; - gv->name = (char *)malloc(size); - if (gv->name) { - memcpy(gv->name, name, size); - gv->get_attr = get_attr; - gv->set_attr = set_attr; - gv->next = v->vars; - } - } - v->vars = gv; -} - -SWIGINTERN PyObject * -SWIG_globals(void) { - static PyObject *globals = 0; - if (!globals) { - globals = SWIG_newvarlink(); - } - return globals; -} - /* ----------------------------------------------------------------------------- * constants/methods manipulation * ----------------------------------------------------------------------------- */ diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 0025184d1..17992453b 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -214,6 +214,222 @@ SWIG_Python_CheckNoKeywords(PyObject *kwargs, const char *name) { #define SWIG_STATIC_POINTER(var) var = 0; if (!var) var #endif +/* Python-specific SWIG API */ +#define SWIG_newvarlink() SWIG_Python_newvarlink() +#define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr) +#define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants) + +/* ----------------------------------------------------------------------------- + * global variable support code. + * ----------------------------------------------------------------------------- */ + +typedef struct swig_globalvar { + char *name; /* Name of global variable */ + PyObject *(*get_attr)(void); /* Return the current value */ + int (*set_attr)(PyObject *); /* Set the value */ + struct swig_globalvar *next; +} swig_globalvar; + +typedef struct swig_varlinkobject { + PyObject_HEAD + swig_globalvar *vars; +} swig_varlinkobject; + +SWIGINTERN PyObject * +swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) { +#if PY_VERSION_HEX >= 0x03000000 + return PyUnicode_InternFromString(""); +#else + return PyString_FromString(""); +#endif +} + +SWIGINTERN PyObject * +swig_varlink_str(swig_varlinkobject *v) { +#if PY_VERSION_HEX >= 0x03000000 + PyObject *str = PyUnicode_InternFromString("("); + PyObject *tail; + PyObject *joined; + swig_globalvar *var; + for (var = v->vars; var; var=var->next) { + tail = PyUnicode_FromString(var->name); + joined = PyUnicode_Concat(str, tail); + Py_DecRef(str); + Py_DecRef(tail); + str = joined; + if (var->next) { + tail = PyUnicode_InternFromString(", "); + joined = PyUnicode_Concat(str, tail); + Py_DecRef(str); + Py_DecRef(tail); + str = joined; + } + } + tail = PyUnicode_InternFromString(")"); + joined = PyUnicode_Concat(str, tail); + Py_DecRef(str); + Py_DecRef(tail); + str = joined; +#else + PyObject *str = PyString_FromString("("); + swig_globalvar *var; + for (var = v->vars; var; var=var->next) { + PyString_ConcatAndDel(&str,PyString_FromString(var->name)); + if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", ")); + } + PyString_ConcatAndDel(&str,PyString_FromString(")")); +#endif + return str; +} + +SWIGINTERN void +swig_varlink_dealloc(swig_varlinkobject *v) { + swig_globalvar *var = v->vars; + while (var) { + swig_globalvar *n = var->next; + free(var->name); + free(var); + var = n; + } +} + +SWIGINTERN PyObject * +swig_varlink_getattr(swig_varlinkobject *v, char *n) { + PyObject *res = NULL; + swig_globalvar *var = v->vars; + while (var) { + if (strcmp(var->name,n) == 0) { + res = (*var->get_attr)(); + break; + } + var = var->next; + } + if (res == NULL && !PyErr_Occurred()) { + PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n); + } + return res; +} + +SWIGINTERN int +swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) { + int res = 1; + swig_globalvar *var = v->vars; + while (var) { + if (strcmp(var->name,n) == 0) { + res = (*var->set_attr)(p); + break; + } + var = var->next; + } + if (res == 1 && !PyErr_Occurred()) { + PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n); + } + return res; +} + +SWIGINTERN PyTypeObject* +swig_varlink_type(void) { + static char varlink__doc__[] = "Swig var link object"; + static PyTypeObject varlink_type; + static int type_init = 0; + if (!type_init) { + const PyTypeObject tmp = { +#if PY_VERSION_HEX >= 0x03000000 + PyVarObject_HEAD_INIT(NULL, 0) +#else + PyObject_HEAD_INIT(NULL) + 0, /* ob_size */ +#endif + "swigvarlink", /* tp_name */ + sizeof(swig_varlinkobject), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor) swig_varlink_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + (getattrfunc) swig_varlink_getattr, /* tp_getattr */ + (setattrfunc) swig_varlink_setattr, /* tp_setattr */ + 0, /* tp_compare */ + (reprfunc) swig_varlink_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + (reprfunc) swig_varlink_str, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + 0, /* tp_flags */ + varlink__doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */ + 0, /* tp_del */ + 0, /* tp_version_tag */ +#if PY_VERSION_HEX >= 0x03040000 + 0, /* tp_finalize */ +#endif +#if PY_VERSION_HEX >= 0x03080000 + 0, /* tp_vectorcall */ +#endif +#if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000) + 0, /* tp_print */ +#endif +#ifdef COUNT_ALLOCS + 0, /* tp_allocs */ + 0, /* tp_frees */ + 0, /* tp_maxalloc */ + 0, /* tp_prev */ + 0 /* tp_next */ +#endif + }; + varlink_type = tmp; + type_init = 1; + if (PyType_Ready(&varlink_type) < 0) + return NULL; + } + return &varlink_type; +} + +/* Create a variable linking object for use later */ +SWIGINTERN PyObject * +SWIG_Python_newvarlink(void) { + swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type()); + if (result) { + result->vars = 0; + } + return ((PyObject*) result); +} + +SWIGINTERN void +SWIG_Python_addvarlink(PyObject *p, const char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) { + swig_varlinkobject *v = (swig_varlinkobject *) p; + swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar)); + if (gv) { + size_t size = strlen(name)+1; + gv->name = (char *)malloc(size); + if (gv->name) { + memcpy(gv->name, name, size); + gv->get_attr = get_attr; + gv->set_attr = set_attr; + gv->next = v->vars; + } + } + v->vars = gv; +} + + +static PyObject *Swig_Globals_global = NULL; + +SWIGINTERN PyObject * +SWIG_globals(void) { + if (Swig_Globals_global == NULL) { + Swig_Globals_global = SWIG_newvarlink(); + } + return Swig_Globals_global; +} + /* ----------------------------------------------------------------------------- * Pointer declarations * ----------------------------------------------------------------------------- */ @@ -1390,11 +1606,15 @@ SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { void *SWIG_ReturnGlobalTypeList(void *); #endif +static PyObject *Swig_TypeCache_global = NULL; + /* The python cached type query */ SWIGRUNTIME PyObject * SWIG_Python_TypeCache(void) { - static PyObject *SWIG_STATIC_POINTER(cache) = PyDict_New(); - return cache; + if (Swig_TypeCache_global == NULL) { + Swig_TypeCache_global = PyDict_New(); + } + return Swig_TypeCache_global; } SWIGRUNTIME swig_module_info * @@ -1431,7 +1651,10 @@ SWIG_Python_DestroyModule(PyObject *obj) } Py_DECREF(SWIG_This()); Swig_This_global = NULL; + Py_DECREF(SWIG_globals()); + Swig_Globals_global = NULL; Py_DECREF(SWIG_Python_TypeCache()); + Swig_TypeCache_global = NULL; } SWIGRUNTIME void diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 7d618635e..8682e6917 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -3424,7 +3424,6 @@ public: Printf(f_init, "#endif\n"); Printf(f_init, "\t }\n"); Printf(f_init, "\t PyDict_SetItemString(md, \"%s\", globals);\n", global_name); - Printf(f_init, "\t Py_DECREF(globals);\n"); if (builtin) Printf(f_init, "\t SwigPyBuiltin_AddPublicSymbol(public_interface, \"%s\");\n", global_name); have_globals = 1; From 26d693105a61da8fa1c679bc4425452021351499 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 1 Dec 2021 18:13:15 +0000 Subject: [PATCH 111/262] GHA: Test node versions 6,8,10 Test the documented minimum version 6 and some later versions as was done on Travis. Using ubuntu-18.04 as I couldn't get these versions to work on newer ubuntu-20.04 (some horrid c++ compilation errors) --- .github/workflows/ci.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab8c68d1f..5374c5428 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,6 +64,21 @@ jobs: VER: '1.17' - SWIGLANG: guile - SWIGLANG: java + - SWIGLANG: javascript + ENGINE: node + VER: '6' + CPPSTD: c++11 + os: ubuntu-18.04 + - SWIGLANG: javascript + ENGINE: node + VER: '8' + CPPSTD: c++11 + os: ubuntu-18.04 + - SWIGLANG: javascript + ENGINE: node + VER: '10' + CPPSTD: c++11 + os: ubuntu-18.04 - SWIGLANG: javascript ENGINE: node VER: '12' From 160b8c5da38ea2c1ef5c23a45cd4e5f65a2f8ec1 Mon Sep 17 00:00:00 2001 From: John Senneker Date: Wed, 1 Dec 2021 15:15:24 -0500 Subject: [PATCH 112/262] Added extern "C" block that was removed in previous commit. --- Lib/python/pyrun.swg | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 17992453b..a49cbb5b3 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -214,6 +214,10 @@ SWIG_Python_CheckNoKeywords(PyObject *kwargs, const char *name) { #define SWIG_STATIC_POINTER(var) var = 0; if (!var) var #endif +#ifdef __cplusplus +extern "C" { +#endif + /* Python-specific SWIG API */ #define SWIG_newvarlink() SWIG_Python_newvarlink() #define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr) @@ -430,6 +434,10 @@ SWIG_globals(void) { return Swig_Globals_global; } +#ifdef __cplusplus +} +#endif + /* ----------------------------------------------------------------------------- * Pointer declarations * ----------------------------------------------------------------------------- */ From e30dfeaab981d3eda82775130bb61446da1782a9 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 2 Dec 2021 14:01:27 +1300 Subject: [PATCH 113/262] [js] Update docs re v8 support We require at least node v6 (which means v8 v5.0) since 7ba19e758632c8aeddcf82ddf48a05f34e218bc9 so updated the manual to reflect this. --- Doc/Manual/Javascript.html | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/Doc/Manual/Javascript.html b/Doc/Manual/Javascript.html index 54bd68521..ab8657510 100644 --- a/Doc/Manual/Javascript.html +++ b/Doc/Manual/Javascript.html @@ -89,24 +89,10 @@ $ swig -javascript -jsc example.i
     $ swig -c++ -javascript -jsc example.i
    -

    The V8 code that SWIG generates should work with most versions from 3.11.10. -However, the only early version that receives some testing is 3.14.5, which is -still shipped with Ubuntu for some reason. Other than that it's probably safer -to assume that versions earlier than 5.0 are no longer supported. Keep in mind -that these are V8 versions, not Node.js. To give some perspective, Node.js v6.0 +

    The V8 code that SWIG generates requires at least V8 5.0. Keep in mind +that this is theV8 version, not Node.js. To give some perspective, Node.js v6.0 uses V8 5.0, v12.0 - 7.4, v14.0 - 8.1...

    -

    The API headers for V8 >= 4.3.10 define constants which SWIG can use to -determine the V8 version it is compiling for. For versions < 4.3.10, you -need to specify the V8 version when running SWIG. This is specified as a hex -constant, but the constant is read as pairs of decimal digits, so for V8 -3.25.30 use constant 0x032530. This scheme can't represent components > 99, -but this constant is only useful for V8 < 4.3.10, and no V8 versions from -that era had a component > 99. For example:

    -
    -
    -$ swig -c++ -javascript -v8 -DV8_VERSION=0x032530 example.i
    -
    -

    If you're targeting V8 >= 4.3.10, you would just run swig like so:

    +

    To generate code for V8, you would run swig like so:

     $ swig -c++ -javascript -v8 example.i
    From 7c97bd5ab305527d1c14a264325e11ae59f2f6b1 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 2 Dec 2021 14:02:59 +1300 Subject: [PATCH 114/262] [js] Remove code to handle v8 < 5.0 We require at least node v6 which means v8 5.0, so code to handle older v8 is no longer useful. --- Lib/javascript/v8/javascriptcode.swg | 96 +-------- Lib/javascript/v8/javascripthelpers.swg | 30 --- Lib/javascript/v8/javascriptinit.swg | 8 - Lib/javascript/v8/javascriptrun.swg | 247 +----------------------- Lib/javascript/v8/javascriptruntime.swg | 34 +--- Lib/javascript/v8/javascriptstrings.swg | 8 - Tools/javascript/v8_shell.cxx | 50 ----- 7 files changed, 10 insertions(+), 463 deletions(-) diff --git a/Lib/javascript/v8/javascriptcode.swg b/Lib/javascript/v8/javascriptcode.swg index 2abed9488..dcda0ee63 100644 --- a/Lib/javascript/v8/javascriptcode.swg +++ b/Lib/javascript/v8/javascriptcode.swg @@ -105,17 +105,10 @@ fail: %{ if(args.Length() == $jsargcount) { errorHandler.err.Clear(); -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) - self = $jswrapper(args, errorHandler); - if(errorHandler.err.IsEmpty()) { - SWIGV8_ESCAPE(self); - } -#else $jswrapper(args, errorHandler); if(errorHandler.err.IsEmpty()) { return; } -#endif } %} @@ -127,22 +120,8 @@ fail: %fragment ("js_dtor", "templates") %{ -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) -static void $jswrapper(v8::Persistent< v8::Value > object, void *parameter) { - SWIGV8_Proxy *proxy = static_cast(parameter); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) -static void $jswrapper(v8::Isolate *isolate, v8::Persistent object, void *parameter) { - SWIGV8_Proxy *proxy = static_cast(parameter); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) -static void $jswrapper(v8::Isolate *isolate, v8::Persistent *object, SWIGV8_Proxy *proxy) { -#elif (V8_MAJOR_VERSION-0) < 5 -static void $jswrapper(const v8::WeakCallbackData &data) { - v8::Local object = data.GetValue(); +static void $jswrapper(const v8::WeakCallbackInfo &data) { SWIGV8_Proxy *proxy = data.GetParameter(); -#else - static void $jswrapper(const v8::WeakCallbackInfo &data) { - SWIGV8_Proxy *proxy = data.GetParameter(); -#endif if(proxy->swigCMemOwn && proxy->swigCObject) { #ifdef SWIGRUNTIME_DEBUG @@ -151,20 +130,6 @@ static void $jswrapper(const v8::WeakCallbackData &dat $jsfree proxy->swigCObject; } delete proxy; - -#if (V8_MAJOR_VERSION-0) < 5 - object.Clear(); -#endif - -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) - object.Dispose(); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) - object.Dispose(isolate); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100) - object->Dispose(isolate); -#elif (V8_MAJOR_VERSION-0) < 5 - object->Dispose(); -#endif } %} @@ -176,40 +141,14 @@ static void $jswrapper(const v8::WeakCallbackData &dat * ----------------------------------------------------------------------------- */ %fragment ("js_dtoroverride", "templates") %{ -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) -static void $jswrapper(v8::Persistent object, void *parameter) { - SWIGV8_Proxy *proxy = static_cast(parameter); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) -static void $jswrapper(v8::Isolate *isolate, v8::Persistent object, void *parameter) { - SWIGV8_Proxy *proxy = static_cast(parameter); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) -static void $jswrapper(v8::Isolate *isolate, v8::Persistent< v8::Object> *object, SWIGV8_Proxy *proxy) { -#elif (V8_MAJOR_VERSION-0) < 5 -static void $jswrapper(const v8::WeakCallbackData &data) { - v8::Local object = data.GetValue(); - SWIGV8_Proxy *proxy = data.GetParameter(); -#else static void $jswrapper(const v8::WeakCallbackInfo &data) { SWIGV8_Proxy *proxy = data.GetParameter(); -#endif if(proxy->swigCMemOwn && proxy->swigCObject) { $jstype arg1 = ($jstype)proxy->swigCObject; ${destructor_action} } delete proxy; - -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) - object.Dispose(); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) - object.Dispose(isolate); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100) - object->Dispose(isolate); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) - object->Dispose(); -#elif (V8_MAJOR_VERSION-0) < 5 - object.Clear(); -#endif } %} @@ -221,11 +160,7 @@ static void $jswrapper(const v8::WeakCallbackInfo &data) { * ----------------------------------------------------------------------------- */ %fragment("js_getter", "templates") %{ -#if (V8_MAJOR_VERSION-0) < 5 -static SwigV8ReturnValue $jswrapper(v8::Local property, const SwigV8PropertyCallbackInfo &info) { -#else static SwigV8ReturnValue $jswrapper(v8::Local property, const SwigV8PropertyCallbackInfo &info) { -#endif SWIGV8_HANDLESCOPE(); SWIGV8_VALUE jsresult; @@ -247,11 +182,7 @@ fail: * ----------------------------------------------------------------------------- */ %fragment("js_setter", "templates") %{ -#if (V8_MAJOR_VERSION-0) < 5 -static void $jswrapper(v8::Local property, v8::Local value, const SwigV8PropertyCallbackInfoVoid &info) { -#else static void $jswrapper(v8::Local property, v8::Local value, const SwigV8PropertyCallbackInfoVoid &info) { -#endif SWIGV8_HANDLESCOPE(); $jslocals @@ -344,17 +275,10 @@ fail: if(args.Length() == $jsargcount) { errorHandler.err.Clear(); -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) - jsresult = $jswrapper(args, errorHandler); - if(errorHandler.err.IsEmpty()) { - SWIGV8_ESCAPE(jsresult); - } -#else $jswrapper(args, errorHandler); if(errorHandler.err.IsEmpty()) { return; } -#endif } %} @@ -394,15 +318,11 @@ fail: %{ if (SWIGTYPE_p$jsbaseclass->clientdata && !(static_cast(SWIGTYPE_p$jsbaseclass->clientdata)->class_templ.IsEmpty())) { -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) - $jsmangledname_class->Inherit(static_cast(SWIGTYPE_p$jsbaseclass->clientdata)->class_templ); -#else $jsmangledname_class->Inherit( v8::Local::New( v8::Isolate::GetCurrent(), static_cast(SWIGTYPE_p$jsbaseclass->clientdata)->class_templ) ); -#endif #ifdef SWIGRUNTIME_DEBUG printf("Inheritance successful $jsmangledname $jsbaseclass\n"); @@ -425,10 +345,7 @@ fail: SWIGV8_FUNCTION_TEMPLATE $jsmangledname_class_0 = SWIGV8_CreateClassTemplate("$jsname"); $jsmangledname_class_0->SetCallHandler($jsctor); $jsmangledname_class_0->Inherit($jsmangledname_class); -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) - $jsmangledname_class_0->SetHiddenPrototype(true); - v8::Handle $jsmangledname_obj = $jsmangledname_class_0->GetFunction(); -#elif (SWIG_V8_VERSION < 0x0704) +#if (SWIG_V8_VERSION < 0x0704) $jsmangledname_class_0->SetHiddenPrototype(true); v8::Local $jsmangledname_obj = $jsmangledname_class_0->GetFunction(); #else @@ -444,12 +361,7 @@ fail: * ----------------------------------------------------------------------------- */ %fragment("jsv8_register_class", "templates") %{ -#if (V8_MAJOR_VERSION-0) < 5 - $jsparent_obj->Set(SWIGV8_SYMBOL_NEW("$jsname"), $jsmangledname_obj); -#else SWIGV8_MAYBE_CHECK($jsparent_obj->Set(context, SWIGV8_SYMBOL_NEW("$jsname"), $jsmangledname_obj)); -#endif - %} /* ----------------------------------------------------------------------------- @@ -469,11 +381,7 @@ fail: * ----------------------------------------------------------------------------- */ %fragment("jsv8_register_namespace", "templates") %{ -#if (V8_MAJOR_VERSION-0) < 5 - $jsparent_obj->Set(SWIGV8_SYMBOL_NEW("$jsname"), $jsmangledname_obj); -#else SWIGV8_MAYBE_CHECK($jsparent_obj->Set(context, SWIGV8_SYMBOL_NEW("$jsname"), $jsmangledname_obj)); -#endif %} /* ----------------------------------------------------------------------------- diff --git a/Lib/javascript/v8/javascripthelpers.swg b/Lib/javascript/v8/javascripthelpers.swg index fdbff000e..ea303fa3d 100644 --- a/Lib/javascript/v8/javascripthelpers.swg +++ b/Lib/javascript/v8/javascripthelpers.swg @@ -1,22 +1,9 @@ %insert(runtime) %{ -// Note: since 3.19 there are new CallBack types, since 03.21.9 the old ones have been removed -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) -typedef v8::InvocationCallback SwigV8FunctionCallback; -typedef v8::AccessorGetter SwigV8AccessorGetterCallback; -typedef v8::AccessorSetter SwigV8AccessorSetterCallback; -typedef v8::AccessorInfo SwigV8PropertyCallbackInfoVoid; -#elif (V8_MAJOR_VERSION-0) < 5 -typedef v8::FunctionCallback SwigV8FunctionCallback; -typedef v8::AccessorGetterCallback SwigV8AccessorGetterCallback; -typedef v8::AccessorSetterCallback SwigV8AccessorSetterCallback; -typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfoVoid; -#else typedef v8::FunctionCallback SwigV8FunctionCallback; typedef v8::AccessorNameGetterCallback SwigV8AccessorGetterCallback; typedef v8::AccessorNameSetterCallback SwigV8AccessorSetterCallback; typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfoVoid; -#endif /** * Creates a class template for a class with specified initialization function. @@ -62,11 +49,7 @@ SWIGRUNTIME void SWIGV8_AddMemberVariable(SWIGV8_FUNCTION_TEMPLATE class_templ, */ SWIGRUNTIME void SWIGV8_AddStaticFunction(SWIGV8_OBJECT obj, const char* symbol, const SwigV8FunctionCallback& _func, v8::Local context) { -#if (V8_MAJOR_VERSION-0) < 5 - obj->Set(SWIGV8_SYMBOL_NEW(symbol), SWIGV8_FUNCTEMPLATE_NEW(_func)->GetFunction()); -#else SWIGV8_MAYBE_CHECK(obj->Set(context, SWIGV8_SYMBOL_NEW(symbol), SWIGV8_FUNCTEMPLATE_NEW(_func)->GetFunction(context).ToLocalChecked())); -#endif } /** @@ -75,27 +58,15 @@ SWIGRUNTIME void SWIGV8_AddStaticFunction(SWIGV8_OBJECT obj, const char* symbol, SWIGRUNTIME void SWIGV8_AddStaticVariable(SWIGV8_OBJECT obj, const char* symbol, SwigV8AccessorGetterCallback getter, SwigV8AccessorSetterCallback setter, v8::Local context) { -#if (V8_MAJOR_VERSION-0) < 5 - obj->SetAccessor(SWIGV8_SYMBOL_NEW(symbol), getter, setter); -#else SWIGV8_MAYBE_CHECK(obj->SetAccessor(context, SWIGV8_SYMBOL_NEW(symbol), getter, setter)); -#endif } -#if (V8_MAJOR_VERSION-0) < 5 -SWIGRUNTIME void JS_veto_set_variable(v8::Local property, v8::Local value, const SwigV8PropertyCallbackInfoVoid& info) -#else SWIGRUNTIME void JS_veto_set_variable(v8::Local property, v8::Local value, const SwigV8PropertyCallbackInfoVoid& info) -#endif { char buffer[256]; char msg[512]; int res; -#if (V8_MAJOR_VERSION-0) < 5 - property->WriteUtf8(buffer, 256); - res = sprintf(msg, "Tried to write read-only variable: %s.", buffer); -#else v8::Local sproperty; if (property->ToString(SWIGV8_CURRENT_CONTEXT()).ToLocal(&sproperty)) { SWIGV8_WRITE_UTF8(sproperty, buffer, 256); @@ -104,7 +75,6 @@ SWIGRUNTIME void JS_veto_set_variable(v8::Local property, v8::Local context, swig_module_info *swig_module) v8::Local global_obj = context->Global(); v8::Local mod = SWIGV8_EXTERNAL_NEW(swig_module); assert(!mod.IsEmpty()); -#if (V8_MAJOR_VERSION-0) < 5 - global_obj->SetHiddenValue(SWIGV8_STRING_NEW("swig_module_info_data"), mod); -#else v8::Local privateKey = v8::Private::ForApi(v8::Isolate::GetCurrent(), SWIGV8_STRING_NEW("swig_module_info_data")); global_obj->SetPrivate(context, privateKey, mod); -#endif } SWIGRUNTIME swig_module_info * SWIG_V8_GetModule(v8::Local context) { v8::Local global_obj = context->Global(); -#if (V8_MAJOR_VERSION-0) < 5 - v8::Local moduleinfo = global_obj->GetHiddenValue(SWIGV8_STRING_NEW("swig_module_info_data")); -#else v8::Local privateKey = v8::Private::ForApi(v8::Isolate::GetCurrent(), SWIGV8_STRING_NEW("swig_module_info_data")); v8::Local moduleinfo; if (!global_obj->GetPrivate(context, privateKey).ToLocal(&moduleinfo)) return 0; -#endif if (moduleinfo.IsEmpty() || moduleinfo->IsNull() || moduleinfo->IsUndefined()) { diff --git a/Lib/javascript/v8/javascriptrun.swg b/Lib/javascript/v8/javascriptrun.swg index 2df342416..518b19a8f 100644 --- a/Lib/javascript/v8/javascriptrun.swg +++ b/Lib/javascript/v8/javascriptrun.swg @@ -4,56 +4,26 @@ * Useful table of versions: https://nodejs.org/en/download/releases/ * ---------------------------------------------------------------------------*/ -// First v8 version that uses "SetWeak" and not "MakeWeak" - -#define SWIGV8_SETWEAK_VERSION 0x032224 - -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031803) -#define SWIGV8_STRING_NEW2(cstr, len) v8::String::New(cstr, len) -#elif (SWIG_V8_VERSION < 0x0704) +#if (SWIG_V8_VERSION < 0x0704) #define SWIGV8_STRING_NEW2(cstr, len) v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), cstr, v8::String::kNormalString, len) #else #define SWIGV8_STRING_NEW2(cstr, len) (v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), cstr, v8::NewStringType::kNormal, len)).ToLocalChecked() #endif -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) -typedef v8::Handle SwigV8ReturnValue; -typedef v8::Arguments SwigV8Arguments; -typedef v8::AccessorInfo SwigV8PropertyCallbackInfo; -#define SWIGV8_RETURN(val) return scope.Close(val) -#define SWIGV8_RETURN_INFO(val, info) return scope.Close(val) -#else typedef void SwigV8ReturnValue; typedef v8::FunctionCallbackInfo SwigV8Arguments; typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; #define SWIGV8_RETURN(val) args.GetReturnValue().Set(val); return #define SWIGV8_RETURN_INFO(val, info) info.GetReturnValue().Set(val); return -#endif -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032117) -#define SWIGV8_HANDLESCOPE() v8::HandleScope scope -#define SWIGV8_HANDLESCOPE_ESC() v8::HandleScope scope -#define SWIGV8_ESCAPE(val) return scope.Close(val) -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032224) -#define SWIGV8_HANDLESCOPE() v8::HandleScope scope(v8::Isolate::GetCurrent()); -#define SWIGV8_HANDLESCOPE_ESC() v8::HandleScope scope(v8::Isolate::GetCurrent()); -#define SWIGV8_ESCAPE(val) return scope.Close(val) -#else #define SWIGV8_HANDLESCOPE() v8::HandleScope scope(v8::Isolate::GetCurrent()); #define SWIGV8_HANDLESCOPE_ESC() v8::EscapableHandleScope scope(v8::Isolate::GetCurrent()); #define SWIGV8_ESCAPE(val) return scope.Escape(val) -#endif -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032224) -#define SWIGV8_ADJUST_MEMORY(size) v8::V8::AdjustAmountOfExternalAllocatedMemory(size) -#define SWIGV8_CURRENT_CONTEXT() v8::Context::GetCurrent() -#define SWIGV8_THROW_EXCEPTION(err) v8::ThrowException(err) -#define SWIGV8_STRING_NEW(str) v8::String::New(str) -#define SWIGV8_SYMBOL_NEW(sym) v8::String::NewSymbol(sym) -#else #define SWIGV8_ADJUST_MEMORY(size) v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(size) #define SWIGV8_CURRENT_CONTEXT() v8::Isolate::GetCurrent()->GetCurrentContext() #define SWIGV8_THROW_EXCEPTION(err) v8::Isolate::GetCurrent()->ThrowException(err) + #if (SWIG_V8_VERSION < 0x0704) #define SWIGV8_STRING_NEW(str) v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), str, v8::String::kNormalString) #define SWIGV8_SYMBOL_NEW(sym) v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), sym, v8::String::kNormalString) @@ -61,37 +31,13 @@ typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; #define SWIGV8_STRING_NEW(str) (v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), str, v8::NewStringType::kNormal)).ToLocalChecked() #define SWIGV8_SYMBOL_NEW(sym) (v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), sym, v8::NewStringType::kNormal)).ToLocalChecked() #endif -#endif -#if (V8_MAJOR_VERSION-0) < 5 -#define SWIGV8_MAYBE_CHECK(maybe) maybe -#elif (SWIG_V8_VERSION < 0x0704) +#if (SWIG_V8_VERSION < 0x0704) #define SWIGV8_MAYBE_CHECK(maybe) maybe.FromJust() #else #define SWIGV8_MAYBE_CHECK(maybe) maybe.Check() #endif -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032318) -#define SWIGV8_ARRAY_NEW(size) v8::Array::New(size) -#define SWIGV8_BOOLEAN_NEW(bool) v8::Boolean::New(bool) -#define SWIGV8_EXTERNAL_NEW(val) v8::External::New(val) -#define SWIGV8_FUNCTEMPLATE_NEW(func) v8::FunctionTemplate::New(func) -#define SWIGV8_FUNCTEMPLATE_NEW_VOID() v8::FunctionTemplate::New() -#define SWIGV8_INT32_NEW(num) v8::Int32::New(num) -#define SWIGV8_INTEGER_NEW(num) v8::Integer::New(num) -#define SWIGV8_INTEGER_NEW_UNS(num) v8::Integer::NewFromUnsigned(num) -#define SWIGV8_NUMBER_NEW(num) v8::Number::New(num) -#define SWIGV8_OBJECT_NEW() v8::Object::New() -#define SWIGV8_UNDEFINED() v8::Undefined() -#define SWIGV8_ARRAY v8::Handle -#define SWIGV8_FUNCTION_TEMPLATE v8::Handle -#define SWIGV8_OBJECT v8::Handle -#define SWIGV8_OBJECT_TEMPLATE v8::Handle -#define SWIGV8_VALUE v8::Handle -#define SWIGV8_NULL() v8::Null() -#define SWIGV8_ARRAY_GET(array, index) (array)->Get(index) -#define SWIGV8_ARRAY_SET(array, index, value) (array)->Set(index, value) -#else #define SWIGV8_ARRAY_NEW(size) v8::Array::New(v8::Isolate::GetCurrent(), size) #define SWIGV8_BOOLEAN_NEW(bool) v8::Boolean::New(v8::Isolate::GetCurrent(), bool) #define SWIGV8_EXTERNAL_NEW(val) v8::External::New(v8::Isolate::GetCurrent(), val) @@ -111,17 +57,10 @@ typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; #define SWIGV8_NULL() v8::Null(v8::Isolate::GetCurrent()) #define SWIGV8_ARRAY_GET(array, index) (array)->Get(SWIGV8_CURRENT_CONTEXT(), index).ToLocalChecked() #define SWIGV8_ARRAY_SET(array, index, value) SWIGV8_MAYBE_CHECK((array)->Set(SWIGV8_CURRENT_CONTEXT(), index, value)) -#endif -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) -#define SWIGV8_SET_CLASS_TEMPL(class_templ, class) class_templ = v8::Persistent::New(class); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) -#define SWIGV8_SET_CLASS_TEMPL(class_templ, class) class_templ = v8::Persistent::New(v8::Isolate::GetCurrent(), class); -#else #define SWIGV8_SET_CLASS_TEMPL(class_templ, class) class_templ.Reset(v8::Isolate::GetCurrent(), class); -#endif -#if (V8_MAJOR_VERSION-0) < 6 || (SWIG_V8_VERSION < 0x0608) +#if SWIG_V8_VERSION < 0x0608 #define SWIGV8_TO_OBJECT(handle) (handle)->ToObject() #define SWIGV8_TO_STRING(handle) (handle)->ToString() #define SWIGV8_NUMBER_VALUE(handle) (handle)->NumberValue() @@ -208,23 +147,8 @@ public: }; ~SWIGV8_Proxy() { -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) - handle.ClearWeak(); - handle.Dispose(); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100) - handle.ClearWeak(v8::Isolate::GetCurrent()); - handle.Dispose(v8::Isolate::GetCurrent()); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) - handle.ClearWeak(); - handle.Dispose(); -#else handle.ClearWeak(); handle.Reset(); -#endif - -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) - handle.Clear(); -#endif SWIGV8_ADJUST_MEMORY(-SWIGV8_AVG_OBJ_SIZE); } @@ -239,17 +163,7 @@ class SWIGV8_ClientData { public: v8::Persistent class_templ; -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) - void (*dtor) (v8::Persistent< v8::Value> object, void *parameter); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) - void (*dtor) (v8::Isolate *isolate, v8::Persistent< v8::Value> object, void *parameter); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) - void (*dtor) (v8::Isolate *isolate, v8::Persistent< v8::Object > *object, SWIGV8_Proxy *proxy); -#elif (V8_MAJOR_VERSION-0) < 5 - void (*dtor) (const v8::WeakCallbackData &data); -#else void (*dtor) (const v8::WeakCallbackInfo &data); -#endif }; SWIGRUNTIME v8::Persistent SWIGV8_SWIGTYPE_Proxy_class_templ; @@ -259,12 +173,7 @@ SWIGRUNTIME int SWIG_V8_ConvertInstancePtr(SWIGV8_OBJECT objRef, void **ptr, swi if(objRef->InternalFieldCount() < 1) return SWIG_ERROR; -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031511) - v8::Handle cdataRef = objRef->GetInternalField(0); - SWIGV8_Proxy *cdata = static_cast(v8::External::Unwrap(cdataRef)); -#else SWIGV8_Proxy *cdata = static_cast(objRef->GetAlignedPointerFromInternalField(0)); -#endif if(cdata == NULL) { return SWIG_ERROR; @@ -292,22 +201,8 @@ SWIGRUNTIME int SWIG_V8_ConvertInstancePtr(SWIGV8_OBJECT objRef, void **ptr, swi } -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) -SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(v8::Persistent< v8::Value > object, void *parameter) { - SWIGV8_Proxy *proxy = static_cast(parameter); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) -SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(v8::Isolate *, v8::Persistent< v8::Value > object, void *parameter) { - SWIGV8_Proxy *proxy = static_cast(parameter); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) -SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(v8::Isolate *, v8::Persistent< v8::Object > *object, SWIGV8_Proxy *proxy) { -#elif (V8_MAJOR_VERSION-0) < 5 -SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(const v8::WeakCallbackData &data) { - SWIGV8_Proxy *proxy = data.GetParameter(); -#else SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(const v8::WeakCallbackInfo &data) { SWIGV8_Proxy *proxy = data.GetParameter(); -#endif - delete proxy; } @@ -319,12 +214,7 @@ SWIGRUNTIME int SWIG_V8_GetInstancePtr(SWIGV8_VALUE valRef, void **ptr) { if(objRef->InternalFieldCount() < 1) return SWIG_ERROR; -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031511) - v8::Handle cdataRef = objRef->GetInternalField(0); - SWIGV8_Proxy *cdata = static_cast(v8::External::Unwrap(cdataRef)); -#else SWIGV8_Proxy *cdata = static_cast(objRef->GetAlignedPointerFromInternalField(0)); -#endif if(cdata == NULL) { return SWIG_ERROR; @@ -341,58 +231,17 @@ SWIGRUNTIME void SWIGV8_SetPrivateData(SWIGV8_OBJECT obj, void *ptr, swig_type_i cdata->swigCMemOwn = (flags & SWIG_POINTER_OWN) ? 1 : 0; cdata->info = info; -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031511) - obj->SetPointerInInternalField(0, cdata); -#else obj->SetAlignedPointerInInternalField(0, cdata); -#endif -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) - cdata->handle = v8::Persistent::New(obj); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) - cdata->handle = v8::Persistent::New(v8::Isolate::GetCurrent(), obj); -#else cdata->handle.Reset(v8::Isolate::GetCurrent(), obj); -#endif -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) - // clientdata must be set for owned data as we need to register the dtor - if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) { - cdata->handle.MakeWeak(cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor); - } else { - cdata->handle.MakeWeak(cdata, SWIGV8_Proxy_DefaultDtor); - } -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031918) - if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) { - cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor); - } else { - cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, SWIGV8_Proxy_DefaultDtor); - } -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) - if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) { - cdata->handle.MakeWeak(cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor); - } else { - cdata->handle.MakeWeak(cdata, SWIGV8_Proxy_DefaultDtor); - } -#elif (V8_MAJOR_VERSION-0) < 5 - if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) { - cdata->handle.SetWeak(cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor); - } else { - cdata->handle.SetWeak(cdata, SWIGV8_Proxy_DefaultDtor); - } -#else if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) { cdata->handle.SetWeak(cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor, v8::WeakCallbackType::kParameter); } else { cdata->handle.SetWeak(cdata, SWIGV8_Proxy_DefaultDtor, v8::WeakCallbackType::kParameter); } -#endif -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) - cdata->handle.MarkIndependent(); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100) - cdata->handle.MarkIndependent(v8::Isolate::GetCurrent()); -#elif (SWIG_V8_VERSION < 0x0704) +#if (SWIG_V8_VERSION < 0x0704) cdata->handle.MarkIndependent(); // Looks like future versions do not require that anymore: // https://monorail-prod.appspot.com/p/chromium/issues/detail?id=923361#c11 @@ -420,21 +269,10 @@ SWIGRUNTIME SWIGV8_VALUE SWIG_V8_NewPointerObj(void *ptr, swig_type_info *info, SWIGV8_FUNCTION_TEMPLATE class_templ; if (ptr == NULL) { -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) - SWIGV8_ESCAPE(SWIGV8_NULL()); -#else v8::Local result = SWIGV8_NULL(); SWIGV8_ESCAPE(result); -#endif } -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) - if(info->clientdata != 0) { - class_templ = ((SWIGV8_ClientData*) info->clientdata)->class_templ; - } else { - class_templ = SWIGV8_SWIGTYPE_Proxy_class_templ; - } -#else v8::Isolate *isolate = v8::Isolate::GetCurrent(); if(info->clientdata != 0) { @@ -442,13 +280,8 @@ SWIGRUNTIME SWIGV8_VALUE SWIG_V8_NewPointerObj(void *ptr, swig_type_info *info, } else { class_templ = v8::Local::New(isolate, SWIGV8_SWIGTYPE_Proxy_class_templ); } -#endif -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) - v8::Local result = class_templ->InstanceTemplate()->NewInstance(); -#else v8::Local result = class_templ->InstanceTemplate()->NewInstance(SWIGV8_CURRENT_CONTEXT()).ToLocalChecked(); -#endif SWIGV8_SetPrivateData(result, ptr, info, flags); @@ -543,14 +376,10 @@ int SwigV8Packed_Check(SWIGV8_VALUE valRef) { SWIGV8_OBJECT objRef = SWIGV8_TO_OBJECT(valRef); if(objRef->InternalFieldCount() < 1) return false; -#if (V8_MAJOR_VERSION-0) < 5 - v8::Handle flag = objRef->GetHiddenValue(SWIGV8_STRING_NEW("__swig__packed_data__")); -#else v8::Local privateKey = v8::Private::ForApi(v8::Isolate::GetCurrent(), SWIGV8_STRING_NEW("__swig__packed_data__")); v8::Local flag; if (!objRef->GetPrivate(SWIGV8_CURRENT_CONTEXT(), privateKey).ToLocal(&flag)) return false; -#endif return (flag->IsBoolean() && SWIGV8_BOOLEAN_VALUE(flag)); } @@ -563,12 +392,7 @@ swig_type_info *SwigV8Packed_UnpackData(SWIGV8_VALUE valRef, void *ptr, size_t s SWIGV8_OBJECT objRef = SWIGV8_TO_OBJECT(valRef); -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031511) - v8::Handle cdataRef = objRef->GetInternalField(0); - sobj = static_cast(v8::External::Unwrap(cdataRef)); -#else sobj = static_cast(objRef->GetAlignedPointerFromInternalField(0)); -#endif if (sobj == NULL || sobj->size != size) return 0; memcpy(ptr, sobj->data, size); return sobj->type; @@ -591,38 +415,9 @@ int SWIGV8_ConvertPacked(SWIGV8_VALUE valRef, void *ptr, size_t sz, swig_type_in return SWIG_OK; } -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) -SWIGRUNTIME void _wrap_SwigV8PackedData_delete(v8::Persistent< v8::Value > object, void *parameter) { - SwigV8PackedData *cdata = static_cast(parameter); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) -SWIGRUNTIME void _wrap_SwigV8PackedData_delete(v8::Isolate *isolate, v8::Persistent object, void *parameter) { - SwigV8PackedData *cdata = static_cast(parameter); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) -SWIGRUNTIME void _wrap_SwigV8PackedData_delete(v8::Isolate *isolate, v8::Persistent *object, SwigV8PackedData *cdata) { -#elif (V8_MAJOR_VERSION-0) < 5 -SWIGRUNTIME void _wrap_SwigV8PackedData_delete(const v8::WeakCallbackData &data) { - v8::Local object = data.GetValue(); - SwigV8PackedData *cdata = data.GetParameter(); -#else SWIGRUNTIME void _wrap_SwigV8PackedData_delete(const v8::WeakCallbackInfo &data) { SwigV8PackedData *cdata = data.GetParameter(); -#endif - delete cdata; - -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) - object.Clear(); - object.Dispose(); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) - object.Clear(); - object.Dispose(isolate); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100) - object->Dispose(isolate); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) - object->Dispose(); -#elif (V8_MAJOR_VERSION-0) < 5 - object.Clear(); -#endif } SWIGRUNTIME @@ -633,46 +428,16 @@ SWIGV8_VALUE SWIGV8_NewPackedObj(void *data, size_t size, swig_type_info *type) // v8::Handle obj = SWIGV8_OBJECT_NEW(); v8::Local obj = SWIGV8_OBJECT_NEW(); -#if (V8_MAJOR_VERSION-0) < 5 - obj->SetHiddenValue(SWIGV8_STRING_NEW("__swig__packed_data__"), SWIGV8_BOOLEAN_NEW(true)); -#else v8::Local privateKey = v8::Private::ForApi(v8::Isolate::GetCurrent(), SWIGV8_STRING_NEW("__swig__packed_data__")); obj->SetPrivate(SWIGV8_CURRENT_CONTEXT(), privateKey, SWIGV8_BOOLEAN_NEW(true)); -#endif -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031511) - obj->SetPointerInInternalField(0, cdata); -#else obj->SetAlignedPointerInInternalField(0, cdata); -#endif -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) - cdata->handle = v8::Persistent::New(obj); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) - cdata->handle = v8::Persistent::New(v8::Isolate::GetCurrent(), obj); -#else cdata->handle.Reset(v8::Isolate::GetCurrent(), obj); -#endif - -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) - cdata->handle.MakeWeak(cdata, _wrap_SwigV8PackedData_delete); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031918) - cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, _wrap_SwigV8PackedData_delete); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION) - cdata->handle.MakeWeak(cdata, _wrap_SwigV8PackedData_delete); -#elif (V8_MAJOR_VERSION-0) < 5 - cdata->handle.SetWeak(cdata, _wrap_SwigV8PackedData_delete); -// v8::V8::SetWeak(&cdata->handle, cdata, _wrap_SwigV8PackedData_delete); -#else cdata->handle.SetWeak(cdata, _wrap_SwigV8PackedData_delete, v8::WeakCallbackType::kParameter); -#endif -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) - cdata->handle.MarkIndependent(); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100) - cdata->handle.MarkIndependent(v8::Isolate::GetCurrent()); -#elif (SWIG_V8_VERSION < 0x0704) +#if (SWIG_V8_VERSION < 0x0704) cdata->handle.MarkIndependent(); // Looks like future versions do not require that anymore: // https://monorail-prod.appspot.com/p/chromium/issues/detail?id=923361#c11 diff --git a/Lib/javascript/v8/javascriptruntime.swg b/Lib/javascript/v8/javascriptruntime.swg index 59909389e..4e93fc4c1 100644 --- a/Lib/javascript/v8/javascriptruntime.swg +++ b/Lib/javascript/v8/javascriptruntime.swg @@ -7,36 +7,8 @@ // ---------------- // // v8 added version macros V8_MAJOR_VERSION, V8_MINOR_VERSION, V8_BUILD_NUMBER -// and V8_PATCH_LEVEL in version 4.3.0. SWIG generated code uses these if -// they are defined - to support earlier versions you can specify the V8 version -// in use via the command line when you run SWIG: -// -// swig -c++ -javascript -v8 -DV8_VERSION=0x032530 example.i -// -// Or code in the interface file using SWIG_V8_VERSION: -// -// %begin %{#define SWIG_V8_VERSION 0x031110%} -// -// This is specified as a hex constant, but the constant is read as pairs of -// decimal digits, so for V8 3.25.30 use constant 0x032530. This scheme can't -// represent components > 99, but this constant is only useful for V8 < 4.3.0, -// and no V8 versions from that era had a component > 99. - -%define %swig_v8_define_version(version) -%insert("runtime") %{ -#ifndef SWIG_V8_VERSION -#define SWIG_V8_VERSION version -#endif -%} -%enddef - -#ifdef V8_VERSION -%swig_v8_define_version(V8_VERSION) -#else -// HACK: defining a default version -%swig_v8_define_version(0x031110) -#endif - +// and V8_PATCH_LEVEL in version 4.3.0. SWIG doesn't support anything that +// old so SWIG generated code can rely on these. // Node support // ------------ @@ -56,13 +28,11 @@ %insert(runtime) %{ #include -#if defined(V8_MAJOR_VERSION) && defined(V8_MINOR_VERSION) #undef SWIG_V8_VERSION #define SWIG_V8_VERSION ((V8_MAJOR_VERSION / 10) * 4096 + \ (V8_MAJOR_VERSION % 10) * 256 + \ (V8_MINOR_VERSION / 10) * 16 + \ (V8_MINOR_VERSION % 10)) -#endif #include #include diff --git a/Lib/javascript/v8/javascriptstrings.swg b/Lib/javascript/v8/javascriptstrings.swg index aaf1b9302..8dc2d945e 100644 --- a/Lib/javascript/v8/javascriptstrings.swg +++ b/Lib/javascript/v8/javascriptstrings.swg @@ -7,11 +7,7 @@ SWIGINTERN int SWIG_AsCharPtrAndSize(SWIGV8_VALUE valRef, char** cptr, size_t* psize, int *alloc) { if(valRef->IsString()) { -%#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) - v8::Handle js_str = v8::Handle::Cast(valRef); -%#else v8::Local js_str = v8::Local::Cast(valRef); -%#endif size_t len = SWIGV8_UTF8_LENGTH(js_str) + 1; char* cstr = (char*) %new_array(len, char); @@ -53,11 +49,7 @@ SWIG_FromCharPtrAndSize(const char* carray, size_t size) // TODO: handle extra long strings return SWIGV8_UNDEFINED(); } else { -%#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) - v8::Handle js_str = SWIGV8_STRING_NEW2(carray, size); -%#else v8::Local js_str = SWIGV8_STRING_NEW2(carray, size); -%#endif return js_str; } } else { diff --git a/Tools/javascript/v8_shell.cxx b/Tools/javascript/v8_shell.cxx index 5001bc25a..b74dd7d2b 100644 --- a/Tools/javascript/v8_shell.cxx +++ b/Tools/javascript/v8_shell.cxx @@ -13,57 +13,24 @@ typedef int (*V8ExtensionInitializer) (v8::Handle module); // Note: these typedefs and defines are used to deal with v8 API changes since version 3.19.00 -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) -typedef v8::Handle SwigV8ReturnValue; -typedef v8::Arguments SwigV8Arguments; -typedef v8::AccessorInfo SwigV8PropertyCallbackInfo; -#define SWIGV8_RETURN(val) return scope.Close(val) -#define SWIGV8_RETURN_INFO(val, info) return scope.Close(val) -#else typedef void SwigV8ReturnValue; typedef v8::FunctionCallbackInfo SwigV8Arguments; typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; #define SWIGV8_RETURN(val) args.GetReturnValue().Set(val); return #define SWIGV8_RETURN_INFO(val, info) info.GetReturnValue().Set(val); return -#endif - -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032117) -#define SWIGV8_HANDLESCOPE() v8::HandleScope scope -#define SWIGV8_HANDLESCOPE_ESC() v8::HandleScope scope -#define SWIGV8_ESCAPE(val) return scope.Close(val) -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032318) -#define SWIGV8_HANDLESCOPE() v8::HandleScope scope(v8::Isolate::GetCurrent()); -#define SWIGV8_HANDLESCOPE_ESC() v8::HandleScope scope(v8::Isolate::GetCurrent()); -#define SWIGV8_ESCAPE(val) return scope.Close(val) -#else #define SWIGV8_HANDLESCOPE() v8::HandleScope scope(v8::Isolate::GetCurrent()); #define SWIGV8_HANDLESCOPE_ESC() v8::EscapableHandleScope scope(v8::Isolate::GetCurrent()); #define SWIGV8_ESCAPE(val) return scope.Escape(val) -#endif -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032318) -#define SWIGV8_CURRENT_CONTEXT() v8::Context::GetCurrent() -#define SWIGV8_STRING_NEW(str) v8::String::New(str) -#define SWIGV8_FUNCTEMPLATE_NEW(func) v8::FunctionTemplate::New(func) -#define SWIGV8_OBJECT_NEW() v8::Object::New() -#define SWIGV8_EXTERNAL_NEW(val) v8::External::New(val) -#define SWIGV8_UNDEFINED() v8::Undefined() -#else #define SWIGV8_CURRENT_CONTEXT() v8::Isolate::GetCurrent()->GetCurrentContext() #define SWIGV8_STRING_NEW(str) v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), str) #define SWIGV8_FUNCTEMPLATE_NEW(func) v8::FunctionTemplate::New(v8::Isolate::GetCurrent(), func) #define SWIGV8_OBJECT_NEW() v8::Object::New(v8::Isolate::GetCurrent()) #define SWIGV8_EXTERNAL_NEW(val) v8::External::New(v8::Isolate::GetCurrent(), val) #define SWIGV8_UNDEFINED() v8::Undefined(v8::Isolate::GetCurrent()) -#endif - -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) -typedef v8::Persistent SwigV8Context; -#else typedef v8::Local SwigV8Context; -#endif class V8Shell: public JSShell { @@ -149,13 +116,7 @@ bool V8Shell::RunScript(const std::string &scriptPath) { context->Exit(); -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) - context.Dispose(); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) - context.Dispose(v8::Isolate::GetCurrent()); -#else // context.Dispose(); -#endif // v8::V8::Dispose(); @@ -193,13 +154,7 @@ bool V8Shell::RunShell() { context->Exit(); -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710) - context.Dispose(); -#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) - context.Dispose(v8::Isolate::GetCurrent()); -#else // context.Dispose(); -#endif // v8::V8::Dispose(); @@ -249,13 +204,8 @@ SwigV8Context V8Shell::CreateShellContext() { global->Set(SWIGV8_STRING_NEW("require"), SWIGV8_FUNCTEMPLATE_NEW(V8Shell::Require)); global->Set(SWIGV8_STRING_NEW("version"), SWIGV8_FUNCTEMPLATE_NEW(V8Shell::Version)); -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900) - SwigV8Context context = v8::Context::New(NULL, global); - return context; -#else SwigV8Context context = v8::Context::New(v8::Isolate::GetCurrent(), NULL, global); return context; -#endif } v8::Handle V8Shell::Import(const std::string &module_path) From bebb3d4c21658db58dddc30378a837e97713dd9f Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 2 Dec 2021 14:31:28 +1300 Subject: [PATCH 115/262] [ci] Remove CI build for unsupported v8 3.14 We only support v8 5.0 and later now. libv8-dev is no longer packaged in newer Ubuntu releases, so it seems there isn't an easy way to update this to test a supported v8 version, but really v8 via node is the configuration people will actually use anyway. --- .github/workflows/ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5374c5428..d23482a76 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,9 +89,6 @@ jobs: CPPSTD: c++14 - SWIGLANG: javascript ENGINE: jsc - - SWIGLANG: javascript - ENGINE: v8 - os: ubuntu-18.04 # libv8-dev only actually provides v8 in 18.04. - SWIGLANG: lua - SWIGLANG: lua VER: '5.3' From c25df7480751ef49db4eadffc6f45ef77b647572 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 2 Dec 2021 18:00:39 +1300 Subject: [PATCH 116/262] [php7] Use destructor action if present If there's a destructor, use its action instead of free(ptr) (for C)/delete ptr (for C++). Fixes #2108 --- Examples/test-suite/php/newobject2_runme.php | 17 ++++++++++ Source/Modules/php.cxx | 35 +++++++++++++++----- 2 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 Examples/test-suite/php/newobject2_runme.php diff --git a/Examples/test-suite/php/newobject2_runme.php b/Examples/test-suite/php/newobject2_runme.php new file mode 100644 index 000000000..f20a6a4f9 --- /dev/null +++ b/Examples/test-suite/php/newobject2_runme.php @@ -0,0 +1,17 @@ +std);\n"); - // expand %delete typemap instead of SWIG_remove? - Printf(s, " if (obj->newobject)\n"); - Printf(s, " SWIG_remove((%s *)obj->ptr);\n", Getattr(n, "classtype")); + Printf(s, " if (obj->newobject)"); + String * type = Getattr(n, "classtype"); + if (destructor_action) { + Printv(s, + " {\n", + type, " * arg1 = (", type, " *)obj->ptr;\n", + destructor_action, "\n", + " }\n", NIL); + } else if (CPlusPlus) { + Printf(s, "\n delete (%s *)obj->ptr;\n", type); + } else { + Printf(s, "\n free(obj->ptr);\n", type); + } Printf(s, "}\n\n"); } @@ -371,9 +383,6 @@ public: Printf(s_header, "}\n"); Printf(s_header, "#endif\n\n"); - Printf(s_header, "#ifdef __cplusplus\n#define SWIG_remove(PTR) delete PTR\n"); - Printf(s_header, "#else\n#define SWIG_remove(PTR) free(PTR)\n#endif\n\n"); - if (directorsEnabled()) { // Insert director runtime Swig_insert_file("director_common.swg", s_header); @@ -1132,10 +1141,12 @@ public: } } - if (Cmp(nodeType, "destructor") == 0) { + if (wrapperType == destructor) { // We don't explicitly wrap the destructor for PHP - Zend manages the // reference counting, and the user can just do `$obj = null;' or similar // to remove a reference to an object. + Setattr(n, "wrap:name", wname); + (void)emit_action(n); return SWIG_OK; } @@ -1535,6 +1546,7 @@ public: String *base_class = NULL; class_name = symname; + destructor_action = NULL; Printf(all_cs_entry, "static zend_function_entry class_%s_functions[] = {\n", class_name); @@ -1811,8 +1823,13 @@ public: /* ------------------------------------------------------------ * destructorHandler() * ------------------------------------------------------------ */ - //virtual int destructorHandler(Node *n) { - //} + virtual int destructorHandler(Node *n) { + wrapperType = destructor; + Language::destructorHandler(n); + destructor_action = Getattr(n, "wrap:action"); + wrapperType = standard; + return SWIG_OK; + } /* ------------------------------------------------------------ * memberconstantHandler() From e2384796f0e389fe6f3da9b247db9624cb06aeda Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 2 Dec 2021 08:56:00 +0000 Subject: [PATCH 117/262] Add Python embedded interpreters fix to changes file --- CHANGES.current | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 0abed204a..f87ba0afe 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2021-12-02: jsenn + [Python] #2102 Fixed crashes when using embedded Python interpreters. + 2021-11-12: wsfulton [Javascript] v8 and node only. Fix mismatched new char[] and free() when wrapping C code char arrays. Now calloc is now used instead of From a5f85beb2da59c91386b99b1b509220dca61670b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 2 Dec 2021 11:38:41 +0000 Subject: [PATCH 118/262] HTML doc fixes --- Doc/Manual/Contents.html | 2 +- Doc/Manual/Php.html | 3 ++- Doc/Manual/Windows.html | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 47b41186e..cf72febef 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -96,7 +96,7 @@
  • Building swig.exe on Windows diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index 5aea878b2..ed2587f1b 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -161,7 +161,7 @@ default extension directory, you also need to specify the path, for example:

    -	extension=/path/to/modulename.so
    +        extension=/path/to/modulename.so
     

    @@ -426,6 +426,7 @@ taking the integer argument.

    32.2.5 Pointers and References

    +

    Since SWIG 4.1.0, SWIG wraps C/C++ classes directly with PHP objects. Pointers to other types are also wrapped as PHP objects - mostly this is an diff --git a/Doc/Manual/Windows.html b/Doc/Manual/Windows.html index eae9ffb84..82d79435f 100644 --- a/Doc/Manual/Windows.html +++ b/Doc/Manual/Windows.html @@ -34,7 +34,7 @@

  • Building swig.exe on Windows @@ -298,7 +298,7 @@ swig.exe -help
    -python -c++ -o C:\Temp\doxygen_parsing.cpp C:\swig\Examples\test-suite\doxygen_parsing.i
    -

    3.3.1.2 Building swig.exe using MSYS2

    +

    3.3.1.2 Building swig.exe using MSYS2

    From 5bdc20781bf458dcafb5b5469e0a1253f067d56f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 2 Dec 2021 11:53:13 +0000 Subject: [PATCH 119/262] Remove bom in Windows.html --- Doc/Manual/Windows.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/Manual/Windows.html b/Doc/Manual/Windows.html index 82d79435f..0e4ffc3e2 100644 --- a/Doc/Manual/Windows.html +++ b/Doc/Manual/Windows.html @@ -1,4 +1,4 @@ - + Getting started on Windows From 8432d3f89b09e6511370cfea1765fabf224e10d9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 4 Dec 2021 09:35:51 +0000 Subject: [PATCH 120/262] GHA: Test currently supported php versions 7.0-8.1 --- .github/workflows/ci.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d23482a76..b690b829a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -95,9 +95,19 @@ jobs: - SWIGLANG: octave CPPSTD: c++11 - SWIGLANG: perl5 + - SWIGLANG: php + VER: '7.0' + - SWIGLANG: php + VER: '7.1' + - SWIGLANG: php + VER: '7.2' + - SWIGLANG: php + VER: '7.3' - SWIGLANG: php VER: '7.4' - SWIGLANG: php + - SWIGLANG: php + VER: '8.1' - SWIGLANG: python - SWIGLANG: python PY3: 3 From ee3c9bd69755bfc81e411059b901bf2f265d5915 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 3 Dec 2021 16:09:07 +1300 Subject: [PATCH 121/262] [php] Check fooCount() in newobject1_runme.php --- Examples/test-suite/php/newobject1_runme.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Examples/test-suite/php/newobject1_runme.php b/Examples/test-suite/php/newobject1_runme.php index a495ab15d..464f09b0b 100644 --- a/Examples/test-suite/php/newobject1_runme.php +++ b/Examples/test-suite/php/newobject1_runme.php @@ -9,9 +9,16 @@ check::classes(array('Foo')); // No new vars check::globals(array()); +check::equal(Foo::fooCount(), 0, "no Foo objects expected"); $foo = Foo::makeFoo(); check::equal(get_class($foo), "Foo", "static failed"); +check::equal(Foo::fooCount(), 1, "1 Foo object expected"); $bar = $foo->makeMore(); check::equal(get_class($bar), "Foo", "regular failed"); +check::equal(Foo::fooCount(), 2, "2 Foo objects expected"); +$foo = null; +check::equal(Foo::fooCount(), 1, "1 Foo object expected"); +$bar = null; +check::equal(Foo::fooCount(), 0, "no Foo objects expected"); check::done(); From 883b42dc708199db0f05f7fc0e72974b75eac001 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 3 Dec 2021 16:15:39 +1300 Subject: [PATCH 122/262] [php] Ensure _runme.php calls check::done() This function doesn't do anything currently so these missing calls are a latent issue. It could be used for e.g. memory leak checking in the future though, and it's potentially a useful place to add code when debugging. --- .../test-suite/php/cpp11_strongly_typed_enumerations_runme.php | 2 ++ Examples/test-suite/php/exception_order_runme.php | 2 ++ Examples/test-suite/php/member_pointer_const_runme.php | 2 ++ Examples/test-suite/php/newobject3_runme.php | 2 ++ Examples/test-suite/php/overload_return_type_runme.php | 2 ++ Examples/test-suite/php/preproc_constants_c_runme.php | 2 ++ Examples/test-suite/php/preproc_constants_runme.php | 2 ++ Examples/test-suite/php/swig_exception_runme.php | 2 ++ Examples/test-suite/php/threads_exception_runme.php | 2 ++ Examples/test-suite/php/virtual_vs_nonvirtual_base_runme.php | 2 ++ 10 files changed, 20 insertions(+) diff --git a/Examples/test-suite/php/cpp11_strongly_typed_enumerations_runme.php b/Examples/test-suite/php/cpp11_strongly_typed_enumerations_runme.php index 82296deb7..ca327d502 100644 --- a/Examples/test-suite/php/cpp11_strongly_typed_enumerations_runme.php +++ b/Examples/test-suite/php/cpp11_strongly_typed_enumerations_runme.php @@ -164,3 +164,5 @@ enumCheck($class1->class1Test2(Class1::Enum12_Val5c), 1121); enumCheck(globalTest1(Enum1_Val5a), 13); enumCheck(globalTest2(Class1::Enum12_Val5c), 1121); #enumCheck(globalTest3(Class1::Struct1.Enum12_Val5f), 3121); + +check::done(); diff --git a/Examples/test-suite/php/exception_order_runme.php b/Examples/test-suite/php/exception_order_runme.php index 9a2c9118b..fb9870659 100644 --- a/Examples/test-suite/php/exception_order_runme.php +++ b/Examples/test-suite/php/exception_order_runme.php @@ -35,3 +35,5 @@ try { } catch (Exception $e) { check::equal($e->getMessage(), 'C++ E2 * exception thrown', ''); } + +check::done(); diff --git a/Examples/test-suite/php/member_pointer_const_runme.php b/Examples/test-suite/php/member_pointer_const_runme.php index 3f55549a8..bd8eaa87c 100644 --- a/Examples/test-suite/php/member_pointer_const_runme.php +++ b/Examples/test-suite/php/member_pointer_const_runme.php @@ -57,3 +57,5 @@ check::equal(3, member_pointer_const::call1(member_pointer_const::ADD_BY_VALUE, check::equal(7, member_pointer_const::call2(member_pointer_const::ADD_BY_VALUE, 3, 4), "Add by pointer"); check::equal(11, member_pointer_const::call3(member_pointer_const::ADD_BY_VALUE, 5, 6), "Add by reference"); */ + +check::done(); diff --git a/Examples/test-suite/php/newobject3_runme.php b/Examples/test-suite/php/newobject3_runme.php index 8efa9891d..29e16be61 100644 --- a/Examples/test-suite/php/newobject3_runme.php +++ b/Examples/test-suite/php/newobject3_runme.php @@ -13,3 +13,5 @@ check::isnull($factory->create(0), "create(0) should be NULL"); check::isnull($factory->create(7, -1), "create(7, -1) should be NULL"); check::isnull($factory->create(0, -1), "create(0, -1) should be NULL"); check::isnull($factory->create("bad", -1), "create(\"bad\", -1) should be NULL"); + +check::done(); diff --git a/Examples/test-suite/php/overload_return_type_runme.php b/Examples/test-suite/php/overload_return_type_runme.php index 5f01bbe19..f03a85d7f 100644 --- a/Examples/test-suite/php/overload_return_type_runme.php +++ b/Examples/test-suite/php/overload_return_type_runme.php @@ -8,3 +8,5 @@ check::classname("A", $b->foo("test")); check::equal(overload_return_type::foo(), 1, "overload_return_type::foo() should be 1"); check::equal(overload_return_type::bar(), 1, "overload_return_type::bar() should be 1"); + +check::done(); diff --git a/Examples/test-suite/php/preproc_constants_c_runme.php b/Examples/test-suite/php/preproc_constants_c_runme.php index a26892b42..411f7d766 100644 --- a/Examples/test-suite/php/preproc_constants_c_runme.php +++ b/Examples/test-suite/php/preproc_constants_c_runme.php @@ -64,3 +64,5 @@ check::equal(gettype(preproc_constants_c::EXPR_CONDITIONAL), "double", "preproc_ check::equal(gettype(preproc_constants_c::EXPR_MIXED1), "double", "preproc_constants.EXPR_MIXED1 has unexpected type"); check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type"); check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type"); + +check::done(); diff --git a/Examples/test-suite/php/preproc_constants_runme.php b/Examples/test-suite/php/preproc_constants_runme.php index 7f45a1bae..80f1a9a59 100644 --- a/Examples/test-suite/php/preproc_constants_runme.php +++ b/Examples/test-suite/php/preproc_constants_runme.php @@ -63,3 +63,5 @@ check::equal(gettype(preproc_constants::EXPR_CONDITIONAL), "double", "preproc_co check::equal(gettype(preproc_constants::EXPR_MIXED1), "double", "preproc_constants.EXPR_MIXED1 has unexpected type"); check::equal(gettype(preproc_constants::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type"); check::equal(gettype(preproc_constants::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type"); + +check::done(); diff --git a/Examples/test-suite/php/swig_exception_runme.php b/Examples/test-suite/php/swig_exception_runme.php index 37a7a59ee..c218890e4 100644 --- a/Examples/test-suite/php/swig_exception_runme.php +++ b/Examples/test-suite/php/swig_exception_runme.php @@ -28,3 +28,5 @@ $e = NULL; if (Shape::nshapes() != 0) { check::fail("Shape::nshapes() should be 0, actually ".Shape::nshapes()); } + +check::done(); diff --git a/Examples/test-suite/php/threads_exception_runme.php b/Examples/test-suite/php/threads_exception_runme.php index 38873dffd..21313aead 100644 --- a/Examples/test-suite/php/threads_exception_runme.php +++ b/Examples/test-suite/php/threads_exception_runme.php @@ -40,3 +40,5 @@ foreach (Array(1,2,3,4) as $i) { } catch (Exception $e) { } } + +check::done(); diff --git a/Examples/test-suite/php/virtual_vs_nonvirtual_base_runme.php b/Examples/test-suite/php/virtual_vs_nonvirtual_base_runme.php index abfb4d307..183825971 100644 --- a/Examples/test-suite/php/virtual_vs_nonvirtual_base_runme.php +++ b/Examples/test-suite/php/virtual_vs_nonvirtual_base_runme.php @@ -6,3 +6,5 @@ $fail = new SimpleClassFail(); $work = new SimpleClassWork(); check::equal($work->getInner()->get(), $fail->getInner()->get(), "should both be 10"); + +check::done(); From 852eab7db33c5cfe073a9c8af983b7482a854075 Mon Sep 17 00:00:00 2001 From: Robert Fries Date: Wed, 12 May 2021 19:44:17 -0400 Subject: [PATCH 123/262] Allow swig wrapped modules to compile with -Bsymbolic --- Lib/octave/octrun.swg | 8 ++++++++ Lib/octave/octruntime.swg | 2 ++ 2 files changed, 10 insertions(+) diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 1069e0e54..a7291df14 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -1178,6 +1178,10 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); #endif { return ptr->print(os, pr_as_read_syntax); } +#if SWIG_OCTAVE_PREREQ(4,4,0) + static void set_type_id(int type_id) { t_id=type_id; } +#endif + virtual type_conv_info numeric_conversion_function(void) const { return octave_base_value::type_conv_info (default_numeric_conversion_function, octave_scalar::static_type_id ()); @@ -1285,6 +1289,10 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); # endif #endif +#if SWIG_OCTAVE_PREREQ(4,4,0) + static void set_type_id(int type_id) { t_id=type_id; } +#endif + private: #if !SWIG_OCTAVE_PREREQ(4,0,0) DECLARE_OCTAVE_ALLOCATOR; diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg index a397fb7c1..ca69e44c4 100644 --- a/Lib/octave/octruntime.swg +++ b/Lib/octave/octruntime.swg @@ -295,9 +295,11 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { for (int i = 0; i < types.numel(); ++i) { if (types(i) == octave_swig_ref::static_type_name()) { register_octave_swig_ref = false; + octave_swig_ref::set_type_id(i); } if (types(i) == octave_swig_packed::static_type_name()) { register_octave_swig_packed = false; + octave_swig_packed::set_type_id(i); } } if (register_octave_swig_ref) { From 81f9e6600f2b4a53465aa07991834d8239e82fb7 Mon Sep 17 00:00:00 2001 From: Robert Fries Date: Wed, 12 May 2021 19:45:24 -0400 Subject: [PATCH 124/262] Octave module lets examples and tests work with Octave-6 * Try-catch replacement for check of error_state * Add execute method in addition to call * Replace oct_mach_info with octave::mach_info * Call from interpreter: global_varval global_assign * Assign a global name requires locating the stack which requires interpreter to tree evaluator to callStack * Do not use discard_error_messages or discard_warning_messages --- Lib/octave/octcontainer.swg | 11 +++++- Lib/octave/octrun.swg | 69 ++++++++++++++++++++++++++++++++++--- Lib/octave/octruntime.swg | 12 +++++-- 3 files changed, 83 insertions(+), 9 deletions(-) diff --git a/Lib/octave/octcontainer.swg b/Lib/octave/octcontainer.swg index 80d593f4f..394c90bac 100644 --- a/Lib/octave/octcontainer.swg +++ b/Lib/octave/octcontainer.swg @@ -569,8 +569,17 @@ namespace swig { } else { return octseq.check() ? SWIG_OK : SWIG_ERROR; } - } catch (std::exception& e) { + } +%#if SWIG_OCTAVE_PREREQ(6,0,0) + catch (octave::execution_exception& exec) { + } +%#endif + catch (std::exception& e) { +%#if SWIG_OCTAVE_PREREQ(6,0,0) + if (seq) // Know that octave is not in an error state +%#else if (seq&&!error_state) +%#endif error("swig type error: %s",e.what()); return SWIG_ERROR; } diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index a7291df14..5100825e7 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -171,7 +171,16 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); octave_function* function_value(bool = false) { return this; } +#if SWIG_OCTAVE_PREREQ(6,0,0) octave_value_list call(octave::tree_evaluator& tw, int nargout = 0, const octave_value_list& args = octave_value_list()) { + return execute(tw,nargout,args); + } +#endif +#if SWIG_OCTAVE_PREREQ(6,0,0) + octave_value_list execute(octave::tree_evaluator& tw, int nargout = 0, const octave_value_list& args = octave_value_list()) { +#else + octave_value_list call(octave::tree_evaluator& tw, int nargout = 0, const octave_value_list& args = octave_value_list()) { +#endif octave_value_list all_args; all_args.append(first_args); all_args.append(args); @@ -456,10 +465,20 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); // Fill in dim_vector for (int k=0;k a; + try { + a = out.int_vector_value(); + } + catch (octave::execution_exception& oee) { + return dim_vector(1,1); + } +#else Array a = out.int_vector_value(); if (error_state) return dim_vector(1,1); +#endif dim_vector d; d.resize(a.numel() < 2 ? 2 : a.numel()); d(0) = d(1) = 1; @@ -874,7 +903,11 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); } virtual bool load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) { +#if SWIG_OCTAVE_PREREQ(6,0,0) + octave::mach_info::float_format fmt) { +#else + oct_mach_info::float_format fmt) { +#endif return true; } @@ -1142,7 +1175,11 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); { return ptr->save_binary(os, save_as_floats); } virtual bool load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) +#if SWIG_OCTAVE_PREREQ(6,0,0) + octave::mach_info::float_format fmt) +#else + oct_mach_info::float_format fmt) +#endif { return ptr->load_binary(is, swap, fmt); } #if defined (HAVE_HDF5) @@ -1261,7 +1298,11 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); } virtual bool load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) { +#if SWIG_OCTAVE_PREREQ(6,0,0) + octave::mach_info::float_format fmt) { +#else + oct_mach_info::float_format fmt) { +#endif return true; } @@ -1515,16 +1556,24 @@ SWIGRUNTIMEINLINE void SWIG_Octave_SetConstant(octave_swig_type *module_ns, cons } SWIGRUNTIMEINLINE octave_value SWIG_Octave_GetGlobalValue(std::string name) { +#if SWIG_OCTAVE_PREREQ(6,0,0) + octave::interpreter *interp = octave::interpreter::the_interpreter (); + return interp->global_varval(name); +#else #if SWIG_OCTAVE_PREREQ(4,4,0) octave::symbol_table& symtab = octave::interpreter::the_interpreter()->get_symbol_table(); return symtab.global_varval(name); #else return get_global_value(name, true); #endif +#endif } SWIGRUNTIME void SWIG_Octave_SetGlobalValue(std::string name, const octave_value& value) { -#if SWIG_OCTAVE_PREREQ(4,4,0) +#if SWIG_OCTAVE_PREREQ(6,0,0) + octave::interpreter *interp = octave::interpreter::the_interpreter (); + interp->global_assign(name, value); +#elif SWIG_OCTAVE_PREREQ(4,4,0) octave::symbol_table& symtab = octave::interpreter::the_interpreter()->get_symbol_table(); symtab.global_assign(name, value); #else @@ -1534,10 +1583,20 @@ SWIGRUNTIME void SWIG_Octave_SetGlobalValue(std::string name, const octave_value SWIGRUNTIME void SWIG_Octave_LinkGlobalValue(std::string name) { #if SWIG_OCTAVE_PREREQ(4,4,0) - octave::symbol_table& symtab = octave::interpreter::the_interpreter()->get_symbol_table(); octave::symbol_scope symscope = octave::interpreter::the_interpreter()->get_current_scope(); +#if SWIG_OCTAVE_PREREQ(6,0,0) + octave::interpreter *interp = octave::interpreter::the_interpreter (); + interp->assign(name, interp->global_varval(name)); + octave::tree_evaluator& tree_eval = interp->get_evaluator(); + octave::call_stack& callStack = tree_eval.get_call_stack(); + std::shared_ptr stackFrame = callStack.get_current_stack_frame(); + octave::symbol_record sym=symscope.lookup_symbol(name); + stackFrame->mark_global(sym); +#else + octave::symbol_table& symtab = octave::interpreter::the_interpreter()->get_symbol_table(); symscope.assign(name, symtab.global_varval(name)); symscope.mark_global(name); +#endif #else #if !SWIG_OCTAVE_PREREQ(3,2,0) link_to_global_variable(curr_sym_tab->lookup(name, true)); diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg index ca69e44c4..e76151f14 100644 --- a/Lib/octave/octruntime.swg +++ b/Lib/octave/octruntime.swg @@ -19,7 +19,8 @@ static bool SWIG_init_user(octave_swig_type* module_ns); SWIGINTERN bool SWIG_Octave_LoadModule(std::string name) { bool retn = false; { -#if SWIG_OCTAVE_PREREQ(4,2,0) +#if SWIG_OCTAVE_PREREQ(6,0,0) +#elif SWIG_OCTAVE_PREREQ(4,2,0) octave::unwind_protect frame; frame.protect_var(discard_error_messages); discard_error_messages = true; frame.protect_var(discard_warning_messages); discard_warning_messages = true; @@ -62,7 +63,8 @@ SWIGINTERN bool SWIG_Octave_LoadModule(std::string name) { SWIGINTERN bool SWIG_Octave_InstallFunction(octave_function *octloadfcn, std::string name) { bool retn = false; { -#if SWIG_OCTAVE_PREREQ(4,2,0) +#if SWIG_OCTAVE_PREREQ(6,0,0) +#elif SWIG_OCTAVE_PREREQ(4,2,0) octave::unwind_protect frame; frame.protect_var(discard_error_messages); discard_error_messages = true; frame.protect_var(discard_warning_messages); discard_warning_messages = true; @@ -316,7 +318,11 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { SWIG_InitializeModule(0); SWIG_PropagateClientData(); -#if SWIG_OCTAVE_PREREQ(4,4,0) +#if SWIG_OCTAVE_PREREQ(6,0,0) + octave::tree_evaluator& tree_eval = octave::interpreter::the_interpreter()->get_evaluator(); + octave::call_stack& stack = tree_eval.get_call_stack(); + octave_function *me = stack.current_function(); +#elif SWIG_OCTAVE_PREREQ(4,4,0) octave::call_stack& stack = octave::interpreter::the_interpreter()->get_call_stack(); octave_function *me = stack.current(); #else From 983b91694fc9891e9c01f968cbbcdde96339434d Mon Sep 17 00:00:00 2001 From: Robert Fries Date: Wed, 12 May 2021 20:22:30 -0400 Subject: [PATCH 125/262] Additional changes due to name changes in octave-6 * is_map to isstruct, is_object to isobject --- Lib/octave/octrun.swg | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 5100825e7..fda4596d6 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -660,7 +660,11 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); return true; } +#if SWIG_OCTAVE_PREREQ(6,0,0) + virtual bool isstruct() const { +#else virtual bool is_map() const { +#endif return true; } @@ -808,7 +812,11 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); return as_value(); } +#if SWIG_OCTAVE_PREREQ(6,0,0) + virtual bool isobject() const { +#else virtual bool is_object() const { +#endif return true; } @@ -1117,8 +1125,13 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); bool is_defined() const { return ptr->is_defined(); } +#if SWIG_OCTAVE_PREREQ(6,0,0) + virtual bool isstruct() const + { return ptr->isstruct(); } +#else virtual bool is_map() const { return ptr->is_map(); } +#endif virtual octave_value subsref(const std::string &ops, const std::list < octave_value_list > &idx) { return ptr->subsref(ops, idx); } @@ -1129,8 +1142,13 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); octave_value subsasgn(const std::string &ops, const std::list < octave_value_list > &idx, const octave_value &rhs) { return ptr->subsasgn(ops, idx, rhs); } +#if SWIG_OCTAVE_PREREQ(6,0,0) + virtual bool isobject() const + { return ptr->isobject(); } +#else virtual bool is_object() const { return ptr->is_object(); } +#endif virtual bool is_string() const { return ptr->is_string(); } From 3947df87a20bf7d7df91b1d5b96d748692fbf34e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 5 Dec 2021 22:24:51 +0000 Subject: [PATCH 126/262] GHA: Test Octave 6.4 --- .github/workflows/ci.yml | 5 +++-- Tools/CI-linux-install.sh | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b690b829a..d328befb0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -94,6 +94,9 @@ jobs: VER: '5.3' - SWIGLANG: octave CPPSTD: c++11 + - SWIGLANG: octave + VER: '6.4' + CPPSTD: c++11 - SWIGLANG: perl5 - SWIGLANG: php VER: '7.0' @@ -196,8 +199,6 @@ jobs: CPPSTD: c++11 - SWIGLANG: lua CPPSTD: c++11 - # - SWIGLANG: octave - # CPPSTD: c++11 - SWIGLANG: perl5 CPPSTD: c++11 - SWIGLANG: php diff --git a/Tools/CI-linux-install.sh b/Tools/CI-linux-install.sh index 7bd141080..1c6686d86 100644 --- a/Tools/CI-linux-install.sh +++ b/Tools/CI-linux-install.sh @@ -79,8 +79,14 @@ case "$SWIGLANG" in $RETRY sudo apt-get -qq install ocaml camlp4 ;; "octave") - $RETRY sudo apt-get -qq update - $RETRY sudo apt-get -qq install liboctave-dev + if [[ "$VER" ]]; then + $RETRY sudo add-apt-repository -y ppa:devacom/science + $RETRY sudo apt-get -qq update + $RETRY sudo apt-get -qq install "liboctave-dev=$VER.*" + else + $RETRY sudo apt-get -qq update + $RETRY sudo apt-get -qq install liboctave-dev + fi ;; "php") if [[ "$VER" ]]; then From 5ada46bcce5bd01632c8bd2566980a943a412cfc Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 5 Dec 2021 22:26:25 +0000 Subject: [PATCH 127/262] Whitespace consistency fix in CI-linux-install.sh --- Tools/CI-linux-install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tools/CI-linux-install.sh b/Tools/CI-linux-install.sh index 1c6686d86..99614550c 100644 --- a/Tools/CI-linux-install.sh +++ b/Tools/CI-linux-install.sh @@ -103,9 +103,9 @@ case "$SWIGLANG" in $RETRY sudo apt-get -qq update $RETRY sudo apt-get -qq install python${VER}-dev WITHLANG=$SWIGLANG$PY3=$SWIGLANG$VER - else - $RETRY sudo apt-get install -qq python${PY3}-dev - WITHLANG=$SWIGLANG$PY3 + else + $RETRY sudo apt-get install -qq python${PY3}-dev + WITHLANG=$SWIGLANG$PY3 fi ;; "r") From e0935404a8bb7dae1c984149448ce655a030123e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 5 Dec 2021 22:31:05 +0000 Subject: [PATCH 128/262] Add Octave 6 to changes file --- CHANGES.current | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index f87ba0afe..cadbbadfb 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,11 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2021-12-05: rwf1 + [Octave] #2020 #1893 Add support for Octave 6 up to and including 6.4. + Also add support for compiling with -Bsymbolic which is used by default + by mkoctfile. + 2021-12-02: jsenn [Python] #2102 Fixed crashes when using embedded Python interpreters. From e902ab516087ef512ea9b3e06564cb246edcc50d Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 6 Dec 2021 23:11:07 +0100 Subject: [PATCH 129/262] Add Python 3.11 support: use Py_SET_TYPE() On Python 3.9 and newer, SwigPyBuiltin_SetMetaType() now calls Py_SET_TYPE(). Py_TYPE() can no longer be usd as an l-value on Python 3.11: * https://docs.python.org/dev/c-api/structures.html#c.Py_SET_TYPE * https://docs.python.org/dev/whatsnew/3.11.html#c-api-changes --- Lib/python/builtin.swg | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index 4f31a8d54..ec092233d 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -414,7 +414,11 @@ SwigPyBuiltin_ThisClosure (PyObject *self, void *SWIGUNUSEDPARM(closure)) { SWIGINTERN void SwigPyBuiltin_SetMetaType (PyTypeObject *type, PyTypeObject *metatype) { +#if PY_VERSION_HEX >= 0x030900A4 + Py_SET_TYPE(type, metatype); +#else Py_TYPE(type) = metatype; +#endif } From c0c7a8dba06c2dc0fddb6d1e9e56f3eab0fb8271 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 8 Dec 2021 13:06:16 +1300 Subject: [PATCH 130/262] [php] Fix two incorrect PHP 8 conditionals The correct macro to test is PHP_MAJOR_VERSION so these two PHP 8 cases weren't ever used, which hid that the PHP8 version of the code was broken in one of them. Highlighted in #2113. --- Lib/exception.i | 8 ++++---- Lib/php/phpinterfaces.i | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/exception.i b/Lib/exception.i index 7508b409b..5cdea58e8 100644 --- a/Lib/exception.i +++ b/Lib/exception.i @@ -14,14 +14,14 @@ #ifdef SWIGPHP %{ -#if PHP_MAJOR >= 8 -# define SWIG_HANDLE_VALUE_ERROR_FOR_PHP8 code == SWIG_ValueError ? zend_ce_value_error : +#if PHP_MAJOR_VERSION >= 8 +# define SWIG_HANDLE_VALUE_ERROR_FOR_PHP8(code) code == SWIG_ValueError ? zend_ce_value_error : #else -# define SWIG_HANDLE_VALUE_ERROR_FOR_PHP8 +# define SWIG_HANDLE_VALUE_ERROR_FOR_PHP8(code) #endif #define SWIG_exception(code, msg) do { zend_throw_exception( \ code == SWIG_TypeError ? zend_ce_type_error : \ - SWIG_HANDLE_VALUE_ERROR_FOR_PHP8 \ + SWIG_HANDLE_VALUE_ERROR_FOR_PHP8(code) \ code == SWIG_DivisionByZero ? zend_ce_division_by_zero_error : \ code == SWIG_SyntaxError ? zend_ce_parse_error : \ code == SWIG_OverflowError ? zend_ce_arithmetic_error : \ diff --git a/Lib/php/phpinterfaces.i b/Lib/php/phpinterfaces.i index dda219d91..5b1da8b79 100644 --- a/Lib/php/phpinterfaces.i +++ b/Lib/php/phpinterfaces.i @@ -54,7 +54,7 @@ #define SWIG_PHP_INTERFACE_JsonSerializable_HEADER "ext/json/php_json.h" // New in PHP 8.0. -#if PHP_MAJOR >= 8 +#if PHP_MAJOR_VERSION >= 8 # define SWIG_PHP_INTERFACE_Stringable_CE zend_ce_stringable # define SWIG_PHP_INTERFACE_Stringable_HEADER "zend_interfaces.h" #endif From c60507ef70212d7d3215d754f7fdfcb00d590454 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 8 Dec 2021 13:09:43 +1300 Subject: [PATCH 131/262] [php] configure: Check for php8.1 binary --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 9bf45c765..e5730cbf0 100644 --- a/configure.ac +++ b/configure.ac @@ -2082,7 +2082,7 @@ if test x"${PHPBIN}" = xno; then PHP= else if test "x$PHPBIN" = xyes; then - AC_CHECK_PROGS(PHP, [php8.0 php7.4 php7.3 php7.2 php7.1 php7.0 php]) + AC_CHECK_PROGS(PHP, [php8.1 php8.0 php7.4 php7.3 php7.2 php7.1 php7.0 php]) else PHP=$PHPBIN fi From fd013c344ac063b9feffc3023bbeee8d7159c841 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 10 Dec 2021 17:10:35 +1300 Subject: [PATCH 132/262] [php] Remove unused variable SWIG_module_entry hasn't actually been used for any of git history which is over 19 years. --- Source/Modules/php.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index e39ad4dbe..f7decbf3c 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -471,8 +471,7 @@ public: Printf(s_init, " NO_VERSION_YET,\n"); } Printf(s_init, " STANDARD_MODULE_PROPERTIES\n"); - Printf(s_init, "};\n"); - Printf(s_init, "zend_module_entry* SWIG_module_entry = &%s_module_entry;\n\n", module); + Printf(s_init, "};\n\n"); Printf(s_init, "#ifdef __cplusplus\n"); Printf(s_init, "extern \"C\" {\n"); From 4467c94fe9e4433a376bdaddaa54ad8b4edb5891 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 10 Dec 2021 18:34:21 +1300 Subject: [PATCH 133/262] Fix removeNode() to really unset previousSibling There was a typo in attribute name so we attempted to remove the non-existent attribute prevSibling instead. --- Source/Swig/tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Swig/tree.c b/Source/Swig/tree.c index 46571fc09..e2162b7f1 100644 --- a/Source/Swig/tree.c +++ b/Source/Swig/tree.c @@ -225,7 +225,7 @@ void removeNode(Node *n) { /* Delete attributes */ Delattr(n,"parentNode"); Delattr(n,"nextSibling"); - Delattr(n,"prevSibling"); + Delattr(n,"previousSibling"); } /* ----------------------------------------------------------------------------- From bf68b377e609b81b4bbb81c70769568a46f18484 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 13 Dec 2021 08:53:23 +1300 Subject: [PATCH 134/262] Remove unused code from PHP backend These are leftovers from the work on wrapping using only PHP's C API. --- Source/Modules/php.cxx | 47 ------------------------------------------ 1 file changed, 47 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index f7decbf3c..f48ab34b9 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -494,7 +494,6 @@ public: * things are being called in the wrong order */ - // Printv(s_init,s_resourcetypes,NIL); Printf(s_oinit, " /* end oinit subsection */\n"); Printf(s_init, "%s\n", s_oinit); @@ -831,31 +830,6 @@ public: * functionWrapper() * ------------------------------------------------------------ */ - /* Helper method for PHP::functionWrapper */ - bool is_class(SwigType *t) { - Node *n = classLookup(t); - if (n) { - String *r = Getattr(n, "php:proxy"); // Set by classDeclaration() - if (!r) - r = Getattr(n, "sym:name"); // Not seen by classDeclaration yet, but this is the name - if (r) - return true; - } - return false; - } - - /* Helper method for PHP::functionWrapper to get class name for parameter*/ - String *get_class_name(SwigType *t) { - Node *n = classLookup(t); - String *r = NULL; - if (n) { - r = Getattr(n, "php:proxy"); // Set by classDeclaration() - if (!r) - r = Getattr(n, "sym:name"); // Not seen by classDeclaration yet, but this is the name - } - return r; - } - /* Helper function to check if class is wrapped */ bool is_class_wrapped(String *className) { if (!className) @@ -864,18 +838,6 @@ public: return n && Getattr(n, "classtype") != NULL; } - /* Is special return type */ - bool is_param_type_pointer(SwigType *t) { - - if (SwigType_ispointer(t) || - SwigType_ismemberpointer(t) || - SwigType_isreference(t) || - SwigType_isarray(t)) - return true; - - return false; - } - void generate_magic_property_methods(Node *class_node, String *base_class) { if (Equal(base_class, "Exception") || !is_class_wrapped(base_class)) { base_class = NULL; @@ -1254,7 +1216,6 @@ public: String *source; /* Skip ignored arguments */ - //while (Getattr(p,"tmap:ignore")) { p = Getattr(p,"tmap:ignore:next");} while (checkAttribute(p, "tmap:in:numinputs", "0")) { p = Getattr(p, "tmap:in:next"); } @@ -1268,14 +1229,6 @@ public: Printf(f->code, "\tif(arg_count > %d) {\n", i); } - String *paramType_class = NULL; - bool paramType_valid = is_class(pt); - - if (paramType_valid) { - paramType_class = get_class_name(pt); - Chop(paramType_class); - } - if ((tm = Getattr(p, "tmap:in"))) { Replaceall(tm, "$input", source); Setattr(p, "emit:input", source); From 7d704023068f527de19275de713b5010e191ba11 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 13 Dec 2021 09:07:50 +1300 Subject: [PATCH 135/262] Update PHP source comment We no longer wrap anything as a PHP resource. --- Source/Modules/php.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index f48ab34b9..2d346d273 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -2171,7 +2171,7 @@ public: static PHP *maininstance = 0; // Collect non-class pointer types from the type table so we can set up PHP -// resource types for them later. +// classes for them later. // // NOTE: it's a function NOT A PHP::METHOD extern "C" { From 48bb7e0e95bd597efe2e9e9a09a39db97498533d Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 13 Dec 2021 09:14:13 +1300 Subject: [PATCH 136/262] Simplify PHP backend code --- Source/Modules/php.cxx | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 2d346d273..e5c61c2a2 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -99,8 +99,6 @@ static Hash *zend_types = 0; static int shadow = 1; -static String *wrapping_member_constant = NULL; - // These static variables are used to pass some state from Handlers into functionWrapper static enum { standard = 0, @@ -1397,6 +1395,7 @@ public: SwigType_remember(type); + String *wrapping_member_constant = Getattr(n, "memberconstantHandler:sym:name"); if (!wrapping_member_constant) { { tm = Swig_typemap_lookup("consttab", n, name, 0); @@ -1783,17 +1782,6 @@ public: return SWIG_OK; } - /* ------------------------------------------------------------ - * memberconstantHandler() - * ------------------------------------------------------------ */ - - virtual int memberconstantHandler(Node *n) { - wrapping_member_constant = Getattr(n, "sym:name"); - Language::memberconstantHandler(n); - wrapping_member_constant = NULL; - return SWIG_OK; - } - int classDirectorInit(Node *n) { String *declaration = Swig_director_declaration(n); Printf(f_directors_h, "%s\n", declaration); From b78f0ee263220c49c4b08295f5d40b0cce624043 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 13 Dec 2021 09:30:42 +1300 Subject: [PATCH 137/262] [php] Add runme for long_long testcase --- Examples/test-suite/php/long_long_runme.php | 61 +++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Examples/test-suite/php/long_long_runme.php diff --git a/Examples/test-suite/php/long_long_runme.php b/Examples/test-suite/php/long_long_runme.php new file mode 100644 index 000000000..ac6c2dfb1 --- /dev/null +++ b/Examples/test-suite/php/long_long_runme.php @@ -0,0 +1,61 @@ + Date: Mon, 13 Dec 2021 09:31:11 +1300 Subject: [PATCH 138/262] [php] Remove redundant in typemap for bool This typemap which would wrap C++ bool as PHP int is later overridden by another which wraps it as PHP bool. The current result is what we want so just remove the redundant one. --- Lib/php/php.swg | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 6e4ee2d2f..b8722ace8 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -219,7 +219,6 @@ unsigned long, signed char, unsigned char, - bool, size_t %{ RETVAL_LONG($1); From 4c7febfb80b2c51cae24d9894402000aea909d00 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 13 Dec 2021 09:33:26 +1300 Subject: [PATCH 139/262] Make DOH Char macro more robust For example, `Char(foo)[0]` now works to get the first character of DOH String `foo`. Previously this gave a confusing error because it expanded to `(char *) Data(foo)[0]` and the `[0]` binds more tightly than the `(char *)`. --- Source/DOH/doh.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/DOH/doh.h b/Source/DOH/doh.h index fd0530e9c..a948bc849 100644 --- a/Source/DOH/doh.h +++ b/Source/DOH/doh.h @@ -364,7 +364,7 @@ extern void DohMemoryDebug(void); #define Push(s,x) DohInsertitem(s,DOH_BEGIN,x) #define Len DohLen #define Data DohData -#define Char (char *) Data +#define Char(X) ((char *) Data(X)) #define Cmp DohCmp #define Equal DohEqual #define Setline DohSetline From 98b8578731832572427ed8fc1d63df50b9570680 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 13 Dec 2021 15:55:22 +1300 Subject: [PATCH 140/262] [php] Tidy up code which processes in typemaps The only functional change is that we now recover after WARN_TYPEMAP_IN_UNDEF better (or at least like most of the other SWIG backends do). --- Source/Modules/php.cxx | 44 ++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index e5c61c2a2..12be53f48 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1211,43 +1211,41 @@ public: // This may mean looking at Language::memberfunctionHandler for (i = 0, p = l; i < num_arguments; i++) { - String *source; - /* Skip ignored arguments */ while (checkAttribute(p, "tmap:in:numinputs", "0")) { p = Getattr(p, "tmap:in:next"); } - SwigType *pt = Getattr(p, "type"); - - source = NewStringf("args[%d]", i); - /* Check if optional */ if (i >= num_required) { Printf(f->code, "\tif(arg_count > %d) {\n", i); } - if ((tm = Getattr(p, "tmap:in"))) { - Replaceall(tm, "$input", source); - Setattr(p, "emit:input", source); - Printf(f->code, "%s\n", tm); - if (i == 0 && Getattr(p, "self")) { - Printf(f->code, "\tif(!arg1) {\n"); - Printf(f->code, "\t zend_throw_exception(zend_ce_type_error, \"this pointer is NULL\", 0);\n"); - Printf(f->code, "\t return;\n"); - Printf(f->code, "\t}\n"); - } - p = Getattr(p, "tmap:in:next"); - if (i >= num_required) { - Printf(f->code, "}\n"); - } - continue; - } else { + tm = Getattr(p, "tmap:in"); + if (!tm) { + SwigType *pt = Getattr(p, "type"); Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0)); + p = nextSibling(p); + continue; } - if (i >= num_required) { + + String *source = NewStringf("args[%d]", i); + Replaceall(tm, "$input", source); + Setattr(p, "emit:input", source); + Printf(f->code, "%s\n", tm); + if (i == 0 && Getattr(p, "self")) { + Printf(f->code, "\tif(!arg1) {\n"); + Printf(f->code, "\t zend_throw_exception(zend_ce_type_error, \"this pointer is NULL\", 0);\n"); + Printf(f->code, "\t return;\n"); Printf(f->code, "\t}\n"); } + + if (i >= num_required) { + Printf(f->code, "}\n"); + } + + p = Getattr(p, "tmap:in:next"); + Delete(source); } From fa2f9dc5da405586ba3857dd515ae84b7868819f Mon Sep 17 00:00:00 2001 From: tytan652 Date: Tue, 14 Dec 2021 11:42:50 +0100 Subject: [PATCH 141/262] [lua] Fix maybe-uninitialized warning in generated code --- Lib/lua/luarun.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index 6ef2c6f15..1de9cc829 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -1796,7 +1796,7 @@ SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State *L,int index,void **ptr,swig_type SWIGRUNTIME void* SWIG_Lua_MustGetPtr(lua_State *L,int index,swig_type_info *type,int flags, int argnum,const char *func_name){ - void *result; + void *result = 0; if (!SWIG_IsOK(SWIG_ConvertPtr(L,index,&result,type,flags))){ luaL_error (L,"Error in %s, expected a %s at argument number %d\n", func_name,(type && type->str)?type->str:"void*",argnum); From 7418da9e5d63451cfd3941f7e4ed91c19ba1f73d Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 13 Dec 2021 18:46:20 +1300 Subject: [PATCH 142/262] Fix transposed outputs in internals doc --- Doc/Devel/internals.html | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Doc/Devel/internals.html b/Doc/Devel/internals.html index c9082d3f6..0fc6623e8 100644 --- a/Doc/Devel/internals.html +++ b/Doc/Devel/internals.html @@ -441,12 +441,12 @@ Resulting output:

    -hash len: 5
    -get: hashval2
    -hash item: hashval5 [h5]
    -hash item: hashval1 [h1]
    -hash item: hashval2 [h2]
    -hash item: hashval3 [h3]
    +list len: 5
    +get: listval2
    +list item: newlistval1
    +list item: listval2
    +list item: listval3
    +list item: listval5
     
    @@ -494,12 +494,12 @@ Resulting output:
    -list len: 5
    -get: listval2
    -list item: newlistval1
    -list item: listval2
    -list item: listval3
    -list item: listval5
    +hash len: 5
    +get: hashval2
    +hash item: hashval5 [h5]
    +hash item: hashval1 [h1]
    +hash item: hashval2 [h2]
    +hash item: hashval3 [h3]
     
    From 6ef820acf919885701d8e623e074ea00d13be979 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 15 Dec 2021 19:30:17 +1300 Subject: [PATCH 143/262] [php] Simplify creating overload dispatch name --- Source/Modules/php.cxx | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 12be53f48..cf5876aca 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1029,7 +1029,6 @@ public: String *wname = NewStringEmpty(); String *overloadwname = NULL; int overloaded = 0; - String *overname = 0; String *modes = NULL; bool static_setter = false; bool static_getter = false; @@ -1047,18 +1046,13 @@ public: if (Getattr(n, "sym:overloaded")) { overloaded = 1; - overname = Getattr(n, "sym:overname"); + overloadwname = NewString(Swig_name_wrapper(iname)); + Printf(overloadwname, "%s", Getattr(n, "sym:overname")); } else { if (!addSymbol(iname, n)) return SWIG_ERROR; } - if (overname) { - // Test for overloading - overloadwname = NewString(Swig_name_wrapper(iname)); - Printf(overloadwname, "%s", overname); - } - if (constructor) { wname = NewString("__construct"); } else if (wrapperType == membervar) { From 9ffa15b3075dc2cf79e9425de0c8653680317e69 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 15 Dec 2021 19:40:06 +1300 Subject: [PATCH 144/262] Tweak source whitespace to match SWIG conventions --- Lib/php/typemaps.i | 1 + Source/Modules/php.cxx | 136 ++++++++++++++++++++--------------------- 2 files changed, 68 insertions(+), 69 deletions(-) diff --git a/Lib/php/typemaps.i b/Lib/php/typemaps.i index 94b351113..3cfa3f0f7 100644 --- a/Lib/php/typemaps.i +++ b/Lib/php/typemaps.i @@ -153,6 +153,7 @@ INT_TYPEMAP(long long); ZVAL_STRING($result, temp); } %} + INT_TYPEMAP(unsigned long long); %typemap(argout,fragment="t_output_helper") unsigned long long *OUTPUT { diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index cf5876aca..732f1ce61 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------- - * This file is part of SWIG, which is licensed as a whole under version 3 + * This file is part of SWIG, which is licensed as a whole under version 3 * (or any later version) of the GNU General Public License. Some additional * terms also apply to certain portions of SWIG. The full details of the SWIG * license and copyrights can be found in the LICENSE and COPYRIGHT files @@ -139,7 +139,7 @@ static void print_creation_free_wrapper(Node *n) { Printf(s, " zend_object_std_dtor(&obj->std);\n"); Printf(s, " if (obj->newobject)"); - String * type = Getattr(n, "classtype"); + String *type = Getattr(n, "classtype"); if (destructor_action) { Printv(s, " {\n", @@ -155,7 +155,7 @@ static void print_creation_free_wrapper(Node *n) { } Printf(s, "/* Object Creation Method for class %s */\n",class_name); - Printf(s, "zend_object * %s_object_new(zend_class_entry *ce) {\n",class_name); + Printf(s, "zend_object *%s_object_new(zend_class_entry *ce) {\n",class_name); Printf(s, " swig_object_wrapper *obj = (swig_object_wrapper*)zend_object_alloc(sizeof(swig_object_wrapper), ce);\n"); Printf(s, " zend_object_std_init(&obj->std, ce);\n"); Printf(s, " object_properties_init(&obj->std, ce);\n"); @@ -178,7 +178,7 @@ static void SwigPHP_emit_pointer_type_registrations() { Printf(s_wrappers, "static zend_object_handlers swig_ptr_object_handlers;\n\n"); Printf(s_wrappers, "/* Object Creation Method for pointer wrapping class */\n"); - Printf(s_wrappers, "static zend_object * swig_ptr_object_new(zend_class_entry *ce) {\n"); + Printf(s_wrappers, "static zend_object *swig_ptr_object_new(zend_class_entry *ce) {\n"); Printf(s_wrappers, " swig_object_wrapper *obj = (swig_object_wrapper*)zend_object_alloc(sizeof(swig_object_wrapper), ce);\n"); Printf(s_wrappers, " zend_object_std_init(&obj->std, ce);\n"); Printf(s_wrappers, " object_properties_init(&obj->std, ce);\n"); @@ -436,7 +436,7 @@ public: /* start the init section */ { - String * s_init_old = s_init; + String *s_init_old = s_init; s_init = NewString("/* init section */\n"); Printv(s_init, "zend_module_entry ", module, "_module_entry = {\n", NIL); Printf(s_init, " STANDARD_MODULE_HEADER,\n"); @@ -639,9 +639,9 @@ public: (Cmp(fname, "__construct") != 0); } else { if (overload) { - Printf(f_h, "ZEND_NAMED_FUNCTION(%s);\n", fname); + Printf(f_h, "ZEND_NAMED_FUNCTION(%s);\n", fname); } else { - Printf(f_h, "PHP_FUNCTION(%s);\n", fname); + Printf(f_h, "PHP_FUNCTION(%s);\n", fname); } } // We want to only emit each different arginfo once, as that reduces the @@ -656,9 +656,9 @@ public: for (Parm *p = l; p; p = Getattr(p, "tmap:in:next")) { if (skip_this) { skip_this = false; - continue; + continue; } - String* tmap_in_numinputs = Getattr(p, "tmap:in:numinputs"); + String *tmap_in_numinputs = Getattr(p, "tmap:in:numinputs"); // tmap:in:numinputs is unset for varargs, which we don't count here. if (!tmap_in_numinputs || Equal(tmap_in_numinputs, "0")) { /* Ignored parameter */ @@ -676,7 +676,7 @@ public: --num_arguments; --num_required; } - String * arginfo_code; + String *arginfo_code; if (overflowed) { // We overflowed the bitmap so just generate a unique name - this only // happens for a function with more parameters than bits in a long @@ -710,7 +710,7 @@ public: skip_this = false; continue; } - String* tmap_in_numinputs = Getattr(p, "tmap:in:numinputs"); + String *tmap_in_numinputs = Getattr(p, "tmap:in:numinputs"); // tmap:in:numinputs is unset for varargs, which we don't count here. if (!tmap_in_numinputs || Equal(tmap_in_numinputs, "0")) { /* Ignored parameter */ @@ -721,7 +721,7 @@ public: Printf(s_arginfo, "ZEND_END_ARG_INFO()\n"); } - String * s = cs_entry; + String *s = cs_entry; if (!s) s = s_entry; if (cname && Cmp(Getattr(n, "storage"), "friend") != 0) { Printf(all_cs_entry, " PHP_ME(%s%s,%s,swig_arginfo_%s,%s)\n", prefix, cname, fname, arginfo_code, modes); @@ -770,10 +770,10 @@ public: if (constructor) { // Renamed constructor - turn into static factory method if (Cmp(class_name, Getattr(n, "constructorHandler:sym:name")) != 0) { - constructorRenameOverload = true; - wname = Copy(Getattr(n, "constructorHandler:sym:name")); + constructorRenameOverload = true; + wname = Copy(Getattr(n, "constructorHandler:sym:name")); } else { - wname = NewString("__construct"); + wname = NewString("__construct"); } } else if (class_name) { wname = Getattr(n, "wrapper:method:name"); @@ -784,7 +784,7 @@ public: if (constructor) { modes = NewString("ZEND_ACC_PUBLIC | ZEND_ACC_CTOR"); if (constructorRenameOverload) { - Append(modes, " | ZEND_ACC_STATIC"); + Append(modes, " | ZEND_ACC_STATIC"); } } else if (wrapperType == staticmemberfn || Cmp(Getattr(n, "storage"), "static") == 0) { modes = NewString("ZEND_ACC_PUBLIC | ZEND_ACC_STATIC"); @@ -832,7 +832,7 @@ public: bool is_class_wrapped(String *className) { if (!className) return false; - Node * n = symbolLookup(className); + Node *n = symbolLookup(className); return n && Getattr(n, "classtype") != NULL; } @@ -984,27 +984,25 @@ public: } bool is_setter_method(Node *n) { - const char *p = GetChar(n, "sym:name"); - if (strlen(p) > 4) { - p += strlen(p) - 4; - if (strcmp(p, "_set") == 0) { - return true; - } + if (strlen(p) > 4) { + p += strlen(p) - 4; + if (strcmp(p, "_set") == 0) { + return true; } - return false; + } + return false; } bool is_getter_method(Node *n) { - const char *p = GetChar(n, "sym:name"); - if (strlen(p) > 4) { - p += strlen(p) - 4; - if (strcmp(p, "_get") == 0) { - return true; - } + if (strlen(p) > 4) { + p += strlen(p) - 4; + if (strcmp(p, "_get") == 0) { + return true; } - return false; + } + return false; } virtual int functionWrapper(Node *n) { @@ -1037,7 +1035,7 @@ public: if (constructor) { Append(modes, " | ZEND_ACC_CTOR"); - } + } if (wrapperType == staticmemberfn || Cmp(Getattr(n, "storage"), "static") == 0) { Append(modes, " | ZEND_ACC_STATIC"); } @@ -1058,9 +1056,9 @@ public: } else if (wrapperType == membervar) { wname = Copy(Getattr(n, "membervariableHandler:sym:name")); if (is_setter_method(n)) { - Append(wname, "_set"); + Append(wname, "_set"); } else if (is_getter_method(n)) { - Append(wname, "_get"); + Append(wname, "_get"); } } else if (wrapperType == memberfn) { wname = Getattr(n, "memberfunctionHandler:sym:name"); @@ -1069,28 +1067,28 @@ public: wname = Getattr(n, "staticmembervariableHandler:sym:name"); /* We get called twice for getter and setter methods. But to maintain - compatibility, Shape::nshapes() is being used for both setter and - getter methods. So using static_setter and static_getter variables - to generate half of the code each time. + compatibility, Shape::nshapes() is being used for both setter and + getter methods. So using static_setter and static_getter variables + to generate half of the code each time. */ static_setter = is_setter_method(n); if (is_getter_method(n)) { - // This is to overcome types that can't be set and hence no setter. - if (Cmp(Getattr(n, "feature:immutable"), "1") != 0) - static_getter = true; + // This is to overcome types that can't be set and hence no setter. + if (Cmp(Getattr(n, "feature:immutable"), "1") != 0) + static_getter = true; } } else if (wrapperType == staticmemberfn) { wname = Getattr(n, "staticmemberfunctionHandler:sym:name"); } else { if (class_name) { - if (Cmp(Getattr(n, "storage"), "friend") == 0 && Cmp(Getattr(n, "view"), "globalfunctionHandler") == 0) { - wname = iname; - } else { - wname = Getattr(n, "destructorHandler:sym:name"); - } + if (Cmp(Getattr(n, "storage"), "friend") == 0 && Cmp(Getattr(n, "view"), "globalfunctionHandler") == 0) { + wname = iname; + } else { + wname = Getattr(n, "destructorHandler:sym:name"); + } } else { - wname = iname; + wname = iname; } } @@ -1114,9 +1112,9 @@ public: if (!overloaded) { if (!static_getter) { - if (class_name && Cmp(Getattr(n, "storage"), "friend") != 0) { - Printv(f->def, "PHP_METHOD(", prefix, class_name, ",", wname, ") {\n", NIL); - } else { + if (class_name && Cmp(Getattr(n, "storage"), "friend") != 0) { + Printv(f->def, "PHP_METHOD(", prefix, class_name, ",", wname, ") {\n", NIL); + } else { if (wrap_nonclass_global) { Printv(f->def, "PHP_METHOD(", fake_class_name(), ",", wname, ") {\n", " PHP_FN(", wname, ")(INTERNAL_FUNCTION_PARAM_PASSTHRU);\n", @@ -1126,7 +1124,7 @@ public: if (wrap_nonclass_fake_class) { Printv(f->def, "PHP_FUNCTION(", wname, ") {\n", NIL); } - } + } } } else { Printv(f->def, "ZEND_NAMED_FUNCTION(", overloadwname, ") {\n", NIL); @@ -1181,9 +1179,9 @@ public: Printf(f->code, "\tWRONG_PARAM_COUNT;\n\n"); } else if (static_setter || static_getter) { if (num_arguments == 0) { - Printf(f->code, "if(ZEND_NUM_ARGS() == 0) {\n"); + Printf(f->code, "if(ZEND_NUM_ARGS() == 0) {\n"); } else { - Printf(f->code, "if(ZEND_NUM_ARGS() == %d && zend_get_parameters_array_ex(%d, args) == SUCCESS) {\n", num_arguments, num_arguments); + Printf(f->code, "if(ZEND_NUM_ARGS() == %d && zend_get_parameters_array_ex(%d, args) == SUCCESS) {\n", num_arguments, num_arguments); } } else { if (num_arguments == 0) { @@ -1392,24 +1390,24 @@ public: { tm = Swig_typemap_lookup("consttab", n, name, 0); Replaceall(tm, "$value", value); - if (Getattr(n, "tmap:consttab:rinit")) { - Printf(r_init, "%s\n", tm); - } else { - Printf(s_cinit, "%s\n", tm); - } + if (Getattr(n, "tmap:consttab:rinit")) { + Printf(r_init, "%s\n", tm); + } else { + Printf(s_cinit, "%s\n", tm); + } } { - tm = Swig_typemap_lookup("classconsttab", n, name, 0); + tm = Swig_typemap_lookup("classconsttab", n, name, 0); - Replaceall(tm, "$class", fake_class_name()); - Replaceall(tm, "$const_name", iname); + Replaceall(tm, "$class", fake_class_name()); + Replaceall(tm, "$const_name", iname); Replaceall(tm, "$value", value); - if (Getattr(n, "tmap:classconsttab:rinit")) { - Printf(r_init, "%s\n", tm); - } else { - Printf(s_cinit, "%s\n", tm); - } + if (Getattr(n, "tmap:classconsttab:rinit")) { + Printf(r_init, "%s\n", tm); + } else { + Printf(s_cinit, "%s\n", tm); + } } } else { tm = Swig_typemap_lookup("classconsttab", n, name, 0); @@ -1417,9 +1415,9 @@ public: Replaceall(tm, "$const_name", wrapping_member_constant); Replaceall(tm, "$value", value); if (Getattr(n, "tmap:classconsttab:rinit")) { - Printf(r_init, "%s\n", tm); + Printf(r_init, "%s\n", tm); } else { - Printf(s_cinit, "%s\n", tm); + Printf(s_cinit, "%s\n", tm); } } @@ -1915,7 +1913,7 @@ public: Append(w->def, " {"); Append(declaration, ";\n"); - /* declare method return value + /* declare method return value * if the return value is a reference or const reference, a specialized typemap must * handle it, including declaration of c_result ($result). */ @@ -2018,7 +2016,7 @@ public: /* wrap complex arguments to zvals */ Append(w->code, wrap_args); - const char * funcname = GetChar(n, "sym:name"); + const char *funcname = GetChar(n, "sym:name"); Append(w->code, "{\n"); Append(w->code, "#if PHP_MAJOR_VERSION < 8\n"); Printf(w->code, "zval swig_funcname;\n"); From 6253583809d66f399cacba251f55bbda6487b6cc Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 17 Dec 2021 09:37:00 +1300 Subject: [PATCH 145/262] Rename php_fetch_object with swig_ prefix We shouldn't be using symbols starting `php` as that risks collisions with future symbols defined by PHP. --- Lib/php/phprun.swg | 6 +++--- Source/Modules/php.cxx | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index a3569a783..6f0cc9650 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -81,10 +81,10 @@ typedef struct { zend_object std; } swig_object_wrapper; -#define SWIG_Z_FETCH_OBJ_P(zv) php_fetch_object(Z_OBJ_P(zv)) +#define SWIG_Z_FETCH_OBJ_P(zv) swig_php_fetch_object(Z_OBJ_P(zv)) static inline -swig_object_wrapper * php_fetch_object(zend_object *obj) { +swig_object_wrapper * swig_php_fetch_object(zend_object *obj) { return (swig_object_wrapper *)((char *)obj - XtOffsetOf(swig_object_wrapper, std)); } @@ -115,7 +115,7 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) { obj = ce->create_object(ce); ZVAL_OBJ(z, obj); } - value = php_fetch_object(obj); + value = swig_php_fetch_object(obj); value->ptr = ptr; value->newobject = (newobject & 1); value->type = type; diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 732f1ce61..e778a735d 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -134,7 +134,7 @@ static void print_creation_free_wrapper(Node *n) { Printf(s, " swig_object_wrapper *obj = 0;\n"); Printf(s, " if (!object)\n"); Printf(s, " return;\n"); - Printf(s, " obj = php_fetch_object(object);\n"); + Printf(s, " obj = swig_php_fetch_object(object);\n"); Printf(s, " zend_object_std_dtor(&obj->std);\n"); @@ -198,7 +198,7 @@ static void SwigPHP_emit_pointer_type_registrations() { Append(s_wrappers, "#if PHP_MAJOR_VERSION < 8\n"); Printf(s_wrappers, " swig_object_wrapper *obj = SWIG_Z_FETCH_OBJ_P(z);\n"); Append(s_wrappers, "#else\n"); - Printf(s_wrappers, " swig_object_wrapper *obj = php_fetch_object(zobj);\n"); + Printf(s_wrappers, " swig_object_wrapper *obj = swig_php_fetch_object(zobj);\n"); Append(s_wrappers, "#endif\n"); Printv(s_wrappers, " sprintf(buf, \"SWIGPointer(%p,owned=%d)\", obj->ptr, obj->newobject);\n", NIL); Printf(s_wrappers, " ZVAL_STRING(retval, buf);\n"); From 5da86a14132ae96d885ef12ad04cf771bdb5dd57 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 17 Dec 2021 09:38:44 +1300 Subject: [PATCH 146/262] Make some generated functions static --- Source/Modules/php.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index e778a735d..3a62282d8 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -124,13 +124,13 @@ static void print_creation_free_wrapper(Node *n) { String *s = s_creation; Printf(s, "/* class entry for %s */\n",class_name); - Printf(s, "zend_class_entry *SWIGTYPE_%s_ce;\n\n",class_name); + Printf(s, "static zend_class_entry *SWIGTYPE_%s_ce;\n\n",class_name); Printf(s, "/* class object handlers for %s */\n",class_name); - Printf(s, "zend_object_handlers %s_object_handlers;\n\n",class_name); + Printf(s, "static zend_object_handlers %s_object_handlers;\n\n",class_name); if (Getattr(n, "has_destructor")) { Printf(s, "/* Garbage Collection Method for class %s */\n",class_name); - Printf(s, "void %s_free_storage(zend_object *object) {\n",class_name); + Printf(s, "static void %s_free_storage(zend_object *object) {\n",class_name); Printf(s, " swig_object_wrapper *obj = 0;\n"); Printf(s, " if (!object)\n"); Printf(s, " return;\n"); @@ -155,7 +155,7 @@ static void print_creation_free_wrapper(Node *n) { } Printf(s, "/* Object Creation Method for class %s */\n",class_name); - Printf(s, "zend_object *%s_object_new(zend_class_entry *ce) {\n",class_name); + Printf(s, "static zend_object *%s_object_new(zend_class_entry *ce) {\n",class_name); Printf(s, " swig_object_wrapper *obj = (swig_object_wrapper*)zend_object_alloc(sizeof(swig_object_wrapper), ce);\n"); Printf(s, " zend_object_std_init(&obj->std, ce);\n"); Printf(s, " object_properties_init(&obj->std, ce);\n"); From 78f5404727f18e821267b0500e811baf8042d892 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 17 Dec 2021 10:11:52 +1300 Subject: [PATCH 147/262] Improve generated object handlers Do more initialisation at module load time. Use a shared set of handlers for cases when the C/C++ object is destroyed with free(). Most of the code in the free_obj and create_object handlers is the same for every wrapped class so factor that out into common functions. --- Lib/php/phprun.swg | 21 ++++++ Source/Modules/php.cxx | 143 +++++++++++++++++++++-------------------- 2 files changed, 95 insertions(+), 69 deletions(-) diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 6f0cc9650..426efe104 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -206,3 +206,24 @@ static swig_module_info *SWIG_Php_GetModule() { static void SWIG_Php_SetModule(swig_module_info *pointer, int module_number) { REGISTER_LONG_CONSTANT(const_name, (long) pointer, CONST_CS | CONST_PERSISTENT); } + +/* Common parts of the "create_object" object handler. */ +static zend_object *SWIG_Php_do_create_object(zend_class_entry *ce, zend_object_handlers *handlers) { + swig_object_wrapper *obj = (swig_object_wrapper*)zend_object_alloc(sizeof(swig_object_wrapper), ce); + zend_object_std_init(&obj->std, ce); + object_properties_init(&obj->std, ce); + obj->std.handlers = handlers; + obj->newobject = 1; + return &obj->std; +} + +/* Common parts of the "free_obj" object handler. + Returns void* pointer if the C/C++ object should be destroyed. */ +static void* SWIG_Php_free_obj(zend_object *object) { + if (object) { + swig_object_wrapper *obj = swig_php_fetch_object(object); + zend_object_std_dtor(&obj->std); + if (obj->newobject) return obj->ptr; + } + return NULL; +} diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 3a62282d8..b83995956 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -74,9 +74,6 @@ static String *fake_class_name() { static String *result = NULL; if (!result) { result = Len(prefix) ? prefix : module; - if (!s_creation) { - s_creation = NewStringEmpty(); - } if (!fake_cs_entry) { fake_cs_entry = NewStringf("static zend_function_entry class_%s_functions[] = {\n", result); } @@ -116,56 +113,6 @@ extern "C" { static void (*r_prevtracefunc) (const SwigType *t, String *mangled, String *clientdata) = 0; } -static void print_creation_free_wrapper(Node *n) { - if (!s_creation) { - s_creation = NewStringEmpty(); - } - - String *s = s_creation; - - Printf(s, "/* class entry for %s */\n",class_name); - Printf(s, "static zend_class_entry *SWIGTYPE_%s_ce;\n\n",class_name); - Printf(s, "/* class object handlers for %s */\n",class_name); - Printf(s, "static zend_object_handlers %s_object_handlers;\n\n",class_name); - - if (Getattr(n, "has_destructor")) { - Printf(s, "/* Garbage Collection Method for class %s */\n",class_name); - Printf(s, "static void %s_free_storage(zend_object *object) {\n",class_name); - Printf(s, " swig_object_wrapper *obj = 0;\n"); - Printf(s, " if (!object)\n"); - Printf(s, " return;\n"); - Printf(s, " obj = swig_php_fetch_object(object);\n"); - - Printf(s, " zend_object_std_dtor(&obj->std);\n"); - - Printf(s, " if (obj->newobject)"); - String *type = Getattr(n, "classtype"); - if (destructor_action) { - Printv(s, - " {\n", - type, " * arg1 = (", type, " *)obj->ptr;\n", - destructor_action, "\n", - " }\n", NIL); - } else if (CPlusPlus) { - Printf(s, "\n delete (%s *)obj->ptr;\n", type); - } else { - Printf(s, "\n free(obj->ptr);\n", type); - } - Printf(s, "}\n\n"); - } - - Printf(s, "/* Object Creation Method for class %s */\n",class_name); - Printf(s, "static zend_object *%s_object_new(zend_class_entry *ce) {\n",class_name); - Printf(s, " swig_object_wrapper *obj = (swig_object_wrapper*)zend_object_alloc(sizeof(swig_object_wrapper), ce);\n"); - Printf(s, " zend_object_std_init(&obj->std, ce);\n"); - Printf(s, " object_properties_init(&obj->std, ce);\n"); - Printf(s, " %s_object_handlers.offset = XtOffsetOf(swig_object_wrapper, std);\n", class_name); - if (Getattr(n, "has_destructor")) { - Printf(s, " %s_object_handlers.free_obj = %s_free_storage;\n", class_name, class_name); - } - Printf(s, " obj->std.handlers = &%s_object_handlers;\n obj->newobject = 1;\n return &obj->std;\n}\n\n\n",class_name); -} - static void SwigPHP_emit_pointer_type_registrations() { if (!zend_types) return; @@ -208,17 +155,13 @@ static void SwigPHP_emit_pointer_type_registrations() { Printf(s_wrappers, "}\n\n"); Printf(s_oinit, "\n /* Register classes to represent non-class pointer types */\n"); - Printf(s_oinit, " memcpy(&swig_ptr_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));\n"); + Printf(s_oinit, " swig_ptr_object_handlers = *zend_get_std_object_handlers();\n"); Printf(s_oinit, " swig_ptr_object_handlers.offset = XtOffsetOf(swig_object_wrapper, std);\n"); Printf(s_oinit, " swig_ptr_object_handlers.cast_object = swig_ptr_cast_object;\n"); while (ki.key) { String *type = ki.key; - if (!s_creation) { - s_creation = NewStringEmpty(); - } - Printf(s_creation, "/* class entry for pointer to %s */\n", type); Printf(s_creation, "zend_class_entry *SWIGTYPE_%s_ce;\n\n", type); @@ -309,6 +252,7 @@ public: r_shutdown = NewStringEmpty(); s_header = NewString("/* header section */\n"); s_wrappers = NewString("/* wrapper section */\n"); + s_creation = NewStringEmpty(); /* subsections of the init section */ s_vdecl = NewString("/* vdecl subsection */\n"); s_cinit = NewString(" /* cinit subsection */\n"); @@ -428,11 +372,9 @@ public: Language::top(n); SwigPHP_emit_pointer_type_registrations(); - if (s_creation) { - Dump(s_creation, s_header); - Delete(s_creation); - s_creation = NULL; - } + Dump(s_creation, s_header); + Delete(s_creation); + s_creation = NULL; /* start the init section */ { @@ -1616,9 +1558,75 @@ public: Delete(interfaces); } - Printf(s_oinit, " SWIGTYPE_%s_ce->create_object = %s_object_new;\n", class_name, class_name); - Printf(s_oinit, " memcpy(&%s_object_handlers,zend_get_std_object_handlers(), sizeof(zend_object_handlers));\n", class_name); - Printf(s_oinit, " %s_object_handlers.clone_obj = NULL;\n", class_name); + Language::classHandler(n); + + static bool emitted_base_object_handlers = false; + if (!emitted_base_object_handlers) { + Printf(s_creation, "static zend_object_handlers SWIGTYPE_base_object_handlers;\n\n"); + + // Set up a base zend_object_handlers structure which we can use as-is + // for classes without a destructor, and copy as the basis for other + // classes. + Printf(s_oinit, " SWIGTYPE_base_object_handlers = *zend_get_std_object_handlers();\n"); + Printf(s_oinit, " SWIGTYPE_base_object_handlers.offset = XtOffsetOf(swig_object_wrapper, std);\n"); + Printf(s_oinit, " SWIGTYPE_base_object_handlers.clone_obj = NULL;\n"); + emitted_base_object_handlers = true; + } + + Printf(s_creation, "static zend_class_entry *SWIGTYPE_%s_ce;\n\n", class_name); + + if (Getattr(n, "has_destructor")) { + if (destructor_action ? Equal(destructor_action, "free((char *) arg1);") : !CPlusPlus) { + // We can use a single function if the destructor action calls free() + // (either explicitly or as the default in C-mode) since free() doesn't + // care about the object's type. We currently only check for the exact + // code that Swig_cdestructor_call() emits. + static bool emitted_common_cdestructor = false; + if (!emitted_common_cdestructor) { + Printf(s_creation, "static zend_object_handlers SWIGTYPE_common_c_object_handlers;\n\n"); + Printf(s_creation, "static void SWIG_Php_common_c_free_obj(zend_object *object) {free(SWIG_Php_free_obj(object));}\n\n"); + Printf(s_creation, "static zend_object *SWIG_Php_common_c_create_object(zend_class_entry *ce) {return SWIG_Php_do_create_object(ce, &SWIGTYPE_common_c_object_handlers);}\n"); + + Printf(s_oinit, " SWIGTYPE_common_c_object_handlers = SWIGTYPE_base_object_handlers;\n"); + Printf(s_oinit, " SWIGTYPE_common_c_object_handlers.free_obj = SWIG_Php_common_c_free_obj;\n"); + + emitted_common_cdestructor = true; + } + + Printf(s_oinit, " SWIGTYPE_%s_ce->create_object = SWIG_Php_common_c_create_object;\n", class_name); + } else { + Printf(s_creation, "static zend_object_handlers %s_object_handlers;\n", class_name); + Printf(s_creation, "static zend_object *SWIG_Php_create_object_%s(zend_class_entry *ce) {return SWIG_Php_do_create_object(ce, &%s_object_handlers);}\n", class_name, class_name); + + Printf(s_creation, "static void SWIG_Php_free_obj_%s(zend_object *object) {",class_name); + String *type = Getattr(n, "classtype"); + // Special case handling the delete call generated by + // Swig_cppdestructor_call() and generate simpler code. + if (destructor_action && !Equal(destructor_action, "delete arg1;")) { + Printv(s_creation, "\n" + " ", type, " *arg1 = (" , type, " *)SWIG_Php_free_obj(object);\n" + " if (arg1) {\n" + " ", destructor_action, "\n" + " }\n", NIL); + } else { + Printf(s_creation, "delete (%s *)SWIG_Php_free_obj(object);", type); + } + Printf(s_creation, "}\n\n"); + + Printf(s_oinit, " SWIGTYPE_%s_ce->create_object = SWIG_Php_create_object_%s;\n", class_name, class_name); + Printf(s_oinit, " %s_object_handlers = SWIGTYPE_base_object_handlers;\n", class_name); + Printf(s_oinit, " %s_object_handlers.free_obj = SWIG_Php_free_obj_%s;\n", class_name, class_name); + } + } else { + static bool emitted_destructorless_create_object = false; + if (!emitted_destructorless_create_object) { + emitted_destructorless_create_object = true; + Printf(s_creation, "static zend_object *SWIG_Php_create_object(zend_class_entry *ce) {return SWIG_Php_do_create_object(ce, &SWIGTYPE_base_object_handlers);}\n", class_name); + } + + Printf(s_oinit, " SWIGTYPE_%s_ce->create_object = SWIG_Php_create_object;\n", class_name); + } + // If not defined we aren't wrapping any functions which use this type as a // parameter or return value, in which case we don't need the clientdata // set. @@ -1627,9 +1635,6 @@ public: Printf(s_oinit, "#endif\n"); Printf(s_oinit, "\n"); - Language::classHandler(n); - - print_creation_free_wrapper(n); generate_magic_property_methods(n, base_class); Printf(all_cs_entry, " ZEND_FE_END\n};\n\n"); From f976927d52cb323a1ba782de17e3181f8dba21dc Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 17 Dec 2021 12:25:40 +1300 Subject: [PATCH 148/262] Fix source code comment typo --- Source/Modules/php.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index b83995956..836c2059e 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1521,7 +1521,7 @@ public: String *interface = Getitem(interface_list, i); // We generate conditional code in both minit and rinit - then we or the user // just need to define SWIG_PHP_INTERFACE_xxx_CE (and optionally - // SWIG_PHP_INTERFACE_xxx_CE) to handle interface `xxx` at minit-time. + // SWIG_PHP_INTERFACE_xxx_HEADER) to handle interface `xxx` at minit-time. Printv(s_header, "#ifdef SWIG_PHP_INTERFACE_", interface, "_HEADER\n", "# include SWIG_PHP_INTERFACE_", interface, "_HEADER\n", From cf802c63f2b1192d1c6a6ef764fca22294bd88b3 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 17 Dec 2021 17:14:54 +1300 Subject: [PATCH 149/262] Improve naming of zend_class_entry structs Previously the zend_class_entry for Foo was named SWIGTYPE_Foo_ce, but this can collide in some cases - e.g. if there's a class named p_Foo then its zend_class entry will be SWIGTYPE_p_Foo_ce, but that's the same as the swig_type_info for a class named p_Foo_ce. --- Lib/php/const.i | 12 ++++----- Source/Modules/php.cxx | 57 +++++++++++++++++++++--------------------- 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/Lib/php/const.i b/Lib/php/const.i index 3b40c2c7f..6e83ffe88 100644 --- a/Lib/php/const.i +++ b/Lib/php/const.i @@ -12,22 +12,22 @@ unsigned char, signed char, enum SWIGTYPE %{ - zend_declare_class_constant_long(SWIGTYPE_$class_ce, "$const_name", sizeof("$const_name") - 1, ($1_type)$value); + zend_declare_class_constant_long(SWIG_Php_ce_$class, "$const_name", sizeof("$const_name") - 1, ($1_type)$value); %} %typemap(classconsttab) bool %{ - zend_declare_class_constant_bool(SWIGTYPE_$class_ce, "$const_name", sizeof("$const_name") - 1, ($1_type)$value); + zend_declare_class_constant_bool(SWIG_Php_ce_$class, "$const_name", sizeof("$const_name") - 1, ($1_type)$value); %} %typemap(classconsttab) float, double %{ - zend_declare_class_constant_double(SWIGTYPE_$class_ce, "$const_name", sizeof("$const_name") - 1, $value); + zend_declare_class_constant_double(SWIG_Php_ce_$class, "$const_name", sizeof("$const_name") - 1, $value); %} %typemap(classconsttab) char %{ { char swig_char = $value; - zend_declare_class_constant_stringl(SWIGTYPE_$class_ce, "$const_name", sizeof("$const_name") - 1, &swig_char, 1); + zend_declare_class_constant_stringl(SWIG_Php_ce_$class, "$const_name", sizeof("$const_name") - 1, &swig_char, 1); } %} @@ -35,7 +35,7 @@ const char *, char [], const char [] %{ - zend_declare_class_constant_string(SWIGTYPE_$class_ce, "$const_name", sizeof("$const_name") - 1, $value); + zend_declare_class_constant_string(SWIG_Php_ce_$class, "$const_name", sizeof("$const_name") - 1, $value); %} // This creates a zend_object to wrap the pointer, and we can't do that @@ -50,7 +50,7 @@ ZVAL_UNDEF(&z); SWIG_SetPointerZval(&z, (void*)$value, $1_descriptor, 0); zval_copy_ctor(&z); - zend_declare_class_constant(SWIGTYPE_$class_ce, "$const_name", sizeof("$const_name") - 1, &z); + zend_declare_class_constant(SWIG_Php_ce_$class, "$const_name", sizeof("$const_name") - 1, &z); } %} diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 836c2059e..f3dac4bfb 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -77,10 +77,11 @@ static String *fake_class_name() { if (!fake_cs_entry) { fake_cs_entry = NewStringf("static zend_function_entry class_%s_functions[] = {\n", result); } - Printf(s_creation, "/* class entry for %s */\n",result); - Printf(s_creation, "zend_class_entry *SWIGTYPE_%s_ce;\n\n",result); + + Printf(s_creation, "zend_class_entry *SWIG_Php_ce_%s;\n\n",result); + Printf(s_oinit, " INIT_CLASS_ENTRY(internal_ce, \"%s\", class_%s_functions);\n", result, result); - Printf(s_oinit, " SWIGTYPE_%s_ce = zend_register_internal_class(&internal_ce);\n", result); + Printf(s_oinit, " SWIG_Php_ce_%s = zend_register_internal_class(&internal_ce);\n", result); Printf(s_oinit, "\n"); } return result; @@ -163,12 +164,12 @@ static void SwigPHP_emit_pointer_type_registrations() { String *type = ki.key; Printf(s_creation, "/* class entry for pointer to %s */\n", type); - Printf(s_creation, "zend_class_entry *SWIGTYPE_%s_ce;\n\n", type); + Printf(s_creation, "zend_class_entry *SWIG_Php_ce_%s;\n\n", type); Printf(s_oinit, " INIT_CLASS_ENTRY(internal_ce, \"%s\\\\%s\", NULL);\n", "SWIG", type); - Printf(s_oinit, " SWIGTYPE_%s_ce = zend_register_internal_class(&internal_ce);\n", type); - Printf(s_oinit, " SWIGTYPE_%s_ce->create_object = swig_ptr_object_new;\n", type); - Printf(s_oinit, " SWIG_TypeClientData(SWIGTYPE%s,SWIGTYPE_%s_ce);\n", type, type); + Printf(s_oinit, " SWIG_Php_ce_%s = zend_register_internal_class(&internal_ce);\n", type); + Printf(s_oinit, " SWIG_Php_ce_%s->create_object = swig_ptr_object_new;\n", type); + Printf(s_oinit, " SWIG_TypeClientData(SWIGTYPE%s,SWIG_Php_ce_%s);\n", type, type); Printf(s_oinit, "\n"); ki = Next(ki); @@ -1480,15 +1481,15 @@ public: } if (Equal(base_class, "Exception")) { - Printf(s_oinit, " SWIGTYPE_%s_ce = zend_register_internal_class_ex(&internal_ce, zend_ce_exception);\n", class_name); + Printf(s_oinit, " SWIG_Php_ce_%s = zend_register_internal_class_ex(&internal_ce, zend_ce_exception);\n", class_name); } else if (is_class_wrapped(base_class)) { - Printf(s_oinit, " SWIGTYPE_%s_ce = zend_register_internal_class_ex(&internal_ce, SWIGTYPE_%s_ce);\n", class_name, base_class); + Printf(s_oinit, " SWIG_Php_ce_%s = zend_register_internal_class_ex(&internal_ce, SWIG_Php_ce_%s);\n", class_name, base_class); } else { - Printf(s_oinit, " SWIGTYPE_%s_ce = zend_register_internal_class(&internal_ce);\n", class_name); + Printf(s_oinit, " SWIG_Php_ce_%s = zend_register_internal_class(&internal_ce);\n", class_name); } if (Getattr(n, "abstracts") && !GetFlag(n, "feature:notabstract")) { - Printf(s_oinit, " SWIGTYPE_%s_ce->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;\n", class_name); + Printf(s_oinit, " SWIG_Php_ce_%s->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;\n", class_name); } { @@ -1529,7 +1530,7 @@ public: NIL); Printv(s_oinit, "#ifdef SWIG_PHP_INTERFACE_", interface, "_CE\n", - " zend_do_implement_interface(SWIGTYPE_", class_name, "_ce, SWIG_PHP_INTERFACE_", interface, "_CE);\n", + " zend_do_implement_interface(SWIG_Php_ce_", class_name, ", SWIG_PHP_INTERFACE_", interface, "_CE);\n", "#endif\n", NIL); Printv(r_init_prefix, @@ -1537,7 +1538,7 @@ public: " {\n", " zend_class_entry *swig_interface_ce = zend_lookup_class(zend_string_init(\"", interface, "\", sizeof(\"", interface, "\") - 1, 0));\n", " if (!swig_interface_ce) zend_throw_exception(zend_ce_error, \"Interface \\\"", interface, "\\\" not found\", 0);\n", - " zend_do_implement_interface(SWIGTYPE_", class_name, "_ce, swig_interface_ce);\n", + " zend_do_implement_interface(SWIG_Php_ce_", class_name, ", swig_interface_ce);\n", " }\n", "#endif\n", NIL); @@ -1562,18 +1563,18 @@ public: static bool emitted_base_object_handlers = false; if (!emitted_base_object_handlers) { - Printf(s_creation, "static zend_object_handlers SWIGTYPE_base_object_handlers;\n\n"); + Printf(s_creation, "static zend_object_handlers Swig_Php_base_object_handlers;\n\n"); // Set up a base zend_object_handlers structure which we can use as-is // for classes without a destructor, and copy as the basis for other // classes. - Printf(s_oinit, " SWIGTYPE_base_object_handlers = *zend_get_std_object_handlers();\n"); - Printf(s_oinit, " SWIGTYPE_base_object_handlers.offset = XtOffsetOf(swig_object_wrapper, std);\n"); - Printf(s_oinit, " SWIGTYPE_base_object_handlers.clone_obj = NULL;\n"); + Printf(s_oinit, " Swig_Php_base_object_handlers = *zend_get_std_object_handlers();\n"); + Printf(s_oinit, " Swig_Php_base_object_handlers.offset = XtOffsetOf(swig_object_wrapper, std);\n"); + Printf(s_oinit, " Swig_Php_base_object_handlers.clone_obj = NULL;\n"); emitted_base_object_handlers = true; } - Printf(s_creation, "static zend_class_entry *SWIGTYPE_%s_ce;\n\n", class_name); + Printf(s_creation, "static zend_class_entry *SWIG_Php_ce_%s;\n\n", class_name); if (Getattr(n, "has_destructor")) { if (destructor_action ? Equal(destructor_action, "free((char *) arg1);") : !CPlusPlus) { @@ -1583,17 +1584,17 @@ public: // code that Swig_cdestructor_call() emits. static bool emitted_common_cdestructor = false; if (!emitted_common_cdestructor) { - Printf(s_creation, "static zend_object_handlers SWIGTYPE_common_c_object_handlers;\n\n"); + Printf(s_creation, "static zend_object_handlers Swig_Php_common_c_object_handlers;\n\n"); Printf(s_creation, "static void SWIG_Php_common_c_free_obj(zend_object *object) {free(SWIG_Php_free_obj(object));}\n\n"); - Printf(s_creation, "static zend_object *SWIG_Php_common_c_create_object(zend_class_entry *ce) {return SWIG_Php_do_create_object(ce, &SWIGTYPE_common_c_object_handlers);}\n"); + Printf(s_creation, "static zend_object *SWIG_Php_common_c_create_object(zend_class_entry *ce) {return SWIG_Php_do_create_object(ce, &Swig_Php_common_c_object_handlers);}\n"); - Printf(s_oinit, " SWIGTYPE_common_c_object_handlers = SWIGTYPE_base_object_handlers;\n"); - Printf(s_oinit, " SWIGTYPE_common_c_object_handlers.free_obj = SWIG_Php_common_c_free_obj;\n"); + Printf(s_oinit, " Swig_Php_common_c_object_handlers = Swig_Php_base_object_handlers;\n"); + Printf(s_oinit, " Swig_Php_common_c_object_handlers.free_obj = SWIG_Php_common_c_free_obj;\n"); emitted_common_cdestructor = true; } - Printf(s_oinit, " SWIGTYPE_%s_ce->create_object = SWIG_Php_common_c_create_object;\n", class_name); + Printf(s_oinit, " SWIG_Php_ce_%s->create_object = SWIG_Php_common_c_create_object;\n", class_name); } else { Printf(s_creation, "static zend_object_handlers %s_object_handlers;\n", class_name); Printf(s_creation, "static zend_object *SWIG_Php_create_object_%s(zend_class_entry *ce) {return SWIG_Php_do_create_object(ce, &%s_object_handlers);}\n", class_name, class_name); @@ -1613,25 +1614,25 @@ public: } Printf(s_creation, "}\n\n"); - Printf(s_oinit, " SWIGTYPE_%s_ce->create_object = SWIG_Php_create_object_%s;\n", class_name, class_name); - Printf(s_oinit, " %s_object_handlers = SWIGTYPE_base_object_handlers;\n", class_name); + Printf(s_oinit, " SWIG_Php_ce_%s->create_object = SWIG_Php_create_object_%s;\n", class_name, class_name); + Printf(s_oinit, " %s_object_handlers = Swig_Php_base_object_handlers;\n", class_name); Printf(s_oinit, " %s_object_handlers.free_obj = SWIG_Php_free_obj_%s;\n", class_name, class_name); } } else { static bool emitted_destructorless_create_object = false; if (!emitted_destructorless_create_object) { emitted_destructorless_create_object = true; - Printf(s_creation, "static zend_object *SWIG_Php_create_object(zend_class_entry *ce) {return SWIG_Php_do_create_object(ce, &SWIGTYPE_base_object_handlers);}\n", class_name); + Printf(s_creation, "static zend_object *SWIG_Php_create_object(zend_class_entry *ce) {return SWIG_Php_do_create_object(ce, &Swig_Php_base_object_handlers);}\n", class_name); } - Printf(s_oinit, " SWIGTYPE_%s_ce->create_object = SWIG_Php_create_object;\n", class_name); + Printf(s_oinit, " SWIG_Php_ce_%s->create_object = SWIG_Php_create_object;\n", class_name); } // If not defined we aren't wrapping any functions which use this type as a // parameter or return value, in which case we don't need the clientdata // set. Printf(s_oinit, "#ifdef SWIGTYPE_p%s\n", SwigType_manglestr(Getattr(n, "classtypeobj"))); - Printf(s_oinit, " SWIG_TypeClientData(SWIGTYPE_p%s,SWIGTYPE_%s_ce);\n", SwigType_manglestr(Getattr(n, "classtypeobj")), class_name); + Printf(s_oinit, " SWIG_TypeClientData(SWIGTYPE_p%s,SWIG_Php_ce_%s);\n", SwigType_manglestr(Getattr(n, "classtypeobj")), class_name); Printf(s_oinit, "#endif\n"); Printf(s_oinit, "\n"); From 4672318b427b7d826dd447653f9ddff4900f199d Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 17 Dec 2021 22:32:07 +1300 Subject: [PATCH 150/262] Make some generated variables static --- Source/Modules/php.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index f3dac4bfb..510e7ea58 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -78,7 +78,7 @@ static String *fake_class_name() { fake_cs_entry = NewStringf("static zend_function_entry class_%s_functions[] = {\n", result); } - Printf(s_creation, "zend_class_entry *SWIG_Php_ce_%s;\n\n",result); + Printf(s_creation, "static zend_class_entry *SWIG_Php_ce_%s;\n\n",result); Printf(s_oinit, " INIT_CLASS_ENTRY(internal_ce, \"%s\", class_%s_functions);\n", result, result); Printf(s_oinit, " SWIG_Php_ce_%s = zend_register_internal_class(&internal_ce);\n", result); @@ -164,7 +164,7 @@ static void SwigPHP_emit_pointer_type_registrations() { String *type = ki.key; Printf(s_creation, "/* class entry for pointer to %s */\n", type); - Printf(s_creation, "zend_class_entry *SWIG_Php_ce_%s;\n\n", type); + Printf(s_creation, "static zend_class_entry *SWIG_Php_ce_%s;\n\n", type); Printf(s_oinit, " INIT_CLASS_ENTRY(internal_ce, \"%s\\\\%s\", NULL);\n", "SWIG", type); Printf(s_oinit, " SWIG_Php_ce_%s = zend_register_internal_class(&internal_ce);\n", type); From 499fb747073e2ff66086bd5a7698ccdd35850df2 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 18 Dec 2021 11:24:00 +1300 Subject: [PATCH 151/262] Remove unused Printf parameters --- Source/Modules/php.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 510e7ea58..4320032d3 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -845,7 +845,7 @@ public: Printf(all_cs_entry, " PHP_ME(%s%s,__get,swig_arginfo_1,ZEND_ACC_PUBLIC)\n", prefix, class_name); Printf(f->code, "PHP_METHOD(%s%s,__get) {\n",prefix, class_name); - Printf(f->code, " swig_object_wrapper *arg = SWIG_Z_FETCH_OBJ_P(ZEND_THIS);\n", class_name); + Printf(f->code, " swig_object_wrapper *arg = SWIG_Z_FETCH_OBJ_P(ZEND_THIS);\n"); Printf(f->code, " zval args[1];\n zval tempZval;\n zend_string *arg2 = 0;\n\n"); Printf(f->code, " if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_array_ex(1, args) != SUCCESS) {\n"); Printf(f->code, "\tWRONG_PARAM_COUNT;\n}\n\n"); @@ -878,7 +878,7 @@ public: Printf(all_cs_entry, " PHP_ME(%s%s,__isset,swig_arginfo_1,ZEND_ACC_PUBLIC)\n", prefix, class_name); Printf(f->code, "PHP_METHOD(%s%s,__isset) {\n",prefix, class_name); - Printf(f->code, " swig_object_wrapper *arg = SWIG_Z_FETCH_OBJ_P(ZEND_THIS);\n", class_name); + Printf(f->code, " swig_object_wrapper *arg = SWIG_Z_FETCH_OBJ_P(ZEND_THIS);\n"); Printf(f->code, " zval args[1];\n zend_string *arg2 = 0;\n\n"); Printf(f->code, " if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_array_ex(1, args) != SUCCESS) {\n"); Printf(f->code, "\tWRONG_PARAM_COUNT;\n}\n\n"); From f04d741d1c752f3af87c90820ee1d386e56a924d Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 18 Dec 2021 14:06:36 +1300 Subject: [PATCH 152/262] [php] Actually implement abstract_inherit_runme.php The previous version didn't really test anything useful. Now we check that trying to instantiate any of the abstract classes fails with the expected error. --- .../test-suite/php/abstract_inherit_runme.php | 15 +++++++++++---- TODO | 4 ---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Examples/test-suite/php/abstract_inherit_runme.php b/Examples/test-suite/php/abstract_inherit_runme.php index 6a0180d78..376a2adaa 100644 --- a/Examples/test-suite/php/abstract_inherit_runme.php +++ b/Examples/test-suite/php/abstract_inherit_runme.php @@ -3,10 +3,17 @@ require "tests.php"; check::classes(array('Foo','Bar','Spam','NRFilter_i','NRRCFilter_i','NRRCFilterpro_i','NRRCFilterpri_i')); -// This constructor attempt should fail as there isn't one -//$spam=new Spam(); -//check::equal(0,$spam->blah(),"spam object method"); -//check::equal(0,Spam::blah($spam),"spam class method"); +// We shouldn't be able to instantiate any of these classes since they are all +// abstract (in each case there's a pure virtual function in the base class +// which isn't implemented). +foreach (array('Foo','Bar','Spam','NRFilter_i','NRRCFilter_i','NRRCFilterpro_i','NRRCFilterpri_i')as $class) { + try { + $obj = eval("new $class();"); + check::fail("Should not be able to instantiate abstract class $class"); + } catch (Error $e) { + check::equal($e->getMessage(), "Cannot instantiate abstract class $class", "Unexpected exception: {$e->getMessage()}"); + } +} check::done(); diff --git a/TODO b/TODO index 38ab4605d..d01168e5f 100644 --- a/TODO +++ b/TODO @@ -204,10 +204,6 @@ PHP mapping to the same object in case it gets twice destroyed. And check if ref count destroying is even working, see smart_pointer_rename -* Work out how classes without even inherited constructors should - interact with the php "new " notation. - See: abstract_inherit_wrap.cpptest - ** Look at pass by point and passby ref, Make sometype** to be auto allocated Make sometype& and sometype* to be autoallocated IF THEY ARE NOT From cc5395a669588f7c9b6347dfc65ed69e0f5221d0 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 18 Dec 2021 14:38:49 +1300 Subject: [PATCH 153/262] [php] Add more checks to some PHP testcases --- .../php/abstract_inherit_ok_runme.php | 19 +++++++++++++++++-- .../test-suite/php/arrays_scope_runme.php | 4 ++++ Examples/test-suite/php/php_pragma_runme.php | 7 +++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/php/abstract_inherit_ok_runme.php b/Examples/test-suite/php/abstract_inherit_ok_runme.php index 6cfea2341..add4191c2 100644 --- a/Examples/test-suite/php/abstract_inherit_ok_runme.php +++ b/Examples/test-suite/php/abstract_inherit_ok_runme.php @@ -2,9 +2,24 @@ require "tests.php"; -check::classes(array('Foo','Spam')); -$spam=new Spam(); +// No new functions +check::functions(array()); +check::classes(array('Foo','Spam')); + +// No new vars +check::globals(array()); + +// We shouldn't be able to instantiate abstract class Foo. +$class = 'Foo'; +try { + $obj = eval("new $class();"); + check::fail("Should not be able to instantiate abstract class $class"); +} catch (Error $e) { + check::equal($e->getMessage(), "Cannot instantiate abstract class $class", "Unexpected exception: {$e->getMessage()}"); +} + +$spam=new Spam(); check::equal(0,$spam->blah(),"spam object method"); check::done(); diff --git a/Examples/test-suite/php/arrays_scope_runme.php b/Examples/test-suite/php/arrays_scope_runme.php index f18037ca7..8455b837c 100644 --- a/Examples/test-suite/php/arrays_scope_runme.php +++ b/Examples/test-suite/php/arrays_scope_runme.php @@ -10,5 +10,9 @@ check::classes(array('arrays_scope','Bar')); check::globals(array()); $bar=new bar(); +$bar->blah($bar->adata, $bar->bdata, $bar->cdata); +// Like C/C++, SWIG treats `int asize[ASIZE]` as `int*` so there's no checking +// of the passed array size. +$bar->blah($bar->bdata, $bar->cdata, $bar->adata); check::done(); diff --git a/Examples/test-suite/php/php_pragma_runme.php b/Examples/test-suite/php/php_pragma_runme.php index e70f2ceda..cf297701d 100644 --- a/Examples/test-suite/php/php_pragma_runme.php +++ b/Examples/test-suite/php/php_pragma_runme.php @@ -2,6 +2,13 @@ require "tests.php"; +// No new functions +check::functions(array()); +// No new classes +check::classes(array()); +// No new vars +check::globals(array()); + check::equal('1.5',(new ReflectionExtension('php_pragma'))->getVersion(),"1.5==version(php_pragma)"); check::done(); From dee8b65823a9468288e37585ce9482a51bb98a13 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 18 Dec 2021 14:41:06 +1300 Subject: [PATCH 154/262] [php] Always use Date: Sat, 18 Dec 2021 15:01:04 +1300 Subject: [PATCH 155/262] TODO: Remove stale PHP entry Ref count destroying has worked for years (and is explicitly tested by swig_exception_runme.php). --- TODO | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/TODO b/TODO index d01168e5f..1fcc992ac 100644 --- a/TODO +++ b/TODO @@ -201,8 +201,7 @@ PHP ** When returning wrapped objects via alternate constructors if that pointer value already exists "out there" as a resource we should use the same resource, we can't have multiple ref-counted resources - mapping to the same object in case it gets twice destroyed. And check - if ref count destroying is even working, see smart_pointer_rename + mapping to the same object in case it gets twice destroyed. ** Look at pass by point and passby ref, Make sometype** to be auto allocated From 7d75e3eb7e760846f8569ecea0e6a379029c9db6 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 18 Dec 2021 15:30:38 +1300 Subject: [PATCH 156/262] [PHP] Add new PHP 8.1 keyword Add PHP keyword 'readonly' (added in 8.1) to the list SWIG knows to automatically rename. This keyword is special in that PHP allows it to be used as a function (or method) name. --- CHANGES.current | 5 +++++ Examples/test-suite/php_namewarn_rename.i | 14 ++++++++++++++ Lib/php/phpkw.swg | 9 +++++++++ 3 files changed, 28 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index cadbbadfb..fc56246c6 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,11 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2021-12-18: olly + [PHP] Add PHP keyword 'readonly' (added in 8.1) to the list SWIG + knows to automatically rename. This keyword is special in that PHP + allows it to be used as a function (or method) name. + 2021-12-05: rwf1 [Octave] #2020 #1893 Add support for Octave 6 up to and including 6.4. Also add support for compiling with -Bsymbolic which is used by default diff --git a/Examples/test-suite/php_namewarn_rename.i b/Examples/test-suite/php_namewarn_rename.i index bb54dba5e..d70cad770 100644 --- a/Examples/test-suite/php_namewarn_rename.i +++ b/Examples/test-suite/php_namewarn_rename.i @@ -8,6 +8,7 @@ %warnfilter(SWIGWARN_PARSE_KEYWORD) null; %warnfilter(SWIGWARN_PARSE_KEYWORD) True; %warnfilter(SWIGWARN_PARSE_KEYWORD) FALSE; +%warnfilter(SWIGWARN_PARSE_KEYWORD) ns::readonly; #endif %ignore prev::operator++; @@ -50,4 +51,17 @@ class FALSE { }; + + // PHP 8.1 made `readonly` a keyword, but (unlike any other keyword it seems) + // it may still be used as a function name. + namespace ns { + class readonly { }; + } + + class readonly_should_be_ok_as_method { + public: + bool readonly() const { return true; } + }; + + bool readonly() { return false; } %} diff --git a/Lib/php/phpkw.swg b/Lib/php/phpkw.swg index e431fc2e4..b6855ce9a 100644 --- a/Lib/php/phpkw.swg +++ b/Lib/php/phpkw.swg @@ -5,6 +5,9 @@ /* Keyword (case insensitive) */ #define PHPKW(x) %keywordwarn("'" `x` "' is a PHP keyword, renaming to 'c_" `x` "'",sourcefmt="%(lower)s",rename="c_%s") `x` +/* Keyword, except ok as a function */ +#define PHPKW_ok_as_function(x) %keywordwarn("'" `x` "' is a PHP keyword, renaming to 'c_" `x` "'",%$not %$isfunction,sourcefmt="%(lower)s",rename="c_%s") `x` + /* Class (case insensitive) */ #define PHPCN(x) %keywordwarn("'" `x` "' is a PHP reserved class name, renaming to 'c_" `x` "'",%$isclass,sourcefmt="%(lower)s",rename="c_%s") `x` @@ -84,6 +87,11 @@ PHPKW(while); PHPKW(xor); PHPKW(yield); +/* PHP 8.1 made `readonly` a keyword, but (unlike any other keyword it seems) + * it may still be used as a function name. + */ +PHPKW_ok_as_function(readonly); + // Compile-time "magic" constants // From: http://php.net/manual/en/reserved.keywords.php // also at: http://php.net/manual/en/language.constants.predefined.php @@ -869,6 +877,7 @@ PHPFN(unset); // "Language construct" PHPFN(usort); #undef PHPKW +#undef PHPKW_ok_as_function #undef PHPBN1a #undef PHPBN1b #undef PHPBN1 From a7f2c3d19b898d9c1d6e836164cb69df567aa7ff Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 18 Dec 2021 18:45:52 +1300 Subject: [PATCH 157/262] [php] Add overload_simple_runme.php --- .../test-suite/php/overload_simple_runme.php | 194 ++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 Examples/test-suite/php/overload_simple_runme.php diff --git a/Examples/test-suite/php/overload_simple_runme.php b/Examples/test-suite/php/overload_simple_runme.php new file mode 100644 index 000000000..3cba1d35b --- /dev/null +++ b/Examples/test-suite/php/overload_simple_runme.php @@ -0,0 +1,194 @@ +foo(3), "foo:int", "Spam::foo:int"); + +check::equal($s->foo(3.0), "foo:double", "Spam::foo(double)"); + +check::equal($s->foo("hello"), "foo:char *", "Spam::foo:char *"); + +check::equal($s->foo($f), "foo:Foo *", "Spam::foo(Foo *)"); + +check::equal($s->foo($b), "foo:Bar *", "Spam::foo(Bar *)"); + +check::equal($s->foo($v), "foo:void *", "Spam::foo(void *)"); + +check::equal(Spam::bar(3), "bar:int", "Spam::bar(int)"); + +check::equal(Spam::bar(3.0), "bar:double", "Spam::bar(double)"); + +check::equal(Spam::bar("hello"), "bar:char *", "Spam::bar(char *)"); + +check::equal(Spam::bar($f), "bar:Foo *", "Spam::bar(Foo *)"); + +check::equal(Spam::bar($b), "bar:Bar *", "Spam::bar(Bar *)"); + +check::equal(Spam::bar($v), "bar:void *", "Spam::bar(void *)"); + +# Test constructors + +$s = new Spam(); +check::is_a($s, "spam"); + +check::equal($s->type, "none", "Spam()"); + +$s = new Spam(3); +check::is_a($s, "spam"); + +check::equal($s->type, "int", "Spam(int)"); + +$s = new Spam(3.0); +check::is_a($s, "spam"); +check::equal($s->type, "double", "Spam(double)"); + +$s = new Spam("hello"); +check::is_a($s, "spam"); +check::equal($s->type, "char *", "Spam(char *)"); + +$s = new Spam($f); +check::is_a($s, "spam"); +check::equal($s->type, "Foo *", "Spam(Foo *)"); + +$s = new Spam($b); +check::is_a($s, "spam"); +check::equal($s->type, "Bar *", "Spam(Bar *)"); + +$s = new Spam($v); +check::is_a($s, "spam"); +check::equal($s->type, "void *", "Spam(void *)"); + +# +# Combine dispatch +# + +check::equal(overload_simple::fid(3, 3.0), "fid:intdouble", "fid(int,double)"); + +check::equal(overload_simple::fid(3.0, 3), "fid:doubleint", "fid(double,int)"); + +check::equal(overload_simple::fid(3.0, 3.0), "fid:doubledouble", "fid(double,double)"); + +check::equal(overload_simple::fid(3, 3), "fid:intint", "fid(int,int)"); + +check::equal(false, overload_simple::fbool(false), "fbool(bool)"); +check::equal(true, overload_simple::fbool(true), "fbool(bool)"); +check::equal(2, overload_simple::fbool(2), "fbool(int)"); + +# int and object overload + +check::equal(overload_simple::int_object(1), 1, "int_object(1)"); +check::equal(overload_simple::int_object(0), 0, "int_object(0)"); +check::equal(overload_simple::int_object(NULL), 999, "int_object(Spam*)"); +check::equal(overload_simple::int_object($s), 999, "int_object(Spam*)"); + +function check($args, $want) { + if ($want === NULL) { + try { + eval("return Spam::bar($args);"); + check::fail("Expected exception"); + } catch (TypeError $e) { + check::equal(substr($e->getMessage(), 0, 35), "No matching function for overloaded", "Not the expected I expected"); + } + return; + } + check::equal(eval("return Spam::bar($args);"), "bar:$want", "bar($args) => $want"); +} + +# normal use patterns +check("11", 'int'); +check("11.0", 'double'); +check("'11'", 'char *'); +check("'11.0'", 'char *'); +check("-13", 'int'); +check("-13.0", 'double'); +check("'-13'", 'char *'); +check("'-13.0'", 'char *'); + +check("' '", 'char *'); +check("' 11 '", 'char *'); + +# Check TypeError is thrown when the wrong type is passed. +check("array()", NULL); +# FIXME: These need fixing +#check("function(){}", NULL); +#check("new stdClass()", NULL); + +check::done(); From 69b580dfb6e39b5463213908b443a86265bdb23c Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sun, 19 Dec 2021 13:03:48 +1300 Subject: [PATCH 158/262] [php] Use SWIG_TypeCheckStruct to check types We have the swig_type_info available and SWIG_TypeCheckStruct is more efficient because it uses a pointer comparison instead of the string comparison SWIG_TypeCheck uses (this change speeds up `make check-php-test-suite` by about 10%). --- Lib/php/phprun.swg | 54 +++++++++++++++------------------------------- Lib/swigrun.swg | 2 +- 2 files changed, 18 insertions(+), 38 deletions(-) diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 426efe104..69b00bc4b 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -122,42 +122,6 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) { } } -/* This pointer conversion routine takes the native pointer p (along with - its type name) and converts it by calling appropriate casting functions - according to ty. The resultant pointer is returned, or NULL is returned - if the pointer can't be cast. - - This is called by SWIG_ConvertPtr which gets the type name from the - swig_object_wrapper. */ -static void * -SWIG_ConvertPtrData(void * p, const char *type_name, swig_type_info *ty, int *own) { - swig_cast_info *tc; - void *result = 0; - - if (!ty) { - /* They don't care about the target type, so just pass on the pointer! */ - return p; - } - - if (! type_name) { - /* can't convert p to ptr type ty if we don't know what type p is */ - return NULL; - } - - /* convert and cast p from type_name to ptr as ty. */ - tc = SWIG_TypeCheck(type_name, ty); - if (tc) { - int newmemory = 0; - result = SWIG_TypeCast(tc, p, &newmemory); - if (newmemory == SWIG_CAST_NEW_MEMORY) { - assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */ - if (own) - *own |= SWIG_CAST_NEW_MEMORY; - } - } - return result; -} - /* We wrap C/C++ pointers as PHP objects. */ static int SWIG_ConvertPtrAndOwn(zval *z, void **ptr, swig_type_info *ty, int flags, swig_owntype *own) { @@ -172,7 +136,23 @@ SWIG_ConvertPtrAndOwn(zval *z, void **ptr, swig_type_info *ty, int flags, swig_o switch (Z_TYPE_P(z)) { case IS_OBJECT: { swig_object_wrapper *value = SWIG_Z_FETCH_OBJ_P(z); - *ptr = SWIG_ConvertPtrData(value->ptr, value->type->name, ty, own); + if (!ty) { + /* They don't care about the target type, so just pass on the pointer! */ + *ptr = value->ptr; + } else { + swig_cast_info *tc = SWIG_TypeCheckStruct(value->type, ty); + if (tc) { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc, value->ptr, &newmemory); + if (newmemory == SWIG_CAST_NEW_MEMORY) { + assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */ + if (own) + *own |= SWIG_CAST_NEW_MEMORY; + } + } else { + *ptr = NULL; + } + } if (*ptr == NULL) return SWIG_ERROR; if (flags & SWIG_POINTER_DISOWN) { value->newobject = 0; diff --git a/Lib/swigrun.swg b/Lib/swigrun.swg index 5f3159916..de0db2dc3 100644 --- a/Lib/swigrun.swg +++ b/Lib/swigrun.swg @@ -290,7 +290,7 @@ SWIG_TypeCheck(const char *c, swig_type_info *ty) { Identical to SWIG_TypeCheck, except strcmp is replaced with a pointer comparison */ SWIGRUNTIME swig_cast_info * -SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *ty) { +SWIG_TypeCheckStruct(const swig_type_info *from, swig_type_info *ty) { if (ty) { swig_cast_info *iter = ty->cast; while (iter) { From 7a9bf3307f9436c0f48eecd155c721c86a0f4058 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 21 Dec 2021 22:36:01 +0000 Subject: [PATCH 159/262] Remove C++ comments from preproc C test Closes issue #2127 --- Examples/test-suite/preproc.i | 77 +++++++++++++++++------------------ 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/Examples/test-suite/preproc.i b/Examples/test-suite/preproc.i index 1bcdcf7ac..04398b25a 100644 --- a/Examples/test-suite/preproc.i +++ b/Examples/test-suite/preproc.i @@ -13,11 +13,11 @@ %{ #if defined(__clang__) -//Suppress: warning: use of logical '&&' with constant operand [-Wconstant-logical-operand] +/*Suppress: warning: use of logical '&&' with constant operand [-Wconstant-logical-operand]*/ #pragma clang diagnostic ignored "-Wconstant-logical-operand" #endif #if defined(_MSC_VER) - #pragma warning(disable: 4003) // not enough actual parameters for macro 'FOO2' + #pragma warning(disable: 4003) /* not enough actual parameters for macro 'FOO2' */ #endif %} @@ -72,14 +72,14 @@ extern "C" TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(boolean) -// preproc_3 +/* preproc_3 */ #define Sum( A, B, \ C) \ A + B + C -// preproc_4 +/* preproc_4 */ %{ int hello0() { @@ -102,33 +102,30 @@ TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(boolean) #define HELLO_TYPE(A, B) ARITH_RTYPE(A, ARITH_RTYPE(A,B)) -// -// These two work fine -// int hello0(); ARITH_RTYPE(double,int) hello1(); -// -// This doesn't work with 1.3.17+ ( but it was ok in 1.3.16 ) -// it gets expanded as (using -E) -// -// ARITH_RTYPE(double,int) hello2(); -// +/* + This doesn't work with 1.3.17+ ( but it was ok in 1.3.16 ) + it gets expanded as (using -E) + + ARITH_RTYPE(double,int) hello2(); +*/ HELLO_TYPE(double,int) hello2(); #define min(x,y) ((x) < (y)) ? (x) : (y) int f(int min); -// preproc_5 +/* preproc_5 */ -%warnfilter(SWIGWARN_PARSE_REDEFINED) A5; // Ruby, wrong constant name -%warnfilter(SWIGWARN_RUBY_WRONG_NAME) a5; // Ruby, wrong constant name -%warnfilter(SWIGWARN_RUBY_WRONG_NAME) b5; // Ruby, wrong constant name -%warnfilter(SWIGWARN_RUBY_WRONG_NAME) c5; // Ruby, wrong constant name -%warnfilter(SWIGWARN_RUBY_WRONG_NAME) d5; // Ruby, wrong constant name +%warnfilter(SWIGWARN_PARSE_REDEFINED) A5; /* Ruby, wrong constant name */ +%warnfilter(SWIGWARN_RUBY_WRONG_NAME) a5; /* Ruby, wrong constant name */ +%warnfilter(SWIGWARN_RUBY_WRONG_NAME) b5; /* Ruby, wrong constant name */ +%warnfilter(SWIGWARN_RUBY_WRONG_NAME) c5; /* Ruby, wrong constant name */ +%warnfilter(SWIGWARN_RUBY_WRONG_NAME) d5; /* Ruby, wrong constant name */ -// Various preprocessor bits of nastiness. +/* Various preprocessor bits of nastiness. */ /* Test argument name substitution */ @@ -138,7 +135,7 @@ int f(int min); %constant char *a5 = foo(hello,world); %constant int b5 = bar(3,4); -// Wrap your brain around this one ;-) +/* Wrap your brain around this one ;-) */ %{ #define cat(x,y) x ## y @@ -168,7 +165,7 @@ NAME 42 #define C4"Hello" -// preproc_6 +/* preproc_6 */ %warnfilter(SWIGWARN_PARSE_REDEFINED) A6; /* Ruby, wrong constant name */ %warnfilter(SWIGWARN_RUBY_WRONG_NAME) a6; /* Ruby, wrong constant name */ @@ -206,7 +203,7 @@ NAME 42 MACRO2(int) -// cpp_macro_noarg. Tests to make sure macros with no arguments work right. +/* cpp_macro_noarg. Tests to make sure macros with no arguments work right. */ #define MACROWITHARG(x) something(x) typedef int MACROWITHARG; @@ -373,8 +370,10 @@ int methodX(int x); int methodX(int x) { return x+100; } %} -// Comma in macro - https://github.com/swig/swig/issues/974 (for /* */) -// and https://github.com/swig/swig/pull/1166 (for //) +/* + Comma in macro - https://github.com/swig/swig/issues/974 (for C comments) + and https://github.com/swig/swig/pull/1166 (for //) +*/ %inline %{ #define swig__attribute__(x) #define TCX_PACKED(d) d swig__attribute__ ((__packed__)) @@ -394,19 +393,19 @@ TCX_PACKED (typedef struct tcxMessageBugImpl TCX_PACKED (typedef struct tcxMessageTestImpl2 { - int mHeader; ///< comment + int mHeader; /**< comment */ }) tcxMessageTest2; TCX_PACKED (typedef struct tcxMessageBugImpl2 { - int mBid; ///< Bid price and size, check PresentMap if available in message + int mBid; /**< Bid price and size, check PresentMap if available in message */ }) tcxMessageBug2; %} -// Regression tests for https://github.com/swig/swig/pull/1111 +/* Regression tests for https://github.com/swig/swig/pull/1111 */ %{ static int foo_func(int x) { return x; } static int foo_func2() { return 0; } @@ -422,22 +421,22 @@ static int baz_func(int a, int b, int c) { return a + b - c; } #define FOOVAR(...) foo_func(__VA_ARGS__) #define BARVAR(...) bar_func(__VA_ARGS__) #define BAZVAR(...) baz_func(__VA_ARGS__) -// This has probably always worked, but make sure that the fix to accept -// an empty X doesn't cause this case to be incorrectly expanded: +/* This has probably always worked, but make sure that the fix to accept + an empty X doesn't cause this case to be incorrectly expanded:*/ const int FOO = 7; -// BAR was incorrectly expanded here, causing: -// Error: Syntax error in input(1). +/* BAR was incorrectly expanded here, causing: + Error: Syntax error in input(1). */ const int BAR = 6; -// This has probably always worked, but make sure that the fix to accept -// an empty X doesn't stop a non-empty X from working: +/* This has probably always worked, but make sure that the fix to accept + an empty X doesn't stop a non-empty X from working: */ FOO(int x) -// FOO() didn't used to get expanded here, causing: -// Syntax error in input(1). +/* FOO() didn't used to get expanded here, causing: + Syntax error in input(1). */ FOO2() -// Check BAR2() still gets expanded here. +/* Check BAR2() still gets expanded here. */ BAR2() { - // Regression test - this used to fail with: - // Error: Macro 'BAZ' expects 3 arguments + /* Regression test - this used to fail with: + Error: Macro 'BAZ' expects 3 arguments */ BAZ(,2,3); BARVAR(); FOOVAR(1); From 1b22fef8ad531c768b10353bbb8e625c23d85b5c Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 22 Dec 2021 12:18:40 +1300 Subject: [PATCH 160/262] [php] Add missing runmes for overload_* testcases --- .../test-suite/php/overload_bool_runme.php | 42 +++++++ .../php/overload_complicated_runme.php | 39 +++++++ .../test-suite/php/overload_copy_runme.php | 13 +++ .../test-suite/php/overload_extend2_runme.php | 16 +++ .../php/overload_extend_c_runme.php | 11 ++ .../test-suite/php/overload_extend_runme.php | 11 ++ .../test-suite/php/overload_subtype_runme.php | 11 ++ .../php/overload_template_fast_runme.php | 110 ++++++++++++++++++ .../php/overload_template_runme.php | 110 ++++++++++++++++++ 9 files changed, 363 insertions(+) create mode 100644 Examples/test-suite/php/overload_bool_runme.php create mode 100644 Examples/test-suite/php/overload_complicated_runme.php create mode 100644 Examples/test-suite/php/overload_copy_runme.php create mode 100644 Examples/test-suite/php/overload_extend2_runme.php create mode 100644 Examples/test-suite/php/overload_extend_c_runme.php create mode 100644 Examples/test-suite/php/overload_extend_runme.php create mode 100644 Examples/test-suite/php/overload_subtype_runme.php create mode 100644 Examples/test-suite/php/overload_template_fast_runme.php create mode 100644 Examples/test-suite/php/overload_template_runme.php diff --git a/Examples/test-suite/php/overload_bool_runme.php b/Examples/test-suite/php/overload_bool_runme.php new file mode 100644 index 000000000..e477330ef --- /dev/null +++ b/Examples/test-suite/php/overload_bool_runme.php @@ -0,0 +1,42 @@ +hip(false), 701, "Test 1 failed"); + +check::equal($p->hip($pInt), 702, "Test 2 failed"); + +# Reverse the order for the above +check::equal($p->hop($pInt), 805, "Test 3 failed"); + +check::equal($p->hop(false), 801, "Test 4 failed"); + +# Few more variations and order shuffled +check::equal($p->pop(false), 901, "Test 5 failed"); + +check::equal($p->pop($pInt), 904, "Test 6 failed"); + +check::equal($p->pop(), 905, "Test 7 failed"); + +# Overload on const only +check::equal($p->bop($pInt), 1001, "Test 8 failed"); + +check::equal($p->bip($pInt), 2002, "Test 9 failed"); + +# Globals +check::equal(muzak(false), 3001, "Test 10 failed"); + +check::equal(muzak($pInt), 3002, "Test 11 failed"); + +check::done(); diff --git a/Examples/test-suite/php/overload_copy_runme.php b/Examples/test-suite/php/overload_copy_runme.php new file mode 100644 index 000000000..893a715c5 --- /dev/null +++ b/Examples/test-suite/php/overload_copy_runme.php @@ -0,0 +1,13 @@ +test(3), 1, '$f->test(3)'); +check::equal($f->test("hello"), 2, '$f->test("hello")'); +check::equal($f->test(3.5, 2.5), 3, '$f->test(3.5, 2.5)'); +check::equal($f->test("hello", 20), 1020, '$f->test("hello", 20)'); +check::equal($f->test("hello", 20, 100), 120, '$f->test("hello", 20, 100)'); + +// C default args +check::equal($f->test($f), 30, '$f->test(f)'); +check::equal($f->test($f, 100), 120, '$f->test(f, 100)'); +check::equal($f->test($f, 100, 200), 300, '$f->test(f, 100, 200)'); + +check::done(); diff --git a/Examples/test-suite/php/overload_extend_c_runme.php b/Examples/test-suite/php/overload_extend_c_runme.php new file mode 100644 index 000000000..55f426c13 --- /dev/null +++ b/Examples/test-suite/php/overload_extend_c_runme.php @@ -0,0 +1,11 @@ +test(), 0, '$f->test()'); +check::equal($f->test(3), 1, '$f->test(3)'); +check::equal($f->test("hello"), 2, '$f->test("hello")'); +check::equal($f->test(3.0, 2.0), 5.0, '$f->test(3, 2)'); +check::equal($f->test(3.0), 1003.0, '$f->test(3.0)'); + +check::done(); diff --git a/Examples/test-suite/php/overload_extend_runme.php b/Examples/test-suite/php/overload_extend_runme.php new file mode 100644 index 000000000..89c0499eb --- /dev/null +++ b/Examples/test-suite/php/overload_extend_runme.php @@ -0,0 +1,11 @@ +test(), 0, '$f->test()'); +check::equal($f->test(3), 1, '$f->test(3)'); +check::equal($f->test("hello"), 2, '$f->test("hello")'); +check::equal($f->test(3.0, 2.0), 5.0, '$f->test(3.0, 2.0)'); +check::equal($f->test(3.0), 1003.0, '$f->test(3.0)'); + +check::done(); diff --git a/Examples/test-suite/php/overload_subtype_runme.php b/Examples/test-suite/php/overload_subtype_runme.php new file mode 100644 index 000000000..f12025cf8 --- /dev/null +++ b/Examples/test-suite/php/overload_subtype_runme.php @@ -0,0 +1,11 @@ +foo(1); + + +check::done(); diff --git a/Examples/test-suite/php/overload_template_runme.php b/Examples/test-suite/php/overload_template_runme.php new file mode 100644 index 000000000..7aa19f693 --- /dev/null +++ b/Examples/test-suite/php/overload_template_runme.php @@ -0,0 +1,110 @@ +foo(1); + + +check::done(); From 2d76057571a77609060d6c6c05f151ec608aa58d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 22 Dec 2021 19:06:00 +0000 Subject: [PATCH 161/262] preproc_cpp test for testing preprocessor and C++ Move C++ comment testing into here. See 7a9bf3307f9436c0f48eecd155c721c86a0f4058. --- Examples/test-suite/preproc.i | 1 + Examples/test-suite/preproc_cpp.i | 36 +++++++++++++++++++ .../test-suite/python/preproc_cpp_runme.py | 4 +++ 3 files changed, 41 insertions(+) create mode 100644 Examples/test-suite/preproc_cpp.i create mode 100644 Examples/test-suite/python/preproc_cpp_runme.py diff --git a/Examples/test-suite/preproc.i b/Examples/test-suite/preproc.i index 04398b25a..feff7b489 100644 --- a/Examples/test-suite/preproc.i +++ b/Examples/test-suite/preproc.i @@ -373,6 +373,7 @@ int methodX(int x) { return x+100; } /* Comma in macro - https://github.com/swig/swig/issues/974 (for C comments) and https://github.com/swig/swig/pull/1166 (for //) + Also see preproc_cpp.i */ %inline %{ #define swig__attribute__(x) diff --git a/Examples/test-suite/preproc_cpp.i b/Examples/test-suite/preproc_cpp.i new file mode 100644 index 000000000..c81f9a74f --- /dev/null +++ b/Examples/test-suite/preproc_cpp.i @@ -0,0 +1,36 @@ +%module preproc_cpp + + +// Comma in macro - https://github.com/swig/swig/issues/974 (for /* */) +// and https://github.com/swig/swig/pull/1166 (for //) +// Also see preproc.i +%inline %{ +#define swig__attribute__(x) +#define TCX_PACKED(d) d swig__attribute__ ((__packed__)) + + +TCX_PACKED (typedef struct tcxMessageTestImpl +{ + int mHeader; /**< comment */ +}) tcxMessageTest; + + +TCX_PACKED (typedef struct tcxMessageBugImpl +{ + int mBid; /**< Bid price and size, check PresentMap if available in message */ +}) tcxMessageBug; + + +TCX_PACKED (typedef struct tcxMessageTestImpl2 +{ + int mHeader; ///< comment +}) tcxMessageTest2; + + +TCX_PACKED (typedef struct tcxMessageBugImpl2 +{ + int mBid; ///< Bid price and size, check PresentMap if available in message +}) tcxMessageBug2; + + +%} diff --git a/Examples/test-suite/python/preproc_cpp_runme.py b/Examples/test-suite/python/preproc_cpp_runme.py new file mode 100644 index 000000000..8c3e21237 --- /dev/null +++ b/Examples/test-suite/python/preproc_cpp_runme.py @@ -0,0 +1,4 @@ +import preproc_cpp + +t1 = preproc_cpp.tcxMessageTest() +t2 = preproc_cpp.tcxMessageBug() From 860731e0ead11c370834eca032fbbce3607057a3 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 23 Dec 2021 11:55:47 +1300 Subject: [PATCH 162/262] Remove redundant test cases With C++ comments changed to C comments, these are now identical to the two cases just above, aside from the `2` suffix on the names. Follow-on for #2027. --- Examples/test-suite/preproc.i | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Examples/test-suite/preproc.i b/Examples/test-suite/preproc.i index feff7b489..a69973f13 100644 --- a/Examples/test-suite/preproc.i +++ b/Examples/test-suite/preproc.i @@ -392,18 +392,6 @@ TCX_PACKED (typedef struct tcxMessageBugImpl }) tcxMessageBug; -TCX_PACKED (typedef struct tcxMessageTestImpl2 -{ - int mHeader; /**< comment */ -}) tcxMessageTest2; - - -TCX_PACKED (typedef struct tcxMessageBugImpl2 -{ - int mBid; /**< Bid price and size, check PresentMap if available in message */ -}) tcxMessageBug2; - - %} /* Regression tests for https://github.com/swig/swig/pull/1111 */ From 9f87d81faec219baf2e2ca2da1bb2b4812958ae8 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 23 Dec 2021 16:18:07 +1300 Subject: [PATCH 163/262] Clean up testcase source whitespace --- Examples/test-suite/li_factory.i | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Examples/test-suite/li_factory.i b/Examples/test-suite/li_factory.i index 7c59d53b2..233c9c36b 100644 --- a/Examples/test-suite/li_factory.i +++ b/Examples/test-suite/li_factory.i @@ -18,32 +18,30 @@ POINT, CIRCLE }; - - virtual ~Geometry() {} + + virtual ~Geometry() {} virtual int draw() = 0; static Geometry *create(GeomType i); - virtual Geometry *clone() = 0; + virtual Geometry *clone() = 0; }; struct Point : Geometry { int draw() { return 1; } - double width() { return 1.0; } - Geometry *clone() { return new Point(); } + double width() { return 1.0; } + Geometry *clone() { return new Point(); } }; struct Circle : Geometry { int draw() { return 2; } - double radius() { return 1.5; } - Geometry *clone() { return new Circle(); } - }; + double radius() { return 1.5; } + Geometry *clone() { return new Circle(); } + }; Geometry *Geometry::create(GeomType type) { switch (type) { case POINT: return new Point(); - case CIRCLE: return new Circle(); + case CIRCLE: return new Circle(); default: return 0; } } } - - From c42e8970a4d51198472f6dcf196c5c0916aab033 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 24 Dec 2021 15:53:00 +1300 Subject: [PATCH 164/262] [php] Improve wording in the manual --- Doc/Manual/Php.html | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index ed2587f1b..7c970d169 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -50,18 +50,21 @@

    -In this chapter, we discuss SWIG's support of PHP. SWIG currently supports -generating wrappers for PHP7 and PHP8. Support for PHP5 was removed in SWIG -4.0.0 and support for PHP4 was removed in SWIG 1.3.37. +In this chapter, we discuss SWIG's support of PHP. Currently any PHP7 or PHP8 +release should work.

    -Currently any PHP7 or PHP8 release should work. +Support for PHP7 was added in SWIG 3.0.11 and for PHP8 in 4.1.0. +Support for PHP5 was removed in SWIG 4.0.0 and support for PHP4 was removed in +SWIG 1.3.37. There never was a PHP6 release. +

    +

    In order to use this module, you will need to have a copy of the PHP -include files to compile the SWIG generated files. If you installed +include files to compile the SWIG generated C/C++ sources. If you installed PHP from a binary package, you may need to install a "php-dev" or "php-devel" package for these to be installed. You can find out where these files are by running php-config --includes. To use the built PHP module you From fa36d6fd289f9294489c6bcfcfe6069562ea8474 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 24 Dec 2021 16:43:25 +1300 Subject: [PATCH 165/262] [python] Add 3.10 to Python versions in configure --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index e5730cbf0..8073bfdb3 100644 --- a/configure.ac +++ b/configure.ac @@ -812,7 +812,7 @@ else if test x"$PYOSNAME" = x"nt" -a x"$PYSEPARATOR" = x"\\" -a $PYVER -ge 3; then PYTHON3="$PYTHON" else - for py_ver in 3 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 ""; do + for py_ver in 3 3.10 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 ""; do AC_CHECK_PROGS(PYTHON3, [python$py_ver]) if test -n "$PYTHON3"; then AC_CHECK_PROGS(PY3CONFIG, [$PYTHON3-config]) From 9e95f7f996c616a931253c0ab795f00feb499f0a Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 29 Dec 2021 15:48:40 +1300 Subject: [PATCH 166/262] [php] Add director_ownership_runme.php This serves as a regression test for https://sourceforge.net/p/swig/bugs/1339/ which was presumably fixed by the change to use PHP's C API to wrap classes. --- .../php/director_ownership_runme.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Examples/test-suite/php/director_ownership_runme.php diff --git a/Examples/test-suite/php/director_ownership_runme.php b/Examples/test-suite/php/director_ownership_runme.php new file mode 100644 index 000000000..a78fb9c03 --- /dev/null +++ b/Examples/test-suite/php/director_ownership_runme.php @@ -0,0 +1,28 @@ +thisown = false; + $container->set_content($content); +} + +$container = new Container(); + +// make a content in PHP (newobject is 1) +$content_php = new ContentDerived(); + +// make a content in C++ (newobject is 1) +$content_cpp = make_content(); + +set_content_and_release($container, $content_php); +check::equal($container->get_content()->get_name(), "ContentDerived", "get_content() not ContentDerived"); + +set_content_and_release($container, $content_cpp); +check::equal($container->get_content()->get_name(), "ContentDerived", "get_content() not ContentDerived"); + +check::done(); From 130813b32042da76bafafc37ed3695fcdf02c871 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 29 Dec 2021 19:15:08 +1300 Subject: [PATCH 167/262] Escape a literal > in PHP.html --- Doc/Manual/Php.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index 7c970d169..8f8ab39c4 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -1162,7 +1162,7 @@ should suffice in most cases:

    -If you only need to support SWIG >= 4.1.0, you can just use the +If you only need to support SWIG >= 4.1.0, you can just use the ($error != NULL) condition.

    From 48eba82ac8847f8422710fac677875baf88566df Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 29 Dec 2021 19:16:36 +1300 Subject: [PATCH 168/262] Remove obsolete code to set SWIG_V8_VERSION We've dropped support for the old V8 versions which lacked version macros, and SWIG_V8_VERSION now gets automatically defined by Lib/javascript/v8/javascriptruntime.swg which will #undef it first if it's already defined. --- Tools/javascript/Makefile.in | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Tools/javascript/Makefile.in b/Tools/javascript/Makefile.in index 5eeec0785..6335d0a65 100644 --- a/Tools/javascript/Makefile.in +++ b/Tools/javascript/Makefile.in @@ -32,12 +32,6 @@ JSCENABLED = @JSCENABLED@ srcdir = @srcdir@ -ifneq (, $(V8_VERSION)) - JSV8_VERSION=$(V8_VERSION) -else - JSV8_VERSION=0x031110 -endif - # Regenerate Makefile if Makefile.in or config.status have changed. Makefile: $(srcdir)/Makefile.in ../../config.status cd ../.. && $(SHELL) ./config.status Tools/javascript/Makefile @@ -45,7 +39,7 @@ Makefile: $(srcdir)/Makefile.in ../../config.status # These settings are provided by 'configure' (see '/configure.in') ifeq (1, $(JSV8ENABLED)) JS_INTERPRETER_SRC_V8 = v8_shell.cxx -JS_INTERPRETER_ENABLE_V8 = -DENABLE_V8 -DSWIG_V8_VERSION=$(JSV8_VERSION) -DV8_DEPRECATION_WARNINGS +JS_INTERPRETER_ENABLE_V8 = -DENABLE_V8 -DV8_DEPRECATION_WARNINGS endif ifeq (1, $(JSCENABLED)) From d73f933c4bb5ca1f327870554f75a87372964162 Mon Sep 17 00:00:00 2001 From: ERROR Date: Tue, 4 Jan 2022 06:12:56 +0700 Subject: [PATCH 169/262] Support std::array in Golang (#2045) Support std::array in Golang Closes #2045 --- Examples/test-suite/cpp11_std_array.i | 2 +- .../test-suite/go/cpp11_std_array_runme.go | 68 +++++++++++++++++++ Lib/go/std_array.i | 43 ++++++++++++ 3 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/go/cpp11_std_array_runme.go create mode 100644 Lib/go/std_array.i diff --git a/Examples/test-suite/cpp11_std_array.i b/Examples/test-suite/cpp11_std_array.i index 3d4771551..9dc11ce9e 100644 --- a/Examples/test-suite/cpp11_std_array.i +++ b/Examples/test-suite/cpp11_std_array.i @@ -1,6 +1,6 @@ %module cpp11_std_array -#if defined(SWIGPYTHON) || defined(SWIGRUBY) || defined(SWIGJAVA) || defined(SWIGCSHARP) +#if defined(SWIGPYTHON) || defined(SWIGRUBY) || defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGGO) %{ #include diff --git a/Examples/test-suite/go/cpp11_std_array_runme.go b/Examples/test-suite/go/cpp11_std_array_runme.go new file mode 100644 index 000000000..97b5df2ec --- /dev/null +++ b/Examples/test-suite/go/cpp11_std_array_runme.go @@ -0,0 +1,68 @@ +package main + +import ( + "fmt" + "swigtests/cpp11_std_array" +) + +func CompareContainers(actual cpp11_std_array.ArrayInt6, expected [6]int) error { + if int(actual.Size()) != len(expected) { + return fmt.Errorf("Sizes are different: %d %d", actual.Size(), len(expected)) + } + for i := 0; i < int(actual.Size()); i++ { + actualValue := actual.Get(i) + expectedValue := expected[i] + if actualValue != expectedValue { + return fmt.Errorf("Value is wrong for element %d. Expected %d got: %d", i, expectedValue, actualValue) + } + } + if actual.IsEmpty() { + return fmt.Errorf("ai should not be empty") + } + return nil +} + +func main() { + ai := cpp11_std_array.NewArrayInt6() + ps := [6]int{0, 0, 0, 0, 0, 0} + CompareContainers(ai, ps) + + vals := [6]int{10, 20, 30, 40, 50, 60} + for i := 0; i < len(vals); i++ { + ai.Set(i, vals[i]) + } + CompareContainers(ai, vals); + + // Check return + vals = [6]int{-2, -1, 0, 0, 1, 2} + CompareContainers(cpp11_std_array.ArrayOutVal(), vals); + CompareContainers(cpp11_std_array.ArrayOutConstRef(), vals); + CompareContainers(cpp11_std_array.ArrayOutRef(), vals); + CompareContainers(cpp11_std_array.ArrayOutPtr(), vals); + + // Check passing arguments + vals = [6]int{9, 8, 7, 6, 5, 4} + valsArrayInt6 := cpp11_std_array.NewArrayInt6() + for i := 0; i < len(vals); i++ { + valsArrayInt6.Set(i, vals[i]) + } + + ai = cpp11_std_array.ArrayInVal(valsArrayInt6); + CompareContainers(ai, vals); + + ai = cpp11_std_array.ArrayInConstRef(valsArrayInt6); + CompareContainers(ai, vals); + + ai = cpp11_std_array.NewArrayInt6(valsArrayInt6); + cpp11_std_array.ArrayInRef(ai); + CompareContainers(ai, vals); + + ai = cpp11_std_array.NewArrayInt6(valsArrayInt6); + cpp11_std_array.ArrayInPtr(ai); + CompareContainers(ai, vals); + + // Fill + ai.Fill(111) + vals = [6]int{111, 111, 111, 111, 111, 111} + CompareContainers(ai, vals); +} diff --git a/Lib/go/std_array.i b/Lib/go/std_array.i new file mode 100644 index 000000000..36c790e3c --- /dev/null +++ b/Lib/go/std_array.i @@ -0,0 +1,43 @@ +/* ----------------------------------------------------------------------------- + * std_array.i + * ----------------------------------------------------------------------------- */ + +%include + +namespace std { + + template class array { + public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef T value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + + array(); + array(const array& other); + + size_type size() const; + %rename(isEmpty) empty; + bool empty() const; + void fill(const T& u); + %extend { + const_reference get(int i) throw (std::out_of_range) { + int size = int(self->size()); + if (i>=0 && isize()); + if (i>=0 && i Date: Sat, 8 Jan 2022 16:29:18 +0000 Subject: [PATCH 170/262] Add recent change to changes file --- CHANGES.current | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index fc56246c6..6632f0126 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,11 +7,17 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2022-01-04: juierror + [Go] #2045 Add support for std::array in std_array.i. + 2021-12-18: olly [PHP] Add PHP keyword 'readonly' (added in 8.1) to the list SWIG knows to automatically rename. This keyword is special in that PHP allows it to be used as a function (or method) name. +2021-12-07: vstinner + [Python] #2116 Python 3.11 support: use Py_SET_TYPE() + 2021-12-05: rwf1 [Octave] #2020 #1893 Add support for Octave 6 up to and including 6.4. Also add support for compiling with -Bsymbolic which is used by default From 0a400f5230818c7a1245d05dd87db45c422cc3db Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 8 Jan 2022 19:22:49 +0000 Subject: [PATCH 171/262] Building distribution fixes and pcre version display [skip-ci] --- Tools/mkdist.py | 12 ++++++------ Tools/mkwindows.sh | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Tools/mkdist.py b/Tools/mkdist.py index 4fba4701d..3d631607a 100755 --- a/Tools/mkdist.py +++ b/Tools/mkdist.py @@ -42,18 +42,18 @@ if dirname.lower() != dirname: sys.exit(3) # If directory and tarball exist, remove it -print("Removing " + dirname) if check_dir_exists(dirpath): + print("Removing " + dirpath) run_command("rm", "-rf", dirpath) -print("Removing " + dirname + ".tar if exists") filename = dirpath + ".tar" if check_file_exists(filename): + print("Removing " + filename) run_command("rm", "-rf", filename) -print("Removing " + dirname + ".tar.gz if exists") filename += ".gz" if check_file_exists(filename): + print("Removing " + filename) run_command("rm", "-rf", filename) # Grab the code from git @@ -89,10 +89,10 @@ if not skip_checks: print("Tagging release") tag = "v" + version -force = "-f " if force_tag else "" +force = "-f" if force_tag else "" command = ["git", "tag", "-a", "-m", "'Release version " + version + "'"] -force and command.extend(force, tag) -not force and command.append(tag) +force and command.append(force) +command.append(tag) run_command(*command) == 0 or failed() outdir = dirname + "/" diff --git a/Tools/mkwindows.sh b/Tools/mkwindows.sh index e6ae84350..5e4d2f0fd 100755 --- a/Tools/mkwindows.sh +++ b/Tools/mkwindows.sh @@ -115,8 +115,9 @@ if test -f "$tarball"; then ./configure $extraconfigureoptions --without-alllang echo "Compiling (quietly)..." make > build.log - echo "Simple check to see if swig.exe runs..." + echo "Simple check to see if swig.exe runs and show versions..." env LD_LIBRARY_PATH= PATH= $wine ./swig.exe -version || exit 1 + env LD_LIBRARY_PATH= PATH= $wine ./swig.exe -pcreversion || exit 1 echo "Simple check to see if ccache-swig.exe runs..." env LD_LIBRARY_PATH= PATH= $wine ./CCache/ccache-swig.exe -V || exit 1 echo "Creating $swigwinbasename.zip..." From b98c78441f996fe911c360264d9e60df7fc96d26 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 10 Jan 2022 20:13:16 +0000 Subject: [PATCH 172/262] GHA debug via ssh info --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d328befb0..c4212a42c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -332,6 +332,10 @@ jobs: with: key: ${{ matrix.os || 'ubuntu-20.04' }}-${{ matrix.compiler || 'gcc' }}${{ matrix.GCC }} +# Uncomment to debug via ssh, see https://github.com/mxschmitt/action-tmate +# - name: Setup tmate session +# uses: mxschmitt/action-tmate@v3 + - name: Install Dependencies run: | set -x From 761099720966c2d6701a1dc1473e918de3571665 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 9 Aug 2021 13:13:17 +0200 Subject: [PATCH 173/262] Stop using Travis CI which doesn't work any longer Unfortunately Travis CI can't be used for building open source projects any longer in practice, as extra credits must be manually requested every time from Travis support, which is just infeasible, as this would need to be done every couple of days if not more often, and support reply time is anything from a couple of days to more than a month. So stop even trying to use it, as it doesn't work anyhow, and switch to using GitHub Actions only. Closes #2067 --- .travis.yml | 499 ---------------------------------- RELEASENOTES | 1 + Tools/brew-install | 25 -- Tools/travis-linux-install.sh | 11 - Tools/travis-osx-install.sh | 41 --- 5 files changed, 1 insertion(+), 576 deletions(-) delete mode 100644 .travis.yml delete mode 100755 Tools/brew-install delete mode 100755 Tools/travis-linux-install.sh delete mode 100755 Tools/travis-osx-install.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c11479fed..000000000 --- a/.travis.yml +++ /dev/null @@ -1,499 +0,0 @@ -language: cpp -matrix: - include: - - compiler: clang - os: linux - env: SWIGLANG= - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG= - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG= BUILDSYSTEM=cmake - dist: xenial - - os: linux - env: SWIGLANG= GCC=4.4 - dist: xenial - - os: linux - env: SWIGLANG= GCC=4.6 - dist: xenial - - os: linux - env: SWIGLANG= GCC=4.7 - dist: xenial - - os: linux - env: SWIGLANG= GCC=4.8 - dist: xenial - - os: linux - env: SWIGLANG= GCC=4.9 - dist: xenial - - os: linux - env: SWIGLANG= GCC=6 - dist: xenial - - os: linux - env: SWIGLANG= GCC=7 - dist: xenial - - os: linux - env: SWIGLANG= GCC=8 - dist: xenial - - os: linux - env: SWIGLANG= GCC=9 - dist: xenial - - os: linux - env: SWIGLANG= GCC=10 - dist: focal - - compiler: gcc - os: linux - env: SWIGLANG=csharp - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=d VER=2.066.0 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=d VER=2.086.1 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=go VER=1.3 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=go VER=1.8 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=go VER=1.12 CSTD=gnu99 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=go VER=1.16 CSTD=gnu99 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=guile - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=java - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=javascript ENGINE=node VER=6 CPP11=1 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=javascript ENGINE=node VER=8 CPP11=1 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=javascript ENGINE=node VER=10 CPP11=1 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=javascript ENGINE=node VER=12 CPP11=1 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=javascript ENGINE=node VER=14 CPP11=1 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=javascript ENGINE=node VER=16 CPP14=1 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=javascript ENGINE=jsc - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=javascript ENGINE=v8 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=lua - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=lua VER=5.3 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=mzscheme - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=ocaml - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=octave SWIGJOBS=-j2 - dist: xenial # Octave v4.0.0 - - compiler: gcc - os: linux - env: SWIGLANG=octave SWIGJOBS=-j2 CPP11=1 - dist: bionic # Octave v4.2.2 - - compiler: gcc - os: linux - env: SWIGLANG=perl5 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=php VER=7.4 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=php VER=8.0 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=php VER=7.0 CONFIGOPTS=--enable-cpp11-testing CPPSTD=c++11 - dist: bionic - - compiler: gcc - os: linux - env: SWIGLANG=php VER=7.1 CONFIGOPTS=--enable-cpp11-testing CPPSTD=c++11 - dist: bionic - - compiler: gcc - os: linux - env: SWIGLANG=php VER=7.2 CONFIGOPTS=--enable-cpp11-testing CPPSTD=c++11 - dist: bionic - - compiler: gcc - os: linux - env: SWIGLANG=php VER=7.3 CONFIGOPTS=--enable-cpp11-testing CPPSTD=c++11 - dist: bionic - - compiler: gcc - os: linux - env: SWIGLANG=php VER=7.4 CONFIGOPTS=--enable-cpp11-testing CPPSTD=c++11 - dist: bionic - - compiler: gcc - os: linux - env: SWIGLANG=php VER=8.0 CONFIGOPTS=--enable-cpp11-testing CPPSTD=c++11 - dist: bionic - - compiler: gcc - os: linux - env: SWIGLANG=python # 2.7 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=python PY3=3 VER=3.2 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=python PY3=3 VER=3.3 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=python PY3=3 VER=3.4 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=python PY3=3 VER=3.5 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=python PY3=3 VER=3.6 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=python PY3=3 VER=3.7 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=python PY3=3 VER=3.8 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=python PY3=3 VER=3.9 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=python SWIG_FEATURES=-builtin - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=python SWIG_FEATURES="-builtin -O" - dist: xenial - - os: linux - env: SWIGLANG=python SWIG_FEATURES=-builtin GCC=6 CPP11=1 - dist: xenial - - os: linux - env: SWIGLANG=python SWIG_FEATURES=-builtin GCC=6 CPP11=1 PY3=3 VER=3.9 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.4 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.5 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.7 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.8 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.9 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=python SWIG_FEATURES="-builtin -O" PY3=3 VER=3.9 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.9 SWIGOPTPY3= - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=python SWIG_FEATURES=-O - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=python SWIG_FEATURES=-O PY3=3 VER=3.9 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=r - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=ruby VER=1.9 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=ruby VER=2.0 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=ruby VER=2.1 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=ruby VER=2.2 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=ruby VER=2.3 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=ruby VER=2.4 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=ruby VER=2.5 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=ruby VER=2.6 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=ruby VER=2.7 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=ruby VER=3.0 CSTD=c99 - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=scilab - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=tcl - dist: xenial - - os: linux - env: SWIGLANG=csharp CPP11=1 - dist: xenial - - os: linux - env: SWIGLANG=go VER=1.6 CPP11=1 - dist: xenial - - os: linux - env: SWIGLANG=java CPP11=1 - dist: xenial - - os: linux - env: SWIGLANG=python CPP11=1 - dist: xenial - - os: linux - env: SWIGLANG=r CPP11=1 # Note: making 'R CMD SHLIB' use a different compiler is non-trivial - dist: xenial - - os: linux - env: SWIGLANG=ruby CPP11=1 - dist: xenial - - os: linux - env: SWIGLANG=tcl CPP11=1 - dist: xenial - - os: linux - env: SWIGLANG=csharp GCC=6 CPP14=1 - dist: xenial - - os: linux - env: SWIGLANG=go VER=1.6 GCC=6 CPP14=1 - dist: xenial - - os: linux - env: SWIGLANG=java GCC=6 CPP14=1 - dist: xenial - - os: linux - env: SWIGLANG=python GCC=6 CPP14=1 - dist: xenial - - os: linux - env: SWIGLANG=ruby GCC=6 CPP14=1 - dist: xenial - - os: linux - env: SWIGLANG=tcl GCC=6 CPP14=1 - dist: xenial - - os: linux - env: SWIGLANG=java GCC=7 CPP14=1 - dist: xenial - - os: linux - env: SWIGLANG=python GCC=7 CPP14=1 - dist: xenial - - os: linux - env: SWIGLANG=csharp GCC=8 CPP17=1 - dist: xenial - - os: linux - env: SWIGLANG=java GCC=8 CPP17=1 - dist: xenial - - os: linux - env: SWIGLANG=python GCC=8 CPP17=1 PY3=3 VER=3.9 - dist: xenial - - os: linux - env: SWIGLANG=csharp GCC=9 CPP17=1 - dist: xenial - - os: linux - env: SWIGLANG=java GCC=9 CPP17=1 - dist: xenial - - os: linux - env: SWIGLANG=python GCC=9 CPP17=1 PY3=3 VER=3.9 - dist: xenial - - os: linux - arch: s390x - env: SWIGLANG=ruby CPP11=1 - dist: xenial - - compiler: gcc - os: osx - osx_image: xcode12.2 - env: SWIGLANG= - - compiler: clang - os: osx - osx_image: xcode12.2 - env: SWIGLANG= BUILDSYSTEM=cmake - - compiler: clang - os: osx - osx_image: xcode12.2 - env: SWIGLANG= - - compiler: clang - os: osx - osx_image: xcode12.2 - env: SWIGLANG=csharp - - compiler: clang - os: osx - osx_image: xcode12.2 - env: SWIGLANG=go CSTD=gnu99 - - compiler: clang - os: osx - osx_image: xcode12.2 - env: SWIGLANG=guile CSTD=c11 - - compiler: clang - os: osx - osx_image: xcode12.2 - env: SWIGLANG=java - - compiler: clang - os: osx - osx_image: xcode12.2 - env: SWIGLANG=lua -# octave-6.1 not working -# - compiler: clang -# os: osx -# osx_image: xcode12.2 -# env: SWIGLANG=octave SWIGJOBS=-j2 CPP11=1 - - compiler: clang - os: osx - osx_image: xcode12.2 - env: SWIGLANG=perl5 - - compiler: clang - os: osx - osx_image: xcode12.2 - env: SWIGLANG=python - - compiler: clang - os: osx - osx_image: xcode12.2 - env: SWIGLANG=python PY3=3 - - compiler: clang - os: osx - osx_image: xcode12.2 - env: SWIGLANG=ruby - - compiler: clang - os: osx - osx_image: xcode12.2 - env: SWIGLANG=tcl - - compiler: clang - os: osx - osx_image: xcode12.2 - env: SWIGLANG=java CPP17=1 - - compiler: clang - os: osx - osx_image: xcode12.2 - env: SWIGLANG=python PY3=3 CPP17=1 - - allow_failures: - # Newer version of D not yet working/supported - - compiler: gcc - os: linux - env: SWIGLANG=d VER=2.086.1 - dist: xenial - # Experimental languages - - compiler: gcc - os: linux - env: SWIGLANG=mzscheme - dist: xenial - - compiler: gcc - os: linux - env: SWIGLANG=ocaml - dist: xenial - -before_install: - - date -u - - uname -a - - if test "$TRAVIS_OS_NAME" = "linux"; then lscpu; grep "model name" /proc/cpuinfo || echo 'Unknown CPU model'; grep "MemTotal" /proc/meminfo || echo 'Unknown system memory amount'; fi - - if test "$TRAVIS_OS_NAME" = "osx"; then sysctl -a | grep brand_string; fi - # Travis overrides CC environment with compiler predefined values - - if test -n "$GCC"; then export CC="gcc-$GCC" && export CXX="g++-$GCC"; fi -install: - - if test "$TRAVIS_OS_NAME" = "linux"; then source Tools/travis-linux-install.sh; fi - - if test "$TRAVIS_OS_NAME" = "osx"; then source Tools/travis-osx-install.sh; fi - - ls -la $(which $CC) $(which $CXX) && $CC --version && $CXX --version -script: - - if test "$BUILDSYSTEM" = "cmake"; then cmake --version && mkdir -p build/build && cd build/build && CXXFLAGS="-Wall -Wextra -Werror" CFLAGS="-Wall -Wextra -Werror" cmake -DCMAKE_INSTALL_PREFIX=~/.local ../.. && make install && ctest --output-on-failure -V && exit 0; fi - - echo 'Configuring...' && echo -en 'travis_fold:start:script.1\\r' - - if test -n "$CPP11"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++11 $CXXFLAGS" "CFLAGS=-std=c11 $CFLAGS") && export CSTD=c11 && export CPPSTD=c++11; fi - - if test -n "$CPP14"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++14 $CXXFLAGS" "CFLAGS=-std=c11 $CFLAGS") && export CSTD=c11 && export CPPSTD=c++14; fi - - if test -n "$CPP17"; then CONFIGOPTS+=(--enable-cpp11-testing "CXXFLAGS=-std=c++17 $CXXFLAGS" "CFLAGS=-std=c17 $CFLAGS") && export CSTD=c17 && export CPPSTD=c++17; fi - - if test -n "$SWIGLANG"; then CONFIGOPTS+=(--without-alllang --with-$WITHLANG); fi - - echo "${CONFIGOPTS[@]}" - - ./autogen.sh && mkdir -p build/build && cd build/build && ../../configure "${CONFIGOPTS[@]}" - - echo -en 'travis_fold:end:script.1\\r' - - make -s $SWIGJOBS - - ./swig -version && ./swig -pcreversion - - if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-ccache; fi - - if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-errors-test-suite; fi - - echo 'Installing...' && echo -en 'travis_fold:start:script.2\\r' - - if test -z "$SWIGLANG"; then sudo make -s install && swig -version && ccache-swig -V; fi - - echo -en 'travis_fold:end:script.2\\r' - # Stricter compile flags for examples. Various headers and SWIG generated code prevents full use of -pedantic. - - if test -n "$SWIGLANG"; then cflags=$($TRAVIS_BUILD_DIR/Tools/testflags.py --language $SWIGLANG --cflags --std=$CSTD --compiler=$CC) && echo $cflags; fi - - if test -n "$SWIGLANG"; then cxxflags=$($TRAVIS_BUILD_DIR/Tools/testflags.py --language $SWIGLANG --cxxflags --std=$CPPSTD --compiler=$CC) && echo $cxxflags; fi - - if test -n "$SWIGLANG"; then make -s check-$SWIGLANG-version; fi - - if test -n "$SWIGLANG"; then make check-$SWIGLANG-enabled; fi - - if test -n "$SWIGLANG"; then make $SWIGJOBS check-$SWIGLANG-examples CFLAGS="$cflags" CXXFLAGS="$cxxflags"; fi - - if test -n "$SWIGLANG"; then make $SWIGJOBS check-$SWIGLANG-test-suite CFLAGS="$cflags" CXXFLAGS="$cxxflags"; fi - - echo 'Cleaning...' && echo -en 'travis_fold:start:script.3\\r' - # Skip on osx as often fails with: rm: Resource temporarily unavailable - - if test "$TRAVIS_OS_NAME" != "osx"; then make check-maintainer-clean && ../../configure $CONFIGOPTS; fi - - echo -en 'travis_fold:end:script.3\\r' diff --git a/RELEASENOTES b/RELEASENOTES index da60d543f..c05ccc4ec 100644 --- a/RELEASENOTES +++ b/RELEASENOTES @@ -10,6 +10,7 @@ published on the SWIG web site at http://swig.org/release.html. SWIG-4.1.0 summary: - Add PHP 8 support. - PHP wrapping is now done entirely via PHP's C API - no more .php wrapper. +- GitHub Actions is now used instead of Travis CI for continuous integration. SWIG-4.0.2 summary: - A few fixes around doxygen comment handling. diff --git a/Tools/brew-install b/Tools/brew-install deleted file mode 100755 index 39fe22bc2..000000000 --- a/Tools/brew-install +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -# Wrapper around 'brew install' emitting a message every minute if the command is still running. -# This is used on Travis to ensure the install isn't killed when there is no output over a long period (10 minutes). -# Usage: brew-install package, where package is the name of the package for brew to install. - -seconds=0 -minutes=0 -brew install "$@" & -while true; do - ps -p$! 2>& 1>/dev/null - if [ $? = 0 ]; then - if [ $seconds = 60 ]; then - let seconds=0 - let minutes=minutes+1 - echo "brew install $1 still running ($minutes min)" - fi - sleep 1 - let seconds=seconds+1 - else - break - fi -done -wait $! -exit $? diff --git a/Tools/travis-linux-install.sh b/Tools/travis-linux-install.sh deleted file mode 100755 index cb64d57d2..000000000 --- a/Tools/travis-linux-install.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -# Install Linux packages where the version has been overridden in .travis.yml - -lsb_release -a -# find location of current script (only works in bash) -script_dir="$( dirname "${BASH_SOURCE[0]}")" - -# run generic script -RETRY=travis-retry -source "$script_dir"/CI-linux-install.sh diff --git a/Tools/travis-osx-install.sh b/Tools/travis-osx-install.sh deleted file mode 100755 index fc69c6654..000000000 --- a/Tools/travis-osx-install.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -# Install MacOS packages where the version has been overridden in .travis.yml - -set -e # exit on failure (same as -o errexit) - -# Disable 'brew cleanup', just wastes Travis job run time -export HOMEBREW_NO_INSTALL_CLEANUP=1 - -sw_vers -travis_retry brew update -echo "Installed packages..." -travis_retry brew list --versions -# travis_retry brew install pcre # Travis Xcode-7.3 has pcre -# travis_retry brew install boost - -WITHLANG=$SWIGLANG - -case "$SWIGLANG" in - "csharp") - travis_retry brew install mono - ;; - "lua") - travis_retry brew install lua - ;; - "octave") - travis_retry Tools/brew-install octave - ;; - "perl5") - travis_retry Tools/brew-install perl - ;; - "python") - WITHLANG=$SWIGLANG$PY3 - ;; - "tcl") - travis_retry Tools/brew-install --cask tcl - ;; -esac - -# Workaround for https://github.com/travis-ci/travis-ci/issues/6522 -set +e # turn off exit on failure (same as +o errexit) From cf8788c411d8096104628dfd5901620b8ea3a315 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 11 Jan 2022 15:11:04 +0000 Subject: [PATCH 174/262] Update Python tests to not use flatstaticmethod access Use Python class staticmethod syntax to access C++ static member functions, such as Klass.memberfunction, instead of Klass_memberfunction. Examples and test-suite changes in preparation for issue #2137. --- Examples/python/import/runme.py | 8 +++---- Examples/python/import_template/runme.py | 8 +++---- Examples/test-suite/python/autodoc_runme.py | 22 ------------------- Examples/test-suite/python/contract_runme.py | 6 ++--- .../test-suite/python/default_args_runme.py | 2 +- .../python/director_abstract_runme.py | 2 +- .../test-suite/python/director_basic_runme.py | 8 +++---- .../python/director_nested_runme.py | 2 +- .../test-suite/python/kwargs_feature_runme.py | 8 +++---- .../python/li_boost_shared_ptr_runme.py | 2 +- .../test-suite/python/li_factory_runme.py | 4 ++-- .../python/li_std_auto_ptr_runme.py | 6 ++--- .../python/operator_overload_runme.py | 2 +- .../python/overload_simple_runme.py | 12 +++++----- .../python/overload_template_runme.py | 2 +- .../python_overload_simple_cast_runme.py | 12 +++++----- Examples/test-suite/python/refcount_runme.py | 6 ++--- .../python/return_const_value_runme.py | 4 ++-- .../python/template_static_runme.py | 2 +- .../python/typemap_out_optimal_runme.py | 2 +- .../test-suite/python/virtual_poly_runme.py | 4 ++-- Examples/test-suite/python/voidtest_runme.py | 2 +- 22 files changed, 52 insertions(+), 74 deletions(-) diff --git a/Examples/python/import/runme.py b/Examples/python/import/runme.py index afa21a2b3..7970dec26 100644 --- a/Examples/python/import/runme.py +++ b/Examples/python/import/runme.py @@ -84,14 +84,14 @@ x.B() print("\nTesting some dynamic casts\n") x = d.toBase() -y = foo.Foo_fromBase(x) +y = foo.Foo.fromBase(x) print(" Spam -> Base -> Foo : {} swig".format("bad" if y else "good")) -y = bar.Bar_fromBase(x) +y = bar.Bar.fromBase(x) print(" Spam -> Base -> Bar : {} swig".format("good" if y else "bad")) -y = spam.Spam_fromBase(x) +y = spam.Spam.fromBase(x) print(" Spam -> Base -> Spam : {} swig".format("good" if y else "bad")) -y = spam.Spam_fromBase(b) +y = spam.Spam.fromBase(b) print(" Foo -> Spam : {} swig".format("bad" if y else "good")) diff --git a/Examples/python/import_template/runme.py b/Examples/python/import_template/runme.py index b14f8d35e..74a918426 100644 --- a/Examples/python/import_template/runme.py +++ b/Examples/python/import_template/runme.py @@ -84,14 +84,14 @@ x.B() print("\nTesting some dynamic casts\n") x = d.toBase() -y = foo.intFoo_fromBase(x) +y = foo.intFoo.fromBase(x) print(" Spam -> Base -> Foo : {} swig".format("bad" if y else "good")) -y = bar.intBar_fromBase(x) +y = bar.intBar.fromBase(x) print(" Spam -> Base -> Bar : {} swig".format("good" if y else "bad")) -y = spam.intSpam_fromBase(x) +y = spam.intSpam.fromBase(x) print(" Spam -> Base -> Spam : {} swig".format("good" if y else "bad")) -y = spam.intSpam_fromBase(b) +y = spam.intSpam.fromBase(b) print(" Foo -> Spam : {} swig".format("bad" if y else "good")) diff --git a/Examples/test-suite/python/autodoc_runme.py b/Examples/test-suite/python/autodoc_runme.py index 7bc918644..960458584 100644 --- a/Examples/test-suite/python/autodoc_runme.py +++ b/Examples/test-suite/python/autodoc_runme.py @@ -65,14 +65,10 @@ check(inspect.getdoc(A.func0static), "func0static(e, arg2, hello, f=2) -> int") check(inspect.getdoc(_autodoc.A_func0static), "A_func0static(e, arg2, hello, f=2) -> int") -check(inspect.getdoc(A_func0static), - "A_func0static(e, arg2, hello, f=2) -> int") check(inspect.getdoc(A.func1static), "func1static(A e, short arg2, Tuple hello, double f=2) -> int") check(inspect.getdoc(_autodoc.A_func1static), "A_func1static(A e, short arg2, Tuple hello, double f=2) -> int") -check(inspect.getdoc(A_func1static), - "A_func1static(A e, short arg2, Tuple hello, double f=2) -> int") check(inspect.getdoc(A.func2static), "func2static(e, arg2, hello, f=2) -> int\n" "\n" @@ -91,15 +87,6 @@ check(inspect.getdoc(_autodoc.A_func2static), "arg2: short\n" "hello: int tuple[2]\n" "f: double") -check(inspect.getdoc(A_func2static), - "A_func2static(e, arg2, hello, f=2) -> int\n" - "\n" - "Parameters\n" - "----------\n" - "e: A *\n" - "arg2: short\n" - "hello: int tuple[2]\n" - "f: double") check(inspect.getdoc(A.func3static), "func3static(A e, short arg2, Tuple hello, double f=2) -> int\n" "\n" @@ -118,15 +105,6 @@ check(inspect.getdoc(_autodoc.A_func3static), "arg2: short\n" "hello: int tuple[2]\n" "f: double") -check(inspect.getdoc(A_func3static), - "A_func3static(A e, short arg2, Tuple hello, double f=2) -> int\n" - "\n" - "Parameters\n" - "----------\n" - "e: A *\n" - "arg2: short\n" - "hello: int tuple[2]\n" - "f: double") check(inspect.getdoc(A.variable_a), "variable_a" diff --git a/Examples/test-suite/python/contract_runme.py b/Examples/test-suite/python/contract_runme.py index b6bab3a09..3194b6ac7 100644 --- a/Examples/test-suite/python/contract_runme.py +++ b/Examples/test-suite/python/contract_runme.py @@ -58,15 +58,15 @@ try: except RuntimeError: pass -contract.Foo_stest_prepost(4, 0) +contract.Foo.stest_prepost(4, 0) try: - contract.Foo_stest_prepost(-4, 2) + contract.Foo.stest_prepost(-4, 2) raise Exception("Failed! Static method preassertion") except RuntimeError: pass try: - contract.Foo_stest_prepost(4, -10) + contract.Foo.stest_prepost(4, -10) raise Exception("Failed! Static method posteassertion") except RuntimeError: pass diff --git a/Examples/test-suite/python/default_args_runme.py b/Examples/test-suite/python/default_args_runme.py index 0ce47ab79..b8077cc28 100644 --- a/Examples/test-suite/python/default_args_runme.py +++ b/Examples/test-suite/python/default_args_runme.py @@ -12,7 +12,7 @@ def run(module_name): de.accelerate() de.accelerate(default_args.EnumClass.SLOW) - if default_args.Statics_staticMethod() != 60: + if default_args.Statics.staticMethod() != 60: raise RuntimeError if default_args.cfunc1(1) != 2: diff --git a/Examples/test-suite/python/director_abstract_runme.py b/Examples/test-suite/python/director_abstract_runme.py index c8c4b36dc..fbc54808e 100644 --- a/Examples/test-suite/python/director_abstract_runme.py +++ b/Examples/test-suite/python/director_abstract_runme.py @@ -37,7 +37,7 @@ class MyExample3(director_abstract.Example3_i): return b me1 = MyExample1() -if director_abstract.Example1_get_color(me1, 1, 2, 3) != 1: +if director_abstract.Example1.get_color(me1, 1, 2, 3) != 1: raise RuntimeError me2 = MyExample2(1, 2) diff --git a/Examples/test-suite/python/director_basic_runme.py b/Examples/test-suite/python/director_basic_runme.py index 79cd0e2eb..2d07c3ad5 100644 --- a/Examples/test-suite/python/director_basic_runme.py +++ b/Examples/test-suite/python/director_basic_runme.py @@ -44,8 +44,8 @@ b = director_basic.Bar(3) d = director_basic.MyClass() c = PyClass() -cc = director_basic.MyClass_get_self(c) -dd = director_basic.MyClass_get_self(d) +cc = director_basic.MyClass.get_self(c) +dd = director_basic.MyClass.get_self(d) bc = cc.cmethod(b) bd = dd.cmethod(b) @@ -86,8 +86,8 @@ for i in range(0, 100): pymult = PyMulti() -p1 = director_basic.Foo_get_self(pymult) -p2 = director_basic.MyClass_get_self(pymult) +p1 = director_basic.Foo.get_self(pymult) +p2 = director_basic.MyClass.get_self(pymult) p1.ping() p2.vmethod(bc) diff --git a/Examples/test-suite/python/director_nested_runme.py b/Examples/test-suite/python/director_nested_runme.py index b2c4b0d40..24216f9dd 100644 --- a/Examples/test-suite/python/director_nested_runme.py +++ b/Examples/test-suite/python/director_nested_runme.py @@ -54,7 +54,7 @@ class C(FooBar_int): pass cc = C() -c = FooBar_int_get_self(cc) +c = FooBar_int.get_self(cc) c.advance() if c.get_name() != "FooBar::get_name hello": diff --git a/Examples/test-suite/python/kwargs_feature_runme.py b/Examples/test-suite/python/kwargs_feature_runme.py index 387658ec3..d07525ffc 100644 --- a/Examples/test-suite/python/kwargs_feature_runme.py +++ b/Examples/test-suite/python/kwargs_feature_runme.py @@ -15,13 +15,13 @@ f = Foo(b=2, a=1) if f.foo(b=1, a=2) != 3: raise RuntimeError -if Foo_statfoo(b=2) != 3: +if Foo.statfoo(b=2) != 3: raise RuntimeError if f.efoo(b=2) != 3: raise RuntimeError -if Foo_sfoo(b=2) != 3: +if Foo.sfoo(b=2) != 3: raise RuntimeError @@ -31,13 +31,13 @@ b = BarInt(b=2, a=1) if b.bar(b=1, a=2) != 3: raise RuntimeError -if BarInt_statbar(b=2) != 3: +if BarInt.statbar(b=2) != 3: raise RuntimeError if b.ebar(b=2) != 3: raise RuntimeError -if BarInt_sbar(b=2) != 3: +if BarInt.sbar(b=2) != 3: raise RuntimeError diff --git a/Examples/test-suite/python/li_boost_shared_ptr_runme.py b/Examples/test-suite/python/li_boost_shared_ptr_runme.py index ecda7fdb1..2e241d590 100644 --- a/Examples/test-suite/python/li_boost_shared_ptr_runme.py +++ b/Examples/test-suite/python/li_boost_shared_ptr_runme.py @@ -20,7 +20,7 @@ class li_boost_shared_ptr_runme: self.runtest() # Expect 1 instance - the one global variable (GlobalValue) - if (li_boost_shared_ptr.Klass_getTotal_count() != 1): + if (li_boost_shared_ptr.Klass.getTotal_count() != 1): raise RuntimeError("Klass.total_count=%s" % li_boost_shared_ptr.Klass.getTotal_count()) diff --git a/Examples/test-suite/python/li_factory_runme.py b/Examples/test-suite/python/li_factory_runme.py index fb2c81e45..ce0e3caef 100644 --- a/Examples/test-suite/python/li_factory_runme.py +++ b/Examples/test-suite/python/li_factory_runme.py @@ -1,11 +1,11 @@ from li_factory import * -circle = Geometry_create(Geometry.CIRCLE) +circle = Geometry.create(Geometry.CIRCLE) r = circle.radius() if (r != 1.5): raise RuntimeError -point = Geometry_create(Geometry.POINT) +point = Geometry.create(Geometry.POINT) w = point.width() if (w != 1.0): raise RuntimeError diff --git a/Examples/test-suite/python/li_std_auto_ptr_runme.py b/Examples/test-suite/python/li_std_auto_ptr_runme.py index 6d2479f87..d62224ff6 100644 --- a/Examples/test-suite/python/li_std_auto_ptr_runme.py +++ b/Examples/test-suite/python/li_std_auto_ptr_runme.py @@ -2,16 +2,16 @@ from li_std_auto_ptr import * k1 = makeKlassAutoPtr("first") k2 = makeKlassAutoPtr("second") -if Klass_getTotal_count() != 2: +if Klass.getTotal_count() != 2: raise "number of objects should be 2" del k1 -if Klass_getTotal_count() != 1: +if Klass.getTotal_count() != 1: raise "number of objects should be 1" if k2.getLabel() != "second": raise "wrong object label" del k2 -if Klass_getTotal_count() != 0: +if Klass.getTotal_count() != 0: raise "no objects should be left" diff --git a/Examples/test-suite/python/operator_overload_runme.py b/Examples/test-suite/python/operator_overload_runme.py index 31c49058e..cd565f619 100644 --- a/Examples/test-suite/python/operator_overload_runme.py +++ b/Examples/test-suite/python/operator_overload_runme.py @@ -1,7 +1,7 @@ from operator_overload import * # first check all the operators are implemented correctly from pure C++ code -Op_sanity_check() +Op.sanity_check() pop = Op(6)/Op(3) diff --git a/Examples/test-suite/python/overload_simple_runme.py b/Examples/test-suite/python/overload_simple_runme.py index 8ad813b86..56763828d 100644 --- a/Examples/test-suite/python/overload_simple_runme.py +++ b/Examples/test-suite/python/overload_simple_runme.py @@ -43,22 +43,22 @@ if s.foo(b) != "foo:Bar *": if s.foo(v) != "foo:void *": raise RuntimeError("Spam::foo(void *)") -if Spam_bar(3) != "bar:int": +if Spam.bar(3) != "bar:int": raise RuntimeError("Spam::bar(int)") -if Spam_bar(3.0) != "bar:double": +if Spam.bar(3.0) != "bar:double": raise RuntimeError("Spam::bar(double)") -if Spam_bar("hello") != "bar:char *": +if Spam.bar("hello") != "bar:char *": raise RuntimeError("Spam::bar(char *)") -if Spam_bar(f) != "bar:Foo *": +if Spam.bar(f) != "bar:Foo *": raise RuntimeError("Spam::bar(Foo *)") -if Spam_bar(b) != "bar:Bar *": +if Spam.bar(b) != "bar:Bar *": raise RuntimeError("Spam::bar(Bar *)") -if Spam_bar(v) != "bar:void *": +if Spam.bar(v) != "bar:void *": raise RuntimeError("Spam::bar(void *)") # Test constructors diff --git a/Examples/test-suite/python/overload_template_runme.py b/Examples/test-suite/python/overload_template_runme.py index a484d8f0e..8bd105add 100644 --- a/Examples/test-suite/python/overload_template_runme.py +++ b/Examples/test-suite/python/overload_template_runme.py @@ -140,6 +140,6 @@ if (nsoverload() != 1050): raise RuntimeError(("nsoverload(const char *)")) -A_foo(1) +A.foo(1) b = B() b.foo(1) diff --git a/Examples/test-suite/python/python_overload_simple_cast_runme.py b/Examples/test-suite/python/python_overload_simple_cast_runme.py index 7a0174af8..2aee5bb53 100644 --- a/Examples/test-suite/python/python_overload_simple_cast_runme.py +++ b/Examples/test-suite/python/python_overload_simple_cast_runme.py @@ -115,22 +115,22 @@ if s.foo(b) != "foo:Bar *": if s.foo(v) != "foo:void *": raise RuntimeError("Spam::foo(void *)") -if Spam_bar(3) != "bar:int": +if Spam.bar(3) != "bar:int": raise RuntimeError("Spam::bar(int)") -if Spam_bar(3.0) != "bar:double": +if Spam.bar(3.0) != "bar:double": raise RuntimeError("Spam::bar(double)") -if Spam_bar("hello") != "bar:char *": +if Spam.bar("hello") != "bar:char *": raise RuntimeError("Spam::bar(char *)") -if Spam_bar(f) != "bar:Foo *": +if Spam.bar(f) != "bar:Foo *": raise RuntimeError("Spam::bar(Foo *)") -if Spam_bar(b) != "bar:Bar *": +if Spam.bar(b) != "bar:Bar *": raise RuntimeError("Spam::bar(Bar *)") -if Spam_bar(v) != "bar:void *": +if Spam.bar(v) != "bar:void *": raise RuntimeError("Spam::bar(void *)") # Test constructors diff --git a/Examples/test-suite/python/refcount_runme.py b/Examples/test-suite/python/refcount_runme.py index 2cab6a77e..5bea25fa1 100644 --- a/Examples/test-suite/python/refcount_runme.py +++ b/Examples/test-suite/python/refcount_runme.py @@ -5,7 +5,7 @@ from refcount import * a = A3() b1 = B(a) -b2 = B_create(a) +b2 = B.create(a) if a.ref_count() != 3: @@ -13,7 +13,7 @@ if a.ref_count() != 3: rca = b2.get_rca() -b3 = B_create(rca) +b3 = B.create(rca) if a.ref_count() != 5: raise RuntimeError("Count = %d" % a.ref_count()) @@ -38,7 +38,7 @@ b5 = global_create(a) if b5.ref_count() != 1: raise RuntimeError -b6 = Factory_create(a) +b6 = Factory.create(a) if b6.ref_count() != 1: raise RuntimeError diff --git a/Examples/test-suite/python/return_const_value_runme.py b/Examples/test-suite/python/return_const_value_runme.py index 809eed97a..8cbac125c 100644 --- a/Examples/test-suite/python/return_const_value_runme.py +++ b/Examples/test-suite/python/return_const_value_runme.py @@ -1,10 +1,10 @@ import return_const_value import sys -p = return_const_value.Foo_ptr_getPtr() +p = return_const_value.Foo_ptr.getPtr() if (p.getVal() != 17): raise RuntimeError("Runtime test1 failed. p.getVal()={}".format(p.getVal())) -p = return_const_value.Foo_ptr_getConstPtr() +p = return_const_value.Foo_ptr.getConstPtr() if (p.getVal() != 17): raise RuntimeError("Runtime test2 failed. p.getVal()={}".format(p.getVal())) diff --git a/Examples/test-suite/python/template_static_runme.py b/Examples/test-suite/python/template_static_runme.py index c87a52439..84da28438 100644 --- a/Examples/test-suite/python/template_static_runme.py +++ b/Examples/test-suite/python/template_static_runme.py @@ -1,3 +1,3 @@ from template_static import * -Foo_bar_double(1) +Foo.bar_double(1) diff --git a/Examples/test-suite/python/typemap_out_optimal_runme.py b/Examples/test-suite/python/typemap_out_optimal_runme.py index c7a34308e..c325ece55 100644 --- a/Examples/test-suite/python/typemap_out_optimal_runme.py +++ b/Examples/test-suite/python/typemap_out_optimal_runme.py @@ -1,4 +1,4 @@ from typemap_out_optimal import * cvar.XX_debug = False -x = XX_create() +x = XX.create() diff --git a/Examples/test-suite/python/virtual_poly_runme.py b/Examples/test-suite/python/virtual_poly_runme.py index 0df6271ef..6708b6f99 100644 --- a/Examples/test-suite/python/virtual_poly_runme.py +++ b/Examples/test-suite/python/virtual_poly_runme.py @@ -29,10 +29,10 @@ if d.get() != dr.get(): # # 'narrowing' also works # -ddc = virtual_poly.NDouble_narrow(d.nnumber()) +ddc = virtual_poly.NDouble.narrow(d.nnumber()) if d.get() != ddc.get(): raise RuntimeError -dic = virtual_poly.NInt_narrow(i.nnumber()) +dic = virtual_poly.NInt.narrow(i.nnumber()) if i.get() != dic.get(): raise RuntimeError diff --git a/Examples/test-suite/python/voidtest_runme.py b/Examples/test-suite/python/voidtest_runme.py index b16cacf00..dd25b4c25 100644 --- a/Examples/test-suite/python/voidtest_runme.py +++ b/Examples/test-suite/python/voidtest_runme.py @@ -4,7 +4,7 @@ voidtest.globalfunc() f = voidtest.Foo() f.memberfunc() -voidtest.Foo_staticmemberfunc() +voidtest.Foo.staticmemberfunc() def fvoid(): From 627f7214dbe6d21487f1ce6800c6b433be92518e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 11 Jan 2022 23:33:22 +0000 Subject: [PATCH 175/262] [Python] Add missing Python kwargs builtin support Accept keyword arguments accessing C++ static member functions when using -builtin and kwargs feature and Python class staticmethod syntax. The missing keyword argument support was only when using the class staticmethod syntax, not when using the flat static method syntax. --- CHANGES.current | 7 +++++++ Examples/test-suite/kwargs_feature.i | 1 + Examples/test-suite/python/kwargs_feature_runme.py | 3 +++ Source/Modules/python.cxx | 4 ++-- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 6632f0126..a5a7b8c34 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,13 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2022-01-11: wsfulton + [Python] Accept keyword arguments accessing static member functions when + using -builtin and kwargs feature and Python class staticmethod syntax. + The missing keyword argument support was only when using the + class staticmethod syntax, such as Klass.memberfunction, and not when + using the flat static method syntax, such as Klass_memberfunction. + 2022-01-04: juierror [Go] #2045 Add support for std::array in std_array.i. diff --git a/Examples/test-suite/kwargs_feature.i b/Examples/test-suite/kwargs_feature.i index dd5b2638d..6db4d407b 100644 --- a/Examples/test-suite/kwargs_feature.i +++ b/Examples/test-suite/kwargs_feature.i @@ -27,6 +27,7 @@ virtual int foo(int a = 1, int b = 0) {return a + b; } static int statfoo(int a = 1, int b = 0) {return a + b; } + static int statfoo_onearg(int x = 10) {return x + x; } static Foo *create(int a = 1, int b = 0) { diff --git a/Examples/test-suite/python/kwargs_feature_runme.py b/Examples/test-suite/python/kwargs_feature_runme.py index d07525ffc..677c9ebd8 100644 --- a/Examples/test-suite/python/kwargs_feature_runme.py +++ b/Examples/test-suite/python/kwargs_feature_runme.py @@ -18,6 +18,9 @@ if f.foo(b=1, a=2) != 3: if Foo.statfoo(b=2) != 3: raise RuntimeError +if Foo.statfoo_onearg(x=4) != 8: + raise RuntimeError + if f.efoo(b=2) != 3: raise RuntimeError diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 8682e6917..9046edcfb 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -4727,6 +4727,7 @@ public: Swig_restore(n); } + int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0; if (builtin && in_class) { if ((GetFlagAttr(n, "feature:extend") || checkAttribute(n, "access", "public")) && !Getattr(class_members, symname)) { @@ -4741,7 +4742,7 @@ public: else if (funpack && argcount == 1) Append(pyflags, "METH_O"); else - Append(pyflags, "METH_VARARGS"); + Append(pyflags, kw ? "METH_VARARGS|METH_KEYWORDS" : "METH_VARARGS"); // Cast via void(*)(void) to suppress GCC -Wcast-function-type warning. // Python should always call the function correctly, but the Python C // API requires us to store it in function pointer of a different type. @@ -4767,7 +4768,6 @@ public: String *staticfunc_name = NewString(fastproxy ? "_swig_new_static_method" : "staticmethod"); bool fast = (fastproxy && !have_addtofunc(n)) || Getattr(n, "feature:callback"); if (!fast || olddefs) { - int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0; String *parms = make_pyParmList(n, false, false, kw); String *callParms = make_pyParmList(n, false, true, kw); Printv(f_shadow, "\n", tab4, "@staticmethod", NIL); From 3aa302c08f609ad15a602b32a8c0124eb48861f9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 14 Jan 2022 20:23:43 +0000 Subject: [PATCH 176/262] %callback and Python class access for C++ static member functions fixes Fix access to C++ static member functions using Python class staticmethod syntax, such as Klass.memberfunction instead of Klass_memberfunction, when using -fastproxy and -builtin in combination with %callback. The docstring containing the callback pointers were not being patched during module initialisation. --- CHANGES.current | 6 ++++++ Examples/test-suite/python/callback_runme.py | 13 +++++++----- Lib/python/pyinit.swg | 13 +++++------- Source/Modules/python.cxx | 21 ++++++++++++++++++-- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index a5a7b8c34..b6c21643b 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,12 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2022-01-14: wsfulton + [Python] Fix %callback and specifying the callback function as a + static member function using Python staticmethod syntax, such as + Klass.memberfunction instead of Klass_memberfunction when using + -builtin and -fastproxy. + 2022-01-11: wsfulton [Python] Accept keyword arguments accessing static member functions when using -builtin and kwargs feature and Python class staticmethod syntax. diff --git a/Examples/test-suite/python/callback_runme.py b/Examples/test-suite/python/callback_runme.py index de8a372f6..19f61c96b 100644 --- a/Examples/test-suite/python/callback_runme.py +++ b/Examples/test-suite/python/callback_runme.py @@ -1,10 +1,14 @@ import _callback from callback import * +# callbacks are implemented by modifying docstrings, useful for debugging: +# print("A_bar doc: {}".format(A_bar.__doc__)) +# print("A.bar doc: {}".format(A.bar.__doc__)) + if foo(2) != 2: raise RuntimeError -if A_bar(2) != 4: +if A.bar(2) != 4: raise RuntimeError if foobar(3, _callback.foo) != foo(3): @@ -13,13 +17,12 @@ if foobar(3, _callback.foo) != foo(3): if foobar(3, foo) != foo(3): raise RuntimeError -# Needs some more work for -builtin -# if foobar(3, A.bar) != A.bar(3): -# raise RuntimeError - if foobar(3, A_bar) != A_bar(3): raise RuntimeError +if foobar(3, A.bar) != A.bar(3): + raise RuntimeError + if foobar(3, foof) != foof(3): raise RuntimeError diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index dfd3940ec..b530fba15 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -58,15 +58,12 @@ SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { } } -/* -----------------------------------------------------------------------------*/ -/* Fix SwigMethods to carry the callback ptrs when needed */ -/* -----------------------------------------------------------------------------*/ +/* ----------------------------------------------------------------------------- + * Patch %callback methods' docstrings to hold the callback ptrs + * -----------------------------------------------------------------------------*/ SWIGINTERN void -SWIG_Python_FixMethods(PyMethodDef *methods, - swig_const_info *const_table, - swig_type_info **types, - swig_type_info **types_initial) { +SWIG_Python_FixMethods(PyMethodDef *methods, const swig_const_info *const_table, swig_type_info **types, swig_type_info **types_initial) { size_t i; for (i = 0; methods[i].ml_name; ++i) { const char *c = methods[i].ml_doc; @@ -74,7 +71,7 @@ SWIG_Python_FixMethods(PyMethodDef *methods, c = strstr(c, "swig_ptr: "); if (c) { int j; - swig_const_info *ci = 0; + const swig_const_info *ci = 0; const char *name = c + 10; for (j = 0; const_table[j].type; ++j) { if (strncmp(const_table[j].name, name, diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 9046edcfb..119a32364 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -73,8 +73,10 @@ static int py3 = 0; /* C++ Support + Shadow Classes */ -static int have_constructor; -static int have_repr; +static int have_constructor = 0; +static int have_repr = 0; +static bool have_builtin_static_member_method_callback = false; +static bool have_fast_proxy_static_member_method_callback = false; static String *real_classname; /* Thread Support */ @@ -815,6 +817,10 @@ public: Append(const_code, "{0, 0, 0, 0.0, 0, 0}};\n"); Printf(f_wrappers, "%s\n", const_code); + + if (have_fast_proxy_static_member_method_callback) + Printf(f_init, " SWIG_Python_FixMethods(SwigMethods_proxydocs, swig_const_table, swig_types, swig_type_initial);\n\n"); + initialize_threads(f_init); Printf(f_init, "#if PY_VERSION_HEX >= 0x03000000\n"); @@ -2478,6 +2484,7 @@ public: Printf(methods, "\"swig_ptr: %s\"", Getattr(n, "feature:callback:name")); if (fastproxy) { Printf(methods_proxydocs, "\"swig_ptr: %s\"", Getattr(n, "feature:callback:name")); + have_fast_proxy_static_member_method_callback = true; } } else { Append(methods, "NULL"); @@ -3935,6 +3942,10 @@ public: int funpack = fastunpack; static String *tp_new = NewString("PyType_GenericNew"); + if (have_builtin_static_member_method_callback) { + Printf(f_init, " SWIG_Python_FixMethods(SwigPyBuiltin_%s_methods, swig_const_table, swig_types, swig_type_initial);\n", mname); + } + Printv(f_init, " SwigPyBuiltin_SetMetaType(builtin_pytype, metatype);\n", NIL); // We can’t statically initialize a structure member with a function defined in another C module @@ -4365,6 +4376,7 @@ public: /* Create new strings for building up a wrapper function */ have_constructor = 0; have_repr = 0; + have_builtin_static_member_method_callback = false; class_name = Getattr(n, "sym:name"); real_classname = Getattr(n, "name"); @@ -4750,6 +4762,11 @@ public: String *ds = cdocstring(n, AUTODOC_STATICFUNC); Printf(builtin_methods, " { \"%s\", (PyCFunction)(void(*)(void))%s, %s, \"%s\" },\n", symname, wname, pyflags, ds); Delete(ds); + } else if (Getattr(n, "feature:callback")) { + String *ds = NewStringf("swig_ptr: %s", Getattr(n, "feature:callback:name")); + Printf(builtin_methods, " { \"%s\", (PyCFunction)(void(*)(void))%s, %s, \"%s\" },\n", symname, wname, pyflags, ds); + Delete(ds); + have_builtin_static_member_method_callback = true; } else { Printf(builtin_methods, " { \"%s\", (PyCFunction)(void(*)(void))%s, %s, \"\" },\n", symname, wname, pyflags); } From 2272d00c1a60ea6f3710e4d9dc17746b9df69780 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 14 Jan 2022 23:58:40 +0000 Subject: [PATCH 177/262] Add Python testcase for testing flatstaticmethod syntax For testing legacy flattened static method access for when issue #2137 is applied. --- Examples/test-suite/python/Makefile.in | 3 +- Examples/test-suite/python/callback_runme.py | 3 - .../python/python_flatstaticmethod_runme.py | 85 +++++++++++++++++++ Examples/test-suite/python_flatstaticmethod.i | 36 ++++++++ 4 files changed, 123 insertions(+), 4 deletions(-) create mode 100644 Examples/test-suite/python/python_flatstaticmethod_runme.py create mode 100644 Examples/test-suite/python_flatstaticmethod.i diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index 0bdbad51e..a5f2670d8 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -54,6 +54,7 @@ CPP_TEST_CASES += \ python_director \ python_docstring \ python_extranative \ + python_flatstaticmethod \ python_moduleimport \ python_overload_simple_cast \ python_pickle \ @@ -97,7 +98,7 @@ LIBS = -L. VALGRIND_OPT += --suppressions=pythonswig.supp # Custom tests - tests with additional commandline options -# none! +#python_flatstaticmethod.cpptest: SWIGOPT += -flatstaticmethod # Rules for the different types of tests %.cpptest: diff --git a/Examples/test-suite/python/callback_runme.py b/Examples/test-suite/python/callback_runme.py index 19f61c96b..dbf957cbb 100644 --- a/Examples/test-suite/python/callback_runme.py +++ b/Examples/test-suite/python/callback_runme.py @@ -17,9 +17,6 @@ if foobar(3, _callback.foo) != foo(3): if foobar(3, foo) != foo(3): raise RuntimeError -if foobar(3, A_bar) != A_bar(3): - raise RuntimeError - if foobar(3, A.bar) != A.bar(3): raise RuntimeError diff --git a/Examples/test-suite/python/python_flatstaticmethod_runme.py b/Examples/test-suite/python/python_flatstaticmethod_runme.py new file mode 100644 index 000000000..f34670013 --- /dev/null +++ b/Examples/test-suite/python/python_flatstaticmethod_runme.py @@ -0,0 +1,85 @@ +from python_flatstaticmethod import * +import inspect + +# This testcase tests C++ class static functions when using legacy "flattened" +# staticmethod access, A_bar, as well as the normal staticmethod access, A.bar. + + +def check(got, expected): + if got != expected: + raise RuntimeError("\ngot :{}\nwant:{}\n".format(got, expected)) + +if A_bar(2) != 4: + raise RuntimeError + +if A.bar(2) != 4: + raise RuntimeError + +# %callback +if foobar(3, A_bar) != A_bar(3): + raise RuntimeError + +if foobar(3, A.bar) != A_bar(3): + raise RuntimeError + +# kwargs +if A_pub() != 1: + raise RuntimeError + +if A_pub(b=2) != 3: + raise RuntimeError + +if A_pub(b=10,a=20) != 30: + raise RuntimeError + +if A.pub() != 1: + raise RuntimeError + +if A.pub(b=2) != 3: + raise RuntimeError + +if A.pub(b=10,a=20) != 30: + raise RuntimeError + +check(inspect.getdoc(A_func0static), + "A_func0static(e, arg2, hello, f=2) -> int") +check(inspect.getdoc(A_func1static), + "A_func1static(A e, short arg2, Tuple hello, double f=2) -> int") + +# overloaded static functions +if A_over(3) != "over:int": + raise RuntimeError("A::over(int)") + +if A_over(3.0) != "over:double": + raise RuntimeError("A::over(double)") + +if A_over("hello") != "over:char *": + raise RuntimeError("A::over(char *)") + +if A.over(3) != "over:int": + raise RuntimeError("A::over(int)") + +if A.over(3.0) != "over:double": + raise RuntimeError("A::over(double)") + +if A.over("hello") != "over:char *": + raise RuntimeError("A::over(char *)") + +# default args +if A_defargs() != 30: + raise RuntimeError + +if A_defargs(1) != 21: + raise RuntimeError + +if A_defargs(1, 2) != 3: + raise RuntimeError + +if A.defargs() != 30: + raise RuntimeError + +if A.defargs(1) != 21: + raise RuntimeError + +if A.defargs(1, 2) != 3: + raise RuntimeError diff --git a/Examples/test-suite/python_flatstaticmethod.i b/Examples/test-suite/python_flatstaticmethod.i new file mode 100644 index 000000000..c0de7d298 --- /dev/null +++ b/Examples/test-suite/python_flatstaticmethod.i @@ -0,0 +1,36 @@ +%module python_flatstaticmethod + +// This testcase tests C++ class static functions when using legacy "flattened" +// staticmethod access, A_bar, as well as the normal staticmethod access, A.bar. + +%callback(1) A::bar; +%feature("kwargs") A::pub; +%feature("autodoc","0") A::func0static; // names +%feature("autodoc","1") A::func1static; // names + types +// special typemap and its docs +%typemap(in) (int c, int d) "$1 = 0; $2 = 0;"; +%typemap(doc,name="hello",type="Tuple") (int c, int d) "hello: int tuple[2]"; + +%inline %{ + struct A { + static int bar(int a) { + return 2*a; + } + static int pub(int a = 1, int b = 0) { + return a + b; + } + static int func0static(A *e, short, int c, int d, double f = 2) { return 0; } + static int func1static(A *e, short, int c, int d, double f = 2) { return 0; } + + static const char *over(int) { return "over:int"; } + static const char *over(double) { return "over:double"; } + static const char *over(char *) { return "over:char *"; } + + static int defargs(int xx = 10, int yy = 20) { return xx + yy; } + }; + + extern "C" int foobar(int a, int (*pf)(int a)) { + return pf(a); + } +%} + From 0fbf23a77be9859a587af2900b863aa5fdc5c788 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sun, 16 Jan 2022 12:35:41 +1300 Subject: [PATCH 178/262] Fix PHP docs formatting issue --- Doc/Manual/Php.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index 8f8ab39c4..813368ec3 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -746,7 +746,10 @@ class Ko { }; -would be executed in PHP as, +

    +would be executed in PHP as +

    +
     Ko::threats();
     
    From 45c125593376adc5e4c8d0bcaa6e98905c9838c2 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 18 Jan 2022 13:56:07 +1300 Subject: [PATCH 179/262] Fix missing HTML escaping in Octave docs --- Doc/Manual/Octave.html | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Doc/Manual/Octave.html b/Doc/Manual/Octave.html index bdef5db7c..151957cff 100644 --- a/Doc/Manual/Octave.html +++ b/Doc/Manual/Octave.html @@ -570,13 +570,13 @@ __mul__ a * b __div__ a / b __pow__ a ^ b __ldiv__ a \ b -__lshift__ a << b -__rshift__ a >> b -__lt__ a < b -__le__ a <= b +__lshift__ a << b +__rshift__ a >> b +__lt__ a < b +__le__ a <= b __eq__ a == b -__ge__ a >= b -__gt__ a > b +__ge__ a >= b +__gt__ a > b __ne__ a != b __el_mul__ a .* b __el_div__ a ./ b @@ -598,16 +598,16 @@ On the C++ side, the default mappings are as follows: %rename(__mul__) *::operator*; %rename(__div__) *::operator/; %rename(__mod__) *::operator%; -%rename(__lshift__) *::operator<<; -%rename(__rshift__) *::operator>>; +%rename(__lshift__) *::operator<<; +%rename(__rshift__) *::operator>>; %rename(__el_and__) *::operator&&; %rename(__el_or__) *::operator||; %rename(__xor__) *::operator^; %rename(__invert__) *::operator~; -%rename(__lt__) *::operator<; -%rename(__le__) *::operator<=; -%rename(__gt__) *::operator>; -%rename(__ge__) *::operator>=; +%rename(__lt__) *::operator<; +%rename(__le__) *::operator<=; +%rename(__gt__) *::operator>; +%rename(__ge__) *::operator>=; %rename(__eq__) *::operator==; %rename(__ne__) *::operator!=; %rename(__not__) *::operator!; @@ -634,7 +634,7 @@ You can use it to define special behavior, like for example defining Octave oper %extend A { string __str__() { stringstream sout; - sout<<$self->value; + sout<<$self->value; return sout.str(); } } From c839066405d0700bdd17d7669eff623dab8fd928 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 18 Jan 2022 14:51:55 +1300 Subject: [PATCH 180/262] [perl] Document explicitly not to use %OWNER directly See #1771 --- Doc/Manual/Perl5.html | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Doc/Manual/Perl5.html b/Doc/Manual/Perl5.html index 85c2545cf..9f2e08ba4 100644 --- a/Doc/Manual/Perl5.html +++ b/Doc/Manual/Perl5.html @@ -2651,8 +2651,8 @@ constructors and destructors for the package and are always named "new" and "DESTROY". The constructor always returns a tied hash table. This hash table is used to access the member variables of a structure in addition to being able to invoke member functions. The -%OWNER and %BLESSEDMEMBERS hash tables are used -internally and described shortly. +%OWNER and %BLESSEDMEMBERS hash tables are +implementation details used internally and described shortly.

    @@ -2740,8 +2740,15 @@ to a C function that remembers the object, and then destroy the corresponding Perl object (this situation turns out to come up frequently when constructing objects like linked lists and trees). When C takes possession of an object, you can change Perl's ownership -by simply deleting the object from the %OWNER hash. This is -done using the DISOWN method. +by calling the DISOWN method (which will delete the object +from the internal %OWNER hash). +

    + +

    +The %OWNER hash is an implementation detail, discussed here +only to help clarify the operation of ACQUIRE and DISOWN. +You should not access %OWNER directly - the details of how it +works (and possibly even its existence) may chance in future SWIG versions.

    
    From c8645aab9ec227f5436bf8a061cc7a20f5a47717 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Sun, 16 Jan 2022 11:09:11 +0000
    Subject: [PATCH 181/262] Ensure GHA fails when testflags.py fails
    
    ---
     .github/workflows/ci.yml | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
    index c4212a42c..1e8faff7d 100644
    --- a/.github/workflows/ci.yml
    +++ b/.github/workflows/ci.yml
    @@ -436,8 +436,8 @@ jobs:
                 esac
     
                 # Stricter compile flags for examples. Various headers and SWIG generated code prevents full use of -pedantic.
    -            cflags=$($GITHUB_WORKSPACE/Tools/testflags.py --language $SWIGLANG --cflags --std=$CSTD --compiler=$CC) && echo $cflags
    -            cxxflags=$($GITHUB_WORKSPACE/Tools/testflags.py --language $SWIGLANG --cxxflags --std=$CPPSTD --compiler=$CC) && echo $cxxflags
    +            cflags=$($GITHUB_WORKSPACE/Tools/testflags.py --language $SWIGLANG --cflags --std=$CSTD --compiler=$CC)
    +            cxxflags=$($GITHUB_WORKSPACE/Tools/testflags.py --language $SWIGLANG --cxxflags --std=$CPPSTD --compiler=$CC)
                 make check-$SWIGLANG-version
                 make check-$SWIGLANG-enabled
                 make $SWIGJOBS check-$SWIGLANG-examples CFLAGS="$cflags" CXXFLAGS="$cxxflags"
    
    From 8c608d646c611820ad58c85315f23b4499331de7 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Tue, 18 Jan 2022 20:14:38 +0000
    Subject: [PATCH 182/262] Fix Appveyor mingw builds - install autotools
    
    ---
     appveyor.yml | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/appveyor.yml b/appveyor.yml
    index 07c4fac28..5eaa77b2f 100644
    --- a/appveyor.yml
    +++ b/appveyor.yml
    @@ -131,7 +131,7 @@ install:
     - if "%OSVARIANT%"=="" bash -c "which csc.exe"
     - if "%OSVARIANT%"=="" bash -c "csc.exe /? | head -n 1"
     - if "%OSVARIANT%"=="cygwin" %CYGWINSETUP% --quiet-mode --packages python2-devel,libpcre-devel,libboost-devel > cygwin-install.txt || bash -c "cat cygwin-install.txt"
    -- if "%OSVARIANT%"=="mingw" bash -c "pacman --noconfirm --sync mingw%MBITS%/mingw-w64-%MARCH%-pcre mingw%MBITS%/mingw-w64-%MARCH%-boost"
    +- if "%OSVARIANT%"=="mingw" bash -c "pacman --noconfirm --sync mingw%MBITS%/mingw-w64-%MARCH%-autotools mingw%MBITS%/mingw-w64-%MARCH%-pcre mingw%MBITS%/mingw-w64-%MARCH%-boost"
     - if not "%WITHLANG%"=="" set SWIGWITHLANG==%WITHLANG%
     - if not "%WITHLANG%"=="" where %WITHLANG%
     - bash -c "which $CC"
    
    From 748a9a5452568b90edba7162e5b9376d4837529d Mon Sep 17 00:00:00 2001
    From: Olly Betts 
    Date: Tue, 18 Jan 2022 15:36:37 +1300
    Subject: [PATCH 183/262] [perl] Require at least Perl 5.8.0
    
    As discussed and agreed in #1629, it's become hard to test with Perl
    5.6 or earlier, such old versions are no longer in active use, and
    4.1.0 is an appropriate time to make such a change.
    
    I've dropped the compatibility code that was obvious to me, but there's
    probably more that can be cleaned up now.
    ---
     CHANGES.current                               |  3 +
     Doc/Manual/Perl5.html                         |  9 ++-
     .../perl5/operator_overload_break_runme.pl    | 11 +---
     .../perl5/operator_overload_runme.pl          | 29 +++------
     .../test-suite/perl5/packageoption_runme.pl   |  9 ---
     Lib/perl5/perlhead.swg                        | 28 +--------
     Lib/perl5/perlinit.swg                        |  4 --
     Lib/perl5/perlrun.swg                         | 62 ++++---------------
     RELEASENOTES                                  |  1 +
     Source/Modules/perl5.cxx                      |  7 ---
     configure.ac                                  |  2 +-
     11 files changed, 34 insertions(+), 131 deletions(-)
    
    diff --git a/CHANGES.current b/CHANGES.current
    index b6c21643b..5aa435e15 100644
    --- a/CHANGES.current
    +++ b/CHANGES.current
    @@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
     Version 4.1.0 (in progress)
     ===========================
     
    +2022-01-18: olly
    +	    [Perl] #1629 Perl 5.8.0 is now the oldest version we aim to support.
    +
     2022-01-14: wsfulton
                 [Python] Fix %callback and specifying the callback function as a
                 static member function using Python staticmethod syntax, such as
    diff --git a/Doc/Manual/Perl5.html b/Doc/Manual/Perl5.html
    index 9f2e08ba4..03dcfe6bb 100644
    --- a/Doc/Manual/Perl5.html
    +++ b/Doc/Manual/Perl5.html
    @@ -91,10 +91,10 @@
     

    This chapter describes SWIG's support of Perl5. Although the Perl5 module is one of the earliest SWIG modules, it has continued to evolve -and has been improved greatly with the help of SWIG users. For the -best results, it is recommended that SWIG be used with Perl 5.8 or -later. We're no longer testing regularly with older versions, but -Perl 5.6 seems to mostly work, while older versions don't. +and has been improved greatly with the help of SWIG users. As of SWIG +4.1.0, the minimum version of Perl we aim to support is Perl 5.8.0. +We can no longer easily test with older versions, and they no longer +seem to be in active use.

    31.1 Overview

    @@ -680,7 +680,6 @@ files(s) field". installation under "Additional include directories".
  • Define the symbols WIN32 and MSWIN32 under preprocessor options. -If using the ActiveWare port, also define the symbol PERL_OBJECT. Note that all extensions to the ActiveWare port must be compiled with the C++ compiler since Perl has been encapsulated in a C++ class. diff --git a/Examples/test-suite/perl5/operator_overload_break_runme.pl b/Examples/test-suite/perl5/operator_overload_break_runme.pl index fd3fe3303..c692dfac7 100644 --- a/Examples/test-suite/perl5/operator_overload_break_runme.pl +++ b/Examples/test-suite/perl5/operator_overload_break_runme.pl @@ -4,15 +4,6 @@ use Test::More tests => 9; use operator_overload_break; -# Workaround for -# ok( not (expression) , "test description" ); -# does not working in older versions of Perl, eg 5.004_04 -sub ok_not ($;$) { - my($test, $name) = @_; - $test = not $test; - ok($test, $name); -} - pass("loaded"); my $op = operator_overload_break::Op->new(5); @@ -32,7 +23,7 @@ $op->{k} = 22; ok((10 == (32 - $op)), "reversed subtraction"); -ok_not((3 == $op), +ok(not(3 == $op), 'not equal'); $op->{k} = 3; diff --git a/Examples/test-suite/perl5/operator_overload_runme.pl b/Examples/test-suite/perl5/operator_overload_runme.pl index ba3f33a64..43a77a961 100644 --- a/Examples/test-suite/perl5/operator_overload_runme.pl +++ b/Examples/test-suite/perl5/operator_overload_runme.pl @@ -4,15 +4,6 @@ use Test::More tests => 39; use operator_overload; -# Workaround for -# ok( not (expression) , "test description" ); -# does not working in older versions of Perl, eg 5.004_04 -sub ok_not ($;$) { - my($test, $name) = @_; - $test = not $test; - ok($test, $name); -} - pass("loaded"); # first check all the operators are implemented correctly from pure C++ code @@ -30,7 +21,7 @@ isa_ok($op2, "operator_overload::Op"); $op->{i} = 5; $op2->{i} = 3; -ok_not(($op == $op2), "operator equal: not equal"); +ok(not($op == $op2), "operator equal: not equal"); $op->{i} = 3; ok(($op == $op2), "operator equal: equal"); @@ -42,7 +33,7 @@ $op2->{i} = 3; ok(($op != $op2), "operator not equal: not equal"); $op->{i} = 3; -ok_not(($op != $op2), "operator not equal: equal"); +ok(not($op != $op2), "operator not equal: equal"); # stringify operator $op->{i} = 3; @@ -99,16 +90,16 @@ is($op3->{i}, 2, "operator modulus"); $op->{i} = 8; $op2->{i} = 3; ok($op > $op2, "operator greater than"); -ok_not(($op2 > $op), "operator greater than"); +ok(not($op2 > $op), "operator greater than"); $op->{i} = 3; -ok_not(($op2 > $op), "operator greater than"); -ok_not(($op > $op2), "operator greater than"); +ok(not($op2 > $op), "operator greater than"); +ok(not($op > $op2), "operator greater than"); # greater than or equal operator $op->{i} = 8; $op2->{i} = 3; ok($op >= $op2, "operator greater than or equal"); -ok_not(($op2 >= $op), "operator greater than or equal"); +ok(not($op2 >= $op), "operator greater than or equal"); $op->{i} = 3; ok(($op2 >= $op), "operator greater than or equal"); ok(($op >= $op2), "operator greater than or equal"); @@ -117,16 +108,16 @@ ok(($op >= $op2), "operator greater than or equal"); $op2->{i} = 8; $op->{i} = 3; ok($op < $op2, "operator lesser than"); -ok_not(($op2 < $op), "operator lesser than"); +ok(not($op2 < $op), "operator lesser than"); $op2->{i} = 3; -ok_not(($op2 < $op), "operator lesser than"); -ok_not(($op < $op2), "operator lesser than"); +ok(not($op2 < $op), "operator lesser than"); +ok(not($op < $op2), "operator lesser than"); # less than or equal operator $op2->{i} = 8; $op->{i} = 3; ok($op <= $op2, "operator lesser than or equal"); -ok_not(($op2 <= $op), "operator lesser than or equal"); +ok(not($op2 <= $op), "operator lesser than or equal"); $op2->{i} = 3; ok(($op2 <= $op), "operator less than or equal"); ok(($op <= $op2), "operator less than or equal"); diff --git a/Examples/test-suite/perl5/packageoption_runme.pl b/Examples/test-suite/perl5/packageoption_runme.pl index d94a7a1fd..02e95f7a8 100644 --- a/Examples/test-suite/perl5/packageoption_runme.pl +++ b/Examples/test-suite/perl5/packageoption_runme.pl @@ -5,15 +5,6 @@ use Test::More tests => 4; BEGIN { use_ok('packageoption_a'); } BEGIN { use_ok('packageoption_b'); } -# Workaround for -# ok( not (expression) , "test description" ); -# does not working in older versions of Perl, eg 5.004_04 -sub ok_not ($;$) { - my($test, $name) = @_; - $test = not $test; - ok($test, $name); -} - my $a = CommonPackage::A->new(); isa_ok($a, 'CommonPackage::A'); diff --git a/Lib/perl5/perlhead.swg b/Lib/perl5/perlhead.swg index 5437af5a5..bb7c1741d 100644 --- a/Lib/perl5/perlhead.swg +++ b/Lib/perl5/perlhead.swg @@ -8,22 +8,9 @@ extern "C" { #include "perl.h" #include "XSUB.h" -/* Add in functionality missing in older versions of Perl. Much of this is based on Devel-PPPort on cpan. */ - -/* Add PERL_REVISION, PERL_VERSION, PERL_SUBVERSION if missing */ -#ifndef PERL_REVISION -# if !defined(__PATCHLEVEL_H_INCLUDED__) && !(defined(PATCHLEVEL) && defined(SUBVERSION)) -# define PERL_PATCHLEVEL_H_IMPLICIT -# include -# endif -# if !(defined(PERL_VERSION) || (defined(SUBVERSION) && defined(PATCHLEVEL))) -# include -# endif -# ifndef PERL_REVISION -# define PERL_REVISION (5) -# define PERL_VERSION PATCHLEVEL -# define PERL_SUBVERSION SUBVERSION -# endif +/* PERL_REVISION was added in Perl 5.6. */ +#if !defined PERL_REVISION || (PERL_REVISION-0 == 5 && PERL_VERSION-0 < 8) +# error SWIG requires Perl >= 5.8.0 #endif #if defined(WIN32) && defined(PERL_OBJECT) && !defined(PerlIO_exportFILE) @@ -38,15 +25,6 @@ extern "C" { # define SvUOK(sv) SvIOK_UV(sv) #endif -#if ((PERL_VERSION < 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION <= 5))) -# define PL_sv_undef sv_undef -# define PL_na na -# define PL_errgv errgv -# define PL_sv_no sv_no -# define PL_sv_yes sv_yes -# define PL_markstack_ptr markstack_ptr -#endif - #ifndef IVSIZE # ifdef LONGSIZE # define IVSIZE LONGSIZE diff --git a/Lib/perl5/perlinit.swg b/Lib/perl5/perlinit.swg index b49040d26..c26b93fad 100644 --- a/Lib/perl5/perlinit.swg +++ b/Lib/perl5/perlinit.swg @@ -4,15 +4,11 @@ #ifdef __cplusplus extern "C" #endif -#ifndef PERL_OBJECT #ifndef MULTIPLICITY SWIGEXPORT void SWIG_init (CV* cv); #else SWIGEXPORT void SWIG_init (pTHXo_ CV* cv); #endif -#else -SWIGEXPORT void SWIG_init (CV *cv, CPerlObj *); -#endif %} /* Module initialization function */ diff --git a/Lib/perl5/perlrun.swg b/Lib/perl5/perlrun.swg index b04002f5d..28703d1a6 100644 --- a/Lib/perl5/perlrun.swg +++ b/Lib/perl5/perlrun.swg @@ -6,13 +6,8 @@ * type checking. * ----------------------------------------------------------------------------- */ -#ifdef PERL_OBJECT -#define SWIG_PERL_OBJECT_DECL CPerlObj *SWIGUNUSEDPARM(pPerl), -#define SWIG_PERL_OBJECT_CALL pPerl, -#else #define SWIG_PERL_OBJECT_DECL #define SWIG_PERL_OBJECT_CALL -#endif /* Common SWIG API */ @@ -88,31 +83,11 @@ extern "C" { #endif /* Macro to call an XS function */ -#ifdef PERL_OBJECT -# define SWIG_CALLXS(_name) _name(cv,pPerl) -#else -# ifndef MULTIPLICITY -# define SWIG_CALLXS(_name) _name(cv) -# else -# define SWIG_CALLXS(_name) _name(PERL_GET_THX, cv) -# endif -#endif - -#ifdef PERL_OBJECT -#define MAGIC_PPERL CPerlObj *pPerl = (CPerlObj *) this; - -#ifdef __cplusplus -extern "C" { +#ifndef MULTIPLICITY +# define SWIG_CALLXS(_name) _name(cv) +#else +# define SWIG_CALLXS(_name) _name(PERL_GET_THX, cv) #endif -typedef int (CPerlObj::*SwigMagicFunc)(SV *, MAGIC *); -#ifdef __cplusplus -} -#endif - -#define SWIG_MAGIC(a,b) (SV *a, MAGIC *b) -#define SWIGCLASS_STATIC - -#else /* PERL_OBJECT */ #define MAGIC_PPERL #define SWIGCLASS_STATIC static SWIGUNUSED @@ -141,24 +116,14 @@ typedef int (*SwigMagicFunc)(struct interpreter *, SV *, MAGIC *); #endif #endif /* MULTIPLICITY */ -#endif /* PERL_OBJECT */ -# ifdef PERL_OBJECT -# define SWIG_croak_null() SWIG_Perl_croak_null(pPerl) -static void SWIGUNUSED SWIG_Perl_croak_null(CPerlObj *pPerl) -# else static void SWIGUNUSED SWIG_croak_null() -# endif { SV *err = get_sv("@", GV_ADD); -# if (PERL_VERSION < 6) - croak("%_", err); -# else if (sv_isobject(err)) croak(0); else croak("%s", SvPV_nolen(err)); -# endif } @@ -462,20 +427,15 @@ typedef struct { } swig_variable_info; /* Magic variable code */ -#ifndef PERL_OBJECT -# ifdef __cplusplus +#ifdef __cplusplus # define swig_create_magic(s,a,b,c) _swig_create_magic(s,const_cast(a),b,c) -# else -# define swig_create_magic(s,a,b,c) _swig_create_magic(s,(char*)(a),b,c) -# endif -# ifndef MULTIPLICITY -SWIGRUNTIME void _swig_create_magic(SV *sv, char *name, int (*set)(SV *, MAGIC *), int (*get)(SV *,MAGIC *)) -# else -SWIGRUNTIME void _swig_create_magic(SV *sv, char *name, int (*set)(struct interpreter*, SV *, MAGIC *), int (*get)(struct interpreter*, SV *,MAGIC *)) -# endif #else -# define swig_create_magic(s,a,b,c) _swig_create_magic(pPerl,s,a,b,c) -SWIGRUNTIME void _swig_create_magic(CPerlObj *pPerl, SV *sv, const char *name, int (CPerlObj::*set)(SV *, MAGIC *), int (CPerlObj::*get)(SV *, MAGIC *)) +# define swig_create_magic(s,a,b,c) _swig_create_magic(s,(char*)(a),b,c) +#endif +#ifndef MULTIPLICITY +SWIGRUNTIME void _swig_create_magic(SV *sv, char *name, int (*set)(SV *, MAGIC *), int (*get)(SV *,MAGIC *)) +#else +SWIGRUNTIME void _swig_create_magic(SV *sv, char *name, int (*set)(struct interpreter*, SV *, MAGIC *), int (*get)(struct interpreter*, SV *,MAGIC *)) #endif { MAGIC *mg; diff --git a/RELEASENOTES b/RELEASENOTES index c05ccc4ec..3a596dd46 100644 --- a/RELEASENOTES +++ b/RELEASENOTES @@ -10,6 +10,7 @@ published on the SWIG web site at http://swig.org/release.html. SWIG-4.1.0 summary: - Add PHP 8 support. - PHP wrapping is now done entirely via PHP's C API - no more .php wrapper. +- Perl 5.8.0 is now the oldest version SWIG supports. - GitHub Actions is now used instead of Travis CI for continuous integration. SWIG-4.0.2 summary: diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index e87f9f310..459d403bf 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -445,13 +445,7 @@ public: Printv(magic, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n", - "#ifdef PERL_OBJECT\n", - "#define MAGIC_CLASS _wrap_", underscore_module, "_var::\n", - "class _wrap_", underscore_module, "_var : public CPerlObj {\n", - "public:\n", - "#else\n", "#define MAGIC_CLASS\n", - "#endif\n", "SWIGCLASS_STATIC int swig_magic_readonly(pTHX_ SV *SWIGUNUSEDPARM(sv), MAGIC *SWIGUNUSEDPARM(mg)) {\n", tab4, "MAGIC_PPERL\n", tab4, "croak(\"Value is read-only.\");\n", tab4, "return 0;\n", "}\n", NIL); @@ -470,7 +464,6 @@ public: /* Dump out variable wrappers */ - Printv(magic, "\n\n#ifdef PERL_OBJECT\n", "};\n", "#endif\n", NIL); Printv(magic, "\n#ifdef __cplusplus\n}\n#endif\n", NIL); Printf(f_header, "%s\n", magic); diff --git a/configure.ac b/configure.ac index 8073bfdb3..ed836205f 100644 --- a/configure.ac +++ b/configure.ac @@ -983,7 +983,7 @@ else # First figure out what the name of Perl5 is if test "x$PERLBIN" = xyes; then -AC_CHECK_PROGS(PERL, perl perl5.6.1 perl5.6.0 perl5.004 perl5.003 perl5.002 perl5.001 perl5 perl) +AC_CHECK_PROGS(PERL, perl perl5) else PERL="$PERLBIN" fi From 76d5a9ec270a763c892ae28070e391cf99e0b7cd Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 18 Jan 2022 21:37:02 +0000 Subject: [PATCH 184/262] gcc-12 warning fix in test-case Closes #2145 --- Examples/test-suite/nested_class.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/nested_class.i b/Examples/test-suite/nested_class.i index b10c33949..c778a12cf 100644 --- a/Examples/test-suite/nested_class.i +++ b/Examples/test-suite/nested_class.i @@ -201,7 +201,7 @@ struct Outer { Integer xx; } MultipleInstanceAnonDerived1, MultipleInstanceAnonDerived2, *MultipleInstanceAnonDerived3, MultipleInstanceAnonDerived4[2]; -#if defined(__GNUC__) || defined(_MSC_VER) || defined(SWIG) +#if (defined(__GNUC__) && __GNUC__ < 12) || defined(_MSC_VER) || defined(SWIG) /* some compilers do not accept these */ struct : public InnerMultiple { Integer xx; From 1f1349741fbe34a1d4444d5158a34ae34b70bbb9 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 20 Jan 2022 10:07:44 +1300 Subject: [PATCH 185/262] [php] Generate PHP type declarations We now automatically generate PHP type declarations for PHP >= 8.0. The generated code still compiles with PHP 7.x but without type declarations. --- Doc/Manual/Php.html | 73 ++++ Examples/test-suite/li_factory.i | 3 +- Examples/test-suite/php/argout_runme.php | 13 +- Examples/test-suite/php/li_factory_runme.php | 3 + Lib/php/factory.i | 2 +- Lib/php/php.swg | 135 +++--- Lib/php/phppointers.i | 36 +- Lib/php/phprun.swg | 21 + Lib/php/std_string.i | 10 +- Lib/php/typemaps.i | 20 +- Lib/php/utils.i | 6 +- Source/Modules/php.cxx | 410 ++++++++++++++----- 12 files changed, 536 insertions(+), 196 deletions(-) diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html index 813368ec3..a887471f3 100644 --- a/Doc/Manual/Php.html +++ b/Doc/Manual/Php.html @@ -346,6 +346,79 @@ $c = bar(3.5); # Use default argument for 2nd parameter
  • +

    +SWIG generates PHP type declarations for function parameters and return +types for PHP 8 and later (we don't try to support PHP 7's more limited type +declarations and the generated wrappers compiled for PHP 7 will not have any +type declarations). +

    + +

    +You can control the generation of PHP type declarations using +the "php:type" %feature. This has three settings: +

    + +
      +
    • If unset or set to "0" then no type declarations are generated, e.g.: %feature("php:type", "0"); +

    • +
    • If set to "1" then type declarations are generated for both parameters and return types, e.g.: %feature("php:type", "1"); +

    • +
    • The default setting is "compat", which is the same as "1" except no + return type declarations are generated for virtual methods for which + directors are enabled. This provides better compatibility for PHP + subclasses of wrapped virtual methods in existing SWIG-generated bindings, e.g.: %feature("php:type", "compat"); +

    • +
    + +

    +If you have an existing PHP interface and are upgrading to SWIG >= 4.1.0 +then the default "compat" setting should work well. +

    + +

    +If you're writing a new set of bindings and only targetting PHP8 or newer +then enabling type declarations everywhere probably makes sense. It will +only actually make a difference if you enable directors and are wrapping C++ +classes with virtual methods, but doing it anyway means you won't forget to if +the code you are wrapping later evolves to have such classes and methods. +

    + +

    +The type declaration information will make the generated source code and +compiler extension module larger, so you might want to turn off type +declarations if keeping these small is important to you. If you find you +need to turn off type declarations to fix a problem, please let us know +via our github issue tracker. +

    + +

    +Note that being a SWIG feature this can be specified globally (like above) or +per class, per method, etc. See the %feature directives +section for full details of how to control at a fine-grained level. +

    + +

    +The PHP type information is specified via a "phptype" attribute on "in" and +"out" typemaps, and these have been added for all the typemaps we supply for +PHP. We don't currently support this for "argout" templates, but probably +will in a future version. +

    + +

    +If you have written custom SWIG typemaps for PHP and want to add PHP type +declarations, then the syntax is very like how you'd specify the type in +PHP code, e.g. %typemap(in, phptype="int|string|Foo") means the +typemap accepts a PHP int or string or an object of class Foo, +%typemap(in, phptype="?int") means a PHP int or NULL, etc. +As well as the standard PHP type declaration types, SWIG also understands the +special type "SWIGTYPE" as an entry in phptype, which means the PHP type +corresponding to the type that this typemap matched on - for a object this +will give you the PHP class for the object, and for a pointer to a non-class +type it will give you the name of the PHP class SWIG created for that +pointer type. +

    +