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.
+
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
-
+
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
+
+
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.
@@ -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.
+
+