From cf7811b17890af6da7174e4e5a65ca38fc55c0e2 Mon Sep 17 00:00:00 2001 From: Nickolay Shmyrev Date: Thu, 12 Jan 2017 15:53:44 +0100 Subject: Proper array typemaps in Javascript https://github.com/swig/swig/issues/865 --- Lib/javascript/jsc/arrays_javascript.i | 87 +++++++++++-------------------- Lib/javascript/v8/arrays_javascript.i | 93 +++++++++++----------------------- Lib/javascript/v8/javascriptrun.swg | 6 +-- 3 files changed, 62 insertions(+), 124 deletions(-) (limited to 'Lib') diff --git a/Lib/javascript/jsc/arrays_javascript.i b/Lib/javascript/jsc/arrays_javascript.i index b9199d86b..713b7ef23 100644 --- a/Lib/javascript/jsc/arrays_javascript.i +++ b/Lib/javascript/jsc/arrays_javascript.i @@ -21,34 +21,39 @@ * fs = example.FiddleSticks; * ----------------------------------------------------------------------------- */ -%fragment("SWIG_JSCGetIntProperty", "header", fragment=SWIG_AsVal_frag(int)) {} + +%fragment("SWIG_JSCGetIntProperty", "header", fragment=SWIG_AsVal_frag(int)) {} %fragment("SWIG_JSCGetNumberProperty", "header", fragment=SWIG_AsVal_frag(double)) {} +%fragment("SWIG_JSCOutInt", "header", fragment=SWIG_From_frag(int)) {} +%fragment("SWIG_JSCOutNumber", "header", fragment=SWIG_From_frag(double)) {} + +%define JAVASCRIPT_ARRAYS_IN_DECL(NAME, CTYPE, ANY, ANYLENGTH) -%typemap(in, fragment="SWIG_JSCGetIntProperty") int[], int[ANY] - (int length = 0, JSObjectRef array, JSValueRef jsvalue, int i = 0, int res = 0, $*1_ltype temp) { +%typemap(in, fragment=NAME) CTYPE[ANY] { if (JSValueIsObject(context, $input)) { + int i; // Convert into Array - array = JSValueToObject(context, $input, NULL); + JSObjectRef array = JSValueToObject(context, $input, NULL); - length = $1_dim0; + int length = ANYLENGTH; $1 = ($*1_ltype *)malloc(sizeof($*1_ltype) * length); // Get each element from array for (i = 0; i < length; i++) { - jsvalue = JSObjectGetPropertyAtIndex(context, array, i, NULL); + JSValueRef jsvalue = JSObjectGetPropertyAtIndex(context, array, i, NULL); + $*1_ltype temp; // Get primitive value from JSObject - res = SWIG_AsVal(int)(jsvalue, &temp); + int res = SWIG_AsVal(CTYPE)(jsvalue, &temp); if (!SWIG_IsOK(res)) { SWIG_exception_fail(SWIG_ERROR, "Failed to convert $input to double"); } arg$argnum[i] = temp; } - } else { @@ -56,68 +61,34 @@ } } -%typemap(freearg) int[], int[ANY] { +%typemap(freearg) CTYPE[ANY] { free($1); } -%typemap(out, fragment=SWIG_From_frag(int)) int[], int[ANY] (int length = 0, int i = 0) -{ - length = $1_dim0; +%enddef + +%define JAVASCRIPT_ARRAYS_OUT_DECL(NAME, CTYPE) + +%typemap(out, fragment=NAME) CTYPE[ANY] { + int length = $1_dim0; JSValueRef values[length]; + int i; for (i = 0; i < length; i++) { - values[i] = SWIG_From(int)($1[i]); + values[i] = SWIG_From(CTYPE)($1[i]); } $result = JSObjectMakeArray(context, length, values, NULL); } -%typemap(in, fragment="SWIG_JSCGetNumberProperty") double[], double[ANY] - (int length = 0, JSObjectRef array, JSValueRef jsvalue, int i = 0, int res = 0, $*1_ltype temp) { - if (JSValueIsObject(context, $input)) - { - // Convert into Array - array = JSValueToObject(context, $input, NULL); +%enddef - length = $1_dim0; - - $1 = ($*1_ltype *)malloc(sizeof($*1_ltype) * length); +JAVASCRIPT_ARRAYS_IN_DECL("SWIG_JSCGetIntProperty", int, , SWIGJSC_ArrayLength(context, array)) +JAVASCRIPT_ARRAYS_IN_DECL("SWIG_JSCGetIntProperty", int, ANY, $1_dim0) +JAVASCRIPT_ARRAYS_IN_DECL("SWIG_JSCGetNumberProperty", double, , SWIGJSC_ArrayLength(context, array)) +JAVASCRIPT_ARRAYS_IN_DECL("SWIG_JSCGetNumberProperty", double, ANY, $1_dim0) - // Get each element from array - for (i = 0; i < length; i++) - { - jsvalue = JSObjectGetPropertyAtIndex(context, array, i, NULL); +JAVASCRIPT_ARRAYS_OUT_DECL("SWIG_JSCOutInt", int) +JAVASCRIPT_ARRAYS_OUT_DECL("SWIG_JSCOutNumber", double) - // Get primitive value from JSObject - res = SWIG_AsVal(double)(jsvalue, &temp); - if (!SWIG_IsOK(res)) - { - SWIG_exception_fail(SWIG_ERROR, "Failed to convert $input to double"); - } - arg$argnum[i] = temp; - } - - } - else - { - SWIG_exception_fail(SWIG_ERROR, "$input is not JSObjectRef"); - } -} - -%typemap(freearg) double[], double[ANY] { - free($1); -} - -%typemap(out, fragment=SWIG_From_frag(double)) double[], double[ANY] (int length = 0, int i = 0) -{ - length = $1_dim0; - JSValueRef values[length]; - - for (i = 0; i < length; i++) - { - values[i] = SWIG_From(double)($1[i]); - } - - $result = JSObjectMakeArray(context, length, values, NULL); -} diff --git a/Lib/javascript/v8/arrays_javascript.i b/Lib/javascript/v8/arrays_javascript.i index 22b50be8f..1808fa840 100644 --- a/Lib/javascript/v8/arrays_javascript.i +++ b/Lib/javascript/v8/arrays_javascript.i @@ -21,105 +21,72 @@ * fs = example.FiddleSticks; * ----------------------------------------------------------------------------- */ -%fragment("SWIG_JSCGetIntProperty", "header", fragment=SWIG_AsVal_frag(int)) {} + +%fragment("SWIG_JSCGetIntProperty", "header", fragment=SWIG_AsVal_frag(int)) {} %fragment("SWIG_JSCGetNumberProperty", "header", fragment=SWIG_AsVal_frag(double)) {} +%fragment("SWIG_JSCOutInt", "header", fragment=SWIG_From_frag(int)) {} +%fragment("SWIG_JSCOutNumber", "header", fragment=SWIG_From_frag(double)) {} + +%define JAVASCRIPT_ARRAYS_IN_DECL(NAME, CTYPE, ANY, ANYLENGTH) -%typemap(in, fragment="SWIG_JSCGetIntProperty") int[], int[ANY] - (int length = 0, v8::Local array, v8::Local jsvalue, int i = 0, int res = 0, $*1_ltype temp) { +%typemap(in, fragment=NAME) CTYPE[ANY] { if ($input->IsArray()) { // Convert into Array - array = v8::Local::Cast($input); + v8::Local array = v8::Local::Cast($input); - length = $1_dim0; + int length = ANYLENGTH; $1 = ($*1_ltype *)malloc(sizeof($*1_ltype) * length); // Get each element from array - for (i = 0; i < length; i++) + for (int i = 0; i < length; i++) { - jsvalue = array->Get(i); + v8::Local jsvalue = array->Get(i); + $*1_ltype temp; // Get primitive value from JSObject - res = SWIG_AsVal(int)(jsvalue, &temp); + int res = SWIG_AsVal(CTYPE)(jsvalue, &temp); if (!SWIG_IsOK(res)) { SWIG_exception_fail(SWIG_ERROR, "Failed to convert $input to double"); } arg$argnum[i] = temp; } - } else { - SWIG_exception_fail(SWIG_ERROR, "$input is not JSObjectRef"); + SWIG_exception_fail(SWIG_ERROR, "$input is not an array"); } } -%typemap(freearg) int[], int[ANY] { +%typemap(freearg) CTYPE[ANY] { free($1); } -%typemap(out, fragment=SWIG_From_frag(int)) int[], int[ANY] (int length = 0, int i = 0) -{ - length = $1_dim0; - v8::Local array = v8::Array::New(length); +%enddef - for (i = 0; i < length; i++) - { - array->Set(i, SWIG_From(int)($1[i])); - } +%define JAVASCRIPT_ARRAYS_OUT_DECL(NAME, CTYPE) +%typemap(out, fragment=NAME) CTYPE[ANY] { + int length = $1_dim0; + v8::Local array = SWIGV8_ARRAY_NEW(length); - $result = array; -} - -%typemap(in, fragment="SWIG_JSCGetNumberProperty") double[], double[ANY] - (int length = 0, v8::Local array, v8::Local jsvalue, int i = 0, int res = 0, $*1_ltype temp) { - if ($input->IsArray()) + for (int i = 0; i < length; i++) { - // Convert into Array - array = v8::Local::Cast($input); - - length = $1_dim0; - - $1 = ($*1_ltype *)malloc(sizeof($*1_ltype) * length); - - // Get each element from array - for (i = 0; i < length; i++) - { - jsvalue = array->Get(i); - - // Get primitive value from JSObject - res = SWIG_AsVal(double)(jsvalue, &temp); - if (!SWIG_IsOK(res)) - { - SWIG_exception_fail(SWIG_ERROR, "Failed to convert $input to double"); - } - arg$argnum[i] = temp; - } - + array->Set(i, SWIG_From(CTYPE)($1[i])); } - else - { - SWIG_exception_fail(SWIG_ERROR, "$input is not JSObjectRef"); - } -} -%typemap(freearg) double[], double[ANY] { - free($1); + $result = array; } -%typemap(out, fragment=SWIG_From_frag(double)) double[], double[ANY] (int length = 0, int i = 0) -{ - length = $1_dim0; - v8::Local array = v8::Array::New(length); +%enddef - for (i = 0; i < length; i++) - { - array->Set(i, SWIG_From(double)($1[i])); - } +JAVASCRIPT_ARRAYS_IN_DECL("SWIG_JSCGetIntProperty", int, , array->Length()) +JAVASCRIPT_ARRAYS_IN_DECL("SWIG_JSCGetIntProperty", int, ANY, $1_dim0) +JAVASCRIPT_ARRAYS_IN_DECL("SWIG_JSCGetNumberProperty", double, , array->Length()) +JAVASCRIPT_ARRAYS_IN_DECL("SWIG_JSCGetNumberProperty", double, ANY, $1_dim0) +JAVASCRIPT_ARRAYS_OUT_DECL("SWIG_JSCOutInt", int) +JAVASCRIPT_ARRAYS_OUT_DECL("SWIG_JSCOutNumber", double) - $result = array; -} diff --git a/Lib/javascript/v8/javascriptrun.swg b/Lib/javascript/v8/javascriptrun.swg index 5ac52a51d..b0bf49834 100644 --- a/Lib/javascript/v8/javascriptrun.swg +++ b/Lib/javascript/v8/javascriptrun.swg @@ -56,7 +56,7 @@ typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; #endif #if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032318) -#define SWIGV8_ARRAY_NEW() v8::Array::New() +#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) @@ -69,7 +69,7 @@ typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; #define SWIGV8_UNDEFINED() v8::Undefined() #define SWIGV8_NULL() v8::Null() #else -#define SWIGV8_ARRAY_NEW() v8::Array::New(v8::Isolate::GetCurrent()) +#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) #define SWIGV8_FUNCTEMPLATE_NEW(func) v8::FunctionTemplate::New(v8::Isolate::GetCurrent(), func) @@ -608,7 +608,7 @@ v8::Handle SWIGV8_AppendOutput(v8::Local result, v8::Handl SWIGV8_HANDLESCOPE_ESC(); if (result->IsUndefined()) { - result = SWIGV8_ARRAY_NEW(); + result = SWIGV8_ARRAY_NEW(0); } #if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) v8::Handle arr = v8::Handle::Cast(result); -- cgit v1.2.1 From 11e2f538403de78f9a031a171e644d7999cb9a22 Mon Sep 17 00:00:00 2001 From: Nihal Date: Sun, 25 Jun 2017 12:17:47 +0530 Subject: Object Structure approach Code Takes care of simple class wrapping with pointers, enum, values, variables, and inheritance. --- Lib/php/php.swg | 19 ++++++++----------- Lib/php/phprun.swg | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 11 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 0ac46e006..b462415f8 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -85,10 +85,9 @@ /* Object passed by value. Convert to a pointer */ %typemap(in) SWIGTYPE ($&1_ltype tmp) %{ - if (SWIG_ConvertPtr(&$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); - } - $1 = *tmp; + $arg2if (SWIG_ConvertPtr(&$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) + $arg2SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); + $arg2$1 = *tmp; %} %typemap(directorout) SWIGTYPE ($&1_ltype tmp) @@ -104,9 +103,8 @@ %typemap(in) SWIGTYPE *, SWIGTYPE [] %{ - if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); - } + $arg2if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0) + $arg2SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); %} %typemap(in) SWIGTYPE & @@ -133,9 +131,8 @@ %typemap(in) SWIGTYPE *DISOWN %{ - if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN ) < 0) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); - } + $arg2if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN ) < 0) + $arg2SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); %} %typemap(argout) SWIGTYPE *, @@ -369,7 +366,7 @@ SWIGTYPE &, SWIGTYPE && %{ - SWIG_SetPointerZval(return_value, (void *)$1, $1_descriptor, $owner); + SWIG_SetZval($result, $newobj , $c_obj, (void *)result, SWIGTYPE$swig_type, $zend_obj); %} %typemap(out) SWIGTYPE *const& diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 5c62d1927..79f3f2cd1 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -237,3 +237,23 @@ static swig_module_info *SWIG_Php_GetModule() { static void SWIG_Php_SetModule(swig_module_info *pointer) { REGISTER_MAIN_LONG_CONSTANT(const_name, (long) pointer, CONST_PERSISTENT | CONST_CS); } + +static void +SWIG_SetZval( zval *zv, int object, int class_obj ,void *ptr, swig_type_info *type, zend_object *std) { + + if (class_obj) + return; + + if (!ptr) { + ZVAL_NULL(zv); + return; + } + + if (object == 1) { + ZVAL_OBJ(zv,std); + } + + if (object == 2) { + SWIG_SetPointerZval(zv,ptr,type,class_obj); + } +} -- cgit v1.2.1 From 4458040975b702d3c17fa11fea5c3e934482a375 Mon Sep 17 00:00:00 2001 From: Nihal Date: Tue, 11 Jul 2017 08:13:40 +0530 Subject: Refactor Code: Change Approach to emit necessary code for pointer params. Use in typemap. --- Lib/php/php.swg | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index b462415f8..3efd0a285 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -85,9 +85,14 @@ /* Object passed by value. Convert to a pointer */ %typemap(in) SWIGTYPE ($&1_ltype tmp) %{ - $arg2if (SWIG_ConvertPtr(&$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) - $arg2SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); - $arg2$1 = *tmp; + if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { + $1 = *$obj_value; + } + else { + if (SWIG_ConvertPtr(&$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + $1 = *tmp; + } %} %typemap(directorout) SWIGTYPE ($&1_ltype tmp) @@ -103,8 +108,13 @@ %typemap(in) SWIGTYPE *, SWIGTYPE [] %{ - $arg2if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0) - $arg2SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { + $1 = $obj_value; + } + else { + if (SWIG_ConvertPtr(&$linput, (void **) &$1, $1_descriptor, 0) < 0) + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + } %} %typemap(in) SWIGTYPE & -- cgit v1.2.1 From 290198495ff16b42ea16a48a3b7bf4dc4acbfe3c Mon Sep 17 00:00:00 2001 From: Nihal Date: Tue, 11 Jul 2017 08:53:32 +0530 Subject: Support Disown functionality. Creating newobject variable under struct which stores this pointer. Using that to implement Disown. --- Lib/php/php.swg | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 3efd0a285..0542ea596 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -141,8 +141,14 @@ %typemap(in) SWIGTYPE *DISOWN %{ - $arg2if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN ) < 0) - $arg2SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); + if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { + Z_$upper_param_OBJ_P(&$input)->newobject = 0; + $1 = Z_$upper_param_OBJ_P(&$input)->$lower_param_obj; + } + else { + if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN ) < 0) + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + } %} %typemap(argout) SWIGTYPE *, -- cgit v1.2.1 From a71b34920473033a68014c34d869d554a3bb755c Mon Sep 17 00:00:00 2001 From: Nihal Date: Tue, 11 Jul 2017 21:08:13 +0530 Subject: Add overload Support. Use in house SWIG_overload_dispatch for class overloaded methods. --- Lib/php/php.swg | 34 +++++++++++++++++++++++----------- Lib/php/phprun.swg | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 11 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 0542ea596..1a8329609 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -119,9 +119,9 @@ %typemap(in) SWIGTYPE & %{ - if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); - } + /*if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + */ %} %typemap(in) SWIGTYPE && @@ -482,8 +482,11 @@ %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE { - void *tmp; - _v = (SWIG_ConvertPtr(&$input, (void **)&tmp, $&1_descriptor, 0) >= 0); + if (Z_TYPE($input) == IS_OBJECT && SWIG_is_correct_object(&$input,$1_descriptor)) + _v = 1; + else + _v = 0; + //_v = (SWIG_ConvertPtr(&$input, (void**)&tmp, $1_descriptor, 0) >= 0); } %typecheck(SWIG_TYPECHECK_POINTER) @@ -493,20 +496,29 @@ SWIGTYPE &&, SWIGTYPE *const& { - void *tmp; - _v = (SWIG_ConvertPtr(&$input, (void**)&tmp, $1_descriptor, 0) >= 0); + if (Z_TYPE($input) == IS_OBJECT && SWIG_is_correct_object(&$input,$1_descriptor)) + _v = 1; + else + _v = 0; + //_v = (SWIG_ConvertPtr(&$input, (void**)&tmp, $1_descriptor, 0) >= 0); } %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *const& { - void *tmp; - _v = (SWIG_ConvertPtr(&$input, (void**)&tmp, $*1_descriptor, 0) >= 0); + if (Z_TYPE($input) == IS_OBJECT && SWIG_is_correct_object(&$input,$1_descriptor)) + _v = 1; + else + _v = 0; + //_v = (SWIG_ConvertPtr(&$input, (void**)&tmp, $1_descriptor, 0) >= 0); } %typecheck(SWIG_TYPECHECK_VOIDPTR) void * { - void *tmp; - _v = (SWIG_ConvertPtr(&$input, (void**)&tmp, 0, 0) >= 0); + if (Z_TYPE($input) == IS_OBJECT && SWIG_is_correct_object(&$input,$1_descriptor)) + _v = 1; + else + _v = 0; + //_v = (SWIG_ConvertPtr(&$input, (void**)&tmp, $1_descriptor, 0) >= 0); } /* Exception handling */ diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 79f3f2cd1..bcc8c482f 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -257,3 +257,47 @@ SWIG_SetZval( zval *zv, int object, int class_obj ,void *ptr, swig_type_info *ty SWIG_SetPointerZval(zv,ptr,type,class_obj); } } + +static int +is_derived_class(zend_class_entry *child_class, zend_class_entry *parent_class) /* {{{ */ +{ + child_class = child_class->parent; + while (child_class) { + if (child_class == parent_class) { + return 1; + } + child_class = child_class->parent; + } + return 0; +} + +static int +SWIG_is_correct_object (zval *zv, swig_type_info *ty) { + + int return_value = 0; + + int excess = strlen(strchr(SWIG_TypePrettyName(ty),' ')); + if (excess == 0) + excess = strlen(strchr(SWIG_TypePrettyName(ty),'*')); + + int needed_length = strlen(SWIG_TypePrettyName(ty))-excess; + + char *ty_name = (char *)malloc(needed_length); + memcpy(ty_name,SWIG_TypePrettyName(ty),needed_length); + + zend_class_entry *lookup_ce = zend_lookup_class(zend_string_init(ty_name, needed_length , 0)); + zend_string *zend_class_name = zend_string_copy(Z_OBJ_P(zv)->ce->name); + zend_class_entry *zval_ce = zend_lookup_class(zend_class_name); + + if (!zval_ce || !lookup_ce) + return 0; + + if (strcmp(zend_class_name->val,ty_name)) { + if (is_derived_class(zval_ce,lookup_ce)) + return_value = 1; + } + else + return_value = 1; + + return return_value; +} -- cgit v1.2.1 From b38e6d958420a3b0f9a9fabdff0456bf96eeff1d Mon Sep 17 00:00:00 2001 From: Nihal Date: Wed, 12 Jul 2017 08:29:27 +0530 Subject: Remove SWIG_Get_Type function usage in class constants. Add class constant typemaps. (classconsttab) --- Lib/php/const.i | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'Lib') diff --git a/Lib/php/const.i b/Lib/php/const.i index d62f162c1..c6cad6a3f 100644 --- a/Lib/php/const.i +++ b/Lib/php/const.i @@ -3,6 +3,27 @@ * * Typemaps for constants * ----------------------------------------------------------------------------- */ +%typemap(classconsttab) int, + unsigned int, + short, + unsigned short, + long, + unsigned long, + unsigned char, + signed char, + enum SWIGTYPE + "zend_declare_class_constant_long($class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, $value);"; + + %typemap(classconsttab) bool + "zend_declare_class_constant_bool($class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, $value);"; + + %typemap(classconsttab) float, + double + "zend_declare_class_constant_double($class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, $value);"; + + %typemap(classconsttab) char, + string + "zend_declare_class_constant_string($class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, \"$value\");"; %typemap(consttab) int, unsigned int, -- cgit v1.2.1 From 4c55919975f03a7af8679aa60c7a358ec2f38ed0 Mon Sep 17 00:00:00 2001 From: Nihal Date: Tue, 18 Jul 2017 23:30:07 +0530 Subject: Refactor Code to use swig_object_wrapper for wrapping classes. And use void * to store class pointers. --- Lib/php/php.swg | 35 +++++++++++------------------------ Lib/php/phprun.swg | 47 ++++++----------------------------------------- 2 files changed, 17 insertions(+), 65 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 1a8329609..4d9812045 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -119,9 +119,8 @@ %typemap(in) SWIGTYPE & %{ - /*if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) + if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); - */ %} %typemap(in) SWIGTYPE && @@ -142,8 +141,8 @@ %typemap(in) SWIGTYPE *DISOWN %{ if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { - Z_$upper_param_OBJ_P(&$input)->newobject = 0; - $1 = Z_$upper_param_OBJ_P(&$input)->$lower_param_obj; + Z_FETCH_OBJ_P(&$input)->newobject = 0; + $1 = ($lower_param *)Z_FETCH_OBJ_P(&$input)->ptr; } else { if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN ) < 0) @@ -482,11 +481,8 @@ %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE { - if (Z_TYPE($input) == IS_OBJECT && SWIG_is_correct_object(&$input,$1_descriptor)) - _v = 1; - else - _v = 0; - //_v = (SWIG_ConvertPtr(&$input, (void**)&tmp, $1_descriptor, 0) >= 0); + void *tmp; + _v = (SWIG_ConvertPtr(&$input, (void **)&tmp, $1_descriptor, 0) >= 0); } %typecheck(SWIG_TYPECHECK_POINTER) @@ -496,29 +492,20 @@ SWIGTYPE &&, SWIGTYPE *const& { - if (Z_TYPE($input) == IS_OBJECT && SWIG_is_correct_object(&$input,$1_descriptor)) - _v = 1; - else - _v = 0; - //_v = (SWIG_ConvertPtr(&$input, (void**)&tmp, $1_descriptor, 0) >= 0); + void *tmp; + _v = (SWIG_ConvertPtr(&$input, (void **)&tmp, $1_descriptor, 0) >= 0); } %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *const& { - if (Z_TYPE($input) == IS_OBJECT && SWIG_is_correct_object(&$input,$1_descriptor)) - _v = 1; - else - _v = 0; - //_v = (SWIG_ConvertPtr(&$input, (void**)&tmp, $1_descriptor, 0) >= 0); + void *tmp; + _v = (SWIG_ConvertPtr(&$input, (void **)&tmp, $1_descriptor, 0) >= 0); } %typecheck(SWIG_TYPECHECK_VOIDPTR) void * { - if (Z_TYPE($input) == IS_OBJECT && SWIG_is_correct_object(&$input,$1_descriptor)) - _v = 1; - else - _v = 0; - //_v = (SWIG_ConvertPtr(&$input, (void**)&tmp, $1_descriptor, 0) >= 0); + void *tmp; + _v = (SWIG_ConvertPtr(&$input, (void **)&tmp, $1_descriptor, 0) >= 0); } /* Exception handling */ diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index bcc8c482f..0c867754c 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -56,6 +56,8 @@ static int default_error_code = E_ERROR; and need freeing, or not */ typedef struct { void * ptr; + zend_object std; + HashTable *extras; int newobject; } swig_object_wrapper; @@ -258,46 +260,9 @@ SWIG_SetZval( zval *zv, int object, int class_obj ,void *ptr, swig_type_info *ty } } -static int -is_derived_class(zend_class_entry *child_class, zend_class_entry *parent_class) /* {{{ */ -{ - child_class = child_class->parent; - while (child_class) { - if (child_class == parent_class) { - return 1; - } - child_class = child_class->parent; - } - return 0; -} - -static int -SWIG_is_correct_object (zval *zv, swig_type_info *ty) { - - int return_value = 0; - - int excess = strlen(strchr(SWIG_TypePrettyName(ty),' ')); - if (excess == 0) - excess = strlen(strchr(SWIG_TypePrettyName(ty),'*')); - - int needed_length = strlen(SWIG_TypePrettyName(ty))-excess; - - char *ty_name = (char *)malloc(needed_length); - memcpy(ty_name,SWIG_TypePrettyName(ty),needed_length); - - zend_class_entry *lookup_ce = zend_lookup_class(zend_string_init(ty_name, needed_length , 0)); - zend_string *zend_class_name = zend_string_copy(Z_OBJ_P(zv)->ce->name); - zend_class_entry *zval_ce = zend_lookup_class(zend_class_name); - - if (!zval_ce || !lookup_ce) - return 0; - - if (strcmp(zend_class_name->val,ty_name)) { - if (is_derived_class(zval_ce,lookup_ce)) - return_value = 1; - } - else - return_value = 1; +#define Z_FETCH_OBJ_P(zv) php_fetch_object(Z_OBJ_P(zv)) - return return_value; +static inline +swig_object_wrapper * php_fetch_object(zend_object *obj) { + return (swig_object_wrapper *)((char *)obj - XtOffsetOf(swig_object_wrapper, std)); } -- cgit v1.2.1 From 67fb198b7343f232408580b8cd7a3b0ebb8d6502 Mon Sep 17 00:00:00 2001 From: Nihal Date: Thu, 27 Jul 2017 18:33:20 +0530 Subject: SWIG Director Support with Class Structure. Refactor Code to support rename. Refactor Code - Support Director Classes. - %rename support of class names and method names. - Creation and destruction methods after inline code. - Test case check::function return true. - Needs Fixup --- Lib/php/director.swg | 22 ++++++++-------------- Lib/php/php.swg | 2 +- 2 files changed, 9 insertions(+), 15 deletions(-) (limited to 'Lib') diff --git a/Lib/php/director.swg b/Lib/php/director.swg index ea0eba8ac..68901a0d5 100644 --- a/Lib/php/director.swg +++ b/Lib/php/director.swg @@ -86,21 +86,15 @@ namespace Swig { ZVAL_COPY_VALUE(&swig_self, self); } - static bool swig_is_overridden_method(const char *cname, const char *lc_fname) { - bool result = false; + static bool swig_is_overridden_method(const char *cname, zval *ptr) { zend_string * cname_str = zend_string_init(cname, strlen(cname), 0); - zend_class_entry *ce = zend_lookup_class(cname_str); - if (ce) { - zval * mptr = zend_hash_str_find(&ce->function_table, lc_fname, strlen(lc_fname)); - if (mptr) { - // common.scope points to zend_class_entry for the declaring class, - // and there's only one of those per class, so we can just use a - // pointer compare here. - result = Z_FUNC_P(mptr)->common.scope != ce; - } - } - zend_string_release(cname_str); - return result; + zend_class_entry *cname_ce = zend_lookup_class(cname_str); + zend_class_entry *ptr_ce = Z_OBJCE_P(ptr); + + if (cname_ce == ptr_ce) + return true; + + return false; } template diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 4d9812045..dca591f53 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -381,7 +381,7 @@ SWIGTYPE &, SWIGTYPE && %{ - SWIG_SetZval($result, $newobj , $c_obj, (void *)result, SWIGTYPE$swig_type, $zend_obj); + SWIG_SetZval($result, $newobj , $c_obj, (void *)result, $1_descriptor, $zend_obj); %} %typemap(out) SWIGTYPE *const& -- cgit v1.2.1 From a930743932f789561325b869aa4d3af8822fb824 Mon Sep 17 00:00:00 2001 From: Nihal Date: Fri, 4 Aug 2017 23:13:19 +0530 Subject: Refactor Code and Support phpinterfaces, factory dispatch - rewire return of type SWIGTYPE - {NULL, NULL, NULL} to ZEND_FE_END - feature:warnfilter - 462 of missing setter - refactor code of return type (replaced) - support conversion_operator --- Lib/php/factory.i | 12 ++++++++++-- Lib/php/php.swg | 36 ++++++++++++++++++++++++++++++++++-- Lib/php/phprun.swg | 31 ++++++++++++++++--------------- 3 files changed, 60 insertions(+), 19 deletions(-) (limited to 'Lib') diff --git a/Lib/php/factory.i b/Lib/php/factory.i index c4e082dd2..6a6b504ec 100644 --- a/Lib/php/factory.i +++ b/Lib/php/factory.i @@ -95,7 +95,15 @@ if (!dcast) { Type *dobj = dynamic_cast($1); if (dobj) { dcast = 1; - SWIG_SetPointerZval(return_value, SWIG_as_voidptr(dobj),$descriptor(Type *), $owner); + zend_object *std = NULL; + if ($newobj) { + zend_class_entry *ce = zend_lookup_class(zend_string_init("Type", sizeof("Type")-1, 0)); + std = ce->create_object(ce); + } + else { + std = $zend_obj; + } + SWIG_SetZval(return_value, $newobj , $c_obj, SWIG_as_voidptr(dobj), $descriptor(Type *), std); } }%enddef @@ -104,6 +112,6 @@ if (!dcast) { int dcast = 0; %formacro(%_factory_dispatch, Types) if (!dcast) { - SWIG_SetPointerZval(return_value, SWIG_as_voidptr($1),$descriptor, $owner); + SWIG_SetZval(return_value, $newobj , $c_obj, SWIG_as_voidptr($1), $descriptor, $zend_obj); } }%enddef diff --git a/Lib/php/php.swg b/Lib/php/php.swg index dca591f53..1ababd48b 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -421,13 +421,45 @@ #ifdef __cplusplus { $&1_ltype resultobj = new $1_ltype((const $1_ltype &) $1); - SWIG_SetPointerZval(return_value, (void *)resultobj, $&1_descriptor, 1); + SWIG_SetZval(return_value, $newobj , $c_obj, (void *)resultobj, $&1_descriptor, $zend_obj); + swig_object_wrapper *obj = NULL; + + HashTable * ht = NULL; + + obj = (swig_object_wrapper *) Z_FETCH_OBJ_P(return_value); + obj->ptr = (void *)resultobj; + ht = Z_OBJ_HT_P(return_value)->get_properties(return_value); + if(ht) { + zval zv; + ZVAL_RES(&zv,zend_register_resource(resultobj,*(int *)($&1_descriptor->clientdata))); + zend_hash_str_add(ht, "_cPtr", sizeof("_cPtr") - 1, &zv); + } + if ($newobj == 1) + obj->newobject = 1; + else + obj->newobject = 0; } #else { $&1_ltype resultobj = ($&1_ltype) emalloc(sizeof($1_type)); memcpy(resultobj, &$1, sizeof($1_type)); - SWIG_SetPointerZval(return_value, (void *)resultobj, $&1_descriptor, 1); + SWIG_SetZval(return_value, $newobj , $c_obj, (void *)resultobj, $&1_descriptor, $zend_obj); + swig_object_wrapper *obj = NULL; + + HashTable * ht = NULL; + + obj = (swig_object_wrapper *) Z_FETCH_OBJ_P(return_value); + obj->ptr = (void *)resultobj; + ht = Z_OBJ_HT_P(return_value)->get_properties(return_value); + if(ht) { + zval zv; + ZVAL_RES(&zv,zend_register_resource(resultobj,*(int *)($&1_descriptor->clientdata))); + zend_hash_str_add(ht, "_cPtr", sizeof("_cPtr") - 1, &zv); + } + if ($newobj) + obj->newobject = 1; + else + obj->newobject = 0; } #endif diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 0c867754c..e6d361c8d 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -225,21 +225,6 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { return -1; } -static char const_name[] = "swig_runtime_data_type_pointer"; -static swig_module_info *SWIG_Php_GetModule() { - zval *pointer = zend_get_constant_str(const_name, sizeof(const_name) - 1); - if (pointer) { - if (Z_TYPE_P(pointer) == IS_LONG) { - return (swig_module_info *) pointer->value.lval; - } - } - return NULL; -} - -static void SWIG_Php_SetModule(swig_module_info *pointer) { - REGISTER_MAIN_LONG_CONSTANT(const_name, (long) pointer, CONST_PERSISTENT | CONST_CS); -} - static void SWIG_SetZval( zval *zv, int object, int class_obj ,void *ptr, swig_type_info *type, zend_object *std) { @@ -266,3 +251,19 @@ static inline swig_object_wrapper * php_fetch_object(zend_object *obj) { return (swig_object_wrapper *)((char *)obj - XtOffsetOf(swig_object_wrapper, std)); } + +static char const_name[] = "swig_runtime_data_type_pointer"; +static swig_module_info *SWIG_Php_GetModule() { + zval *pointer = zend_get_constant_str(const_name, sizeof(const_name) - 1); + if (pointer) { + if (Z_TYPE_P(pointer) == IS_LONG) { + return (swig_module_info *) pointer->value.lval; + } + } + return NULL; +} + +static void SWIG_Php_SetModule(swig_module_info *pointer) { + REGISTER_MAIN_LONG_CONSTANT(const_name, (long) pointer, CONST_PERSISTENT | CONST_CS); +} + -- cgit v1.2.1 From da53351cac975ce91d2745556ef4f2d98972f8d2 Mon Sep 17 00:00:00 2001 From: Nihal Date: Sat, 5 Aug 2017 10:22:51 +0530 Subject: Refactor code and introduce some functionalities. Code Refactor - Refactor code for return type of SWIGTYPE - Workaround for Namespaced classes. - Refactor code of SWIG_SetZval to take care of objects in class constructor. - Introduce SWIG_generalize_object to generalize each object to swig object wrapper. - Catch feature:immutable instead of feature:warnfilter - 462 for missing setter. - Refactor code to create PHP objects for all instances of value, reference and pointer return types of C++ objects. - Introduce getAccessMode to get the Access Mode of a method for generating Wrapper. - Refactor free_object creation to include need_free condition. This is to check if there is a need to free. (Virtual Protected Destructors) - Support for feature:exceptionclass. Extends class Exception. - Improve condition check in Director class constructor to distinguish between, extended class creation or not. Swig::Director::swig_is_overridden_method is used. --- Lib/php/factory.i | 4 +- Lib/php/php.swg | 106 +++++++++++++++++++++-------------------------------- Lib/php/phprun.swg | 38 ++++++++++++++----- 3 files changed, 73 insertions(+), 75 deletions(-) (limited to 'Lib') diff --git a/Lib/php/factory.i b/Lib/php/factory.i index 6a6b504ec..565383c40 100644 --- a/Lib/php/factory.i +++ b/Lib/php/factory.i @@ -103,7 +103,7 @@ if (!dcast) { else { std = $zend_obj; } - SWIG_SetZval(return_value, $newobj , $c_obj, SWIG_as_voidptr(dobj), $descriptor(Type *), std); + SWIG_SetZval(return_value, $classZv, $owner, $newobj, $c_obj, SWIG_as_voidptr(dobj), $descriptor(Type *), std); } }%enddef @@ -112,6 +112,6 @@ if (!dcast) { int dcast = 0; %formacro(%_factory_dispatch, Types) if (!dcast) { - SWIG_SetZval(return_value, $newobj , $c_obj, SWIG_as_voidptr($1), $descriptor, $zend_obj); + SWIG_SetZval(return_value, $classZv, $owner, $newobj, $c_obj, SWIG_as_voidptr($1), $descriptor, $zend_obj); } }%enddef diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 1ababd48b..b521d452e 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -85,30 +85,30 @@ /* Object passed by value. Convert to a pointer */ %typemap(in) SWIGTYPE ($&1_ltype tmp) %{ - if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { + if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { $1 = *$obj_value; } else { if (SWIG_ConvertPtr(&$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1&_descriptor"); $1 = *tmp; } %} %typemap(directorout) SWIGTYPE ($&1_ltype tmp) %{ - /* If exit was via exception, PHP NULL is returned so skip the conversion. */ - if (!EG(exception)) { - if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); - $result = *tmp; - } + /* If exit was via exception, PHP NULL is returned so skip the conversion. */ + if (!EG(exception)) { + if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); + $result = *tmp; + } %} %typemap(in) SWIGTYPE *, SWIGTYPE [] %{ - if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { + if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { $1 = $obj_value; } else { @@ -119,30 +119,40 @@ %typemap(in) SWIGTYPE & %{ - if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) + if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { + $1 = $obj_value; + } + else { + if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + } %} %typemap(in) SWIGTYPE && %{ - if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); - } + if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { + $1 = $obj_value; + } + else { + if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) { + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + } + } %} %typemap(in) SWIGTYPE *const& ($*ltype temp) %{ - if (SWIG_ConvertPtr(&$input, (void **) &temp, $*1_descriptor, 0) < 0) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $*1_descriptor"); - } - $1 = ($1_ltype)&temp; + if (SWIG_ConvertPtr(&$input, (void **) &temp, $*1_descriptor, 0) < 0) { + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $*1_descriptor"); + } + $1 = ($1_ltype)&temp; %} %typemap(in) SWIGTYPE *DISOWN %{ if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { - Z_FETCH_OBJ_P(&$input)->newobject = 0; - $1 = ($lower_param *)Z_FETCH_OBJ_P(&$input)->ptr; + SWIG_Z_FETCH_OBJ_P(&$input)->newobject = 0; + $1 = ($lower_param *)SWIG_Z_FETCH_OBJ_P(&$input)->ptr; } else { if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN ) < 0) @@ -157,12 +167,12 @@ %typemap(in) void * %{ - if (SWIG_ConvertPtr(&$input, (void **) &$1, 0, 0) < 0) { - /* Allow NULL from php for void* */ - if (Z_ISNULL($input)) $1=0; - else - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); - } + if (SWIG_ConvertPtr(&$input, (void **) &$1, 0, 0) < 0) { + /* Allow NULL from php for void* */ + if (Z_ISNULL($input)) $1=0; + else + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); + } %} /* Special case when void* is passed by reference so it can be made to point @@ -381,12 +391,12 @@ SWIGTYPE &, SWIGTYPE && %{ - SWIG_SetZval($result, $newobj , $c_obj, (void *)result, $1_descriptor, $zend_obj); + SWIG_SetZval($result, $classZv, $owner, $newobj, $c_obj, (void *)result, $1_descriptor, $zend_obj); %} %typemap(out) SWIGTYPE *const& %{ - SWIG_SetPointerZval(return_value, (void *)*$1, $*1_descriptor, $owner); + SWIG_SetZval(return_value, $classZv, $owner, $newobj, $c_obj, (void *)*$1, $*1_descriptor, $zend_obj); %} %typemap(directorin) SWIGTYPE *, @@ -421,45 +431,13 @@ #ifdef __cplusplus { $&1_ltype resultobj = new $1_ltype((const $1_ltype &) $1); - SWIG_SetZval(return_value, $newobj , $c_obj, (void *)resultobj, $&1_descriptor, $zend_obj); - swig_object_wrapper *obj = NULL; - - HashTable * ht = NULL; - - obj = (swig_object_wrapper *) Z_FETCH_OBJ_P(return_value); - obj->ptr = (void *)resultobj; - ht = Z_OBJ_HT_P(return_value)->get_properties(return_value); - if(ht) { - zval zv; - ZVAL_RES(&zv,zend_register_resource(resultobj,*(int *)($&1_descriptor->clientdata))); - zend_hash_str_add(ht, "_cPtr", sizeof("_cPtr") - 1, &zv); - } - if ($newobj == 1) - obj->newobject = 1; - else - obj->newobject = 0; + SWIG_SetZval(return_value, $classZv, $owner, $newobj, $c_obj, (void *)resultobj, $&1_descriptor, $zend_obj); } #else { $&1_ltype resultobj = ($&1_ltype) emalloc(sizeof($1_type)); memcpy(resultobj, &$1, sizeof($1_type)); - SWIG_SetZval(return_value, $newobj , $c_obj, (void *)resultobj, $&1_descriptor, $zend_obj); - swig_object_wrapper *obj = NULL; - - HashTable * ht = NULL; - - obj = (swig_object_wrapper *) Z_FETCH_OBJ_P(return_value); - obj->ptr = (void *)resultobj; - ht = Z_OBJ_HT_P(return_value)->get_properties(return_value); - if(ht) { - zval zv; - ZVAL_RES(&zv,zend_register_resource(resultobj,*(int *)($&1_descriptor->clientdata))); - zend_hash_str_add(ht, "_cPtr", sizeof("_cPtr") - 1, &zv); - } - if ($newobj) - obj->newobject = 1; - else - obj->newobject = 0; + SWIG_SetZval(return_value, $classZv, $owner, $newobj, $c_obj, (void *)resultobj, $&1_descriptor, $zend_obj); } #endif @@ -514,7 +492,7 @@ %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE { void *tmp; - _v = (SWIG_ConvertPtr(&$input, (void **)&tmp, $1_descriptor, 0) >= 0); + _v = (SWIG_ConvertPtr(&$input, (void **)&tmp, $&1_descriptor, 0) >= 0); } %typecheck(SWIG_TYPECHECK_POINTER) @@ -531,13 +509,13 @@ %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *const& { void *tmp; - _v = (SWIG_ConvertPtr(&$input, (void **)&tmp, $1_descriptor, 0) >= 0); + _v = (SWIG_ConvertPtr(&$input, (void **)&tmp, $*1_descriptor, 0) >= 0); } %typecheck(SWIG_TYPECHECK_VOIDPTR) void * { void *tmp; - _v = (SWIG_ConvertPtr(&$input, (void **)&tmp, $1_descriptor, 0) >= 0); + _v = (SWIG_ConvertPtr(&$input, (void **)&tmp, 0, 0) >= 0); } /* Exception handling */ diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index e6d361c8d..b048dc569 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -225,11 +225,37 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { return -1; } +#define SWIG_Z_FETCH_OBJ_P(zv) php_fetch_object(Z_OBJ_P(zv)) + +static inline +swig_object_wrapper * php_fetch_object(zend_object *obj) { + return (swig_object_wrapper *)((char *)obj - XtOffsetOf(swig_object_wrapper, std)); +} + static void -SWIG_SetZval( zval *zv, int object, int class_obj ,void *ptr, swig_type_info *type, zend_object *std) { +SWIG_generalize_object(zval *zval_obj, void *ptr, int class_obj, int userNewObj ,swig_type_info *type) { + swig_object_wrapper *obj = NULL; + + HashTable * ht = NULL; + + obj = (swig_object_wrapper *) SWIG_Z_FETCH_OBJ_P(zval_obj); + obj->ptr = (void *)ptr; + ht = Z_OBJ_HT_P(zval_obj)->get_properties(zval_obj); + if(ht) { + zval zv; + ZVAL_RES(&zv,zend_register_resource(ptr,*(int *)(type->clientdata))); + zend_hash_str_add(ht, "_cPtr", sizeof("_cPtr") - 1, &zv); + } + obj->newobject = userNewObj; +} - if (class_obj) +static void +SWIG_SetZval( zval *zv, zval *class_zv, int userNewObj ,int object, int class_obj ,void *ptr, swig_type_info *type, zend_object *std) { + + if (class_obj) { + SWIG_generalize_object(class_zv, ptr, class_obj, userNewObj ,type); return; + } if (!ptr) { ZVAL_NULL(zv); @@ -238,6 +264,7 @@ SWIG_SetZval( zval *zv, int object, int class_obj ,void *ptr, swig_type_info *ty if (object == 1) { ZVAL_OBJ(zv,std); + SWIG_generalize_object(zv, ptr, class_obj, userNewObj, type); } if (object == 2) { @@ -245,13 +272,6 @@ SWIG_SetZval( zval *zv, int object, int class_obj ,void *ptr, swig_type_info *ty } } -#define Z_FETCH_OBJ_P(zv) php_fetch_object(Z_OBJ_P(zv)) - -static inline -swig_object_wrapper * php_fetch_object(zend_object *obj) { - return (swig_object_wrapper *)((char *)obj - XtOffsetOf(swig_object_wrapper, std)); -} - static char const_name[] = "swig_runtime_data_type_pointer"; static swig_module_info *SWIG_Php_GetModule() { zval *pointer = zend_get_constant_str(const_name, sizeof(const_name) - 1); -- cgit v1.2.1 From a687b020e27ecb969b84caa9473f06f3f9eec60e Mon Sep 17 00:00:00 2001 From: Nihal Date: Sun, 13 Aug 2017 12:14:09 +0530 Subject: Refactor code and change change enum_scope_template test to use class enums. Fix few test cases. - Change enum_scope_template test to use class enums. - Move the conversion of void* of ptr in swig wrapper to class pointer to Lib files. - Synchronize between old and new flow. Old flow to accept newly created objects, with the use of a new property SWIG_classWrapper to newly created objects. - ZEND_BEGIN_ARG_INFO_EX to hold exact number of arguments required. - Fix the constructor overloading bug in the in-house Swig_class_overload_dispatch function - Add helper function to check if the class is wrapped. - Add ZEND_ACC_ABSTRACT to virtual functions to make the class abstract. - Change how wname is selected for staticmemberfn. - Helper function to get names without namespace getNameWithoutNamespace. - Fix bugs on class entry level at class handler. - Move all entry level code to class handler from class decleration. - Checking if base.item is null before using it. - Check if the parent class is wrapped before using its class entry. --- Lib/php/php.swg | 17 +++++++++++------ Lib/php/phprun.swg | 25 ++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 9 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index b521d452e..ebd58fe13 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -86,7 +86,7 @@ %typemap(in) SWIGTYPE ($&1_ltype tmp) %{ if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { - $1 = *$obj_value; + $1 = *(($1_ltype *)$obj_value); } else { if (SWIG_ConvertPtr(&$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) @@ -109,7 +109,7 @@ SWIGTYPE [] %{ if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { - $1 = $obj_value; + $1 = ($1_ltype) $obj_value; } else { if (SWIG_ConvertPtr(&$linput, (void **) &$1, $1_descriptor, 0) < 0) @@ -120,7 +120,7 @@ %typemap(in) SWIGTYPE & %{ if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { - $1 = $obj_value; + $1 = ($1_ltype) $obj_value; } else { if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) @@ -131,7 +131,7 @@ %typemap(in) SWIGTYPE && %{ if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { - $1 = $obj_value; + $1 = ($1_ltype) $obj_value; } else { if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) { @@ -142,10 +142,15 @@ %typemap(in) SWIGTYPE *const& ($*ltype temp) %{ - if (SWIG_ConvertPtr(&$input, (void **) &temp, $*1_descriptor, 0) < 0) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $*1_descriptor"); + if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { + $1 = ($1_ltype) $obj_value; } + else { + if (SWIG_ConvertPtr(&$input, (void **) &temp, $*1_descriptor, 0) < 0) { + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $*1_descriptor"); + } $1 = ($1_ltype)&temp; + } %} %typemap(in) SWIGTYPE *DISOWN diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index b048dc569..8edfa119e 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -185,6 +185,14 @@ SWIG_ConvertResourcePtr(zval *z, swig_type_info *ty, int flags) { type_name=zend_rsrc_list_get_rsrc_type(Z_RES_P(z)); + if (!type_name) { + if (Z_TYPE_P(z) == IS_OBJECT) { + HashTable * ht = Z_OBJ_HT_P(z)->get_properties(z); + zval * _cPtr = zend_hash_str_find(ht, "_cPtr", sizeof("_cPtr") - 1); + type_name=zend_rsrc_list_get_rsrc_type(Z_RES_P(_cPtr)); + } + } + return SWIG_ConvertResourceData(p, type_name, ty); } @@ -207,7 +215,13 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { _cPtr = Z_INDIRECT_P(_cPtr); } if (Z_TYPE_P(_cPtr) == IS_RESOURCE) { - *ptr = SWIG_ConvertResourcePtr(_cPtr, ty, flags); + zval *zv; + if (!zend_hash_str_exists(ht, "SWIG_classWrapper", sizeof("SWIG_classWrapper") - 1)) + zv = _cPtr; + else + zv = z; + + *ptr = SWIG_ConvertResourcePtr(zv, ty, flags); return (*ptr == NULL ? -1 : 0); } } @@ -245,6 +259,8 @@ SWIG_generalize_object(zval *zval_obj, void *ptr, int class_obj, int userNewObj zval zv; ZVAL_RES(&zv,zend_register_resource(ptr,*(int *)(type->clientdata))); zend_hash_str_add(ht, "_cPtr", sizeof("_cPtr") - 1, &zv); + ZVAL_TRUE(&zv); + zend_hash_str_add(ht, "SWIG_classWrapper", sizeof("SWIG_classWrapper") - 1, &zv); } obj->newobject = userNewObj; } @@ -252,7 +268,7 @@ SWIG_generalize_object(zval *zval_obj, void *ptr, int class_obj, int userNewObj static void SWIG_SetZval( zval *zv, zval *class_zv, int userNewObj ,int object, int class_obj ,void *ptr, swig_type_info *type, zend_object *std) { - if (class_obj) { + if (class_obj == 1) { SWIG_generalize_object(class_zv, ptr, class_obj, userNewObj ,type); return; } @@ -268,7 +284,10 @@ SWIG_SetZval( zval *zv, zval *class_zv, int userNewObj ,int object, int class_ob } if (object == 2) { - SWIG_SetPointerZval(zv,ptr,type,class_obj); + int newobj = class_obj; + if (class_obj == 2) + newobj = 1; + SWIG_SetPointerZval(zv,ptr,type,newobj); } } -- cgit v1.2.1 From 9fea6fc5ac81882221b019c47383b478145675a2 Mon Sep 17 00:00:00 2001 From: Nihal Date: Fri, 18 Aug 2017 08:41:14 +0530 Subject: Refactor code and solve few test cases. - Change the need of runtime check on old or new flow at wrapper generation time. - Change the check on add ZEND_ACC_ABSTRACT to GetFlag(n, "abstract") && Swig_directorclass(Swig_methodclass(n)) - workaround to solve abstract testcases at the moment. - Remove redundant code in class handler for getting namespaces (Not the correct approact) and use of zend_register_class_alias_ex. - Refactor choosing of class name to use sym:name by default. --- Lib/php/php.swg | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index ebd58fe13..5b20d9a6c 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -85,7 +85,7 @@ /* Object passed by value. Convert to a pointer */ %typemap(in) SWIGTYPE ($&1_ltype tmp) %{ - if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { + if ($needNewFlow) { $1 = *(($1_ltype *)$obj_value); } else { @@ -108,7 +108,7 @@ %typemap(in) SWIGTYPE *, SWIGTYPE [] %{ - if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { + if ($needNewFlow) { $1 = ($1_ltype) $obj_value; } else { @@ -119,7 +119,7 @@ %typemap(in) SWIGTYPE & %{ - if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { + if ($needNewFlow) { $1 = ($1_ltype) $obj_value; } else { @@ -130,7 +130,7 @@ %typemap(in) SWIGTYPE && %{ - if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { + if ($needNewFlow) { $1 = ($1_ltype) $obj_value; } else { @@ -142,7 +142,7 @@ %typemap(in) SWIGTYPE *const& ($*ltype temp) %{ - if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { + if ($needNewFlow) { $1 = ($1_ltype) $obj_value; } else { @@ -155,7 +155,7 @@ %typemap(in) SWIGTYPE *DISOWN %{ - if (zend_lookup_class(zend_string_init("$lower_param",sizeof("$lower_param")-1,0))) { + if ($needNewFlow) { SWIG_Z_FETCH_OBJ_P(&$input)->newobject = 0; $1 = ($lower_param *)SWIG_Z_FETCH_OBJ_P(&$input)->ptr; } -- cgit v1.2.1 From 4252b31f8fcac46e53e0fd3ded67992e214965b2 Mon Sep 17 00:00:00 2001 From: Nihal Date: Sun, 20 Aug 2017 01:54:07 +0530 Subject: Refactor code to rename class entry variables and ConvertPtr to work with wrapped objects. - Rename class entry variables to SWIGTYPE_class_ce - Refactor factory code to use SWIGTYPE_class_ce to create objects - Refactor ConvertPtr to work of wrapped class objects. --- Lib/php/const.i | 8 ++++---- Lib/php/factory.i | 9 +-------- Lib/php/phprun.swg | 26 ++++++++++++-------------- 3 files changed, 17 insertions(+), 26 deletions(-) (limited to 'Lib') diff --git a/Lib/php/const.i b/Lib/php/const.i index c6cad6a3f..666e86eee 100644 --- a/Lib/php/const.i +++ b/Lib/php/const.i @@ -12,18 +12,18 @@ unsigned char, signed char, enum SWIGTYPE - "zend_declare_class_constant_long($class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, $value);"; + "zend_declare_class_constant_long(SWIGTYPE_$class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, $value);"; %typemap(classconsttab) bool - "zend_declare_class_constant_bool($class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, $value);"; + "zend_declare_class_constant_bool(SWIGTYPE_$class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, $value);"; %typemap(classconsttab) float, double - "zend_declare_class_constant_double($class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, $value);"; + "zend_declare_class_constant_double(SWIGTYPE_$class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, $value);"; %typemap(classconsttab) char, string - "zend_declare_class_constant_string($class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, \"$value\");"; + "zend_declare_class_constant_string(SWIGTYPE_$class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, \"$value\");"; %typemap(consttab) int, unsigned int, diff --git a/Lib/php/factory.i b/Lib/php/factory.i index 565383c40..7dcd517ec 100644 --- a/Lib/php/factory.i +++ b/Lib/php/factory.i @@ -95,14 +95,7 @@ if (!dcast) { Type *dobj = dynamic_cast($1); if (dobj) { dcast = 1; - zend_object *std = NULL; - if ($newobj) { - zend_class_entry *ce = zend_lookup_class(zend_string_init("Type", sizeof("Type")-1, 0)); - std = ce->create_object(ce); - } - else { - std = $zend_obj; - } + zend_object *std = $descriptor(Type)##_ce->create_object($descriptor(Type)##_ce); SWIG_SetZval(return_value, $classZv, $owner, $newobj, $c_obj, SWIG_as_voidptr(dobj), $descriptor(Type *), std); } }%enddef diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 8edfa119e..acb856958 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -196,6 +196,13 @@ SWIG_ConvertResourcePtr(zval *z, swig_type_info *ty, int flags) { return SWIG_ConvertResourceData(p, type_name, ty); } +#define SWIG_Z_FETCH_OBJ_P(zv) php_fetch_object(Z_OBJ_P(zv)) + +static inline +swig_object_wrapper * php_fetch_object(zend_object *obj) { + return (swig_object_wrapper *)((char *)obj - XtOffsetOf(swig_object_wrapper, std)); +} + /* We allow passing of a RESOURCE pointing to the object or an OBJECT whose _cPtr is a resource pointing to the object */ static int @@ -211,17 +218,15 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { if (ht) { zval * _cPtr = zend_hash_str_find(ht, "_cPtr", sizeof("_cPtr") - 1); if (_cPtr) { + if (zend_hash_str_exists(ht, "SWIG_classWrapper", sizeof("SWIG_classWrapper") - 1)) { + *ptr = SWIG_Z_FETCH_OBJ_P(z)->ptr; + return (*ptr == NULL ? -1 : 0); + } if (Z_TYPE_P(_cPtr) == IS_INDIRECT) { _cPtr = Z_INDIRECT_P(_cPtr); } if (Z_TYPE_P(_cPtr) == IS_RESOURCE) { - zval *zv; - if (!zend_hash_str_exists(ht, "SWIG_classWrapper", sizeof("SWIG_classWrapper") - 1)) - zv = _cPtr; - else - zv = z; - - *ptr = SWIG_ConvertResourcePtr(zv, ty, flags); + *ptr = SWIG_ConvertResourcePtr(_cPtr, ty, flags); return (*ptr == NULL ? -1 : 0); } } @@ -239,13 +244,6 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { return -1; } -#define SWIG_Z_FETCH_OBJ_P(zv) php_fetch_object(Z_OBJ_P(zv)) - -static inline -swig_object_wrapper * php_fetch_object(zend_object *obj) { - return (swig_object_wrapper *)((char *)obj - XtOffsetOf(swig_object_wrapper, std)); -} - static void SWIG_generalize_object(zval *zval_obj, void *ptr, int class_obj, int userNewObj ,swig_type_info *type) { swig_object_wrapper *obj = NULL; -- cgit v1.2.1 From 9c40bbdb85b6962fd9cc5a35e46ededcb2e77774 Mon Sep 17 00:00:00 2001 From: Nihal Date: Mon, 28 Aug 2017 03:46:16 +0530 Subject: Refactor SWIG_SetZval to simplify the arguments. Solve constructor rename bug - Refactor SWIG_SetZval. - Fix the Renamed constructor - turn into static factory method bug. Conflicts: Source/Modules/php.cxx --- Lib/php/factory.i | 4 ++-- Lib/php/php.swg | 8 ++++---- Lib/php/phprun.swg | 38 +++++++++++++++++--------------------- 3 files changed, 23 insertions(+), 27 deletions(-) (limited to 'Lib') diff --git a/Lib/php/factory.i b/Lib/php/factory.i index 7dcd517ec..399ef8c1b 100644 --- a/Lib/php/factory.i +++ b/Lib/php/factory.i @@ -96,7 +96,7 @@ if (!dcast) { if (dobj) { dcast = 1; zend_object *std = $descriptor(Type)##_ce->create_object($descriptor(Type)##_ce); - SWIG_SetZval(return_value, $classZv, $owner, $newobj, $c_obj, SWIG_as_voidptr(dobj), $descriptor(Type *), std); + SWIG_SetZval(return_value, $needNewFlow, $owner, SWIG_as_voidptr(dobj), $descriptor(Type *), std); } }%enddef @@ -105,6 +105,6 @@ if (!dcast) { int dcast = 0; %formacro(%_factory_dispatch, Types) if (!dcast) { - SWIG_SetZval(return_value, $classZv, $owner, $newobj, $c_obj, SWIG_as_voidptr($1), $descriptor, $zend_obj); + SWIG_SetZval(return_value, $needNewFlow, $owner, SWIG_as_voidptr($1), $descriptor, $zend_obj); } }%enddef diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 5b20d9a6c..55fafcdbe 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -396,12 +396,12 @@ SWIGTYPE &, SWIGTYPE && %{ - SWIG_SetZval($result, $classZv, $owner, $newobj, $c_obj, (void *)result, $1_descriptor, $zend_obj); + SWIG_SetZval($result, $needNewFlow, $owner, (void *)result, $1_descriptor, $zend_obj); %} %typemap(out) SWIGTYPE *const& %{ - SWIG_SetZval(return_value, $classZv, $owner, $newobj, $c_obj, (void *)*$1, $*1_descriptor, $zend_obj); + SWIG_SetZval(return_value, $needNewFlow, $owner, (void *)*$1, $*1_descriptor, $zend_obj); %} %typemap(directorin) SWIGTYPE *, @@ -436,13 +436,13 @@ #ifdef __cplusplus { $&1_ltype resultobj = new $1_ltype((const $1_ltype &) $1); - SWIG_SetZval(return_value, $classZv, $owner, $newobj, $c_obj, (void *)resultobj, $&1_descriptor, $zend_obj); + SWIG_SetZval(return_value, $needNewFlow, $owner, (void *)resultobj, $&1_descriptor, $zend_obj); } #else { $&1_ltype resultobj = ($&1_ltype) emalloc(sizeof($1_type)); memcpy(resultobj, &$1, sizeof($1_type)); - SWIG_SetZval(return_value, $classZv, $owner, $newobj, $c_obj, (void *)resultobj, $&1_descriptor, $zend_obj); + SWIG_SetZval(return_value, $needNewFlow, $owner, (void *)resultobj, $&1_descriptor, $zend_obj); } #endif diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index acb856958..0467b5bd1 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -245,14 +245,19 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { } static void -SWIG_generalize_object(zval *zval_obj, void *ptr, int class_obj, int userNewObj ,swig_type_info *type) { +SWIG_pack_zval(zval *zv, void *ptr, int userNewObj) { swig_object_wrapper *obj = NULL; + obj = (swig_object_wrapper *) SWIG_Z_FETCH_OBJ_P(zv); + obj->ptr = ptr; + obj->newobject = userNewObj; +} - HashTable * ht = NULL; +static void +SWIG_generalize_object(zval *zval_obj, void *ptr, int userNewObj ,swig_type_info *type) { + SWIG_pack_zval(zval_obj, ptr, userNewObj); + + HashTable *ht = Z_OBJ_HT_P(zval_obj)->get_properties(zval_obj); - obj = (swig_object_wrapper *) SWIG_Z_FETCH_OBJ_P(zval_obj); - obj->ptr = (void *)ptr; - ht = Z_OBJ_HT_P(zval_obj)->get_properties(zval_obj); if(ht) { zval zv; ZVAL_RES(&zv,zend_register_resource(ptr,*(int *)(type->clientdata))); @@ -260,32 +265,23 @@ SWIG_generalize_object(zval *zval_obj, void *ptr, int class_obj, int userNewObj ZVAL_TRUE(&zv); zend_hash_str_add(ht, "SWIG_classWrapper", sizeof("SWIG_classWrapper") - 1, &zv); } - obj->newobject = userNewObj; } static void -SWIG_SetZval( zval *zv, zval *class_zv, int userNewObj ,int object, int class_obj ,void *ptr, swig_type_info *type, zend_object *std) { - - if (class_obj == 1) { - SWIG_generalize_object(class_zv, ptr, class_obj, userNewObj ,type); - return; - } +SWIG_SetZval( zval *zv, int newFlow, int userNewObj, void *ptr, swig_type_info *type, zend_object *std) { if (!ptr) { ZVAL_NULL(zv); return; } - if (object == 1) { - ZVAL_OBJ(zv,std); - SWIG_generalize_object(zv, ptr, class_obj, userNewObj, type); + if (newFlow) { + if (newFlow == 1) + ZVAL_OBJ(zv,std); + SWIG_generalize_object(zv, ptr, userNewObj, type); } - - if (object == 2) { - int newobj = class_obj; - if (class_obj == 2) - newobj = 1; - SWIG_SetPointerZval(zv,ptr,type,newobj); + else { + SWIG_SetPointerZval(zv, ptr, type, userNewObj); } } -- cgit v1.2.1 From f054f765442ed25d439f4ccb9947d4eefdcb093e Mon Sep 17 00:00:00 2001 From: Nihal Date: Sun, 3 Sep 2017 10:29:18 +0530 Subject: Bug Fix Director upcall functions to return object pointers - Refactor php.swg to adhere to checkstyle --- Lib/php/php.swg | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 55fafcdbe..692fd2969 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -87,8 +87,7 @@ %{ if ($needNewFlow) { $1 = *(($1_ltype *)$obj_value); - } - else { + } else { if (SWIG_ConvertPtr(&$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1&_descriptor"); $1 = *tmp; @@ -99,9 +98,16 @@ %{ /* If exit was via exception, PHP NULL is returned so skip the conversion. */ if (!EG(exception)) { - if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); - $result = *tmp; + if ($needNewFlow) { + swig_object_wrapper *obj = SWIG_Z_FETCH_OBJ_P(result); + tmp = ($&1_ltype) &obj->ptr; + c_result = *tmp; + obj->newobject = 0; + } else { + if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); + $result = *tmp; + } } %} @@ -110,8 +116,7 @@ %{ if ($needNewFlow) { $1 = ($1_ltype) $obj_value; - } - else { + } else { if (SWIG_ConvertPtr(&$linput, (void **) &$1, $1_descriptor, 0) < 0) SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); } @@ -121,8 +126,7 @@ %{ if ($needNewFlow) { $1 = ($1_ltype) $obj_value; - } - else { + } else { if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); } @@ -132,8 +136,7 @@ %{ if ($needNewFlow) { $1 = ($1_ltype) $obj_value; - } - else { + } else { if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) { SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); } @@ -144,8 +147,7 @@ %{ if ($needNewFlow) { $1 = ($1_ltype) $obj_value; - } - else { + } else { if (SWIG_ConvertPtr(&$input, (void **) &temp, $*1_descriptor, 0) < 0) { SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $*1_descriptor"); } @@ -158,8 +160,7 @@ if ($needNewFlow) { SWIG_Z_FETCH_OBJ_P(&$input)->newobject = 0; $1 = ($lower_param *)SWIG_Z_FETCH_OBJ_P(&$input)->ptr; - } - else { + } else { if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN ) < 0) SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); } -- cgit v1.2.1 From 98d1a2f8c51a4cd7b1c9e188f7ae7d3acbd65a67 Mon Sep 17 00:00:00 2001 From: Nihal Date: Tue, 5 Sep 2017 21:17:36 +0530 Subject: Fix bug in *const& "in" typemaps. - Refactored the reference check logic to Lib files. --- Lib/php/php.swg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 692fd2969..beb20408e 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -146,7 +146,8 @@ %typemap(in) SWIGTYPE *const& ($*ltype temp) %{ if ($needNewFlow) { - $1 = ($1_ltype) $obj_value; + void *tempPointer = $obj_value; + $1 = ($1_ltype) &tempPointer; } else { if (SWIG_ConvertPtr(&$input, (void **) &temp, $*1_descriptor, 0) < 0) { SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $*1_descriptor"); -- cgit v1.2.1 From 7e66388cf395f86ca3aa206e8024ebf65074f93a Mon Sep 17 00:00:00 2001 From: Nihal Date: Wed, 13 Sep 2017 01:05:57 +0530 Subject: Fix director_basic test case - This fixes director_basic test case. Uses the new flow in director class methods. - It also correctly fixes the double free problem in director_detect. --- Lib/php/php.swg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index beb20408e..5172cddef 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -411,7 +411,7 @@ SWIGTYPE &, SWIGTYPE && %{ - SWIG_SetPointerZval($input, (void *)&$1, $1_descriptor, ($owner)|2); + SWIG_SetZval($input, $needNewFlow, $owner, (void *)&$1, $1_descriptor, $zend_obj); %} %typemap(out, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*) @@ -450,7 +450,7 @@ %typemap(directorin) SWIGTYPE %{ - SWIG_SetPointerZval($input, SWIG_as_voidptr(new $1_ltype((const $1_ltype &)$1)), $&1_descriptor, 1|2); + SWIG_SetZval($input, $needNewFlow, $owner, SWIG_as_voidptr(new $1_ltype((const $1_ltype &)$1)), $&1_descriptor, $zend_obj); %} %typemap(out) void ""; -- cgit v1.2.1 From 0185b6114f9171d47e4a7524acbeb082054a8290 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 14 Sep 2017 09:32:16 +1200 Subject: Fix memory leaks in SWIGTYPE typemaps The "out" and "directorin" typemaps allocate a new object, but weren't specifying that this object should be owned. --- Lib/php/php.swg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 5172cddef..b06a6a563 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -438,19 +438,19 @@ #ifdef __cplusplus { $&1_ltype resultobj = new $1_ltype((const $1_ltype &) $1); - SWIG_SetZval(return_value, $needNewFlow, $owner, (void *)resultobj, $&1_descriptor, $zend_obj); + SWIG_SetZval(return_value, $needNewFlow, 1, (void *)resultobj, $&1_descriptor, $zend_obj); } #else { $&1_ltype resultobj = ($&1_ltype) emalloc(sizeof($1_type)); memcpy(resultobj, &$1, sizeof($1_type)); - SWIG_SetZval(return_value, $needNewFlow, $owner, (void *)resultobj, $&1_descriptor, $zend_obj); + SWIG_SetZval(return_value, $needNewFlow, 1, (void *)resultobj, $&1_descriptor, $zend_obj); } #endif %typemap(directorin) SWIGTYPE %{ - SWIG_SetZval($input, $needNewFlow, $owner, SWIG_as_voidptr(new $1_ltype((const $1_ltype &)$1)), $&1_descriptor, $zend_obj); + SWIG_SetZval($input, $needNewFlow, 1, SWIG_as_voidptr(new $1_ltype((const $1_ltype &)$1)), $&1_descriptor, $zend_obj); %} %typemap(out) void ""; -- cgit v1.2.1 From 6c3f5155b2bdeb2f8f4ba87ed2ac4ec46966e01e Mon Sep 17 00:00:00 2001 From: Nihal Date: Sat, 23 Sep 2017 01:04:49 +0530 Subject: Refactor declarations inside if-else block. - This is to support C90 --- Lib/php/php.swg | 7 +++---- Lib/php/phprun.swg | 15 ++++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index b06a6a563..996af4cd0 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -99,10 +99,9 @@ /* If exit was via exception, PHP NULL is returned so skip the conversion. */ if (!EG(exception)) { if ($needNewFlow) { - swig_object_wrapper *obj = SWIG_Z_FETCH_OBJ_P(result); - tmp = ($&1_ltype) &obj->ptr; + tmp = ($&1_ltype) &SWIG_Z_FETCH_OBJ_P(result)->ptr; c_result = *tmp; - obj->newobject = 0; + SWIG_Z_FETCH_OBJ_P(result)->newobject = 0; } else { if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); @@ -146,7 +145,7 @@ %typemap(in) SWIGTYPE *const& ($*ltype temp) %{ if ($needNewFlow) { - void *tempPointer = $obj_value; + tempPointer = $obj_value; $1 = ($1_ltype) &tempPointer; } else { if (SWIG_ConvertPtr(&$input, (void **) &temp, $*1_descriptor, 0) < 0) { diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 0467b5bd1..b57c88eeb 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -254,16 +254,17 @@ SWIG_pack_zval(zval *zv, void *ptr, int userNewObj) { static void SWIG_generalize_object(zval *zval_obj, void *ptr, int userNewObj ,swig_type_info *type) { - SWIG_pack_zval(zval_obj, ptr, userNewObj); + zval tempZval; + HashTable *ht = 0; - HashTable *ht = Z_OBJ_HT_P(zval_obj)->get_properties(zval_obj); + SWIG_pack_zval(zval_obj, ptr, userNewObj); + ht = Z_OBJ_HT_P(zval_obj)->get_properties(zval_obj); if(ht) { - zval zv; - ZVAL_RES(&zv,zend_register_resource(ptr,*(int *)(type->clientdata))); - zend_hash_str_add(ht, "_cPtr", sizeof("_cPtr") - 1, &zv); - ZVAL_TRUE(&zv); - zend_hash_str_add(ht, "SWIG_classWrapper", sizeof("SWIG_classWrapper") - 1, &zv); + ZVAL_RES(&tempZval,zend_register_resource(ptr,*(int *)(type->clientdata))); + zend_hash_str_add(ht, "_cPtr", sizeof("_cPtr") - 1, &tempZval); + ZVAL_TRUE(&tempZval); + zend_hash_str_add(ht, "SWIG_classWrapper", sizeof("SWIG_classWrapper") - 1, &tempZval); } } -- cgit v1.2.1 From 0215eaa3445b8ac624ca559304e80e60774698d4 Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Sun, 28 Feb 2021 17:05:07 +0100 Subject: Lib/javascript/v8/javascriptrun.swg: minor versioning cleanup. || (SWIG_V8_VERSION < 0x0704) is better handled in SWIGV8_MAYBE_CHECK. --- Lib/javascript/v8/javascriptrun.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib') diff --git a/Lib/javascript/v8/javascriptrun.swg b/Lib/javascript/v8/javascriptrun.swg index 62c7bf829..bab259c03 100644 --- a/Lib/javascript/v8/javascriptrun.swg +++ b/Lib/javascript/v8/javascriptrun.swg @@ -450,7 +450,7 @@ SWIGRUNTIME SWIGV8_VALUE SWIG_V8_NewPointerObj(void *ptr, swig_type_info *info, } #endif -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) || (SWIG_V8_VERSION < 0x0704) +#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(); -- cgit v1.2.1 From b0c01ea85117ba50754aeeaa18875f8bcdae6279 Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Sun, 28 Feb 2021 17:08:14 +0100 Subject: Lib/javascript/v8: use context-aware initialization. Context-aware initialization allows to instantiate add-ons multiple times, most importantly in multiple Workers' contexts. Workers made first appearance in v10.5. Context-aware initialization was option earlier than that, even before supported minimum v6.x, yet condition is chosen more conservatively as NODE_MODULE_VERSION >= 64, a.k.a. v10.0. --- Lib/javascript/v8/javascriptcode.swg | 10 +++++----- Lib/javascript/v8/javascripthelpers.swg | 11 ++++++----- Lib/javascript/v8/javascriptinit.swg | 35 +++++++++++++++++++-------------- Lib/swiginit.swg | 5 ++++- 4 files changed, 35 insertions(+), 26 deletions(-) (limited to 'Lib') diff --git a/Lib/javascript/v8/javascriptcode.swg b/Lib/javascript/v8/javascriptcode.swg index 0b0f1304e..60b1aba3a 100644 --- a/Lib/javascript/v8/javascriptcode.swg +++ b/Lib/javascript/v8/javascriptcode.swg @@ -432,7 +432,7 @@ fail: $jsmangledname_class_0->SetHiddenPrototype(true); v8::Local $jsmangledname_obj = $jsmangledname_class_0->GetFunction(); #else - v8::Local $jsmangledname_obj = $jsmangledname_class_0->GetFunction(SWIGV8_CURRENT_CONTEXT()).ToLocalChecked(); + v8::Local $jsmangledname_obj = $jsmangledname_class_0->GetFunction(context).ToLocalChecked(); #endif %} @@ -447,7 +447,7 @@ fail: #if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) $jsparent_obj->Set(SWIGV8_SYMBOL_NEW("$jsname"), $jsmangledname_obj); #else - SWIGV8_MAYBE_CHECK($jsparent_obj->Set(SWIGV8_CURRENT_CONTEXT(), SWIGV8_SYMBOL_NEW("$jsname"), $jsmangledname_obj)); + SWIGV8_MAYBE_CHECK($jsparent_obj->Set(context, SWIGV8_SYMBOL_NEW("$jsname"), $jsmangledname_obj)); #endif %} @@ -472,7 +472,7 @@ fail: #if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) $jsparent_obj->Set(SWIGV8_SYMBOL_NEW("$jsname"), $jsmangledname_obj); #else - SWIGV8_MAYBE_CHECK($jsparent_obj->Set(SWIGV8_CURRENT_CONTEXT(), SWIGV8_SYMBOL_NEW("$jsname"), $jsmangledname_obj)); + SWIGV8_MAYBE_CHECK($jsparent_obj->Set(context, SWIGV8_SYMBOL_NEW("$jsname"), $jsmangledname_obj)); #endif %} @@ -509,7 +509,7 @@ fail: * ----------------------------------------------------------------------------- */ %fragment("jsv8_register_static_function", "templates") %{ - SWIGV8_AddStaticFunction($jsparent_obj, "$jsname", $jswrapper); + SWIGV8_AddStaticFunction($jsparent_obj, "$jsname", $jswrapper, context); %} /* ----------------------------------------------------------------------------- @@ -523,5 +523,5 @@ fail: * ----------------------------------------------------------------------------- */ %fragment("jsv8_register_static_variable", "templates") %{ - SWIGV8_AddStaticVariable($jsparent_obj, "$jsname", $jsgetter, $jssetter); + SWIGV8_AddStaticVariable($jsparent_obj, "$jsname", $jsgetter, $jssetter, context); %} diff --git a/Lib/javascript/v8/javascripthelpers.swg b/Lib/javascript/v8/javascripthelpers.swg index 9da3ad639..9c3296d82 100644 --- a/Lib/javascript/v8/javascripthelpers.swg +++ b/Lib/javascript/v8/javascripthelpers.swg @@ -61,11 +61,11 @@ SWIGRUNTIME void SWIGV8_AddMemberVariable(SWIGV8_FUNCTION_TEMPLATE class_templ, * Registers a class method with given name for a given object. */ SWIGRUNTIME void SWIGV8_AddStaticFunction(SWIGV8_OBJECT obj, const char* symbol, - const SwigV8FunctionCallback& _func) { -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) || (SWIG_V8_VERSION < 0x0704) + const SwigV8FunctionCallback& _func, v8::Local context) { +#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) obj->Set(SWIGV8_SYMBOL_NEW(symbol), SWIGV8_FUNCTEMPLATE_NEW(_func)->GetFunction()); #else - SWIGV8_MAYBE_CHECK(obj->Set(SWIGV8_CURRENT_CONTEXT(), SWIGV8_SYMBOL_NEW(symbol), SWIGV8_FUNCTEMPLATE_NEW(_func)->GetFunction(SWIGV8_CURRENT_CONTEXT()).ToLocalChecked())); + SWIGV8_MAYBE_CHECK(obj->Set(context, SWIGV8_SYMBOL_NEW(symbol), SWIGV8_FUNCTEMPLATE_NEW(_func)->GetFunction(context).ToLocalChecked())); #endif } @@ -73,11 +73,12 @@ SWIGRUNTIME void SWIGV8_AddStaticFunction(SWIGV8_OBJECT obj, const char* symbol, * Registers a class method with given name for a given object. */ SWIGRUNTIME void SWIGV8_AddStaticVariable(SWIGV8_OBJECT obj, const char* symbol, - SwigV8AccessorGetterCallback getter, SwigV8AccessorSetterCallback setter) { + 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(SWIGV8_CURRENT_CONTEXT(), SWIGV8_SYMBOL_NEW(symbol), getter, setter)); + SWIGV8_MAYBE_CHECK(obj->SetAccessor(context, SWIGV8_SYMBOL_NEW(symbol), getter, setter)); #endif } diff --git a/Lib/javascript/v8/javascriptinit.swg b/Lib/javascript/v8/javascriptinit.swg index 401f9ae1f..772189787 100644 --- a/Lib/javascript/v8/javascriptinit.swg +++ b/Lib/javascript/v8/javascriptinit.swg @@ -5,27 +5,27 @@ %insert(init) %{ SWIGRUNTIME void -SWIG_V8_SetModule(void *, swig_module_info *swig_module) { - v8::Local global_obj = SWIGV8_CURRENT_CONTEXT()->Global(); +SWIG_V8_SetModule(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(SWIGV8_CURRENT_CONTEXT(), privateKey, mod); + global_obj->SetPrivate(context, privateKey, mod); #endif } SWIGRUNTIME swig_module_info * -SWIG_V8_GetModule(void *) { - v8::Local global_obj = SWIGV8_CURRENT_CONTEXT()->Global(); +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(SWIGV8_CURRENT_CONTEXT(), privateKey).ToLocal(&moduleinfo)) + if (!global_obj->GetPrivate(context, privateKey).ToLocal(&moduleinfo)) return 0; #endif @@ -52,6 +52,7 @@ SWIG_V8_GetModule(void *) { #define SWIG_GetModule(clientdata) SWIG_V8_GetModule(clientdata) #define SWIG_SetModule(clientdata, pointer) SWIG_V8_SetModule(clientdata, pointer) +#define SWIG_INIT_CLIENT_DATA_TYPE v8::Local %} @@ -64,20 +65,20 @@ SWIG_V8_GetModule(void *) { %} %insert(init) %{ +#if !defined(NODE_MODULE_VERSION) || (NODE_MODULE_VERSION < 12) // Note: 'extern "C"'' disables name mangling which makes it easier to load the symbol manually -// TODO: is it ok to do that? -extern "C" -#if (NODE_MODULE_VERSION < 0x000C) -void SWIGV8_INIT (SWIGV8_OBJECT exports) +extern "C" void SWIGV8_INIT (SWIGV8_OBJECT exports_obj) +#elif (NODE_MODULE_VERSION < 64) +void SWIGV8_INIT (SWIGV8_OBJECT exports_obj, SWIGV8_VALUE /*module*/, void*) #else -void SWIGV8_INIT (SWIGV8_OBJECT exports, SWIGV8_OBJECT /*module*/) +void SWIGV8_INIT (SWIGV8_OBJECT exports_obj, SWIGV8_VALUE /*module*/, v8::Local context, void*) #endif { - SWIG_InitializeModule(static_cast(&exports)); +#if !defined(NODE_MODULE_VERSION) || NODE_MODULE_VERSION < 64 + v8::Local context = SWIGV8_CURRENT_CONTEXT(); +#endif - SWIGV8_HANDLESCOPE(); - - SWIGV8_OBJECT exports_obj = exports; + SWIG_InitializeModule(context); %} @@ -124,6 +125,10 @@ void SWIGV8_INIT (SWIGV8_OBJECT exports, SWIGV8_OBJECT /*module*/) } #if defined(BUILDING_NODE_EXTENSION) +#if (NODE_MODULE_VERSION < 64) NODE_MODULE($jsname, $jsname_initialize) +#else +NODE_MODULE_CONTEXT_AWARE($jsname, $jsname_initialize) +#endif #endif %} diff --git a/Lib/swiginit.swg b/Lib/swiginit.swg index 33926b10f..e50b1b46d 100644 --- a/Lib/swiginit.swg +++ b/Lib/swiginit.swg @@ -50,9 +50,12 @@ extern "C" { #define SWIGRUNTIME_DEBUG #endif +#ifndef SWIG_INIT_CLIENT_DATA_TYPE +#define SWIG_INIT_CLIENT_DATA_TYPE void * +#endif SWIGRUNTIME void -SWIG_InitializeModule(void *clientdata) { +SWIG_InitializeModule(SWIG_INIT_CLIENT_DATA_TYPE clientdata) { size_t i; swig_module_info *module_head, *iter; int init; -- cgit v1.2.1 From 53bdc3964df3be6f380bc3e54f26561026e19f98 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 3 Mar 2021 22:19:22 +0000 Subject: Fix for new SWIGV8_ARRAY_NEW definition --- Lib/javascript/v8/javascriptcomplex.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib') diff --git a/Lib/javascript/v8/javascriptcomplex.swg b/Lib/javascript/v8/javascriptcomplex.swg index b73d5e2dd..e6b78899c 100644 --- a/Lib/javascript/v8/javascriptcomplex.swg +++ b/Lib/javascript/v8/javascriptcomplex.swg @@ -17,7 +17,7 @@ SWIG_From_dec(Type)(%ifcplusplus(const Type&, Type) c) { SWIGV8_HANDLESCOPE_ESC(); - v8::Local vals = SWIGV8_ARRAY_NEW(); + v8::Local vals = SWIGV8_ARRAY_NEW(0); SWIGV8_ARRAY_SET(vals, 0, SWIG_From(double)(Real(c))); SWIGV8_ARRAY_SET(vals, 1, SWIG_From(double)(Imag(c))); -- cgit v1.2.1 From c4d003e4427af05c635f343b6ced44f793eed2c0 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 3 Mar 2021 22:19:29 +0000 Subject: Fix Javascript arrays for modern node versions --- Lib/javascript/v8/arrays_javascript.i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Lib') diff --git a/Lib/javascript/v8/arrays_javascript.i b/Lib/javascript/v8/arrays_javascript.i index 1808fa840..8bcbee83c 100644 --- a/Lib/javascript/v8/arrays_javascript.i +++ b/Lib/javascript/v8/arrays_javascript.i @@ -42,7 +42,7 @@ // Get each element from array for (int i = 0; i < length; i++) { - v8::Local jsvalue = array->Get(i); + v8::Local jsvalue = SWIGV8_ARRAY_GET(array, i); $*1_ltype temp; // Get primitive value from JSObject @@ -74,7 +74,7 @@ for (int i = 0; i < length; i++) { - array->Set(i, SWIG_From(CTYPE)($1[i])); + SWIGV8_ARRAY_SET(array, i, SWIG_From(CTYPE)($1[i])); } $result = array; -- cgit v1.2.1 From b6aa39b82ab8e786fe75b4ef4c687a2272ccfd58 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 3 Mar 2021 22:22:47 +0000 Subject: Javascript code formatting corrections --- Lib/javascript/v8/arrays_javascript.i | 20 +++++++------------- Lib/javascript/v8/javascriptcomplex.swg | 16 ++++++++-------- 2 files changed, 15 insertions(+), 21 deletions(-) (limited to 'Lib') diff --git a/Lib/javascript/v8/arrays_javascript.i b/Lib/javascript/v8/arrays_javascript.i index 8bcbee83c..6dc7e4b9b 100644 --- a/Lib/javascript/v8/arrays_javascript.i +++ b/Lib/javascript/v8/arrays_javascript.i @@ -30,38 +30,33 @@ %define JAVASCRIPT_ARRAYS_IN_DECL(NAME, CTYPE, ANY, ANYLENGTH) %typemap(in, fragment=NAME) CTYPE[ANY] { - if ($input->IsArray()) - { + if ($input->IsArray()) { // Convert into Array v8::Local array = v8::Local::Cast($input); int length = ANYLENGTH; - $1 = ($*1_ltype *)malloc(sizeof($*1_ltype) * length); + $1 = ($*1_ltype *)malloc(sizeof($*1_ltype) * length); // Get each element from array - for (int i = 0; i < length; i++) - { + for (int i = 0; i < length; i++) { v8::Local jsvalue = SWIGV8_ARRAY_GET(array, i); $*1_ltype temp; // Get primitive value from JSObject int res = SWIG_AsVal(CTYPE)(jsvalue, &temp); - if (!SWIG_IsOK(res)) - { + if (!SWIG_IsOK(res)) { SWIG_exception_fail(SWIG_ERROR, "Failed to convert $input to double"); } arg$argnum[i] = temp; } - } - else - { + } else { SWIG_exception_fail(SWIG_ERROR, "$input is not an array"); } } %typemap(freearg) CTYPE[ANY] { - free($1); + free($1); } %enddef @@ -72,8 +67,7 @@ int length = $1_dim0; v8::Local array = SWIGV8_ARRAY_NEW(length); - for (int i = 0; i < length; i++) - { + for (int i = 0; i < length; i++) { SWIGV8_ARRAY_SET(array, i, SWIG_From(CTYPE)($1[i])); } diff --git a/Lib/javascript/v8/javascriptcomplex.swg b/Lib/javascript/v8/javascriptcomplex.swg index e6b78899c..7b3c5547e 100644 --- a/Lib/javascript/v8/javascriptcomplex.swg +++ b/Lib/javascript/v8/javascriptcomplex.swg @@ -39,23 +39,23 @@ SWIG_AsVal_dec(Type) (SWIGV8_VALUE o, Type* val) if (o->IsArray()) { SWIGV8_ARRAY array = SWIGV8_ARRAY::Cast(o); - if(array->Length() != 2) SWIG_Error(SWIG_TypeError, "Illegal argument for complex: must be array[2]."); + if (array->Length() != 2) SWIG_Error(SWIG_TypeError, "Illegal argument for complex: must be array[2]."); double re, im; int res; res = SWIG_AsVal(double)(SWIGV8_ARRAY_GET(array, 0), &re); - if(!SWIG_IsOK(res)) { + if (!SWIG_IsOK(res)) { return SWIG_TypeError; } res = SWIG_AsVal(double)(SWIGV8_ARRAY_GET(array, 1), &im); - if(!SWIG_IsOK(res)) { + if (!SWIG_IsOK(res)) { return SWIG_TypeError; } if (val) *val = Constructor(re, im); return SWIG_OK; - } else if(o->IsNumber()){ + } else if (o->IsNumber()) { double d; int res = SWIG_AddCast(SWIG_AsVal(double)(o, &d)); if (SWIG_IsOK(res)) { @@ -81,17 +81,17 @@ SWIG_AsVal_dec(Type) (SWIGV8_VALUE o, Type* val) if (o->IsArray()) { SWIGV8_ARRAY array = SWIGV8_ARRAY::Cast(o); - if(array->Length() != 2) SWIG_Error(SWIG_TypeError, "Illegal argument for complex: must be array[2]."); + if (array->Length() != 2) SWIG_Error(SWIG_TypeError, "Illegal argument for complex: must be array[2]."); double re, im; int res; res = SWIG_AsVal(double)(SWIGV8_ARRAY_GET(array, 0), &re); - if(!SWIG_IsOK(res)) { + if (!SWIG_IsOK(res)) { return SWIG_TypeError; } res = SWIG_AsVal(double)(SWIGV8_ARRAY_GET(array, 1), &im); - if(!SWIG_IsOK(res)) { + if (!SWIG_IsOK(res)) { return SWIG_TypeError; } @@ -102,7 +102,7 @@ SWIG_AsVal_dec(Type) (SWIGV8_VALUE o, Type* val) } else { return SWIG_OverflowError; } - } else if(o->IsNumber()){ + } else if (o->IsNumber()) { float re; int res = SWIG_AddCast(SWIG_AsVal(float)(o, &re)); if (SWIG_IsOK(res)) { -- cgit v1.2.1 From fee5e239ecdc9ecf994f2647ab719a3fc52a86a8 Mon Sep 17 00:00:00 2001 From: Sergio Garcia Murillo Date: Fri, 5 Mar 2021 15:08:17 +0100 Subject: Use SWIG_TypeCast in SWIG_V8_ConvertInstancePtr if types don't match (#3) Use SWIG_TypeCast in SWIG_V8_ConvertInstancePtr if types don't match --- Lib/javascript/v8/javascriptrun.swg | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'Lib') diff --git a/Lib/javascript/v8/javascriptrun.swg b/Lib/javascript/v8/javascriptrun.swg index 642908a37..477913cef 100644 --- a/Lib/javascript/v8/javascriptrun.swg +++ b/Lib/javascript/v8/javascriptrun.swg @@ -289,8 +289,12 @@ SWIGRUNTIME int SWIG_V8_ConvertInstancePtr(SWIGV8_OBJECT objRef, void **ptr, swi if(!type_valid) { return SWIG_TypeError; } + int newmemory = 0; + *ptr = SWIG_TypeCast(tc, cdata->swigCObject, &newmemory); + } else { + *ptr = cdata->swigCObject; } - *ptr = cdata->swigCObject; + if(flags & SWIG_POINTER_DISOWN) { cdata->swigCMemOwn = false; } -- cgit v1.2.1 From 0c10c0596f8ae1dc7af439f704f76869618cc6ff Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Sun, 7 Mar 2021 12:18:37 +0100 Subject: Lib/javascript/jsc/javascriptinit.swg: shortcut JSGlobalContextRef casts. --- Lib/javascript/jsc/javascriptinit.swg | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'Lib') diff --git a/Lib/javascript/jsc/javascriptinit.swg b/Lib/javascript/jsc/javascriptinit.swg index 8df5488b0..b0138b39a 100644 --- a/Lib/javascript/jsc/javascriptinit.swg +++ b/Lib/javascript/jsc/javascriptinit.swg @@ -1,19 +1,16 @@ %insert(init) %{ SWIGRUNTIME void -SWIG_JSC_SetModule(void *clientdata, swig_module_info *swig_module) { - JSGlobalContextRef context; +SWIG_JSC_SetModule(JSGlobalContextRef context, swig_module_info *swig_module) { JSObjectRef globalObject; JSStringRef moduleName; JSClassDefinition classDef; JSClassRef classRef; JSObjectRef object; - if(clientdata == 0){ + if(context == 0){ return; } - context = (JSGlobalContextRef)clientdata; - globalObject = JSContextGetGlobalObject(context); moduleName = JSStringCreateWithUTF8CString("swig_module_info_data"); @@ -29,19 +26,16 @@ SWIG_JSC_SetModule(void *clientdata, swig_module_info *swig_module) { JSStringRelease(moduleName); } SWIGRUNTIME swig_module_info * -SWIG_JSC_GetModule(void *clientdata) { - JSGlobalContextRef context; +SWIG_JSC_GetModule(JSGlobalContextRef context) { JSObjectRef globalObject; JSStringRef moduleName; JSValueRef value; JSObjectRef object; - if(clientdata == 0){ + if(context == 0){ return 0; } - context = (JSGlobalContextRef)clientdata; - globalObject = JSContextGetGlobalObject(context); moduleName = JSStringCreateWithUTF8CString("swig_module_info_data"); @@ -59,6 +53,7 @@ SWIG_JSC_GetModule(void *clientdata) { #define SWIG_GetModule(clientdata) SWIG_JSC_GetModule(clientdata) #define SWIG_SetModule(clientdata, pointer) SWIG_JSC_SetModule(clientdata, pointer) +#define SWIG_INIT_CLIENT_DATA_TYPE JSGlobalContextRef %} %insert(init) "swiginit.swg" @@ -76,7 +71,7 @@ extern "C" { #endif bool SWIGJSC_INIT (JSGlobalContextRef context, JSObjectRef *exports) { - SWIG_InitializeModule((void*)context); + SWIG_InitializeModule(context); %} /* ----------------------------------------------------------------------------- -- cgit v1.2.1 From b56814ce08ff27cc4bd195b427dbe43c7b6e354e Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Tue, 9 Mar 2021 15:34:31 +0100 Subject: Lib/javascript/v8/javascriptrun.swg: clean up pre-processor conditions. Harmonize javascriptcode.swg javascripthelpers.swg and clarify documentation. --- Lib/javascript/v8/javascriptcode.swg | 4 ++-- Lib/javascript/v8/javascripthelpers.swg | 2 +- Lib/javascript/v8/javascriptrun.swg | 33 +++++++++++---------------------- 3 files changed, 14 insertions(+), 25 deletions(-) (limited to 'Lib') diff --git a/Lib/javascript/v8/javascriptcode.swg b/Lib/javascript/v8/javascriptcode.swg index 60b1aba3a..2abed9488 100644 --- a/Lib/javascript/v8/javascriptcode.swg +++ b/Lib/javascript/v8/javascriptcode.swg @@ -444,7 +444,7 @@ fail: * ----------------------------------------------------------------------------- */ %fragment("jsv8_register_class", "templates") %{ -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) +#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)); @@ -469,7 +469,7 @@ fail: * ----------------------------------------------------------------------------- */ %fragment("jsv8_register_namespace", "templates") %{ -#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) +#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)); diff --git a/Lib/javascript/v8/javascripthelpers.swg b/Lib/javascript/v8/javascripthelpers.swg index 9c3296d82..fdbff000e 100644 --- a/Lib/javascript/v8/javascripthelpers.swg +++ b/Lib/javascript/v8/javascripthelpers.swg @@ -62,7 +62,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) < 4 && (SWIG_V8_VERSION < 0x031903) +#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())); diff --git a/Lib/javascript/v8/javascriptrun.swg b/Lib/javascript/v8/javascriptrun.swg index 642908a37..c6e31ff9d 100644 --- a/Lib/javascript/v8/javascriptrun.swg +++ b/Lib/javascript/v8/javascriptrun.swg @@ -50,21 +50,22 @@ typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; #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) -#elif (SWIG_V8_VERSION < 0x0704) +#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) #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) #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 (SWIG_V8_VERSION < 0x0704) +#if (V8_MAJOR_VERSION-0) < 5 +#define SWIGV8_MAYBE_CHECK(maybe) maybe +#elif (SWIG_V8_VERSION < 0x0704) #define SWIGV8_MAYBE_CHECK(maybe) maybe.FromJust() #else #define SWIGV8_MAYBE_CHECK(maybe) maybe.Check() @@ -120,15 +121,7 @@ typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; #define SWIGV8_SET_CLASS_TEMPL(class_templ, class) class_templ.Reset(v8::Isolate::GetCurrent(), class); #endif -#ifdef NODE_VERSION -#if NODE_VERSION_AT_LEAST(10, 12, 0) -#define SWIG_NODE_AT_LEAST_1012 -#endif -#endif - -//Necessary to check Node.js version because V8 API changes are backported in Node.js -#if (defined(NODE_VERSION) && !defined(SWIG_NODE_AT_LEAST_1012)) || \ - (!defined(NODE_VERSION) && (V8_MAJOR_VERSION-0) < 7) +#if (V8_MAJOR_VERSION-0) < 6 || (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() @@ -136,22 +129,18 @@ typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; #define SWIGV8_BOOLEAN_VALUE(handle) (handle)->BooleanValue() #define SWIGV8_WRITE_UTF8(handle, buffer, len) (handle)->WriteUtf8(buffer, len) #define SWIGV8_UTF8_LENGTH(handle) (handle)->Utf8Length() -#elif (SWIG_V8_VERSION < 0x0704) +#else #define SWIGV8_TO_OBJECT(handle) (handle)->ToObject(SWIGV8_CURRENT_CONTEXT()).ToLocalChecked() #define SWIGV8_TO_STRING(handle) (handle)->ToString(SWIGV8_CURRENT_CONTEXT()).ToLocalChecked() #define SWIGV8_NUMBER_VALUE(handle) (handle)->NumberValue(SWIGV8_CURRENT_CONTEXT()).ToChecked() #define SWIGV8_INTEGER_VALUE(handle) (handle)->IntegerValue(SWIGV8_CURRENT_CONTEXT()).ToChecked() -#define SWIGV8_BOOLEAN_VALUE(handle) (handle)->BooleanValue(SWIGV8_CURRENT_CONTEXT()).ToChecked() #define SWIGV8_WRITE_UTF8(handle, buffer, len) (handle)->WriteUtf8(v8::Isolate::GetCurrent(), buffer, len) #define SWIGV8_UTF8_LENGTH(handle) (handle)->Utf8Length(v8::Isolate::GetCurrent()) +#if (SWIG_V8_VERSION < 0x0704) +#define SWIGV8_BOOLEAN_VALUE(handle) (handle)->BooleanValue(SWIGV8_CURRENT_CONTEXT()).ToChecked() #else -#define SWIGV8_TO_OBJECT(handle) (handle)->ToObject(SWIGV8_CURRENT_CONTEXT()).ToLocalChecked() -#define SWIGV8_TO_STRING(handle) (handle)->ToString(SWIGV8_CURRENT_CONTEXT()).ToLocalChecked() -#define SWIGV8_NUMBER_VALUE(handle) (handle)->NumberValue(SWIGV8_CURRENT_CONTEXT()).ToChecked() -#define SWIGV8_INTEGER_VALUE(handle) (handle)->IntegerValue(SWIGV8_CURRENT_CONTEXT()).ToChecked() #define SWIGV8_BOOLEAN_VALUE(handle) (handle)->BooleanValue(v8::Isolate::GetCurrent()) -#define SWIGV8_WRITE_UTF8(handle, buffer, len) (handle)->WriteUtf8(v8::Isolate::GetCurrent(), buffer, len) -#define SWIGV8_UTF8_LENGTH(handle) (handle)->Utf8Length(v8::Isolate::GetCurrent()) +#endif #endif /* --------------------------------------------------------------------------- -- cgit v1.2.1 From 2870e750f08443c9b830c9d2ee303c792e83db99 Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Wed, 10 Mar 2021 14:48:47 +0100 Subject: Lib/javascript/v8: use ::Cast instead of To* when possible. If type is checked with Is*, it's safe to use corresponding ::Cast, which is more optimal. --- Lib/javascript/v8/javascriptrun.swg | 4 ++-- Lib/javascript/v8/javascriptstrings.swg | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'Lib') diff --git a/Lib/javascript/v8/javascriptrun.swg b/Lib/javascript/v8/javascriptrun.swg index c6e31ff9d..e7fa69e38 100644 --- a/Lib/javascript/v8/javascriptrun.swg +++ b/Lib/javascript/v8/javascriptrun.swg @@ -310,7 +310,7 @@ SWIGRUNTIME int SWIG_V8_GetInstancePtr(SWIGV8_VALUE valRef, void **ptr) { if(!valRef->IsObject()) { return SWIG_TypeError; } - SWIGV8_OBJECT objRef = SWIGV8_TO_OBJECT(valRef); + SWIGV8_OBJECT objRef = SWIGV8_OBJECT::Cast(valRef); if(objRef->InternalFieldCount() < 1) return SWIG_ERROR; @@ -405,7 +405,7 @@ SWIGRUNTIME int SWIG_V8_ConvertPtr(SWIGV8_VALUE valRef, void **ptr, swig_type_in if(!valRef->IsObject()) { return SWIG_TypeError; } - SWIGV8_OBJECT objRef = SWIGV8_TO_OBJECT(valRef); + SWIGV8_OBJECT objRef = SWIGV8_OBJECT::Cast(valRef); return SWIG_V8_ConvertInstancePtr(objRef, ptr, info, flags); } diff --git a/Lib/javascript/v8/javascriptstrings.swg b/Lib/javascript/v8/javascriptstrings.swg index 9c0919172..42d0b86b5 100644 --- a/Lib/javascript/v8/javascriptstrings.swg +++ b/Lib/javascript/v8/javascriptstrings.swg @@ -8,9 +8,9 @@ SWIG_AsCharPtrAndSize(SWIGV8_VALUE valRef, char** cptr, size_t* psize, int *allo { if(valRef->IsString()) { %#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903) - v8::Handle js_str = SWIGV8_TO_STRING(valRef); + v8::Handle js_str = v8::Handle::Cast(valRef); %#else - v8::Local js_str = SWIGV8_TO_STRING(valRef); + v8::Local js_str = v8::Local::Cast(valRef); %#endif size_t len = SWIGV8_UTF8_LENGTH(js_str) + 1; @@ -24,7 +24,7 @@ SWIG_AsCharPtrAndSize(SWIGV8_VALUE valRef, char** cptr, size_t* psize, int *allo return SWIG_OK; } else { if(valRef->IsObject()) { - SWIGV8_OBJECT obj = SWIGV8_TO_OBJECT(valRef); + SWIGV8_OBJECT obj = SWIGV8_OBJECT::Cast(valRef); // try if the object is a wrapped char[] swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); if (pchar_descriptor) { -- cgit v1.2.1 From 04b46cc8a364ad99e47c138b076a9c6ed81e6584 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 11 Mar 2021 08:10:00 +0000 Subject: Javascript type conversion support Add testcase for previous commit. Add missing assert for future type conversions support that will use the heap instead of pointer casts (for smart pointer type conversions). Closes #1963 --- Lib/javascript/v8/javascriptrun.swg | 1 + Lib/javascript/v8/javascriptruntime.swg | 1 + 2 files changed, 2 insertions(+) (limited to 'Lib') diff --git a/Lib/javascript/v8/javascriptrun.swg b/Lib/javascript/v8/javascriptrun.swg index 477913cef..053cf7cee 100644 --- a/Lib/javascript/v8/javascriptrun.swg +++ b/Lib/javascript/v8/javascriptrun.swg @@ -291,6 +291,7 @@ SWIGRUNTIME int SWIG_V8_ConvertInstancePtr(SWIGV8_OBJECT objRef, void **ptr, swi } int newmemory = 0; *ptr = SWIG_TypeCast(tc, cdata->swigCObject, &newmemory); + assert(!newmemory); /* newmemory handling not yet implemented */ } else { *ptr = cdata->swigCObject; } diff --git a/Lib/javascript/v8/javascriptruntime.swg b/Lib/javascript/v8/javascriptruntime.swg index 773014f2a..115554a5a 100644 --- a/Lib/javascript/v8/javascriptruntime.swg +++ b/Lib/javascript/v8/javascriptruntime.swg @@ -64,6 +64,7 @@ #include #include #include +#include %} %insert(runtime) "swigrun.swg"; /* SWIG API */ -- cgit v1.2.1 From 6aef217438328f6653be270fa0e2296a5254a89c Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 11 Mar 2021 20:16:38 +0000 Subject: Add Javascript (JSC) support for type conversion Fix types_directive testcase to ensure the %types code is actually called and not just cast from one type to the other. --- Lib/javascript/jsc/javascriptrun.swg | 30 ++++++++++++++---------------- Lib/javascript/jsc/javascriptruntime.swg | 1 + 2 files changed, 15 insertions(+), 16 deletions(-) (limited to 'Lib') diff --git a/Lib/javascript/jsc/javascriptrun.swg b/Lib/javascript/jsc/javascriptrun.swg index 26c440244..d092ea4ab 100644 --- a/Lib/javascript/jsc/javascriptrun.swg +++ b/Lib/javascript/jsc/javascriptrun.swg @@ -117,27 +117,25 @@ SWIGRUNTIME int SWIG_JSC_ConvertInstancePtr(JSContextRef context, JSObjectRef ob SwigPrivData *cdata; cdata = (SwigPrivData *) JSObjectGetPrivate(objRef); - if(cdata == NULL) { + if (cdata == NULL) { return SWIG_ERROR; } - if(cdata->info != info) { - bool type_valid = false; - swig_cast_info *t = info->cast; - while(t != NULL) { - if(t->type == cdata->info) { - type_valid = true; - break; - } - t = t->next; - } - if(!type_valid) { - return SWIG_TypeError; + assert(ptr); + *ptr = NULL; + if (cdata->info == info) { + *ptr = cdata->swigCObject; + } else { + swig_cast_info *tc = SWIG_TypeCheckStruct(cdata->info, info); + if (tc) { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc, cdata->swigCObject, &newmemory); + assert(!newmemory); /* newmemory handling not yet implemented */ + } else { + return SWIG_ERROR; } } - *ptr = cdata->swigCObject; - - if(flags & SWIG_POINTER_DISOWN) { + if (flags & SWIG_POINTER_DISOWN) { cdata->swigCMemOwn = false; } diff --git a/Lib/javascript/jsc/javascriptruntime.swg b/Lib/javascript/jsc/javascriptruntime.swg index 8f8390890..a626390cc 100644 --- a/Lib/javascript/jsc/javascriptruntime.swg +++ b/Lib/javascript/jsc/javascriptruntime.swg @@ -11,6 +11,7 @@ #include #include #include +#include %} %insert(runtime) "swigrun.swg"; /* SWIG API */ -- cgit v1.2.1 From 4e0997cd5a2360ccb639436783dc76b855d1ef59 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 17 Mar 2021 09:43:15 +1300 Subject: Conditionalise math.i for PHP PHP already provides all the wrapped constants and all the wrapped functions except fabs() (PHP provides abs() instead). Rewrapping the constants causes warnings or errors (depending on PHP version) and the rewrapped functions seem to be hidden by the built-in versions, so only wrap fabs() for PHP. (Even a wrapper for fabs() seems of little use since abs() is already provided, but really math.i seems of little use more generally since any general purpose programming language will provide its own maths functions and constants - the key motivation here is to eliminate warnings and errors from running the testsuite.) --- Lib/math.i | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'Lib') diff --git a/Lib/math.i b/Lib/math.i index a37c92d19..ac8d9a6eb 100644 --- a/Lib/math.i +++ b/Lib/math.i @@ -9,6 +9,8 @@ #include %} +#ifndef SWIGPHP /* PHP already provides all these functions except fabs() */ + extern double cos(double x); /* Cosine of x */ @@ -54,9 +56,6 @@ extern double pow(double x, double y); extern double sqrt(double x); /* Square root. x >= 0 */ -extern double fabs(double x); -/* Absolute value of x */ - extern double ceil(double x); /* Smallest integer not less than x, as a double */ @@ -66,6 +65,13 @@ extern double floor(double x); extern double fmod(double x, double y); /* Floating-point remainder of x/y, with the same sign as x. */ +#endif + +extern double fabs(double x); +/* Absolute value of x */ + +#ifndef SWIGPHP /* PHP already provides these constants and it's an error to redefine them */ + #define M_E 2.7182818284590452354 #define M_LOG2E 1.4426950408889634074 #define M_LOG10E 0.43429448190325182765 @@ -80,3 +86,4 @@ extern double fmod(double x, double y); #define M_SQRT2 1.41421356237309504880 #define M_SQRT1_2 0.70710678118654752440 +#endif -- cgit v1.2.1 From b7dedecfdd708c5323addc1b28e16cc727e01980 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 18 Mar 2021 10:53:58 +1300 Subject: php: Fix char* typecheck typemap to accept Null The corresponding in typemap already does. Fixes #1655, reported by CJSlominski. --- Lib/php/php.swg | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 4eba6be2a..ccfd371ab 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -465,7 +465,10 @@ %php_typecheck(double,SWIG_TYPECHECK_DOUBLE,IS_DOUBLE) %php_typecheck(char,SWIG_TYPECHECK_CHAR,IS_STRING) -%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) char *, char *&, char [] +%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) char *, char *& + " $1 = (Z_TYPE($input) == IS_STRING || Z_TYPE($input) == IS_NULL); " + +%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) char [] " $1 = (Z_TYPE($input) == IS_STRING); " %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE -- cgit v1.2.1 From 71475b0af9677deeaf6fe55c0c5f53fec9f730d2 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 18 Mar 2021 15:50:52 +1300 Subject: Improve PHP object creation Reportedly the code we were using in the directorin case gave segfaults in PHP 7.2 and later - we've been unable to reproduce these, but the new approach is also simpler and should be bit faster too. Fixes #1527, #1975 --- Lib/php/phprun.swg | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'Lib') diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index a07a1b9f8..f3a4e6ad1 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -90,15 +90,13 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) { } else { /* * Wrap the resource in an object, the resource will be accessible - * via the "_cPtr" member. This is currently only used by + * via the "_cPtr" property. This code path is currently only used by * directorin typemaps. */ - zval resource; zend_class_entry *ce = NULL; const char *type_name = type->name+3; /* +3 so: _p_Foo -> Foo */ size_t type_name_len; const char * p; - HashTable * ht; /* Namespace__Foo -> Foo */ /* FIXME: ugly and goes wrong for classes with __ in their names. */ @@ -107,7 +105,6 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) { } type_name_len = strlen(type_name); - ZVAL_RES(&resource, zend_register_resource(value, *(int *)(type->clientdata))); if (SWIG_PREFIX_LEN > 0) { zend_string * classname = zend_string_alloc(SWIG_PREFIX_LEN + type_name_len, 0); memcpy(classname->val, SWIG_PREFIX, SWIG_PREFIX_LEN); @@ -121,13 +118,12 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) { } if (ce == NULL) { /* class does not exist */ - ce = zend_standard_class_def; + object_init(z); + } else { + object_init_ex(z, ce); } - ALLOC_HASHTABLE(ht); - zend_hash_init(ht, 1, NULL, NULL, 0); - zend_hash_str_update(ht, "_cPtr", sizeof("_cPtr") - 1, &resource); - object_and_properties_init(z, ce, ht); + add_property_resource_ex(z, "_cPtr", sizeof("_cPtr") - 1, zend_register_resource(value, *(int *)(type->clientdata))); } return; } -- cgit v1.2.1 From 3584c7d49cb598ce79d5e285d6c17b2dedfe3ecb Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 17 Mar 2021 12:45:17 +1300 Subject: Add initial support for PHP8 Testcase director_overload2 is failing, but the rest of the testsuite passes. --- Lib/cdata.i | 2 +- Lib/exception.i | 2 +- Lib/php/phprun.swg | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) (limited to 'Lib') diff --git a/Lib/cdata.i b/Lib/cdata.i index f18ed4af5..cd1526643 100644 --- a/Lib/cdata.i +++ b/Lib/cdata.i @@ -21,7 +21,7 @@ typedef struct SWIGCDATA { } %typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH); -#elif SWIGPHP7 +#elif SWIGPHP %typemap(out) SWIGCDATA { ZVAL_STRINGL($result, $1.data, $1.len); diff --git a/Lib/exception.i b/Lib/exception.i index ee9ce9bc6..3d6eeccdf 100644 --- a/Lib/exception.i +++ b/Lib/exception.i @@ -12,7 +12,7 @@ %insert("runtime") "swigerrors.swg" -#ifdef SWIGPHP7 +#ifdef SWIGPHP %{ #include "zend_exceptions.h" #define SWIG_exception(code, msg) do { zend_throw_exception(NULL, (char*)msg, code); goto thrown; } while (0) diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index f3a4e6ad1..049198787 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -12,8 +12,8 @@ extern "C" { #include "zend_exceptions.h" #include "php.h" -#if PHP_MAJOR_VERSION != 7 -# error These bindings need PHP7 - to generate PHP5 bindings use: SWIG < 4.0.0 and swig -php5 +#if PHP_MAJOR_VERSION < 7 +# error These bindings need PHP 7 or later - to generate PHP5 bindings use: SWIG < 4.0.0 and swig -php5 #endif #include "ext/standard/php_string.h" @@ -200,7 +200,11 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { switch (Z_TYPE_P(z)) { case IS_OBJECT: { +#if PHP_MAJOR_VERSION < 8 HashTable * ht = Z_OBJ_HT_P(z)->get_properties(z); +#else + HashTable * ht = Z_OBJ_HT_P(z)->get_properties(Z_OBJ_P(z)); +#endif if (ht) { zval * _cPtr = zend_hash_str_find(ht, "_cPtr", sizeof("_cPtr") - 1); if (_cPtr) { -- cgit v1.2.1 From 971e1154af7a608a0f2f96ee98189da4aa001412 Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Fri, 22 Jan 2021 18:22:05 +0100 Subject: Lib/java/javahead.swg: clean up jlong handling. As for __int64 definition. __int64 is a non-standard Visual-C-specific type used in win32/jni_md.h. It is defined by other Win32 compilers in one way or another, obviously for compatibility. It's more appropriate to give the compiler a chance to make necessary arrangements instead of reinventing the wheel. This, giving a chance, can be achieved by including virtually any standard header. Since jni.h includes stdio.h, defining __int64 in javahead.swg is redundant. Since doing so actually triggers compilation errors on MinGW if a system header is included in the %begin section, it's arguably appropriate to omit it. As for #undef _LP64 removal. Undefining a pre-defined macro, which _LP64 is, is bad style, and if followed by inclusion of systems headers, it's actually error-prone. Log suggests that it was added to resolve a warning. I'm inclined to believe that it rather was a misunderstanding of some kind. Or a bug in warning subsystem of some particular compiler version, in which case it would have been more appropriate to advise users to ignore the warning. --- Lib/java/javahead.swg | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'Lib') diff --git a/Lib/java/javahead.swg b/Lib/java/javahead.swg index 2e10254f3..1fc327909 100644 --- a/Lib/java/javahead.swg +++ b/Lib/java/javahead.swg @@ -30,18 +30,6 @@ #endif %insert(runtime) %{ -/* Fix for jlong on some versions of gcc on Windows */ -#if defined(__GNUC__) && !defined(__INTEL_COMPILER) - typedef long long __int64; -#endif - -/* Fix for jlong on 64-bit x86 Solaris */ -#if defined(__x86_64) -# ifdef _LP64 -# undef _LP64 -# endif -#endif - #include #include #include -- cgit v1.2.1 From 1eebc2335a7d607e3bb7466ce125a9495304c029 Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Sun, 24 Jan 2021 13:01:36 +0100 Subject: Lib/java/arrays_java.i: use actual C/C++ type in JAVA_ARRAYS_TYPEMAPS. long long[] map was using JNI type as C/C++ type. General spirit of JAVA_ARRAYS_TYPEMAPS is to cast individual array elements, not to rely on potentially incompatible pointer casts. --- Lib/java/arrays_java.i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Lib') diff --git a/Lib/java/arrays_java.i b/Lib/java/arrays_java.i index dd38438a3..a57da64b4 100644 --- a/Lib/java/arrays_java.i +++ b/Lib/java/arrays_java.i @@ -104,7 +104,7 @@ JAVA_ARRAYS_DECL(int, jint, Int, Int) /* int[] */ JAVA_ARRAYS_DECL(unsigned int, jlong, Long, Uint) /* unsigned int[] */ JAVA_ARRAYS_DECL(long, jint, Int, Long) /* long[] */ JAVA_ARRAYS_DECL(unsigned long, jlong, Long, Ulong) /* unsigned long[] */ -JAVA_ARRAYS_DECL(jlong, jlong, Long, Longlong) /* long long[] */ +JAVA_ARRAYS_DECL(long long, jlong, Long, Longlong) /* long long[] */ JAVA_ARRAYS_DECL(float, jfloat, Float, Float) /* float[] */ JAVA_ARRAYS_DECL(double, jdouble, Double, Double) /* double[] */ @@ -128,7 +128,7 @@ JAVA_ARRAYS_IMPL(int, jint, Int, Int) /* int[] */ JAVA_ARRAYS_IMPL(unsigned int, jlong, Long, Uint) /* unsigned int[] */ JAVA_ARRAYS_IMPL(long, jint, Int, Long) /* long[] */ JAVA_ARRAYS_IMPL(unsigned long, jlong, Long, Ulong) /* unsigned long[] */ -JAVA_ARRAYS_IMPL(jlong, jlong, Long, Longlong) /* long long[] */ +JAVA_ARRAYS_IMPL(long long, jlong, Long, Longlong) /* long long[] */ JAVA_ARRAYS_IMPL(float, jfloat, Float, Float) /* float[] */ JAVA_ARRAYS_IMPL(double, jdouble, Double, Double) /* double[] */ -- cgit v1.2.1 From 786efd0ae0e6252dc35a36e5744ef16cd23722a6 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 24 Mar 2021 11:59:25 +1300 Subject: Eliminate irrelevant formatting differences from master --- Lib/php/phprun.swg | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'Lib') diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 0467b5bd1..287a0fbef 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -188,8 +188,8 @@ SWIG_ConvertResourcePtr(zval *z, swig_type_info *ty, int flags) { if (!type_name) { if (Z_TYPE_P(z) == IS_OBJECT) { HashTable * ht = Z_OBJ_HT_P(z)->get_properties(z); - zval * _cPtr = zend_hash_str_find(ht, "_cPtr", sizeof("_cPtr") - 1); - type_name=zend_rsrc_list_get_rsrc_type(Z_RES_P(_cPtr)); + zval * _cPtr = zend_hash_str_find(ht, "_cPtr", sizeof("_cPtr") - 1); + type_name=zend_rsrc_list_get_rsrc_type(Z_RES_P(_cPtr)); } } @@ -299,4 +299,3 @@ static swig_module_info *SWIG_Php_GetModule() { static void SWIG_Php_SetModule(swig_module_info *pointer) { REGISTER_MAIN_LONG_CONSTANT(const_name, (long) pointer, CONST_PERSISTENT | CONST_CS); } - -- cgit v1.2.1 From 9f84ca8a00f6506d2c737e4bea50ac9c894953d8 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 8 Feb 2019 14:49:23 +1300 Subject: [php] Fix function constants for PHP 7.3 The code we were generating no longer compiled. --- Lib/php/const.i | 3 +-- Lib/php/phprun.swg | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'Lib') diff --git a/Lib/php/const.i b/Lib/php/const.i index 666e86eee..a0837cb6d 100644 --- a/Lib/php/const.i +++ b/Lib/php/const.i @@ -60,8 +60,7 @@ SWIG_SetPointerZval(&c.value, (void*)$value, $1_descriptor, 0); zval_copy_ctor(&c.value); c.name = zend_string_init("$symname", sizeof("$symname") - 1, 0); - c.flags = CONST_CS; - c.module_number = module_number; + SWIG_ZEND_CONSTANT_SET_FLAGS(&c, CONST_CS, module_number); zend_register_constant(&c); } diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 287a0fbef..bfa72cea1 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -32,6 +32,13 @@ extern "C" { REGISTER_STRINGL_CONSTANT(#N, &swig_char, 1, CONST_CS | CONST_PERSISTENT);\ } while (0) +/* ZEND_CONSTANT_SET_FLAGS is new in PHP 7.3. */ +#ifdef ZEND_CONSTANT_SET_FLAGS +# define SWIG_ZEND_CONSTANT_SET_FLAGS ZEND_CONSTANT_SET_FLAGS +#else +# define SWIG_ZEND_CONSTANT_SET_FLAGS(C, F, N) do { (C).flags = (F); (C).module_number = (N); } while (0) +#endif + #ifdef __cplusplus } #endif -- cgit v1.2.1 From 351f98195274cef44194e2a8091338a04c92258c Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 8 Feb 2019 16:58:22 +1300 Subject: [php] Fix SWIG_ZEND_CONSTANT_SET_FLAGS for PHP < 7.3 --- Lib/php/phprun.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib') diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index bfa72cea1..8ff107461 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -36,7 +36,7 @@ extern "C" { #ifdef ZEND_CONSTANT_SET_FLAGS # define SWIG_ZEND_CONSTANT_SET_FLAGS ZEND_CONSTANT_SET_FLAGS #else -# define SWIG_ZEND_CONSTANT_SET_FLAGS(C, F, N) do { (C).flags = (F); (C).module_number = (N); } while (0) +# define SWIG_ZEND_CONSTANT_SET_FLAGS(C, F, N) do { (C)->flags = (F); (C)->module_number = (N); } while (0) #endif #ifdef __cplusplus -- cgit v1.2.1 From 76c2c4675b40ba0acd7ff4f845499a6e75ab89db Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 26 Mar 2021 08:23:19 +1300 Subject: [PHP] Update PHP keyword list Add PHP keywords 'fn' (added in 7.4) and 'match' (added in 8.0) to the list SWIG knows to automatically rename. --- Lib/php/phpkw.swg | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Lib') diff --git a/Lib/php/phpkw.swg b/Lib/php/phpkw.swg index 5c5296a1f..58c108968 100644 --- a/Lib/php/phpkw.swg +++ b/Lib/php/phpkw.swg @@ -55,6 +55,7 @@ PHPKW(endwhile); PHPKW(extends); PHPKW(final); PHPKW(finally); +PHPKW(fn); // as of PHP 7.4 PHPKW(for); PHPKW(foreach); PHPKW(function); @@ -65,6 +66,7 @@ PHPKW(implements); PHPKW(instanceof); PHPKW(insteadof); PHPKW(interface); +PHPKW(match); // as of PHP 8.0 PHPKW(namespace); PHPKW(new); PHPKW(or); -- cgit v1.2.1 From c882f39e3c6923adf4850c999a271fc4f6751d4b Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 26 Mar 2021 10:06:43 +1300 Subject: [php] Fix misleadingly indented void* in typemap --- Lib/php/php.swg | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index ccfd371ab..5d70f055e 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -146,12 +146,13 @@ %typemap(in) void * %{ - if (SWIG_ConvertPtr(&$input, (void **) &$1, 0, 0) < 0) { - /* Allow NULL from php for void* */ - if (Z_ISNULL($input)) $1=0; - else - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); - } + if (SWIG_ConvertPtr(&$input, (void **) &$1, 0, 0) < 0) { + /* Allow NULL from php for void* */ + if (Z_ISNULL($input)) + $1=0; + else + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + } %} /* Special case when void* is passed by reference so it can be made to point -- cgit v1.2.1 From 3fba8e7daa24c23c56ce6d7451831fc8f6961851 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 26 Mar 2021 10:19:57 +1300 Subject: php: Trim trailing whitespace from PHP typemaps --- Lib/php/factory.i | 64 ++++++++++++++++++++++++++-------------------------- Lib/php/phprun.swg | 4 ++-- Lib/php/std_common.i | 1 - Lib/php/std_map.i | 2 +- Lib/php/std_vector.i | 2 -- Lib/php/stl.i | 1 - 6 files changed, 35 insertions(+), 39 deletions(-) (limited to 'Lib') diff --git a/Lib/php/factory.i b/Lib/php/factory.i index c4e082dd2..b47b4791a 100644 --- a/Lib/php/factory.i +++ b/Lib/php/factory.i @@ -3,41 +3,41 @@ you have: ---- geometry.h -------- - struct Geometry { - enum GeomType{ - POINT, - CIRCLE - }; - - virtual ~Geometry() {} + struct Geometry { + enum GeomType{ + POINT, + CIRCLE + }; + + virtual ~Geometry() {} virtual int draw() = 0; - + // // Factory method for all the Geometry objects // - static Geometry *create(GeomType i); - }; - - struct Point : Geometry { - int draw() { return 1; } - double width() { return 1.0; } - }; - - struct Circle : Geometry { - int draw() { return 2; } - double radius() { return 1.5; } - }; - + static Geometry *create(GeomType i); + }; + + struct Point : Geometry { + int draw() { return 1; } + double width() { return 1.0; } + }; + + struct Circle : Geometry { + int draw() { return 2; } + double radius() { return 1.5; } + }; + // // Factory method for all the Geometry objects // Geometry *Geometry::create(GeomType type) { - switch (type) { - case POINT: return new Point(); - case CIRCLE: return new Circle(); - default: return 0; - } - } + switch (type) { + case POINT: return new Point(); + case CIRCLE: return new Circle(); + default: return 0; + } + } ---- geometry.h -------- @@ -57,16 +57,16 @@ NOTES: remember to fully qualify all the type names and don't use %factory inside a namespace declaration, ie, instead of - + namespace Foo { %factory(Geometry *Geometry::create, Point, Circle); } use - %factory(Foo::Geometry *Foo::Geometry::create, Foo::Point, Foo::Circle); + %factory(Foo::Geometry *Foo::Geometry::create, Foo::Point, Foo::Circle); + - */ /* for loop for macro with one argument */ @@ -90,13 +90,13 @@ /* for loop for macro with two arguments */ %define %formacro_2(macro,...)%_formacro_2(macro, __VA_ARGS__, __fordone__)%enddef -%define %_factory_dispatch(Type) +%define %_factory_dispatch(Type) if (!dcast) { Type *dobj = dynamic_cast($1); if (dobj) { dcast = 1; SWIG_SetPointerZval(return_value, SWIG_as_voidptr(dobj),$descriptor(Type *), $owner); - } + } }%enddef %define %factory(Method,Types...) diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 049198787..44f1087bf 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -152,7 +152,7 @@ SWIG_ConvertResourceData(void * p, const char *type_name, swig_type_info *ty) { return p; } - if (! type_name) { + if (! type_name) { /* can't convert p to ptr type ty if we don't know what type p is */ return NULL; } @@ -237,7 +237,7 @@ static swig_module_info *SWIG_Php_GetModule() { if (Z_TYPE_P(pointer) == IS_LONG) { return (swig_module_info *) pointer->value.lval; } - } + } return NULL; } diff --git a/Lib/php/std_common.i b/Lib/php/std_common.i index 092bf012b..1b69fc779 100644 --- a/Lib/php/std_common.i +++ b/Lib/php/std_common.i @@ -7,4 +7,3 @@ %include %apply size_t { std::size_t }; - diff --git a/Lib/php/std_map.i b/Lib/php/std_map.i index 7c0157353..fed3cf0b3 100644 --- a/Lib/php/std_map.i +++ b/Lib/php/std_map.i @@ -35,7 +35,7 @@ namespace std { map(); map(const map& other); - + unsigned int size() const; void clear(); %extend { diff --git a/Lib/php/std_vector.i b/Lib/php/std_vector.i index e633bc3ad..382b37ca0 100644 --- a/Lib/php/std_vector.i +++ b/Lib/php/std_vector.i @@ -112,5 +112,3 @@ namespace std { %define specialize_std_vector(T) #warning "specialize_std_vector - specialization for type T no longer needed" %enddef - - diff --git a/Lib/php/stl.i b/Lib/php/stl.i index 04f86014f..38aba67b8 100644 --- a/Lib/php/stl.i +++ b/Lib/php/stl.i @@ -7,4 +7,3 @@ %include %include %include - -- cgit v1.2.1 From f77113ea71e2373ae655c8187c71069a0ee82904 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 26 Mar 2021 13:58:02 +1300 Subject: php: Eliminate SWIG_ZEND_NAMED_FE It existed to work around const-correctness issues in older versions of PHP's C API. It's conceivable user code might be using it, but unlikely and the switch to creating classes via the API is a natural time for a compatibility break. --- Lib/php/phprun.swg | 4 ---- 1 file changed, 4 deletions(-) (limited to 'Lib') diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 76eee87da..bec32df61 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -19,10 +19,6 @@ extern "C" { #include "ext/standard/php_string.h" #include /* for abort(), used in generated code. */ -/* This indirection is to work around const correctness issues in older PHP. - * FIXME: Remove for PHP7? Or might user code be using it? */ -#define SWIG_ZEND_NAMED_FE(ZN, N, A) ZEND_NAMED_FE(ZN, N, A) - #define SWIG_BOOL_CONSTANT(N, V) REGISTER_BOOL_CONSTANT(#N, V, CONST_CS | CONST_PERSISTENT) #define SWIG_LONG_CONSTANT(N, V) REGISTER_LONG_CONSTANT(#N, V, CONST_CS | CONST_PERSISTENT) #define SWIG_DOUBLE_CONSTANT(N, V) REGISTER_DOUBLE_CONSTANT(#N, V, CONST_CS | CONST_PERSISTENT) -- cgit v1.2.1 From 478bdcdfbf6d5d0f17f778e83b42decf986eb62e Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 26 Mar 2021 16:41:28 +1300 Subject: Whitespace tweaks --- Lib/php/php.swg | 2 +- Lib/php/phprun.swg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index b285d897a..50a46bd51 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -127,7 +127,7 @@ if ($needNewFlow) { $1 = ($1_ltype) $obj_value; } else { - if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) + if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); } %} diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index bec32df61..18120e839 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -256,7 +256,7 @@ SWIG_pack_zval(zval *zv, void *ptr, int userNewObj) { } static void -SWIG_generalize_object(zval *zval_obj, void *ptr, int userNewObj ,swig_type_info *type) { +SWIG_generalize_object(zval *zval_obj, void *ptr, int userNewObj, swig_type_info *type) { zval tempZval; HashTable *ht = 0; -- cgit v1.2.1 From 0da436aa83df02ff44b588644a36f37fa1d0611c Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 26 Mar 2021 16:41:39 +1300 Subject: Simplify assignment --- Lib/php/phprun.swg | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Lib') diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 18120e839..8b393608e 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -249,8 +249,7 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { static void SWIG_pack_zval(zval *zv, void *ptr, int userNewObj) { - swig_object_wrapper *obj = NULL; - obj = (swig_object_wrapper *) SWIG_Z_FETCH_OBJ_P(zv); + swig_object_wrapper *obj = SWIG_Z_FETCH_OBJ_P(zv); obj->ptr = ptr; obj->newobject = userNewObj; } -- cgit v1.2.1 From d87b3fb7457cdac6a0a948a0204bee8959bf2d7f Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 26 Mar 2021 16:45:14 +1300 Subject: Add FIXME comment This looks to be the reason why testcases overload_null and overload_polymorphic are failing. --- Lib/php/phprun.swg | 1 + 1 file changed, 1 insertion(+) (limited to 'Lib') diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 8b393608e..c41abc86b 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -222,6 +222,7 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { zval * _cPtr = zend_hash_str_find(ht, "_cPtr", sizeof("_cPtr") - 1); if (_cPtr) { if (zend_hash_str_exists(ht, "SWIG_classWrapper", sizeof("SWIG_classWrapper") - 1)) { + /* FIXME - we need to check the type is compatible here! */ *ptr = SWIG_Z_FETCH_OBJ_P(z)->ptr; return (*ptr == NULL ? -1 : 0); } -- cgit v1.2.1 From c03679acefe36a9afaa27cea8287c0cda21eac00 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 26 Mar 2021 17:15:34 +1300 Subject: Improve how we allocate swig_object_wrapper Use zend_object_alloc() and put the zend_object member last so that Zend can put object properties after it. --- Lib/php/phprun.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib') diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index c41abc86b..8b27be260 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -59,9 +59,9 @@ static int default_error_code = E_ERROR; and need freeing, or not */ typedef struct { void * ptr; - zend_object std; HashTable *extras; int newobject; + zend_object std; } swig_object_wrapper; #define SWIG_as_voidptr(a) const_cast< void * >(static_cast< const void * >(a)) -- cgit v1.2.1 From dfa5353f27a8a5a2e81b85987a59992461f8861c Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 27 Mar 2021 19:57:37 +1300 Subject: Eliminate extras hash table This was used to store custom properties, but we can just ask the PHP object to store them like it normally would, after checking for our custom pseudo-properties. --- Lib/php/phprun.swg | 1 - 1 file changed, 1 deletion(-) (limited to 'Lib') diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 8b27be260..fc5e3970e 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -59,7 +59,6 @@ static int default_error_code = E_ERROR; and need freeing, or not */ typedef struct { void * ptr; - HashTable *extras; int newobject; zend_object std; } swig_object_wrapper; -- cgit v1.2.1 From b45bd65dbca23084c46e4fd6f366ae69ff56cca2 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sun, 28 Mar 2021 06:58:46 +1300 Subject: Add compatibility for PHP 7.3 and earlier --- Lib/php/phprun.swg | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'Lib') diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index fc5e3970e..695f25be9 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -28,13 +28,27 @@ extern "C" { REGISTER_STRINGL_CONSTANT(#N, &swig_char, 1, CONST_CS | CONST_PERSISTENT);\ } while (0) -/* ZEND_CONSTANT_SET_FLAGS is new in PHP 7.3. */ +/* ZEND_CONSTANT_SET_FLAGS was new in PHP 7.3. */ #ifdef ZEND_CONSTANT_SET_FLAGS # define SWIG_ZEND_CONSTANT_SET_FLAGS ZEND_CONSTANT_SET_FLAGS #else # define SWIG_ZEND_CONSTANT_SET_FLAGS(C, F, N) do { (C)->flags = (F); (C)->module_number = (N); } while (0) #endif +/* zend_object_alloc was new in PHP 7.3. */ +#if PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION < 3 +static zend_always_inline void *zend_object_alloc(size_t obj_size, zend_class_entry *ce) { + void *obj = emalloc(obj_size + zend_object_properties_size(ce)); + memset(obj, 0, obj_size - sizeof(zval)); + return obj; +} +#endif + +/* ZEND_THIS was new in PHP 7.4. */ +#ifndef ZEND_THIS +# define ZEND_THIS &EX(This) +#endif + #ifdef __cplusplus } #endif -- cgit v1.2.1 From 4b055c343de92a9484b14c0a77ee1fc79507612c Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sun, 28 Mar 2021 19:46:51 +1300 Subject: Fix compatibility with PHP8 --- Lib/php/phprun.swg | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'Lib') diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 695f25be9..29e4e2083 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -199,7 +199,11 @@ SWIG_ConvertResourcePtr(zval *z, swig_type_info *ty, int flags) { if (!type_name) { if (Z_TYPE_P(z) == IS_OBJECT) { +#if PHP_MAJOR_VERSION < 8 HashTable * ht = Z_OBJ_HT_P(z)->get_properties(z); +#else + HashTable * ht = Z_OBJ_HT_P(z)->get_properties(Z_OBJ_P(z)); +#endif zval * _cPtr = zend_hash_str_find(ht, "_cPtr", sizeof("_cPtr") - 1); type_name=zend_rsrc_list_get_rsrc_type(Z_RES_P(_cPtr)); } @@ -274,7 +278,11 @@ SWIG_generalize_object(zval *zval_obj, void *ptr, int userNewObj, swig_type_info HashTable *ht = 0; SWIG_pack_zval(zval_obj, ptr, userNewObj); +#if PHP_MAJOR_VERSION < 8 ht = Z_OBJ_HT_P(zval_obj)->get_properties(zval_obj); +#else + ht = Z_OBJ_HT_P(zval_obj)->get_properties(Z_OBJ_P(zval_obj)); +#endif if(ht) { ZVAL_RES(&tempZval,zend_register_resource(ptr,*(int *)(type->clientdata))); -- cgit v1.2.1 From 3f1286ba4f8cbdff20bb2ed6951d6c88f2b66a00 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 29 Mar 2021 17:30:30 +1300 Subject: Use standard SWIG overload dispatch Instead of having a slightly modified PHP-specific variant of Swig_overload_dispatch we now advance the ParmList over the this pointer. --- Lib/php/php.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 50a46bd51..793082241 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -117,7 +117,7 @@ if ($needNewFlow) { $1 = ($1_ltype) $obj_value; } else { - if (SWIG_ConvertPtr(&$linput, (void **) &$1, $1_descriptor, 0) < 0) + if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0) SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); } %} -- cgit v1.2.1 From 5482a02dd48bc14eae03f0e77cad045f929095bf Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 29 Mar 2021 17:48:17 +1300 Subject: Fix handling of strongly-typed enums Testcase cpp11_strongly_typed_enumerations.cpptest now passes. --- Lib/php/const.i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Lib') diff --git a/Lib/php/const.i b/Lib/php/const.i index a0837cb6d..228f73c85 100644 --- a/Lib/php/const.i +++ b/Lib/php/const.i @@ -12,10 +12,10 @@ unsigned char, signed char, enum SWIGTYPE - "zend_declare_class_constant_long(SWIGTYPE_$class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, $value);"; + "zend_declare_class_constant_long(SWIGTYPE_$class_ce, \"$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, $value);"; + "zend_declare_class_constant_bool(SWIGTYPE_$class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, ($1_type)$value);"; %typemap(classconsttab) float, double -- cgit v1.2.1 From f56d8ce103697c53179956c216387b44c52e8935 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 29 Mar 2021 18:17:19 +1300 Subject: Fix memory leak in director upcall check --- Lib/php/director.swg | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'Lib') diff --git a/Lib/php/director.swg b/Lib/php/director.swg index 68901a0d5..19fdb713d 100644 --- a/Lib/php/director.swg +++ b/Lib/php/director.swg @@ -86,15 +86,11 @@ namespace Swig { ZVAL_COPY_VALUE(&swig_self, self); } - static bool swig_is_overridden_method(const char *cname, zval *ptr) { + static bool swig_is_overridden_method(const char *cname, zval *z) { zend_string * cname_str = zend_string_init(cname, strlen(cname), 0); - zend_class_entry *cname_ce = zend_lookup_class(cname_str); - zend_class_entry *ptr_ce = Z_OBJCE_P(ptr); - - if (cname_ce == ptr_ce) - return true; - - return false; + zend_class_entry *ce = zend_lookup_class(cname_str); + zend_string_release(cname_str); + return ce == Z_OBJCE_P(z); } template -- cgit v1.2.1 From c863ca8b1ff2f51e6d2ede5eaefc1aed23fedec7 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 29 Mar 2021 18:18:37 +1300 Subject: Use zstring access macros These are likely to be more future-proof than accessing struct members directly. --- Lib/php/phprun.swg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Lib') diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 29e4e2083..3f808fce1 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -118,8 +118,8 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) { if (SWIG_PREFIX_LEN > 0) { zend_string * classname = zend_string_alloc(SWIG_PREFIX_LEN + type_name_len, 0); - memcpy(classname->val, SWIG_PREFIX, SWIG_PREFIX_LEN); - memcpy(classname->val + SWIG_PREFIX_LEN, type_name, type_name_len); + memcpy(ZSTR_VAL(classname), SWIG_PREFIX, SWIG_PREFIX_LEN); + memcpy(ZSTR_VAL(classname) + SWIG_PREFIX_LEN, type_name, type_name_len); ce = zend_lookup_class(classname); zend_string_release(classname); } else { -- cgit v1.2.1 From 5838f10aa08ffadbc12b91f2866a60b2cc52cf3b Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 31 Mar 2021 16:21:32 +1300 Subject: wrap fake class constants via C API --- Lib/php/const.i | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) (limited to 'Lib') diff --git a/Lib/php/const.i b/Lib/php/const.i index 228f73c85..9c65640db 100644 --- a/Lib/php/const.i +++ b/Lib/php/const.i @@ -11,19 +11,46 @@ unsigned long, unsigned char, signed char, - enum SWIGTYPE - "zend_declare_class_constant_long(SWIGTYPE_$class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, ($1_type)$value);"; + enum SWIGTYPE %{ + zend_declare_class_constant_long(SWIGTYPE_$class_ce, "$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);"; +%typemap(classconsttab) bool %{ + zend_declare_class_constant_bool(SWIGTYPE_$class_ce, "$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);"; +%typemap(classconsttab) float, + double %{ + zend_declare_class_constant_double(SWIGTYPE_$class_ce, "$const_name", sizeof("$const_name") - 1, $value); +%} - %typemap(classconsttab) char, - string - "zend_declare_class_constant_string(SWIGTYPE_$class_ce, \"$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); +} +%} + +%typemap(classconsttab) char *, + const char *, + char [], + const char [] %{ + zend_declare_class_constant_string(SWIGTYPE_$class_ce, "$const_name", sizeof("$const_name") - 1, $value); +%} + +%typemap(classconsttab) SWIGTYPE *, + SWIGTYPE &, + SWIGTYPE &&, + SWIGTYPE [] %{ +{ + zval 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); +} +%} + +%typemap(classconsttab) SWIGTYPE (CLASS::*) ""; %typemap(consttab) int, unsigned int, -- cgit v1.2.1 From e0cffb81dd92bcfbfadf2ae53220caf519c8db52 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 1 Apr 2021 15:10:10 +1300 Subject: Eliminate SWIG_classWrapper property Instead set the _cPtr property to PHP NULL to signal that this object uses swig_object_wrapper. --- Lib/php/phprun.swg | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'Lib') diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 3f808fce1..cbc1b4682 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -238,7 +238,7 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { if (ht) { zval * _cPtr = zend_hash_str_find(ht, "_cPtr", sizeof("_cPtr") - 1); if (_cPtr) { - if (zend_hash_str_exists(ht, "SWIG_classWrapper", sizeof("SWIG_classWrapper") - 1)) { + if (Z_TYPE_P(_cPtr) == IS_NULL) { /* FIXME - we need to check the type is compatible here! */ *ptr = SWIG_Z_FETCH_OBJ_P(z)->ptr; return (*ptr == NULL ? -1 : 0); @@ -274,7 +274,6 @@ SWIG_pack_zval(zval *zv, void *ptr, int userNewObj) { static void SWIG_generalize_object(zval *zval_obj, void *ptr, int userNewObj, swig_type_info *type) { - zval tempZval; HashTable *ht = 0; SWIG_pack_zval(zval_obj, ptr, userNewObj); @@ -285,10 +284,9 @@ SWIG_generalize_object(zval *zval_obj, void *ptr, int userNewObj, swig_type_info #endif if(ht) { - ZVAL_RES(&tempZval,zend_register_resource(ptr,*(int *)(type->clientdata))); - zend_hash_str_add(ht, "_cPtr", sizeof("_cPtr") - 1, &tempZval); - ZVAL_TRUE(&tempZval); - zend_hash_str_add(ht, "SWIG_classWrapper", sizeof("SWIG_classWrapper") - 1, &tempZval); + zval z; + ZVAL_NULL(&z); + zend_hash_str_add(ht, "_cPtr", sizeof("_cPtr") - 1, &z); } } -- cgit v1.2.1 From 40da8bcbb652c1ad1e390ed4e08aac1463ab17cc Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sun, 4 Apr 2021 07:45:20 +1200 Subject: php: Wrap classes using only swig_object_wrapper We no longer use PHP resources to wrap classes, and the proxy classes no longer has a _cPtr property. --- Lib/php/phprun.swg | 157 ++++++++++++----------------------------------------- 1 file changed, 34 insertions(+), 123 deletions(-) (limited to 'Lib') diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index cbc1b4682..fd772267e 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -77,64 +77,40 @@ typedef struct { zend_object std; } swig_object_wrapper; +#define SWIG_Z_FETCH_OBJ_P(zv) php_fetch_object(Z_OBJ_P(zv)) + +static inline +swig_object_wrapper * php_fetch_object(zend_object *obj) { + return (swig_object_wrapper *)((char *)obj - XtOffsetOf(swig_object_wrapper, std)); +} + #define SWIG_as_voidptr(a) const_cast< void * >(static_cast< const void * >(a)) static void SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) { - /* - * First test for Null pointers. Return those as PHP native NULL - */ - if (!ptr ) { + // Return PHP NULL for a C/C++ NULL pointer. + if (!ptr) { ZVAL_NULL(z); return; } if (type->clientdata) { - swig_object_wrapper *value; - if (! (*(int *)(type->clientdata))) - zend_error(E_ERROR, "Type: %s failed to register with zend",type->name); - value=(swig_object_wrapper *)emalloc(sizeof(swig_object_wrapper)); - value->ptr=ptr; - value->newobject=(newobject & 1); if ((newobject & 2) == 0) { - /* Just register the pointer as a resource. */ - ZVAL_RES(z, zend_register_resource(value, *(int *)(type->clientdata))); + int resource_type = *(int *)(type->clientdata); + if (resource_type == 0) + zend_error(E_ERROR, "Type: %s failed to register with zend", type->name); + /* Register the pointer as a resource. */ + swig_object_wrapper *value=(swig_object_wrapper *)emalloc(sizeof(swig_object_wrapper)); + value->ptr = ptr; + value->newobject = (newobject & 1); + ZVAL_RES(z, zend_register_resource(value, resource_type)); } else { - /* - * Wrap the resource in an object, the resource will be accessible - * via the "_cPtr" property. This code path is currently only used by - * directorin typemaps. - */ - zend_class_entry *ce = NULL; - const char *type_name = type->name+3; /* +3 so: _p_Foo -> Foo */ - size_t type_name_len; - const char * p; - - /* Namespace__Foo -> Foo */ - /* FIXME: ugly and goes wrong for classes with __ in their names. */ - while ((p = strstr(type_name, "__")) != NULL) { - type_name = p + 2; - } - type_name_len = strlen(type_name); - - if (SWIG_PREFIX_LEN > 0) { - zend_string * classname = zend_string_alloc(SWIG_PREFIX_LEN + type_name_len, 0); - memcpy(ZSTR_VAL(classname), SWIG_PREFIX, SWIG_PREFIX_LEN); - memcpy(ZSTR_VAL(classname) + SWIG_PREFIX_LEN, type_name, type_name_len); - ce = zend_lookup_class(classname); - zend_string_release(classname); - } else { - zend_string * classname = zend_string_init(type_name, type_name_len, 0); - ce = zend_lookup_class(classname); - zend_string_release(classname); - } - if (ce == NULL) { - /* class does not exist */ - object_init(z); - } else { - object_init_ex(z, ce); - } - - add_property_resource_ex(z, "_cPtr", sizeof("_cPtr") - 1, zend_register_resource(value, *(int *)(type->clientdata))); + /* This code path is currently only used by directorin typemaps. */ + zend_class_entry *ce = (zend_class_entry*)(type->clientdata); + zend_object *obj = ce->create_object(ce); + swig_object_wrapper *value = php_fetch_object(obj); + value->ptr = ptr; + value->newobject = (newobject & 1); + ZVAL_OBJ(z, obj); } return; } @@ -197,30 +173,11 @@ SWIG_ConvertResourcePtr(zval *z, swig_type_info *ty, int flags) { type_name=zend_rsrc_list_get_rsrc_type(Z_RES_P(z)); - if (!type_name) { - if (Z_TYPE_P(z) == IS_OBJECT) { -#if PHP_MAJOR_VERSION < 8 - HashTable * ht = Z_OBJ_HT_P(z)->get_properties(z); -#else - HashTable * ht = Z_OBJ_HT_P(z)->get_properties(Z_OBJ_P(z)); -#endif - zval * _cPtr = zend_hash_str_find(ht, "_cPtr", sizeof("_cPtr") - 1); - type_name=zend_rsrc_list_get_rsrc_type(Z_RES_P(_cPtr)); - } - } - return SWIG_ConvertResourceData(p, type_name, ty); } -#define SWIG_Z_FETCH_OBJ_P(zv) php_fetch_object(Z_OBJ_P(zv)) - -static inline -swig_object_wrapper * php_fetch_object(zend_object *obj) { - return (swig_object_wrapper *)((char *)obj - XtOffsetOf(swig_object_wrapper, std)); -} - -/* We allow passing of a RESOURCE pointing to the object or an OBJECT whose - _cPtr is a resource pointing to the object */ +/* We allow passing of a RESOURCE wrapping a non-class pointer or an OBJECT + wrapping a pointer to an object. */ static int SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { if (z == NULL) { @@ -229,31 +186,10 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { } switch (Z_TYPE_P(z)) { - case IS_OBJECT: { -#if PHP_MAJOR_VERSION < 8 - HashTable * ht = Z_OBJ_HT_P(z)->get_properties(z); -#else - HashTable * ht = Z_OBJ_HT_P(z)->get_properties(Z_OBJ_P(z)); -#endif - if (ht) { - zval * _cPtr = zend_hash_str_find(ht, "_cPtr", sizeof("_cPtr") - 1); - if (_cPtr) { - if (Z_TYPE_P(_cPtr) == IS_NULL) { - /* FIXME - we need to check the type is compatible here! */ - *ptr = SWIG_Z_FETCH_OBJ_P(z)->ptr; - return (*ptr == NULL ? -1 : 0); - } - if (Z_TYPE_P(_cPtr) == IS_INDIRECT) { - _cPtr = Z_INDIRECT_P(_cPtr); - } - if (Z_TYPE_P(_cPtr) == IS_RESOURCE) { - *ptr = SWIG_ConvertResourcePtr(_cPtr, ty, flags); - return (*ptr == NULL ? -1 : 0); - } - } - } - break; - } + case IS_OBJECT: + /* FIXME - we need to check the type is compatible here! */ + *ptr = SWIG_Z_FETCH_OBJ_P(z)->ptr; + return (*ptr == NULL ? -1 : 0); case IS_RESOURCE: *ptr = SWIG_ConvertResourcePtr(z, ty, flags); return (*ptr == NULL ? -1 : 0); @@ -265,34 +201,8 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { return -1; } -static void -SWIG_pack_zval(zval *zv, void *ptr, int userNewObj) { - swig_object_wrapper *obj = SWIG_Z_FETCH_OBJ_P(zv); - obj->ptr = ptr; - obj->newobject = userNewObj; -} - -static void -SWIG_generalize_object(zval *zval_obj, void *ptr, int userNewObj, swig_type_info *type) { - HashTable *ht = 0; - - SWIG_pack_zval(zval_obj, ptr, userNewObj); -#if PHP_MAJOR_VERSION < 8 - ht = Z_OBJ_HT_P(zval_obj)->get_properties(zval_obj); -#else - ht = Z_OBJ_HT_P(zval_obj)->get_properties(Z_OBJ_P(zval_obj)); -#endif - - if(ht) { - zval z; - ZVAL_NULL(&z); - zend_hash_str_add(ht, "_cPtr", sizeof("_cPtr") - 1, &z); - } -} - static void SWIG_SetZval( zval *zv, int newFlow, int userNewObj, void *ptr, swig_type_info *type, zend_object *std) { - if (!ptr) { ZVAL_NULL(zv); return; @@ -301,9 +211,10 @@ SWIG_SetZval( zval *zv, int newFlow, int userNewObj, void *ptr, swig_type_info * if (newFlow) { if (newFlow == 1) ZVAL_OBJ(zv,std); - SWIG_generalize_object(zv, ptr, userNewObj, type); - } - else { + swig_object_wrapper *obj = SWIG_Z_FETCH_OBJ_P(zv); + obj->ptr = ptr; + obj->newobject = userNewObj; + } else { SWIG_SetPointerZval(zv, ptr, type, userNewObj); } } -- cgit v1.2.1 From f0e0f7e391c6751fb887cbb8f4786f137afaa619 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 5 Apr 2021 17:30:43 +1200 Subject: Rename userNewObj to newobject Better to use the same name we use elsewhere. --- Lib/php/phprun.swg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Lib') diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index fd772267e..f392d57f8 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -202,7 +202,7 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { } static void -SWIG_SetZval( zval *zv, int newFlow, int userNewObj, void *ptr, swig_type_info *type, zend_object *std) { +SWIG_SetZval(zval *zv, int newFlow, int newobject, void *ptr, swig_type_info *type, zend_object *std) { if (!ptr) { ZVAL_NULL(zv); return; @@ -213,9 +213,9 @@ SWIG_SetZval( zval *zv, int newFlow, int userNewObj, void *ptr, swig_type_info * ZVAL_OBJ(zv,std); swig_object_wrapper *obj = SWIG_Z_FETCH_OBJ_P(zv); obj->ptr = ptr; - obj->newobject = userNewObj; + obj->newobject = newobject; } else { - SWIG_SetPointerZval(zv, ptr, type, userNewObj); + SWIG_SetPointerZval(zv, ptr, type, newobject); } } -- cgit v1.2.1 From 8fd2a1cb75a22db1dafc8a5f8b213487a2f7c50e Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 5 Apr 2021 17:34:34 +1200 Subject: Fix mixed declarations and code SWIG still aims to generate C90-compatible code. --- Lib/php/phprun.swg | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'Lib') diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index f392d57f8..a3afc9190 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -96,13 +96,15 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) { if (type->clientdata) { if ((newobject & 2) == 0) { int resource_type = *(int *)(type->clientdata); - if (resource_type == 0) + if (resource_type == 0) { zend_error(E_ERROR, "Type: %s failed to register with zend", type->name); - /* Register the pointer as a resource. */ - swig_object_wrapper *value=(swig_object_wrapper *)emalloc(sizeof(swig_object_wrapper)); - value->ptr = ptr; - value->newobject = (newobject & 1); - ZVAL_RES(z, zend_register_resource(value, resource_type)); + } else { + /* Register the pointer as a resource. */ + swig_object_wrapper *value=(swig_object_wrapper *)emalloc(sizeof(swig_object_wrapper)); + value->ptr = ptr; + value->newobject = (newobject & 1); + ZVAL_RES(z, zend_register_resource(value, resource_type)); + } } else { /* This code path is currently only used by directorin typemaps. */ zend_class_entry *ce = (zend_class_entry*)(type->clientdata); @@ -209,9 +211,10 @@ SWIG_SetZval(zval *zv, int newFlow, int newobject, void *ptr, swig_type_info *ty } if (newFlow) { + swig_object_wrapper *obj; if (newFlow == 1) ZVAL_OBJ(zv,std); - swig_object_wrapper *obj = SWIG_Z_FETCH_OBJ_P(zv); + obj = SWIG_Z_FETCH_OBJ_P(zv); obj->ptr = ptr; obj->newobject = newobject; } else { -- cgit v1.2.1 From 9987d7168a59a328c4ecd385cb3f0679df5296ac Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 12 Apr 2021 17:29:39 +1200 Subject: Implement type-checking of wrapped objects The testsuite now all passes (with PHP 7.4 at least) --- Lib/php/phprun.swg | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'Lib') diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index a3afc9190..a1179ccea 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -74,6 +74,7 @@ static int default_error_code = E_ERROR; typedef struct { void * ptr; int newobject; + const swig_type_info * type; zend_object std; } swig_object_wrapper; @@ -103,6 +104,7 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) { swig_object_wrapper *value=(swig_object_wrapper *)emalloc(sizeof(swig_object_wrapper)); value->ptr = ptr; value->newobject = (newobject & 1); + value->type = type; ZVAL_RES(z, zend_register_resource(value, resource_type)); } } else { @@ -112,6 +114,7 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) { swig_object_wrapper *value = php_fetch_object(obj); value->ptr = ptr; value->newobject = (newobject & 1); + value->type = type; ZVAL_OBJ(z, obj); } return; @@ -188,10 +191,14 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { } switch (Z_TYPE_P(z)) { - case IS_OBJECT: - /* FIXME - we need to check the type is compatible here! */ - *ptr = SWIG_Z_FETCH_OBJ_P(z)->ptr; + case IS_OBJECT: { + swig_object_wrapper *value = SWIG_Z_FETCH_OBJ_P(z); + if (flags & SWIG_POINTER_DISOWN) { + value->newobject = 0; + } + *ptr = SWIG_ConvertResourceData(value->ptr, value->type->name, ty); return (*ptr == NULL ? -1 : 0); + } case IS_RESOURCE: *ptr = SWIG_ConvertResourcePtr(z, ty, flags); return (*ptr == NULL ? -1 : 0); @@ -217,6 +224,7 @@ SWIG_SetZval(zval *zv, int newFlow, int newobject, void *ptr, swig_type_info *ty obj = SWIG_Z_FETCH_OBJ_P(zv); obj->ptr = ptr; obj->newobject = newobject; + obj->type = type; } else { SWIG_SetPointerZval(zv, ptr, type, newobject); } -- cgit v1.2.1 From 5161acdd240c220cbb07887e9a17069ef93380ba Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 13 Apr 2021 09:07:31 +1200 Subject: Eliminate direct reference to c_result in typemap Typemaps should use $result. --- Lib/php/php.swg | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 793082241..ebbfadf18 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -101,13 +101,12 @@ if (!EG(exception)) { if ($needNewFlow) { tmp = ($&1_ltype) &SWIG_Z_FETCH_OBJ_P(result)->ptr; - c_result = *tmp; SWIG_Z_FETCH_OBJ_P(result)->newobject = 0; } else { if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); - $result = *tmp; } + $result = *tmp; } %} -- cgit v1.2.1 From d2eb06fbc0aae2a039db741ca03afe40ab28c308 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 13 Apr 2021 09:52:43 +1200 Subject: Merge 2 functionally identical typemaps The only difference is code formatting. --- Lib/php/php.swg | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index ebbfadf18..6cb88062c 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -121,17 +121,8 @@ } %} -%typemap(in) SWIGTYPE & -%{ - if ($needNewFlow) { - $1 = ($1_ltype) $obj_value; - } else { - if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); - } -%} - -%typemap(in) SWIGTYPE && +%typemap(in) SWIGTYPE &, + SWIGTYPE && %{ if ($needNewFlow) { $1 = ($1_ltype) $obj_value; -- cgit v1.2.1 From 60e7deda2c3ac70b097614eaafca6a4ba9910625 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 13 Apr 2021 10:03:03 +1200 Subject: Eliminate non-standard $lower_param typemap variable --- Lib/php/php.swg | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 6cb88062c..9118bf58e 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -148,12 +148,8 @@ %typemap(in) SWIGTYPE *DISOWN %{ - if ($needNewFlow) { - SWIG_Z_FETCH_OBJ_P(&$input)->newobject = 0; - $1 = ($lower_param *)SWIG_Z_FETCH_OBJ_P(&$input)->ptr; - } else { - if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN ) < 0) - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN) < 0) { + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); } %} -- cgit v1.2.1 From 0a72bfc630bc78e5cab0786ecbc2058b2d5f318f Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 13 Apr 2021 10:18:47 +1200 Subject: Eliminate tempPointer variable --- Lib/php/php.swg | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 9118bf58e..49c34d0d2 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -136,14 +136,13 @@ %typemap(in) SWIGTYPE *const& ($*ltype temp) %{ if ($needNewFlow) { - tempPointer = $obj_value; - $1 = ($1_ltype) &tempPointer; + temp = ($*1_ltype) $obj_value; } else { if (SWIG_ConvertPtr(&$input, (void **) &temp, $*1_descriptor, 0) < 0) { SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $*1_descriptor"); } - $1 = ($1_ltype)&temp; } + $1 = ($1_ltype)&temp; %} %typemap(in) SWIGTYPE *DISOWN -- cgit v1.2.1 From 762a309373c4e5556beb449d7ebe063a8cbc90ba Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 13 Apr 2021 10:31:22 +1200 Subject: Fix typemap formatting incosistencies --- Lib/php/php.swg | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 49c34d0d2..1c02d8f39 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -89,8 +89,9 @@ if ($needNewFlow) { $1 = *(($1_ltype *)$obj_value); } else { - if (SWIG_ConvertPtr(&$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1&_descriptor"); + if (SWIG_ConvertPtr(&$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) { + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); + } $1 = *tmp; } %} @@ -103,8 +104,9 @@ tmp = ($&1_ltype) &SWIG_Z_FETCH_OBJ_P(result)->ptr; SWIG_Z_FETCH_OBJ_P(result)->newobject = 0; } else { - if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); + if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) { + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); + } } $result = *tmp; } @@ -116,8 +118,9 @@ if ($needNewFlow) { $1 = ($1_ltype) $obj_value; } else { - if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0) + if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0) { SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + } } %} -- cgit v1.2.1 From 3b43a7bf9b79f2106bda12a9a7b376b2def4e41c Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 13 Apr 2021 13:22:03 +1200 Subject: Refactor to eliminate SWIG_ConvertResourcePtr() --- Lib/php/phprun.swg | 52 +++++++++++++++++++++------------------------------- 1 file changed, 21 insertions(+), 31 deletions(-) (limited to 'Lib') diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index a1179ccea..98fac7778 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -130,10 +130,8 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) { Sadly PHP has no API to find a type name from a type id, only from an instance of a resource of the type id, so we have to pass type_name as well. - The two functions which might call this are: - SWIG_ConvertResourcePtr which gets the type name from the resource - and the registered zend destructors for which we have one per type each - with the type name hard wired in. */ + This is called by SWIG_ConvertPtr which gets the type name from the + swig_object_wrapper or resource type. */ static void * SWIG_ConvertResourceData(void * p, const char *type_name, swig_type_info *ty) { swig_cast_info *tc; @@ -159,35 +157,13 @@ SWIG_ConvertResourceData(void * p, const char *type_name, swig_type_info *ty) { return result; } -/* This function returns a pointer of type ty by extracting the pointer - and type info from the resource in z. z must be a resource. - If it fails, NULL is returned. - It uses SWIG_ConvertResourceData to do the real work. */ -static void * -SWIG_ConvertResourcePtr(zval *z, swig_type_info *ty, int flags) { - swig_object_wrapper *value; - void *p; - const char *type_name; - - if (Z_RES_TYPE_P(z) == -1) return NULL; - value = (swig_object_wrapper *) Z_RES_VAL_P(z); - if (flags & SWIG_POINTER_DISOWN) { - value->newobject = 0; - } - p = value->ptr; - - type_name=zend_rsrc_list_get_rsrc_type(Z_RES_P(z)); - - return SWIG_ConvertResourceData(p, type_name, ty); -} - /* We allow passing of a RESOURCE wrapping a non-class pointer or an OBJECT wrapping a pointer to an object. */ static int SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { if (z == NULL) { *ptr = 0; - return 0; + return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK; } switch (Z_TYPE_P(z)) { @@ -197,11 +173,25 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { value->newobject = 0; } *ptr = SWIG_ConvertResourceData(value->ptr, value->type->name, ty); - return (*ptr == NULL ? -1 : 0); + return (*ptr == NULL ? SWIG_ERROR : SWIG_OK); + } + case IS_RESOURCE: { + swig_object_wrapper *value; + void *p; + const char *type_name; + + if (Z_RES_TYPE_P(z) == -1) return -1; + value = (swig_object_wrapper *) Z_RES_VAL_P(z); + if (flags & SWIG_POINTER_DISOWN) { + value->newobject = 0; + } + p = value->ptr; + + type_name=zend_rsrc_list_get_rsrc_type(Z_RES_P(z)); + + *ptr = SWIG_ConvertResourceData(p, type_name, ty); + return (*ptr == NULL ? SWIG_ERROR : SWIG_OK); } - case IS_RESOURCE: - *ptr = SWIG_ConvertResourcePtr(z, ty, flags); - return (*ptr == NULL ? -1 : 0); case IS_NULL: *ptr = 0; return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK; -- cgit v1.2.1 From 2da0127f5fee879467d308fa74f995e02c6ae041 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 13 Apr 2021 14:47:06 +1200 Subject: php: Merge two identical typemaps --- Lib/php/php.swg | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 5d70f055e..598564226 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -110,14 +110,8 @@ } %} -%typemap(in) SWIGTYPE & -%{ - if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); - } -%} - -%typemap(in) SWIGTYPE && +%typemap(in) SWIGTYPE &, + SWIGTYPE && %{ if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) { SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); -- cgit v1.2.1 From 3912c572ffe3acec1c59c274a2fdfa4966bd047f Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 13 Apr 2021 14:50:33 +1200 Subject: php: Make typemap formatting more consistent --- Lib/php/php.swg | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 598564226..07213faac 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -86,49 +86,49 @@ /* Object passed by value. Convert to a pointer */ %typemap(in) SWIGTYPE ($&1_ltype tmp) %{ - if (SWIG_ConvertPtr(&$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); - } - $1 = *tmp; + if (SWIG_ConvertPtr(&$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) { + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); + } + $1 = *tmp; %} %typemap(directorout) SWIGTYPE ($&1_ltype tmp) %{ - /* If exit was via exception, PHP NULL is returned so skip the conversion. */ - if (!EG(exception)) { - if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); - $result = *tmp; - } + /* If exit was via exception, PHP NULL is returned so skip the conversion. */ + if (!EG(exception)) { + if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); + $result = *tmp; + } %} %typemap(in) SWIGTYPE *, SWIGTYPE [] %{ - if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); - } + if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0) { + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + } %} %typemap(in) SWIGTYPE &, SWIGTYPE && %{ - if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); - } + if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) { + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + } %} %typemap(in) SWIGTYPE *const& ($*ltype temp) %{ - if (SWIG_ConvertPtr(&$input, (void **) &temp, $*1_descriptor, 0) < 0) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $*1_descriptor"); - } - $1 = ($1_ltype)&temp; + if (SWIG_ConvertPtr(&$input, (void **) &temp, $*1_descriptor, 0) < 0) { + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $*1_descriptor"); + } + $1 = ($1_ltype)&temp; %} %typemap(in) SWIGTYPE *DISOWN %{ - if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN ) < 0) { + if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN) < 0) { SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); } %} -- cgit v1.2.1 From 836258b9d33c30a70fdd33504d9ca75bb8ba5440 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 13 Apr 2021 15:54:25 +1200 Subject: Fix some cases of converting PHP NULL to C++ NULL Fixes testcase overload_null for PHP 8.0 --- Lib/php/php.swg | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 1c02d8f39..192782a5f 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -86,14 +86,10 @@ /* Object passed by value. Convert to a pointer */ %typemap(in) SWIGTYPE ($&1_ltype tmp) %{ - if ($needNewFlow) { - $1 = *(($1_ltype *)$obj_value); - } else { - if (SWIG_ConvertPtr(&$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); - } - $1 = *tmp; + if (SWIG_ConvertPtr(&$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) { + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); } + $1 = *tmp; %} %typemap(directorout) SWIGTYPE ($&1_ltype tmp) @@ -115,35 +111,23 @@ %typemap(in) SWIGTYPE *, SWIGTYPE [] %{ - if ($needNewFlow) { - $1 = ($1_ltype) $obj_value; - } else { - if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); - } + if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0) { + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); } %} %typemap(in) SWIGTYPE &, SWIGTYPE && %{ - if ($needNewFlow) { - $1 = ($1_ltype) $obj_value; - } else { - if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); - } + if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) { + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); } %} %typemap(in) SWIGTYPE *const& ($*ltype temp) %{ - if ($needNewFlow) { - temp = ($*1_ltype) $obj_value; - } else { - if (SWIG_ConvertPtr(&$input, (void **) &temp, $*1_descriptor, 0) < 0) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $*1_descriptor"); - } + if (SWIG_ConvertPtr(&$input, (void **) &temp, $*1_descriptor, 0) < 0) { + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $*1_descriptor"); } $1 = ($1_ltype)&temp; %} -- cgit v1.2.1 From 451998f27ba9a89d1b2d9aadfecf914f8b55afb3 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 14 Apr 2021 17:05:19 +1200 Subject: Fix in typemap for void** and void*& Mark the parameter as "byref" and write back through the reference after the call. Adjust testcase argout to uncomment the part that's meant to test this, and to remove lingering traces of PHP's old call-time pass-by-reference (which was completely removed before PHP 7). Fixes #1457 --- Lib/php/php.swg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 192782a5f..0e5689abe 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -157,7 +157,7 @@ /* Special case when void* is passed by reference so it can be made to point to opaque api structs */ -%typemap(in) void ** ($*1_ltype ptr, int force), +%typemap(in, byref=1) void ** ($*1_ltype ptr, int force), void *& ($*1_ltype ptr, int force) { /* If they pass NULL by reference, make it into a void* @@ -184,8 +184,8 @@ %typemap(argout) void **, void *& %{ - if (force$argnum) { - SWIG_SetPointerZval(&$input, (void*) ptr$argnum, $*1_descriptor, 1); + if (force$argnum && Z_ISREF($input)) { + SWIG_SetPointerZval(Z_REFVAL($input), (void*) ptr$argnum, $*1_descriptor, 1); } %} -- cgit v1.2.1 From 97733543e2c267c1f54560a50ff61ffab4f15419 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 15 Apr 2021 12:50:32 +1200 Subject: Fix directorout typemap for const TYPE & Previous we were returning a pointer or reference to a local variable. --- Lib/php/utils.i | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'Lib') diff --git a/Lib/php/utils.i b/Lib/php/utils.i index ed6e08ff4..09507fc8b 100644 --- a/Lib/php/utils.i +++ b/Lib/php/utils.i @@ -79,12 +79,21 @@ CONVERT_IN($result, $1_ltype, *$input); } %} -%typemap(directorout) const TYPE & ($*1_ltype temp) +%typemap(directorout) const TYPE & %{ + $*1_ltype swig_val; if (!EG(exception)) { - CONVERT_IN(temp, $*1_ltype, *$input); + CONVERT_IN(swig_val, $*1_ltype, *$input); + $1_ltype temp = new $*1_ltype(($*1_ltype)swig_val); + swig_acquire_ownership(temp); + $result = temp; + } +%} +%typemap(directorfree) const TYPE & +%{ + if (director) { + director->swig_release_ownership(%as_voidptr($input)); } - $result = &temp; %} %enddef -- cgit v1.2.1 From dcdaaba7ba5207d548f05a71bae9525f5de20b8d Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 16 Apr 2021 13:13:24 +1200 Subject: Eliminate $zend_obj typemap variable We can just get the zend_class_entry from the swig_type_info when we need it. --- Lib/php/factory.i | 5 ++--- Lib/php/php.swg | 12 ++++++------ Lib/php/phprun.swg | 8 +++++--- 3 files changed, 13 insertions(+), 12 deletions(-) (limited to 'Lib') diff --git a/Lib/php/factory.i b/Lib/php/factory.i index 2f641fe40..854720a86 100644 --- a/Lib/php/factory.i +++ b/Lib/php/factory.i @@ -95,8 +95,7 @@ if (!dcast) { Type *dobj = dynamic_cast($1); if (dobj) { dcast = 1; - zend_object *std = $descriptor(Type)##_ce->create_object($descriptor(Type)##_ce); - SWIG_SetZval(return_value, $needNewFlow, $owner, SWIG_as_voidptr(dobj), $descriptor(Type *), std); + SWIG_SetZval(return_value, $needNewFlow, $owner, SWIG_as_voidptr(dobj), $descriptor(Type *)); } }%enddef @@ -105,6 +104,6 @@ if (!dcast) { int dcast = 0; %formacro(%_factory_dispatch, Types) if (!dcast) { - SWIG_SetZval(return_value, $needNewFlow, $owner, SWIG_as_voidptr($1), $descriptor, $zend_obj); + SWIG_SetZval(return_value, $needNewFlow, $owner, SWIG_as_voidptr($1), $descriptor); } }%enddef diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 0e5689abe..9e5c0a000 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -371,12 +371,12 @@ SWIGTYPE &, SWIGTYPE && %{ - SWIG_SetZval($result, $needNewFlow, $owner, (void *)result, $1_descriptor, $zend_obj); + SWIG_SetZval($result, $needNewFlow, $owner, (void *)result, $1_descriptor); %} %typemap(out) SWIGTYPE *const& %{ - SWIG_SetZval(return_value, $needNewFlow, $owner, (void *)*$1, $*1_descriptor, $zend_obj); + SWIG_SetZval(return_value, $needNewFlow, $owner, (void *)*$1, $*1_descriptor); %} %typemap(directorin) SWIGTYPE *, @@ -384,7 +384,7 @@ SWIGTYPE &, SWIGTYPE && %{ - SWIG_SetZval($input, $needNewFlow, $owner, (void *)&$1, $1_descriptor, $zend_obj); + SWIG_SetZval($input, $needNewFlow, $owner, (void *)&$1, $1_descriptor); %} %typemap(out, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*) @@ -411,19 +411,19 @@ #ifdef __cplusplus { $&1_ltype resultobj = new $1_ltype((const $1_ltype &) $1); - SWIG_SetZval(return_value, $needNewFlow, 1, (void *)resultobj, $&1_descriptor, $zend_obj); + SWIG_SetZval(return_value, $needNewFlow, 1, (void *)resultobj, $&1_descriptor); } #else { $&1_ltype resultobj = ($&1_ltype) emalloc(sizeof($1_type)); memcpy(resultobj, &$1, sizeof($1_type)); - SWIG_SetZval(return_value, $needNewFlow, 1, (void *)resultobj, $&1_descriptor, $zend_obj); + SWIG_SetZval(return_value, $needNewFlow, 1, (void *)resultobj, $&1_descriptor); } #endif %typemap(directorin) SWIGTYPE %{ - SWIG_SetZval($input, $needNewFlow, 1, SWIG_as_voidptr(new $1_ltype((const $1_ltype &)$1)), $&1_descriptor, $zend_obj); + SWIG_SetZval($input, $needNewFlow, 1, SWIG_as_voidptr(new $1_ltype((const $1_ltype &)$1)), $&1_descriptor); %} %typemap(out) void ""; diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 98fac7778..a786f7c10 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -201,7 +201,7 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { } static void -SWIG_SetZval(zval *zv, int newFlow, int newobject, void *ptr, swig_type_info *type, zend_object *std) { +SWIG_SetZval(zval *zv, int newFlow, int newobject, void *ptr, swig_type_info *type) { if (!ptr) { ZVAL_NULL(zv); return; @@ -209,8 +209,10 @@ SWIG_SetZval(zval *zv, int newFlow, int newobject, void *ptr, swig_type_info *ty if (newFlow) { swig_object_wrapper *obj; - if (newFlow == 1) - ZVAL_OBJ(zv,std); + if (newFlow == 1) { + zend_class_entry *ce = (zend_class_entry*)type->clientdata; + ZVAL_OBJ(zv, ce->create_object(ce)); + } obj = SWIG_Z_FETCH_OBJ_P(zv); obj->ptr = ptr; obj->newobject = newobject; -- cgit v1.2.1 From 2629764e3f777adf60eed8922b1dc97cdff41169 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 17 Apr 2021 05:59:18 +1200 Subject: Remove remnants of attempts to wrap to PHP global vars This isn't really workable since PHP doesn't support intercepting accesses to global variables (nor to static class properties, so we can't wrap C/C++ global variables that way either). The _get() and _set() function wrappers actually work and have been generated for a very long time. --- Lib/php/php.swg | 1 - 1 file changed, 1 deletion(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 9e5c0a000..b6ee30c67 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -10,7 +10,6 @@ %include // PHP initialization routine. -%include // Global variables. %include // use %init %{ "/*code goes here*/ " %} -- cgit v1.2.1 From 2f888a851eff43aa4e04a9b3cd276649c2a259c0 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 19 Apr 2021 16:44:59 +1200 Subject: Fix GCC -Wempty-body warning --- Lib/php/phprun.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib') diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index a786f7c10..749029333 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -63,7 +63,7 @@ static int default_error_code = E_ERROR; #define SWIG_PHP_Error(code,msg) do { SWIG_ErrorCode() = code; SWIG_ErrorMsg() = msg; SWIG_fail; } while (0) #define SWIG_contract_assert(expr,msg) \ - if (!(expr) ) { zend_printf("Contract Assert Failed %s\n",msg ); } else + do { if (!(expr)) zend_printf("Contract Assert Failed %s\n", msg); } while (0) /* Standard SWIG API */ #define SWIG_GetModule(clientdata) SWIG_Php_GetModule() -- cgit v1.2.1 From 90e65e17fc4f479d28e7b9165d80b2a39d679b6c Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 19 Apr 2021 16:49:08 +1200 Subject: Remote Lib/php/globalvar.i It's unused since 2629764e3f777adf60eed8922b1dc97cdff41169 but it seems I failed to actually remove it there. --- Lib/php/globalvar.i | 293 ---------------------------------------------------- 1 file changed, 293 deletions(-) delete mode 100644 Lib/php/globalvar.i (limited to 'Lib') diff --git a/Lib/php/globalvar.i b/Lib/php/globalvar.i deleted file mode 100644 index 6b31207a6..000000000 --- a/Lib/php/globalvar.i +++ /dev/null @@ -1,293 +0,0 @@ -/* ----------------------------------------------------------------------------- - * globalvar.i - * - * Global variables - add the variable to PHP - * ----------------------------------------------------------------------------- */ - -%typemap(varinit) char * -{ - zval z_var; - if ($1) { - ZVAL_STRING(&z_var, $1); - } else { - ZVAL_STR(&z_var, ZSTR_EMPTY_ALLOC()); - } - zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &z_var); -} - -%typemap(varinit) char [] -{ - zval z_var; - ZVAL_STRING(&z_var, $1); - zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &z_var); -} - -%typemap(varinit) int, - unsigned int, - unsigned short, - short, - unsigned short, - long, - unsigned long, - signed char, - unsigned char, - enum SWIGTYPE -{ - zval z_var; - ZVAL_LONG(&z_var, (long)$1); - zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &z_var); -} - -%typemap(varinit) bool -{ - zval z_var; - ZVAL_BOOL(&z_var, ($1)?1:0); - zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &z_var); -} - -%typemap(varinit) float, double -{ - zval z_var; - ZVAL_DOUBLE(&z_var, (double)$1); - zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &z_var); -} - -%typemap(varinit) char -{ - zval z_var; - char c = $1; - ZVAL_STRINGL(&z_var, &c, 1); - zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &z_var); -} - -%typemap(varinit) SWIGTYPE *, SWIGTYPE [] -{ - zval z_var; - SWIG_SetPointerZval(&z_var, (void*)$1, $1_descriptor, 0); - zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &z_var); -} - -%typemap(varinit) SWIGTYPE, SWIGTYPE &, SWIGTYPE && -{ - zval z_var; - SWIG_SetPointerZval(&z_var, (void*)&$1, $&1_descriptor, 0); - zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &z_var); -} - -%typemap(varinit) char [ANY] -{ - zval z_var; - /* varinit char [ANY] */ - ZVAL_STRINGL(&z_var, $1, $1_dim0); - zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &z_var); -} - -%typemap(varinit, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*) -{ - zval resource; - void * p = emalloc(sizeof($1)); - memcpy(p, &$1, sizeof($1)); - ZVAL_RES(&resource, zend_register_resource(p, swig_member_ptr)); - zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &resource); -} - -%typemap(varin) int, unsigned int, short, unsigned short, long, unsigned long, signed char, unsigned char, enum SWIGTYPE -{ - zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1); - $1 = zval_get_long(z_var); -} - -%typemap(varin) bool -{ - zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1); - convert_to_boolean(z_var); - $1 = (Z_TYPE_P(z_var) == IS_TRUE); -} - -%typemap(varin) double,float -{ - zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1); - $1 = zval_get_double(z_var); -} - -%typemap(varin) char -{ - zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1); - convert_to_string(z_var); - if ($1 != Z_STRVAL_P(z_var)[0]) { - $1 = Z_STRVAL_P(z_var)[0]; - } -} - -%typemap(varin) char * -{ - zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1); - char *s1; - convert_to_string(z_var); - s1 = Z_STRVAL_P(z_var); - if ((s1 == NULL) || ($1 == NULL) || strcmp(s1, $1)) { - if (s1) - $1 = estrdup(s1); - else - $1 = NULL; - } -} - - -%typemap(varin) SWIGTYPE [] -{ - if ($1) { - zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1); - SWIG_SetPointerZval(z_var, (void*)$1, $1_descriptor, $owner); - } -} - -%typemap(varin) char [ANY] -{ - zval **z_var; - char *s1; - - zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1, (void**)&z_var); - s1 = Z_STRVAL_P(z_var); - if ((s1 == NULL) || ($1 == NULL) || strcmp(s1, $1)) { - if (s1) - strncpy($1, s1, $1_dim0); - } -} - -%typemap(varin) SWIGTYPE -{ - zval *z_var; - $&1_ltype _temp; - - z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1); - if (SWIG_ConvertPtr(z_var, (void**)&_temp, $&1_descriptor, 0) < 0) { - SWIG_PHP_Error(E_ERROR,"Type error in value of $symname. Expected $&1_descriptor"); - } - - $1 = *($&1_ltype)_temp; -} - -%typemap(varin) SWIGTYPE *, SWIGTYPE &, SWIGTYPE && -{ - zval *z_var; - $1_ltype _temp; - - z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1); - if (SWIG_ConvertPtr(z_var, (void **)&_temp, $1_descriptor, 0) < 0) { - SWIG_PHP_Error(E_ERROR,"Type error in value of $symname. Expected $&1_descriptor"); - } - - $1 = ($1_ltype)_temp; -} - -%typemap(varin, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*) -{ - zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1); - void * p = (void*)zend_fetch_resource_ex(z_var, SWIG_MEMBER_PTR, swig_member_ptr); - memcpy(&$1, p, sizeof($1)); -} - -%typemap(varout) int, - unsigned int, - unsigned short, - short, - long, - unsigned long, - signed char, - unsigned char, - enum SWIGTYPE -{ - zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1); - if ($1 != ($1_ltype)Z_LVAL_P(z_var)) { - z_var->value.lval = (long)$1; - } -} - -//SAMFIX need to cast zval->type, what if zend-hash_find fails? etc? -%typemap(varout) bool -{ - zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1); - if ($1 != ($1_ltype)Z_LVAL_P(z_var)) { - z_var->value.lval = (long)$1; - } -} - -%typemap(varout) double, float -{ - zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1); - if ($1 != ($1_ltype)Z_DVAL_P(z_var)) { - z_var->value.dval = (double)$1; - } -} - -%typemap(varout) char -{ - zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1); - char c = $1; - if ($1 != Z_STRVAL_P(z_val)[0]) { - ZVAL_STRING(z_var, &c); - } -} - -%typemap(varout) char * -{ - zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1); - const char *s1 = Z_STRVAL_P(z_var); - if ((s1 == NULL) || ($1 == NULL) || strcmp(s1, $1)) { - if (s1) - efree(s1); - if ($1) { - (z_var)->value.str.val = estrdup($1); - (z_var)->value.str.len = strlen($1) + 1; - } else { - (z_var)->value.str.val = 0; - (z_var)->value.str.len = 0; - } - } -} - -%typemap(varout) SWIGTYPE -{ - zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1); - SWIG_SetPointerZval(z_var, (void*)&$1, $&1_descriptor, 0); -} - -%typemap(varout) SWIGTYPE [] -{ - if($1) { - zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1); - SWIG_SetPointerZval(z_var, (void*)$1, $1_descriptor, 0); - } -} - -%typemap(varout) char [ANY] -{ - zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1); - const char *s1 = Z_STRVAL_P(z_var); -deliberate error cos this code looks bogus to me - if ((s1 == NULL) || strcmp(s1, $1)) { - if ($1) { - (z_var)->value.str.val = estrdup($1); - (z_var)->value.str.len = strlen($1) + 1; - } else { - (z_var)->value.str.val = 0; - (z_var)->value.str.len = 0; - } - } -} - -%typemap(varout) SWIGTYPE *, SWIGTYPE &, SWIGTYPE && -{ - zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1); - SWIG_SetPointerZval(z_var, (void*)$1, $1_descriptor, 0); -} - -%typemap(varout, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*) -{ - zval resource; - void * p = emalloc(sizeof($1)); - memcpy(p, &$1, sizeof($1)); - ZVAL_RES(&resource, zend_register_resource(p, swig_member_ptr)); - zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &resource); -} -- cgit v1.2.1 From 175b8d85428136884b1a98cf76e82de63b68c498 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 19 Apr 2021 16:52:59 +1200 Subject: Fix -Wimplicit-fallthrough warnings We already have the magic comment to do this, but they weren't in quite the right place. --- Lib/php/utils.i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Lib') diff --git a/Lib/php/utils.i b/Lib/php/utils.i index 09507fc8b..d1930bf15 100644 --- a/Lib/php/utils.i +++ b/Lib/php/utils.i @@ -17,8 +17,8 @@ errno = 0; lvar = (t) strtoll(Z_STRVAL(invar), &endptr, 10); if (*endptr && !errno) break; - /* FALL THRU */ } + /* FALL THRU */ default: lvar = (t) zval_get_long(&invar); } @@ -34,8 +34,8 @@ errno = 0; lvar = (t) strtoull(Z_STRVAL(invar), &endptr, 10); if (*endptr && !errno) break; - /* FALL THRU */ } + /* FALL THRU */ default: lvar = (t) zval_get_long(&invar); } -- cgit v1.2.1 From 8d09b1263b2ccd5ceb1a34a88ecc804f74cdf178 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 19 Apr 2021 17:54:21 +1200 Subject: Fix GCC -Wsign-compare warning --- Lib/php/php.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index b6ee30c67..889a7928c 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -429,7 +429,7 @@ %typemap(out) char [ANY] { - int len = 0; + size_t len = 0; while (len < $1_dim0 && $1[len]) ++len; RETVAL_STRINGL($1, len); } -- cgit v1.2.1 From 26f218327b6b0d0ffef885fc45cc55cca7e07e29 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 20 Apr 2021 16:22:40 +1200 Subject: Don't special case NULL in the REF in typemap PHP doesn't accept literal NULL for a parameter passed by reference; passing a variable with a value of NULL is just like passing a variable with a different value - we get a PHP reference to the variable, not NULL. --- Lib/php/phppointers.i | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'Lib') diff --git a/Lib/php/phppointers.i b/Lib/php/phppointers.i index d79697b5e..14756837c 100644 --- a/Lib/php/phppointers.i +++ b/Lib/php/phppointers.i @@ -2,15 +2,11 @@ %typemap(in, byref=1) TYPE *REF ($*1_ltype tmp), TYPE &REF ($*1_ltype tmp) %{ - /* First Check for SWIG wrapped type */ - if (Z_ISNULL($input)) { - $1 = 0; - } else if (Z_ISREF($input)) { - /* Not swig wrapped type, so we check if it's a PHP reference type */ - CONVERT_IN(tmp, $*1_ltype, $input); - $1 = &tmp; + if (Z_ISREF($input)) { + CONVERT_IN(tmp, $*1_ltype, $input); + $1 = &tmp; } else { - SWIG_PHP_Error(E_ERROR, SWIG_PHP_Arg_Error_Msg($argnum, Expected a reference)); + SWIG_PHP_Error(E_ERROR, SWIG_PHP_Arg_Error_Msg($argnum, Expected a reference)); } %} %typemap(argout) TYPE *REF, -- cgit v1.2.1 From c705ef8f328570453473dad85cc5fcd8817536a6 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 21 Apr 2021 15:40:35 +1200 Subject: Use PHP objects instead of resources to wrap pointers Pointer to member is currently still wrapped as a resource. --- Lib/php/factory.i | 4 +-- Lib/php/php.swg | 4 +-- Lib/php/phpinit.swg | 1 + Lib/php/phprun.swg | 83 +++++++++++++++-------------------------------------- 4 files changed, 28 insertions(+), 64 deletions(-) (limited to 'Lib') diff --git a/Lib/php/factory.i b/Lib/php/factory.i index 854720a86..54851944c 100644 --- a/Lib/php/factory.i +++ b/Lib/php/factory.i @@ -95,7 +95,7 @@ if (!dcast) { Type *dobj = dynamic_cast($1); if (dobj) { dcast = 1; - SWIG_SetZval(return_value, $needNewFlow, $owner, SWIG_as_voidptr(dobj), $descriptor(Type *)); + SWIG_SetZval(return_value, $needNewFlow-0, $owner, SWIG_as_voidptr(dobj), $descriptor(Type *)); } }%enddef @@ -104,6 +104,6 @@ if (!dcast) { int dcast = 0; %formacro(%_factory_dispatch, Types) if (!dcast) { - SWIG_SetZval(return_value, $needNewFlow, $owner, SWIG_as_voidptr($1), $descriptor); + SWIG_SetZval(return_value, $needNewFlow-0, $owner, SWIG_as_voidptr($1), $descriptor); } }%enddef diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 889a7928c..37be5b4a2 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -383,7 +383,7 @@ SWIGTYPE &, SWIGTYPE && %{ - SWIG_SetZval($input, $needNewFlow, $owner, (void *)&$1, $1_descriptor); + SWIG_SetPointerZval($input, (void *)&$1, $1_descriptor, $owner); %} %typemap(out, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*) @@ -422,7 +422,7 @@ %typemap(directorin) SWIGTYPE %{ - SWIG_SetZval($input, $needNewFlow, 1, SWIG_as_voidptr(new $1_ltype((const $1_ltype &)$1)), $&1_descriptor); + SWIG_SetPointerZval($input, SWIG_as_voidptr(new $1_ltype((const $1_ltype &)$1)), $&1_descriptor, 1); %} %typemap(out) void ""; diff --git a/Lib/php/phpinit.swg b/Lib/php/phpinit.swg index 1665f5dc4..b4d25d29e 100644 --- a/Lib/php/phpinit.swg +++ b/Lib/php/phpinit.swg @@ -21,5 +21,6 @@ static int swig_member_ptr = 0; %} %fragment("swig_php_init_member_ptr", "init", fragment="swig_php_init_member_ptr2") %{ + // FIXME: Make this a class instead swig_member_ptr = zend_register_list_destructors_ex(swig_member_ptr_dtor, NULL, SWIG_MEMBER_PTR, module_number); %} diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 749029333..6aea8e5a4 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -94,32 +94,21 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) { ZVAL_NULL(z); return; } - if (type->clientdata) { - if ((newobject & 2) == 0) { - int resource_type = *(int *)(type->clientdata); - if (resource_type == 0) { - zend_error(E_ERROR, "Type: %s failed to register with zend", type->name); - } else { - /* Register the pointer as a resource. */ - swig_object_wrapper *value=(swig_object_wrapper *)emalloc(sizeof(swig_object_wrapper)); - value->ptr = ptr; - value->newobject = (newobject & 1); - value->type = type; - ZVAL_RES(z, zend_register_resource(value, resource_type)); - } - } else { - /* This code path is currently only used by directorin typemaps. */ - zend_class_entry *ce = (zend_class_entry*)(type->clientdata); - zend_object *obj = ce->create_object(ce); - swig_object_wrapper *value = php_fetch_object(obj); - value->ptr = ptr; - value->newobject = (newobject & 1); - value->type = type; - ZVAL_OBJ(z, obj); - } + + if (!type->clientdata) { + zend_error(E_ERROR, "Type: %s not registered with zend", type->name); return; } - zend_error(E_ERROR, "Type: %s not registered with zend",type->name); + + { + zend_class_entry *ce = (zend_class_entry*)(type->clientdata); + zend_object *obj = ce->create_object(ce); + swig_object_wrapper *value = php_fetch_object(obj); + value->ptr = ptr; + value->newobject = (newobject & 1); + value->type = type; + ZVAL_OBJ(z, obj); + } } /* This pointer conversion routine takes the native pointer p (along with @@ -127,13 +116,10 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) { according to ty. The resultant pointer is returned, or NULL is returned if the pointer can't be cast. - Sadly PHP has no API to find a type name from a type id, only from an - instance of a resource of the type id, so we have to pass type_name as well. - This is called by SWIG_ConvertPtr which gets the type name from the - swig_object_wrapper or resource type. */ + swig_object_wrapper. */ static void * -SWIG_ConvertResourceData(void * p, const char *type_name, swig_type_info *ty) { +SWIG_ConvertPtrData(void * p, const char *type_name, swig_type_info *ty) { swig_cast_info *tc; void *result = 0; @@ -157,8 +143,7 @@ SWIG_ConvertResourceData(void * p, const char *type_name, swig_type_info *ty) { return result; } -/* We allow passing of a RESOURCE wrapping a non-class pointer or an OBJECT - wrapping a pointer to an object. */ +/* We wrap C/C++ pointers as PHP objects. */ static int SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { if (z == NULL) { @@ -172,24 +157,7 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { if (flags & SWIG_POINTER_DISOWN) { value->newobject = 0; } - *ptr = SWIG_ConvertResourceData(value->ptr, value->type->name, ty); - return (*ptr == NULL ? SWIG_ERROR : SWIG_OK); - } - case IS_RESOURCE: { - swig_object_wrapper *value; - void *p; - const char *type_name; - - if (Z_RES_TYPE_P(z) == -1) return -1; - value = (swig_object_wrapper *) Z_RES_VAL_P(z); - if (flags & SWIG_POINTER_DISOWN) { - value->newobject = 0; - } - p = value->ptr; - - type_name=zend_rsrc_list_get_rsrc_type(Z_RES_P(z)); - - *ptr = SWIG_ConvertResourceData(p, type_name, ty); + *ptr = SWIG_ConvertPtrData(value->ptr, value->type->name, ty); return (*ptr == NULL ? SWIG_ERROR : SWIG_OK); } case IS_NULL: @@ -202,18 +170,13 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { static void SWIG_SetZval(zval *zv, int newFlow, int newobject, void *ptr, swig_type_info *type) { - if (!ptr) { - ZVAL_NULL(zv); - return; - } - - if (newFlow) { - swig_object_wrapper *obj; - if (newFlow == 1) { - zend_class_entry *ce = (zend_class_entry*)type->clientdata; - ZVAL_OBJ(zv, ce->create_object(ce)); + if (newFlow > 1) { + if (!ptr) { + ZVAL_NULL(zv); + return; } - obj = SWIG_Z_FETCH_OBJ_P(zv); + + swig_object_wrapper * obj = SWIG_Z_FETCH_OBJ_P(zv); obj->ptr = ptr; obj->newobject = newobject; obj->type = type; -- cgit v1.2.1 From abda4caeae1a18d07a5f5ab394a42e90470430bf Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 20 Apr 2021 11:23:58 +0200 Subject: swigrun.swg: fix typo Spotted by lintian QA tool used by Debian packaging --- Lib/swigrun.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib') diff --git a/Lib/swigrun.swg b/Lib/swigrun.swg index 59118ecad..5f3159916 100644 --- a/Lib/swigrun.swg +++ b/Lib/swigrun.swg @@ -115,7 +115,7 @@ SWIG errors code. Finally, if the SWIG_CASTRANK_MODE is enabled, the result code - allows to return the 'cast rank', for example, if you have this + allows returning the 'cast rank', for example, if you have this int food(double) int fooi(int); -- cgit v1.2.1 From f198ff0a43b3bb7c71088c8789d72026b7dae279 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 21 Apr 2021 15:54:46 +1200 Subject: Fix more "allows to" and other typos --- Lib/csharp/std_auto_ptr.i | 2 +- Lib/java/std_auto_ptr.i | 2 +- Lib/lua/luarun.swg | 8 ++++---- Lib/python/std_auto_ptr.i | 2 +- Lib/ruby/std_auto_ptr.i | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) (limited to 'Lib') diff --git a/Lib/csharp/std_auto_ptr.i b/Lib/csharp/std_auto_ptr.i index d7e5f167e..1d91c9872 100644 --- a/Lib/csharp/std_auto_ptr.i +++ b/Lib/csharp/std_auto_ptr.i @@ -1,5 +1,5 @@ /* - The typemaps here allow to handle functions returning std::auto_ptr<>, + The typemaps here allow handling functions returning std::auto_ptr<>, which is the most common use of this type. If you have functions taking it as parameter, these typemaps can't be used for them and you need to do something else (e.g. use shared_ptr<> which SWIG supports fully). diff --git a/Lib/java/std_auto_ptr.i b/Lib/java/std_auto_ptr.i index 9b3cd7315..69ac2841f 100644 --- a/Lib/java/std_auto_ptr.i +++ b/Lib/java/std_auto_ptr.i @@ -1,5 +1,5 @@ /* - The typemaps here allow to handle functions returning std::auto_ptr<>, + The typemaps here allow handling functions returning std::auto_ptr<>, which is the most common use of this type. If you have functions taking it as parameter, these typemaps can't be used for them and you need to do something else (e.g. use shared_ptr<> which SWIG supports fully). diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index b8ddf000a..6ef2c6f15 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -1344,14 +1344,14 @@ SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L); /*forward declaration /* The real function that resolves a metamethod. * Function searches given class and all it's bases(recursively) for first instance of something that is - * not equal to SWIG_Lua_resolve_metatmethod. (Almost always this 'something' is actual metamethod implementation + * not equal to SWIG_Lua_resolve_metamethod. (Almost always this 'something' is actual metamethod implementation * and it is a SWIG-generated C function.). It returns value on the top of the L and there is no garbage below the * answer. * Returns 1 if found, 0 otherwise. * clss is class which metatable we will search for method * metamethod_name_idx is index in L where metamethod name (as string) lies - * skip_check allows to skip searching metamethod in givel clss and immideatelly go to searching in bases. skip_check - * is not caried to subsequent recursive calls - false is always passed. It is set to true only at first call from + * skip_check allows skipping searching metamethod in the given class and immediately going to searching in bases. skip_check + * is not carried to subsequent recursive calls - false is always passed. It is set to true only at first call from * SWIG_Lua_resolve_metamethod * */ SWIGINTERN int SWIG_Lua_do_resolve_metamethod(lua_State *L, const swig_lua_class *clss, int metamethod_name_idx, @@ -1497,7 +1497,7 @@ SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class } } - lua_pop(L,1); /* remove inheritable metatmethods table */ + lua_pop(L,1); /* remove inheritable metamethods table */ /* Special handling for __tostring method */ lua_pushstring(L, "__tostring"); diff --git a/Lib/python/std_auto_ptr.i b/Lib/python/std_auto_ptr.i index e310e00c8..c94006a68 100644 --- a/Lib/python/std_auto_ptr.i +++ b/Lib/python/std_auto_ptr.i @@ -1,5 +1,5 @@ /* - The typemaps here allow to handle functions returning std::auto_ptr<>, + The typemaps here allow handling functions returning std::auto_ptr<>, which is the most common use of this type. If you have functions taking it as parameter, these typemaps can't be used for them and you need to do something else (e.g. use shared_ptr<> which SWIG supports fully). diff --git a/Lib/ruby/std_auto_ptr.i b/Lib/ruby/std_auto_ptr.i index 3a415b942..eab8ec53d 100644 --- a/Lib/ruby/std_auto_ptr.i +++ b/Lib/ruby/std_auto_ptr.i @@ -1,5 +1,5 @@ /* - The typemaps here allow to handle functions returning std::auto_ptr<>, + The typemaps here allow handling functions returning std::auto_ptr<>, which is the most common use of this type. If you have functions taking it as parameter, these typemaps can't be used for them and you need to do something else (e.g. use shared_ptr<> which SWIG supports fully). -- cgit v1.2.1 From 2804e3b208b38c83e80176554347dd4562ab3daf Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 21 Apr 2021 16:05:41 +1200 Subject: Fix mixed declarations and code --- Lib/php/phprun.swg | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'Lib') diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 6aea8e5a4..2795f5b6a 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -176,10 +176,12 @@ SWIG_SetZval(zval *zv, int newFlow, int newobject, void *ptr, swig_type_info *ty return; } - swig_object_wrapper * obj = SWIG_Z_FETCH_OBJ_P(zv); - obj->ptr = ptr; - obj->newobject = newobject; - obj->type = type; + { + swig_object_wrapper * obj = SWIG_Z_FETCH_OBJ_P(zv); + obj->ptr = ptr; + obj->newobject = newobject; + obj->type = type; + } } else { SWIG_SetPointerZval(zv, ptr, type, newobject); } -- cgit v1.2.1 From 5577257301f6dc9c9b7b3fc723e2339290355fea Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 21 Apr 2021 16:32:56 +1200 Subject: Eliminate $needNewFlow from factory.i $needNewFlow in an output typemap is now only relevant when wrapping to a PHP __construct method, and there the return type is known so factory.i isn't useful. --- Lib/php/factory.i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Lib') diff --git a/Lib/php/factory.i b/Lib/php/factory.i index 54851944c..5a1f9dc06 100644 --- a/Lib/php/factory.i +++ b/Lib/php/factory.i @@ -95,7 +95,7 @@ if (!dcast) { Type *dobj = dynamic_cast($1); if (dobj) { dcast = 1; - SWIG_SetZval(return_value, $needNewFlow-0, $owner, SWIG_as_voidptr(dobj), $descriptor(Type *)); + SWIG_SetPointerZval(return_value, SWIG_as_voidptr(dobj), $descriptor(Type *), $owner); } }%enddef @@ -104,6 +104,6 @@ if (!dcast) { int dcast = 0; %formacro(%_factory_dispatch, Types) if (!dcast) { - SWIG_SetZval(return_value, $needNewFlow-0, $owner, SWIG_as_voidptr($1), $descriptor); + SWIG_SetPointerZval(return_value, SWIG_as_voidptr($1), $descriptor, $owner); } }%enddef -- cgit v1.2.1 From 33feca7527758466af7b6ffc503cf46fc18d0ee2 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 21 Apr 2021 17:43:12 +1200 Subject: Eliminate SWIG_SetZval() $needNewFlow is now only used for a different hack in a directorout typemap. --- Lib/php/php.swg | 15 ++++++--------- Lib/php/phprun.swg | 32 ++++++++++---------------------- 2 files changed, 16 insertions(+), 31 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 37be5b4a2..8dd613620 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -370,12 +370,12 @@ SWIGTYPE &, SWIGTYPE && %{ - SWIG_SetZval($result, $needNewFlow, $owner, (void *)result, $1_descriptor); + SWIG_SetPointerZval($result, (void *)$1, $1_descriptor, $owner); %} %typemap(out) SWIGTYPE *const& %{ - SWIG_SetZval(return_value, $needNewFlow, $owner, (void *)*$1, $*1_descriptor); + SWIG_SetPointerZval($result, (void *)*$1, $*1_descriptor, $owner); %} %typemap(directorin) SWIGTYPE *, @@ -403,22 +403,19 @@ SWIGTYPE &DYNAMIC { swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor, (void **) &$1); - SWIG_SetPointerZval(return_value, (void *)$1, ty, $owner); + SWIG_SetPointerZval($result, (void *)$1, ty, $owner); } %typemap(out) SWIGTYPE -#ifdef __cplusplus { +#ifdef __cplusplus $&1_ltype resultobj = new $1_ltype((const $1_ltype &) $1); - SWIG_SetZval(return_value, $needNewFlow, 1, (void *)resultobj, $&1_descriptor); -} #else -{ $&1_ltype resultobj = ($&1_ltype) emalloc(sizeof($1_type)); memcpy(resultobj, &$1, sizeof($1_type)); - SWIG_SetZval(return_value, $needNewFlow, 1, (void *)resultobj, $&1_descriptor); -} #endif + SWIG_SetPointerZval($result, (void *)resultobj, $&1_descriptor, 1); +} %typemap(directorin) SWIGTYPE %{ diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 2795f5b6a..a1eeb3aae 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -101,13 +101,20 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) { } { - zend_class_entry *ce = (zend_class_entry*)(type->clientdata); - zend_object *obj = ce->create_object(ce); + zend_object *obj; + if (Z_TYPE_P(z) == IS_OBJECT) { + /* The PHP object is already initialised - this is the case when wrapping + * the return value from a PHP constructor. */ + obj = Z_OBJ_P(z); + } else { + zend_class_entry *ce = (zend_class_entry*)(type->clientdata); + obj = ce->create_object(ce); + ZVAL_OBJ(z, obj); + } swig_object_wrapper *value = php_fetch_object(obj); value->ptr = ptr; value->newobject = (newobject & 1); value->type = type; - ZVAL_OBJ(z, obj); } } @@ -168,25 +175,6 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { return -1; } -static void -SWIG_SetZval(zval *zv, int newFlow, int newobject, void *ptr, swig_type_info *type) { - if (newFlow > 1) { - if (!ptr) { - ZVAL_NULL(zv); - return; - } - - { - swig_object_wrapper * obj = SWIG_Z_FETCH_OBJ_P(zv); - obj->ptr = ptr; - obj->newobject = newobject; - obj->type = type; - } - } else { - SWIG_SetPointerZval(zv, ptr, type, newobject); - } -} - static const char const_name[] = "swig_runtime_data_type_pointer"; static swig_module_info *SWIG_Php_GetModule() { zval *pointer = zend_get_constant_str(const_name, sizeof(const_name) - 1); -- cgit v1.2.1 From 49d5909b083e321eafb513af15798281e21a8d83 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 21 Apr 2021 17:44:24 +1200 Subject: Use $1 instead of result in out typemaps --- Lib/php/php.swg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 8dd613620..a4d6e56fa 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -96,8 +96,8 @@ /* If exit was via exception, PHP NULL is returned so skip the conversion. */ if (!EG(exception)) { if ($needNewFlow) { - tmp = ($&1_ltype) &SWIG_Z_FETCH_OBJ_P(result)->ptr; - SWIG_Z_FETCH_OBJ_P(result)->newobject = 0; + tmp = ($&1_ltype) &SWIG_Z_FETCH_OBJ_P($1)->ptr; + SWIG_Z_FETCH_OBJ_P($1)->newobject = 0; } else { if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) { SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); -- cgit v1.2.1 From 2920ba1cf6983bcfcf80e4f491a952be30793bad Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 21 Apr 2021 18:18:59 +1200 Subject: Use malloc() not emalloc() when free() gets used --- Lib/php/php.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index a4d6e56fa..4cef9028d 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -411,7 +411,7 @@ #ifdef __cplusplus $&1_ltype resultobj = new $1_ltype((const $1_ltype &) $1); #else - $&1_ltype resultobj = ($&1_ltype) emalloc(sizeof($1_type)); + $&1_ltype resultobj = ($&1_ltype) malloc(sizeof($1_type)); memcpy(resultobj, &$1, sizeof($1_type)); #endif SWIG_SetPointerZval($result, (void *)resultobj, $&1_descriptor, 1); -- cgit v1.2.1 From 50b13275dc8df83de4558387005fd026ac4eaa49 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 22 Apr 2021 07:42:39 +1200 Subject: Fix mixed declarations and code --- Lib/php/phprun.swg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Lib') diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index a1eeb3aae..cad0f840c 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -102,6 +102,7 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) { { zend_object *obj; + swig_object_wrapper *value; if (Z_TYPE_P(z) == IS_OBJECT) { /* The PHP object is already initialised - this is the case when wrapping * the return value from a PHP constructor. */ @@ -111,7 +112,7 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) { obj = ce->create_object(ce); ZVAL_OBJ(z, obj); } - swig_object_wrapper *value = php_fetch_object(obj); + value = php_fetch_object(obj); value->ptr = ptr; value->newobject = (newobject & 1); value->type = type; -- cgit v1.2.1 From ad61e33e229ec9e2e812108bb211409a4b9b50e0 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 22 Apr 2021 07:56:25 +1200 Subject: Wrap pointer to member as object not resource --- Lib/php/php.swg | 8 ++++---- Lib/php/phpinit.swg | 15 --------------- 2 files changed, 4 insertions(+), 19 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 4cef9028d..db47f49a4 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -386,16 +386,16 @@ SWIG_SetPointerZval($input, (void *)&$1, $1_descriptor, $owner); %} -%typemap(out, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*) +%typemap(out) SWIGTYPE (CLASS::*) { void * p = emalloc(sizeof($1)); memcpy(p, &$1, sizeof($1)); - RETVAL_RES(zend_register_resource(p, swig_member_ptr)); + SWIG_SetPointerZval($result, (void *)p, $&1_descriptor, 1); } -%typemap(in, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*) +%typemap(in) SWIGTYPE (CLASS::*) { - void * p = (void*)zend_fetch_resource_ex(&$input, SWIG_MEMBER_PTR, swig_member_ptr); + void * p = SWIG_Z_FETCH_OBJ_P(&$input)->ptr; memcpy(&$1, p, sizeof($1)); } diff --git a/Lib/php/phpinit.swg b/Lib/php/phpinit.swg index b4d25d29e..9e3dc75e5 100644 --- a/Lib/php/phpinit.swg +++ b/Lib/php/phpinit.swg @@ -9,18 +9,3 @@ SWIG_php_minit { SWIG_InitializeModule((void*)&module_number); %} - -%fragment("swig_php_init_member_ptr2", "header") %{ -#define SWIG_MEMBER_PTR "CLASS::*" - -static void swig_member_ptr_dtor(zend_resource *res) { - efree(res->ptr); -} - -static int swig_member_ptr = 0; -%} - -%fragment("swig_php_init_member_ptr", "init", fragment="swig_php_init_member_ptr2") %{ - // FIXME: Make this a class instead - swig_member_ptr = zend_register_list_destructors_ex(swig_member_ptr_dtor, NULL, SWIG_MEMBER_PTR, module_number); -%} -- cgit v1.2.1 From 10d87100ea41b810ec341b6daf8ff7bc0ffcd50a Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 22 Apr 2021 12:25:13 +1200 Subject: Whitespace tweaks --- Lib/php/director.swg | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Lib') diff --git a/Lib/php/director.swg b/Lib/php/director.swg index 19fdb713d..fe5175785 100644 --- a/Lib/php/director.swg +++ b/Lib/php/director.swg @@ -140,8 +140,7 @@ namespace Swig { }; /* any php exception that occurs during a director method call */ - class DirectorMethodException : public DirectorException - { + class DirectorMethodException : public DirectorException { public: DirectorMethodException() : DirectorException(E_ERROR, "SWIG director method error", NULL) { -- cgit v1.2.1 From 50426aae2058c1b2997e104400681f1224ac1336 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 22 Apr 2021 14:40:21 +1200 Subject: Make PHP directors work more like other languages A PHP exception now gets translated to a C++ exception to skips over C++ code to get back to PHP, avoiding the need to gate every directorout typemap on EG(exception). --- Lib/php/php.swg | 17 +++++++---------- Lib/php/phprun.swg | 3 +++ Lib/php/std_string.i | 4 ---- Lib/php/utils.i | 14 +++++--------- 4 files changed, 15 insertions(+), 23 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index db47f49a4..496e1029e 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -93,18 +93,15 @@ %typemap(directorout) SWIGTYPE ($&1_ltype tmp) %{ - /* If exit was via exception, PHP NULL is returned so skip the conversion. */ - if (!EG(exception)) { - if ($needNewFlow) { - tmp = ($&1_ltype) &SWIG_Z_FETCH_OBJ_P($1)->ptr; - SWIG_Z_FETCH_OBJ_P($1)->newobject = 0; - } else { - if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); - } + if ($needNewFlow) { + tmp = ($&1_ltype) &SWIG_Z_FETCH_OBJ_P($1)->ptr; + SWIG_Z_FETCH_OBJ_P($1)->newobject = 0; + } else { + if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) { + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); } - $result = *tmp; } + $result = *tmp; %} %typemap(in) SWIGTYPE *, diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index cad0f840c..2011229e4 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -55,6 +55,9 @@ static zend_always_inline void *zend_object_alloc(size_t obj_size, zend_class_en #define SWIG_fail goto fail +// If there's an active PHP exception, just return so it can propagate. +#define SWIG_FAIL() do { if (!EG(exception)) zend_error_noreturn(SWIG_ErrorCode(), "%s", SWIG_ErrorMsg()); goto thrown; } while (0) + static const char *default_error_msg = "Unknown error occurred"; static int default_error_code = E_ERROR; diff --git a/Lib/php/std_string.i b/Lib/php/std_string.i index b55751f07..082a32ce1 100644 --- a/Lib/php/std_string.i +++ b/Lib/php/std_string.i @@ -33,10 +33,8 @@ namespace std { %} %typemap(directorout) string %{ - if (!EG(exception)) { convert_to_string($input); $result.assign(Z_STRVAL_P($input), Z_STRLEN_P($input)); - } %} %typemap(out) string %{ @@ -74,12 +72,10 @@ namespace std { %} %typemap(directorout) string & ($*1_ltype *temp) %{ - if (!EG(exception)) { convert_to_string($input); temp = new $*1_ltype(Z_STRVAL_P($input), Z_STRLEN_P($input)); swig_acquire_ownership(temp); $result = temp; - } %} %typemap(argout) string & %{ diff --git a/Lib/php/utils.i b/Lib/php/utils.i index d1930bf15..b8fd9091d 100644 --- a/Lib/php/utils.i +++ b/Lib/php/utils.i @@ -75,19 +75,15 @@ %} %typemap(directorout) TYPE %{ - if (!EG(exception)) { - CONVERT_IN($result, $1_ltype, *$input); - } + CONVERT_IN($result, $1_ltype, *$input); %} %typemap(directorout) const TYPE & %{ $*1_ltype swig_val; - if (!EG(exception)) { - CONVERT_IN(swig_val, $*1_ltype, *$input); - $1_ltype temp = new $*1_ltype(($*1_ltype)swig_val); - swig_acquire_ownership(temp); - $result = temp; - } + CONVERT_IN(swig_val, $*1_ltype, *$input); + $1_ltype temp = new $*1_ltype(($*1_ltype)swig_val); + swig_acquire_ownership(temp); + $result = temp; %} %typemap(directorfree) const TYPE & %{ -- cgit v1.2.1 From a6a52f2f79942435938153b0d425127ba79d84fc Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 22 Apr 2021 14:52:39 +1200 Subject: Eliminate remaining use of $needNewFlow --- Lib/php/php.swg | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 496e1029e..6da09e7a0 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -93,13 +93,8 @@ %typemap(directorout) SWIGTYPE ($&1_ltype tmp) %{ - if ($needNewFlow) { - tmp = ($&1_ltype) &SWIG_Z_FETCH_OBJ_P($1)->ptr; - SWIG_Z_FETCH_OBJ_P($1)->newobject = 0; - } else { - if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); - } + if (SWIG_ConvertPtr($input, (void **) &tmp, $1_descriptor, 0) < 0 || tmp == NULL) { + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); } $result = *tmp; %} -- cgit v1.2.1 From 837dfa1e7e9afe1d19c2db545bbecedda2590c3b Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 22 Apr 2021 17:49:57 +1200 Subject: Fix directorout SWIGTYPE typemaps --- Lib/php/director.swg | 6 ++++++ Lib/php/php.swg | 22 ++++++++++++++++++++-- Lib/php/phprun.swg | 25 ++++++++++++++++++++----- 3 files changed, 46 insertions(+), 7 deletions(-) (limited to 'Lib') diff --git a/Lib/php/director.swg b/Lib/php/director.swg index fe5175785..7a81cd518 100644 --- a/Lib/php/director.swg +++ b/Lib/php/director.swg @@ -99,6 +99,12 @@ namespace Swig { swig_owner[vptr] = new GCItem_T(vptr); } } + + void swig_acquire_ownership_obj(void *vptr, int own) const { + if (vptr && own) { + swig_owner[vptr] = new GCItem_Object(own); + } + } }; /* base class for director exceptions */ diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 6da09e7a0..468c7bb55 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -93,8 +93,8 @@ %typemap(directorout) SWIGTYPE ($&1_ltype tmp) %{ - if (SWIG_ConvertPtr($input, (void **) &tmp, $1_descriptor, 0) < 0 || tmp == NULL) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) { + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); } $result = *tmp; %} @@ -107,6 +107,15 @@ } %} +%typemap(directorout) SWIGTYPE * (swig_owntype own), + SWIGTYPE [] (swig_owntype own) +%{ + if (SWIG_ConvertPtrAndOwn($input, (void **)&$result, $1_descriptor, SWIG_POINTER_DISOWN, &own) < 0) { + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + } + swig_acquire_ownership_obj((void*)$result, own); +%} + %typemap(in) SWIGTYPE &, SWIGTYPE && %{ @@ -115,6 +124,15 @@ } %} +%typemap(directorout) SWIGTYPE & ($1_ltype tmp), + SWIGTYPE && ($1_ltype tmp) +%{ + if (SWIG_ConvertPtr($input, (void **) &tmp, $1_descriptor, 0) < 0 || tmp == NULL) { + SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + } + $result = tmp; +%} + %typemap(in) SWIGTYPE *const& ($*ltype temp) %{ if (SWIG_ConvertPtr(&$input, (void **) &temp, $*1_descriptor, 0) < 0) { diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 2011229e4..252c152cf 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -4,6 +4,8 @@ * PHP runtime library * ----------------------------------------------------------------------------- */ +#define swig_owntype int + #ifdef __cplusplus extern "C" { #endif @@ -130,7 +132,7 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) { 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) { +SWIG_ConvertPtrData(void * p, const char *type_name, swig_type_info *ty, int *own) { swig_cast_info *tc; void *result = 0; @@ -149,14 +151,21 @@ SWIG_ConvertPtrData(void * p, const char *type_name, swig_type_info *ty) { if (tc) { int newmemory = 0; result = SWIG_TypeCast(tc, p, &newmemory); - assert(!newmemory); /* newmemory handling not yet implemented */ + 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_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { +SWIG_ConvertPtrAndOwn(zval *z, void **ptr, swig_type_info *ty, int flags, swig_owntype *own) { + if (own) + *own = 0; + if (z == NULL) { *ptr = 0; return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK; @@ -165,11 +174,12 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { 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 (*ptr == NULL) return SWIG_ERROR; if (flags & SWIG_POINTER_DISOWN) { value->newobject = 0; } - *ptr = SWIG_ConvertPtrData(value->ptr, value->type->name, ty); - return (*ptr == NULL ? SWIG_ERROR : SWIG_OK); + return SWIG_OK; } case IS_NULL: *ptr = 0; @@ -179,6 +189,11 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { return -1; } +static int +SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) { + return SWIG_ConvertPtrAndOwn(z, ptr, ty, flags, 0); +} + static const char const_name[] = "swig_runtime_data_type_pointer"; static swig_module_info *SWIG_Php_GetModule() { zval *pointer = zend_get_constant_str(const_name, sizeof(const_name) - 1); -- cgit v1.2.1 From 13158bda9a1da399d10bf0761749a2cf448d9589 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 24 Apr 2021 10:38:50 +0100 Subject: Member function pointer typemap tweaks Use sizeof variable name rather than variable type. Workaround Visual C++ unable to parse some complex C++11 types, such as sizeof(short (Funcs::*)(bool) const &&) --- Lib/chicken/chicken.swg | 4 ++-- Lib/guile/typemaps.i | 12 ++++++------ Lib/lua/luatypemaps.swg | 6 +++--- Lib/perl5/perltypemaps.swg | 2 +- Lib/typemaps/swigtype.swg | 14 +++++++------- 5 files changed, 19 insertions(+), 19 deletions(-) (limited to 'Lib') diff --git a/Lib/chicken/chicken.swg b/Lib/chicken/chicken.swg index 7df676754..f42fd27b9 100644 --- a/Lib/chicken/chicken.swg +++ b/Lib/chicken/chicken.swg @@ -258,7 +258,7 @@ SIMPLE_TYPEMAP(double, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEO if (!SWIG_ConvertPtr(C_block_item($input,1), &result, $descriptor, 0)) { C_word ptr = C_block_item($input,0); if (C_swig_is_string(ptr)) { - SWIG_UnpackData(C_c_string(ptr), (void *) &$1, sizeof($type)); + SWIG_UnpackData(C_c_string(ptr), (void *) &$1, sizeof($1)); } else { snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", $argnum, ($descriptor->str ? $descriptor->str : $descriptor->name)); SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg); @@ -293,7 +293,7 @@ SIMPLE_TYPEMAP(double, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEO if (!SWIG_ConvertPtr(C_block_item($input,1), &result, $descriptor, 0)) { C_word ptr = C_block_item($input,0); if (C_swig_is_string(ptr)) { - SWIG_UnpackData(C_c_string(ptr), (void *) &$1, sizeof($type)); + SWIG_UnpackData(C_c_string(ptr), (void *) &$1, sizeof($1)); } else { snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", 1, ($descriptor->str ? $descriptor->str : $descriptor->name)); SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg); diff --git a/Lib/guile/typemaps.i b/Lib/guile/typemaps.i index cfccced88..84a754d8b 100644 --- a/Lib/guile/typemaps.i +++ b/Lib/guile/typemaps.i @@ -378,26 +378,26 @@ typedef unsigned long SCM; #define %argument_fail(code, type, name, argn) scm_wrong_type_arg((char *) FUNC_NAME, argn, $input); #define %as_voidptr(ptr) (void*)(ptr) -%typemap(in) SWIGTYPE (CLASS::*) { - int res = SWIG_ConvertMember($input, %as_voidptr(&$1), sizeof($type),$descriptor); +%typemap(in) SWIGTYPE (CLASS::*) { + int res = SWIG_ConvertMember($input, %as_voidptr(&$1), sizeof($1), $descriptor); if (!SWIG_IsOK(res)) { - %argument_fail(res,"$type",$symname, $argnum); + %argument_fail(res,"$type",$symname, $argnum); } } %typemap(out,noblock=1) SWIGTYPE (CLASS::*) { - %set_output(SWIG_NewMemberObj(%as_voidptr(&$1), sizeof($type), $descriptor)); + %set_output(SWIG_NewMemberObj(%as_voidptr(&$1), sizeof($1), $descriptor)); } %typemap(varin) SWIGTYPE (CLASS::*) { - int res = SWIG_ConvertMember($input,%as_voidptr(&$1), sizeof($type), $descriptor); + int res = SWIG_ConvertMember($input,%as_voidptr(&$1), sizeof($1), $descriptor); if (!SWIG_IsOK(res)) { scm_wrong_type_arg((char *) FUNC_NAME, 1, $input); } } %typemap(varout,noblock=1) SWIGTYPE (CLASS::*) { - %set_varoutput(SWIG_NewMemberObj(%as_voidptr(&$1), sizeof($type), $descriptor)); + %set_varoutput(SWIG_NewMemberObj(%as_voidptr(&$1), sizeof($1), $descriptor)); } /* ------------------------------------------------------------ diff --git a/Lib/lua/luatypemaps.swg b/Lib/lua/luatypemaps.swg index 8959f201e..6c92e3b59 100644 --- a/Lib/lua/luatypemaps.swg +++ b/Lib/lua/luatypemaps.swg @@ -237,13 +237,13 @@ $1=($1_ltype)&temp;%} // therefore a special wrapping functions SWIG_ConvertMember() & SWIG_NewMemberObj() were written %typemap(in,checkfn="lua_isuserdata") SWIGTYPE (CLASS::*) %{ - if (!SWIG_IsOK(SWIG_ConvertMember(L,$input,(void*)(&$1),sizeof($type),$descriptor))) + if (!SWIG_IsOK(SWIG_ConvertMember(L,$input,(void*)(&$1),sizeof($1),$descriptor))) SWIG_fail_ptr("$symname",$argnum,$descriptor); %} %typemap(out) SWIGTYPE (CLASS::*) -%{ - SWIG_NewMemberObj(L,(void*)(&$1),sizeof($type),$descriptor); SWIG_arg++; +%{ + SWIG_NewMemberObj(L,(void*)(&$1),sizeof($1),$descriptor); SWIG_arg++; %} diff --git a/Lib/perl5/perltypemaps.swg b/Lib/perl5/perltypemaps.swg index bf1596e9f..bab3d7acd 100644 --- a/Lib/perl5/perltypemaps.swg +++ b/Lib/perl5/perltypemaps.swg @@ -95,7 +95,7 @@ "sv_setiv(SvRV($result), PTR2IV(&$1));"; %typemap(varout,type="$1_descriptor") SWIGTYPE (CLASS::*) { - SWIG_MakePackedObj($result, (void *) &$1, sizeof($1_type), $1_descriptor); + SWIG_MakePackedObj($result, (void *) &$1, sizeof($1), $1_descriptor); } %typemap(varout) SWIGTYPE *const = SWIGTYPE *; diff --git a/Lib/typemaps/swigtype.swg b/Lib/typemaps/swigtype.swg index 581de1a90..402313ebf 100644 --- a/Lib/typemaps/swigtype.swg +++ b/Lib/typemaps/swigtype.swg @@ -562,29 +562,29 @@ * ------------------------------------------------------------ */ %typemap(in) SWIGTYPE (CLASS::*) { - int res = SWIG_ConvertMember($input, %as_voidptr(&$1), sizeof($type),$descriptor); + int res = SWIG_ConvertMember($input, %as_voidptr(&$1), sizeof($1),$descriptor); if (!SWIG_IsOK(res)) { %argument_fail(res,"$type",$symname, $argnum); } } %typemap(out,noblock=1) SWIGTYPE (CLASS::*) { - %set_output(SWIG_NewMemberObj(%as_voidptr(&$1), sizeof($type), $descriptor)); + %set_output(SWIG_NewMemberObj(%as_voidptr(&$1), sizeof($1), $descriptor)); } %typemap(varin) SWIGTYPE (CLASS::*) { - int res = SWIG_ConvertMember($input,%as_voidptr(&$1), sizeof($type), $descriptor); + int res = SWIG_ConvertMember($input,%as_voidptr(&$1), sizeof($1), $descriptor); if (!SWIG_IsOK(res)) { %variable_fail(res, "$type", "$name"); } } %typemap(varout,noblock=1) SWIGTYPE (CLASS::*) { - %set_varoutput(SWIG_NewMemberObj(%as_voidptr(&$1), sizeof($type), $descriptor)); + %set_varoutput(SWIG_NewMemberObj(%as_voidptr(&$1), sizeof($1), $descriptor)); } %typemap(constcode,noblock=1) SWIGTYPE (CLASS::*) { - %set_constant("$symname", SWIG_NewMemberObj(%as_voidptr(&$value), sizeof($type), $descriptor)); + %set_constant("$symname", SWIG_NewMemberObj(%as_voidptr(&$value), sizeof($value), $descriptor)); } #if defined(SWIG_DIRECTOR_TYPEMAPS) @@ -592,13 +592,13 @@ /* directorin */ %typemap(directorin,noblock=1) SWIGTYPE (CLASS::*) { - $input = SWIG_NewMemberObj(%as_voidptr(&$1), sizeof($type), $descriptor); + $input = SWIG_NewMemberObj(%as_voidptr(&$1), sizeof($1), $descriptor); } /* directorout */ %typemap(directorout) SWIGTYPE (CLASS::*) { - int swig_res = SWIG_ConvertMember($input,%as_voidptr(&$result), sizeof($type), $descriptor); + int swig_res = SWIG_ConvertMember($input,%as_voidptr(&$result), sizeof($result), $descriptor); if (!SWIG_IsOK(swig_res)) { %dirout_fail(swig_res,"$type"); } -- cgit v1.2.1 From 429288fa1c753dcb2d34f363e51c3b924ac173bb Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 27 Apr 2021 23:37:18 +0100 Subject: Fix Java %interface family of macros when returning by const pointer reference Closes #1987 --- Lib/java/swiginterface.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib') diff --git a/Lib/java/swiginterface.i b/Lib/java/swiginterface.i index 334464157..0a0f7806a 100644 --- a/Lib/java/swiginterface.i +++ b/Lib/java/swiginterface.i @@ -28,7 +28,7 @@ } %typemap(javaout) CTYPE *const& { long cPtr = $jnicall; - return (cPtr == 0) ? null : ($javainterfacename)new $javaclassname(cPtr, $owner); + return (cPtr == 0) ? null : ($*javainterfacename)new $*javaclassname(cPtr, $owner); } %typemap(javadirectorin) CTYPE "($&javainterfacename)new $&javaclassname($jniinput, true)" -- cgit v1.2.1 From 04bacf689b5c9ddc5b6d3ef84c281c3a499a00ad Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 3 May 2021 16:00:30 +1200 Subject: Implement director-disown for PHP --- Lib/php/director.swg | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'Lib') diff --git a/Lib/php/director.swg b/Lib/php/director.swg index 7a81cd518..ead731a48 100644 --- a/Lib/php/director.swg +++ b/Lib/php/director.swg @@ -8,6 +8,8 @@ #ifndef SWIG_DIRECTOR_PHP_HEADER_ #define SWIG_DIRECTOR_PHP_HEADER_ +#define SWIG_DIRECTOR_CAST(ARG) dynamic_cast(ARG) + #include #include #include @@ -76,16 +78,34 @@ namespace Swig { }; class Director { + private: + /* flag indicating whether the object is owned by PHP or C++ */ + mutable bool swig_disown_flag; + protected: // "mutable" so we can get a non-const pointer to it in const methods. mutable zval swig_self; typedef std::map swig_ownership_map; mutable swig_ownership_map swig_owner; + public: - Director(zval *self) { + Director(zval *self) : swig_disown_flag(false) { ZVAL_COPY_VALUE(&swig_self, self); } + ~Director() { + if (swig_disown_flag) { + Z_DELREF(swig_self); + } + } + + void swig_disown() const { + if (!swig_disown_flag) { + swig_disown_flag = true; + Z_ADDREF(swig_self); + } + } + static bool swig_is_overridden_method(const char *cname, zval *z) { zend_string * cname_str = zend_string_init(cname, strlen(cname), 0); zend_class_entry *ce = zend_lookup_class(cname_str); -- cgit v1.2.1 From 586eb24efe52137a81b7b23fcf9ec3934df12476 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 23 Mar 2021 11:49:57 +1300 Subject: php: Stop using dl() With modern PHP it only works with the CLI version of PHP, so it's better to direct users to load the extension via "extension=" in php.ini. Suggested by ferdynator in #1529. --- Lib/php/const.i | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'Lib') diff --git a/Lib/php/const.i b/Lib/php/const.i index 9c65640db..79c6d2449 100644 --- a/Lib/php/const.i +++ b/Lib/php/const.i @@ -38,7 +38,10 @@ zend_declare_class_constant_string(SWIGTYPE_$class_ce, "$const_name", sizeof("$const_name") - 1, $value); %} -%typemap(classconsttab) SWIGTYPE *, +// This creates a zend_object to wrap the pointer, and we can't do that +// before the Zend runtime has been initialised so we delay it until +// RINIT. The downside is it then happens for every request. +%typemap(classconsttab,rinit=1) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] %{ @@ -79,7 +82,10 @@ const char [] "SWIG_STRING_CONSTANT($symname, $value);"; -%typemap(consttab) SWIGTYPE *, +// This creates a zend_object to wrap the pointer, and we can't do that +// before the Zend runtime has been initialised so we delay it until +// RINIT. The downside is it then happens for every request. +%typemap(consttab,rinit=1) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] { -- cgit v1.2.1 From 6e6d720d8866e4f5d4b3b0f9ea12777f440be453 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 4 May 2021 11:34:24 +1200 Subject: Fix segfault in exception class creation We can't safely lookup the Exception class entry at MINIT time, but we can just use zend_ce_exception instead, which will be a bit faster too. --- Lib/php/phpinit.swg | 1 + 1 file changed, 1 insertion(+) (limited to 'Lib') diff --git a/Lib/php/phpinit.swg b/Lib/php/phpinit.swg index 9e3dc75e5..40f7b0766 100644 --- a/Lib/php/phpinit.swg +++ b/Lib/php/phpinit.swg @@ -7,5 +7,6 @@ %init %{ SWIG_php_minit { + zend_class_entry SWIGUNUSED internal_ce; SWIG_InitializeModule((void*)&module_number); %} -- cgit v1.2.1 From 82b244c1d37411e181b5505c17eb1656beaa7a06 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 5 May 2021 09:35:52 +1200 Subject: [php] Remove redundant conditional include We always include zend_exceptions.h via phprun.swg. --- Lib/exception.i | 1 - 1 file changed, 1 deletion(-) (limited to 'Lib') diff --git a/Lib/exception.i b/Lib/exception.i index 3d6eeccdf..9bf3a19d4 100644 --- a/Lib/exception.i +++ b/Lib/exception.i @@ -14,7 +14,6 @@ #ifdef SWIGPHP %{ -#include "zend_exceptions.h" #define SWIG_exception(code, msg) do { zend_throw_exception(NULL, (char*)msg, code); goto thrown; } while (0) %} #endif -- cgit v1.2.1 From 228b04974dcc395b7da8ad9b5141fce6f1213c20 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 5 May 2021 10:48:10 +1200 Subject: Clean up includes of PHP API headers Eliminate redundant and unused includes. Only include the minimum headers needed before the PHP_MAJOR_VERSION check in case future PHP versions remove some of the headers we include. --- Lib/php/phprun.swg | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'Lib') diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 252c152cf..b0376314e 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -9,16 +9,15 @@ #ifdef __cplusplus extern "C" { #endif -#include "zend.h" -#include "zend_API.h" -#include "zend_exceptions.h" + #include "php.h" #if PHP_MAJOR_VERSION < 7 # error These bindings need PHP 7 or later - to generate PHP5 bindings use: SWIG < 4.0.0 and swig -php5 #endif -#include "ext/standard/php_string.h" +#include "zend_exceptions.h" + #include /* for abort(), used in generated code. */ #define SWIG_BOOL_CONSTANT(N, V) REGISTER_BOOL_CONSTANT(#N, V, CONST_CS | CONST_PERSISTENT) -- cgit v1.2.1 From 542f6ca440ea6c6d21a6c2e376a4545e1b2d4903 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 5 May 2021 11:55:07 +1200 Subject: Fix uses of uninitialised zval SWIG_SetPointerZval() now checks if the passed zval is an object, so use ZVAL_UNDEF() before in cases where we create a zval to pass. --- Lib/php/const.i | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Lib') diff --git a/Lib/php/const.i b/Lib/php/const.i index 79c6d2449..3b40c2c7f 100644 --- a/Lib/php/const.i +++ b/Lib/php/const.i @@ -47,6 +47,7 @@ SWIGTYPE [] %{ { zval z; + 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); @@ -90,6 +91,7 @@ SWIGTYPE &&, SWIGTYPE [] { zend_constant c; + ZVAL_UNDEF(&c.value); SWIG_SetPointerZval(&c.value, (void*)$value, $1_descriptor, 0); zval_copy_ctor(&c.value); c.name = zend_string_init("$symname", sizeof("$symname") - 1, 0); -- cgit v1.2.1 From 853c511057b9477d14d3b45121121f086c4e39b0 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 12 May 2021 15:36:41 +1200 Subject: [php] Update keyword list Add some missing entries, remove some long obsolete entries (from the "ming" extension for generating SWF files, which was split out from PHP core in 2008), and entry for "static" as a reserved class name (`static::` is used for late static bindings, but attempting to name a PHP class `static` fails because `static` is a keyword and we also list it as such). --- Lib/php/phpkw.swg | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'Lib') diff --git a/Lib/php/phpkw.swg b/Lib/php/phpkw.swg index 58c108968..e199eacd5 100644 --- a/Lib/php/phpkw.swg +++ b/Lib/php/phpkw.swg @@ -121,6 +121,10 @@ PHPBN2(PHP_SAPI); PHPBN2(PHP_EOL); PHPBN2(PHP_INT_MAX); PHPBN2(PHP_INT_SIZE); +PHPBN2(PHP_FLOAT_DIG); // Since 7.2.0 +PHPBN2(PHP_FLOAT_EPSILON); // Since 7.2.0 +PHPBN2(PHP_FLOAT_MIN); // Since 7.2.0 +PHPBN2(PHP_FLOAT_MAX); // Since 7.2.0 PHPBN2(DEFAULT_INCLUDE_PATH); PHPBN2(PEAR_INSTALL_DIR); PHPBN2(PEAR_EXTENSION_DIR); @@ -136,6 +140,7 @@ PHPBN2(PHP_LOCALSTATEDIR); PHPBN2(PHP_CONFIG_FILE_PATH); PHPBN2(PHP_CONFIG_FILE_SCAN_DIR); PHPBN2(PHP_SHLIB_SUFFIX); +PHPBN2(PHP_FD_SETSIZE); // Since 7.1.0 PHPBN2(E_ERROR); PHPBN2(E_WARNING); PHPBN2(E_PARSE); @@ -147,6 +152,7 @@ PHPBN2(E_COMPILE_WARNING); PHPBN2(E_USER_ERROR); PHPBN2(E_USER_WARNING); PHPBN2(E_USER_NOTICE); +PHPBN2(E_RECOVERABLE_ERROR); PHPBN2(E_DEPRECATED); PHPBN2(E_USER_DEPRECATED); PHPBN2(E_ALL); @@ -158,6 +164,9 @@ PHPBN2(__COMPILER_HALT_OFFSET__); PHPBN2(PHP_OUTPUT_HANDLER_START); PHPBN2(PHP_OUTPUT_HANDLER_CONT); PHPBN2(PHP_OUTPUT_HANDLER_END); +/* Since 7.4.0 (Microsoft Windows only) */ +PHPBN2(PHP_WINDOWS_EVENT_CTRL_C); +PHPBN2(PHP_WINDOWS_EVENT_CTRL_BREAK); /* These don't actually seem to be set (tested on Linux, I guess they're * Windows only?) */ PHPBN2(PHP_WINDOWS_NT_DOMAIN_CONTROLLER); @@ -404,21 +413,6 @@ PHPBN2(CURLOPT_TCP_NODELAY); PHPBN2(CURLOPT_TIMEOUT_MS); PHPBN2(CURLOPT_CONNECTTIMEOUT_MS); PHPBN2(GMP_VERSION); -PHPBN2(SWFTEXTFIELD_USEFONT); -PHPBN2(SWFTEXTFIELD_AUTOSIZE); -PHPBN2(SWF_SOUND_NOT_COMPRESSED); -PHPBN2(SWF_SOUND_ADPCM_COMPRESSED); -PHPBN2(SWF_SOUND_MP3_COMPRESSED); -PHPBN2(SWF_SOUND_NOT_COMPRESSED_LE); -PHPBN2(SWF_SOUND_NELLY_COMPRESSED); -PHPBN2(SWF_SOUND_5KHZ); -PHPBN2(SWF_SOUND_11KHZ); -PHPBN2(SWF_SOUND_22KHZ); -PHPBN2(SWF_SOUND_44KHZ); -PHPBN2(SWF_SOUND_8BITS); -PHPBN2(SWF_SOUND_16BITS); -PHPBN2(SWF_SOUND_MONO); -PHPBN2(SWF_SOUND_STEREO); PHPBN2(OPENSSL_VERSION_NUMBER); PHPBN2(SNMP_OID_OUTPUT_FULL); PHPBN2(SNMP_OID_OUTPUT_NUMERIC); @@ -633,14 +627,12 @@ PHPBN2(PGSQL_POLLING_WRITING); PHPCN(directory); PHPCN(stdclass); PHPCN(__php_incomplete_class); -/* Added in PHP5. */ PHPCN(exception); PHPCN(errorexception); PHPCN(php_user_filter); PHPCN(closure); PHPCN(generator); PHPCN(self); -PHPCN(static); PHPCN(parent); /* http://php.net/manual/en/migration70.incompatible.php#migration70.incompatible.other.classes */ PHPCN(bool); // As of PHP 7.0 @@ -657,6 +649,14 @@ PHPCN(numeric); // As of PHP 7.0 (currently works but reserved) /* http://php.net/manual/en/migration71.incompatible.php#migration71.incompatible.invalid-class-names */ PHPCN(iterable); // As of PHP 7.1 PHPCN(void); // As of PHP 7.1 +/* Predefined interfaces and classes, introduced in PHP 7.0.0 */ +PHPCN(arithmeticerror); +PHPCN(assertionerror); +PHPCN(divisionbyzeroerror); +PHPCN(error); +PHPCN(throwable); +PHPCN(parseerror); +PHPCN(typeerror); /* From extensions (which of these are actually predefined depends which * extensions are loaded by default). */ PHPCN(xmlwriter); -- cgit v1.2.1 From b671a37e891c13f0f55be8f6363a81a549c40d87 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 12 May 2021 16:39:57 +1200 Subject: [php] Fix reserved class names TRUE, FALSE, NULL PHPCN(x) does a string compare of x with the lower-cased class name, so x needs to be in lowercase or else the entry has no effect. The entries for TRUE, FALSE and NULL weren't working as a result. --- Lib/php/phpkw.swg | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'Lib') diff --git a/Lib/php/phpkw.swg b/Lib/php/phpkw.swg index e199eacd5..e431fc2e4 100644 --- a/Lib/php/phpkw.swg +++ b/Lib/php/phpkw.swg @@ -623,7 +623,8 @@ PHPBN2(PGSQL_POLLING_OK); PHPBN2(PGSQL_POLLING_READING); PHPBN2(PGSQL_POLLING_WRITING); -/* Class names reserved by PHP (case insensitive) */ +/* Class names reserved by PHP. */ +/* Check is case insensitive - these *MUST* be listed in lower case here. */ PHPCN(directory); PHPCN(stdclass); PHPCN(__php_incomplete_class); @@ -639,9 +640,9 @@ PHPCN(bool); // As of PHP 7.0 PHPCN(int); // As of PHP 7.0 PHPCN(float); // As of PHP 7.0 PHPCN(string); // As of PHP 7.0 -PHPCN(NULL); // As of PHP 7.0 -PHPCN(TRUE); // As of PHP 7.0 -PHPCN(FALSE); // As of PHP 7.0 +PHPCN(null); // As of PHP 7.0 +PHPCN(true); // As of PHP 7.0 +PHPCN(false); // As of PHP 7.0 PHPCN(resource); // As of PHP 7.0 (currently works but reserved) PHPCN(object); // As of PHP 7.0 (currently works but reserved) PHPCN(mixed); // As of PHP 7.0 (currently works but reserved) -- cgit v1.2.1 From 353baebfcfeaa4f7c40c9e844c05076d003e01d6 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 13 May 2021 10:38:40 +1200 Subject: [Allegrocl] Remove code for Allegro Common Lisp We dropped support for it in SWIG 4.0.0 and nobody has stepped forward to revive it in over 2 years. See #2009. --- Lib/allegrocl/allegrocl.swg | 615 ----------------------------------------- Lib/allegrocl/inout_typemaps.i | 111 -------- Lib/allegrocl/longlongs.i | 49 ---- Lib/allegrocl/std_list.i | 230 --------------- Lib/allegrocl/std_string.i | 209 -------------- Lib/allegrocl/typemaps.i | 4 - 6 files changed, 1218 deletions(-) delete mode 100644 Lib/allegrocl/allegrocl.swg delete mode 100644 Lib/allegrocl/inout_typemaps.i delete mode 100644 Lib/allegrocl/longlongs.i delete mode 100644 Lib/allegrocl/std_list.i delete mode 100644 Lib/allegrocl/std_string.i delete mode 100644 Lib/allegrocl/typemaps.i (limited to 'Lib') diff --git a/Lib/allegrocl/allegrocl.swg b/Lib/allegrocl/allegrocl.swg deleted file mode 100644 index 524aa7c11..000000000 --- a/Lib/allegrocl/allegrocl.swg +++ /dev/null @@ -1,615 +0,0 @@ -/* Define a C preprocessor symbol that can be used in interface files - to distinguish between the SWIG language modules. */ - -#define SWIG_ALLEGRO_CL - -#define %ffargs(...) %feature("ffargs", "1", ##__VA_ARGS__) -%ffargs(strings_convert="t"); - -/* typemaps for argument and result type conversions. */ -%typemap(lin,numinputs=1) SWIGTYPE "(cl::let (($out $in))\n $body)"; - -%typemap(lout) bool, char, unsigned char, signed char, - short, signed short, unsigned short, - int, signed int, unsigned int, - long, signed long, unsigned long, - float, double, long double, char *, void *, - enum SWIGTYPE "(cl::setq ACL_ffresult $body)"; -%typemap(lout) void "$body"; -#ifdef __cplusplus -%typemap(lout) SWIGTYPE[ANY], SWIGTYPE *, SWIGTYPE &, SWIGTYPE && -%{ (cl:let* ((address $body) - (new-inst (cl:make-instance '$lclass :foreign-address address))) - (cl:when (cl:and $owner (cl:not (cl:zerop address))) - (excl:schedule-finalization new-inst #'$ldestructor)) - (cl:setq ACL_ffresult new-inst)) %} - -%typemap(lout) SWIGTYPE "(cl::let* ((address $body)\n (new-inst (cl::make-instance '$lclass :foreign-address address)))\n (cl::unless (cl::zerop address)\n (excl:schedule-finalization new-inst #'$ldestructor))\n (cl::setq ACL_ffresult new-inst))"; -#else -%typemap(lout) SWIGTYPE[ANY], SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE -%{ (cl:let* ((address $body) - (new-inst (cl:make-instance '$lclass :foreign-address address))) - (cl:setq ACL_ffresult new-inst)) %} -#endif - -%typemap(lisptype) bool, const bool "cl:boolean"; -%typemap(lisptype) char, const char "cl:character"; -%typemap(lisptype) unsigned char, const unsigned char "cl:integer"; -%typemap(lisptype) signed char, const signed char "cl:integer"; - -%typemap(ffitype) bool, const bool ":int"; -%typemap(ffitype) char, const char, - signed char, const signed char ":char"; -%typemap(ffitype) unsigned char, const unsigned char ":unsigned-char"; -%typemap(ffitype) short, const short, - signed short, const signed short ":short"; -%typemap(ffitype) unsigned short, const unsigned short ":unsigned-short"; -%typemap(ffitype) int, const int, signed int, const signed int ":int"; -%typemap(ffitype) unsigned int, const unsigned int ":unsigned-int"; -%typemap(ffitype) long, const long, signed long, const signed long ":long"; -%typemap(ffitype) unsigned long, const unsigned long ":unsigned-long"; -%typemap(ffitype) float, const float ":float"; -%typemap(ffitype) double, const double ":double"; -%typemap(ffitype) char *, const char *, signed char *, - const signed char *, signed char &, - const signed char & "(* :char)"; -%typemap(ffitype) unsigned char *, const unsigned char *, - unsigned char &, const unsigned char & "(* :unsigned-char)"; -%typemap(ffitype) short *, const short *, short &, - const short & "(* :short)"; -%typemap(ffitype) unsigned short *, const unsigned short *, - unsigned short &, const unsigned short & "(* :unsigned-short)"; -%typemap(ffitype) int *, const int *, int &, const int & "(* :int)"; -%typemap(ffitype) unsigned int *, const unsigned int *, - unsigned int &, const unsigned int & "(* :unsigned-int)"; -%typemap(ffitype) void * "(* :void)"; -%typemap(ffitype) void ":void"; -%typemap(ffitype) enum SWIGTYPE ":int"; -%typemap(ffitype) SWIGTYPE & "(* :void)"; -%typemap(ffitype) SWIGTYPE && "(* :void)"; - -/* const typemaps -idea: marshall all primitive c types to their respective lisp types -to maintain const corretness. For pointers/references, all bets -are off if you try to modify them. - -idea: add a constant-p slot to the base foreign-pointer class. For -constant pointer/references check this value when setting (around method?) -and error if a setf operation is performed on the address of this object. - -*/ - -/* -%exception %{ - try { - $action - } catch (...) { - return $null; - } -%} - -*/ - -// %typemap(throws) SWIGTYPE { -// (void)$1; -// SWIG_fail; -// } - -%typemap(ctype) bool, const bool "int"; -%typemap(ctype) char, unsigned char, signed char, - short, signed short, unsigned short, - int, signed int, unsigned int, - long, signed long, unsigned long, - float, double, long double, char *, void *, void, - enum SWIGTYPE, SWIGTYPE *, SWIGTYPE[], - SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE &&, const SWIGTYPE "$1_ltype"; -%typemap(ctype) SWIGTYPE "$&1_type"; - -%typemap(in) bool "$1 = (bool)$input;"; -%typemap(in) char, unsigned char, signed char, - short, signed short, unsigned short, - int, signed int, unsigned int, - long, signed long, unsigned long, - float, double, long double, char *, void *, void, - enum SWIGTYPE, SWIGTYPE *, SWIGTYPE[], - SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE && "$1 = $input;"; -%typemap(in) SWIGTYPE "$1 = *$input;"; - -/* We don't need to do any actual C-side typechecking, but need to - use the precedence values to choose which overloaded function - interfaces to generate when conflicts arise. */ - -/* predefined precedence values - -Symbolic Name Precedence Value ------------------------------- ------------------ -SWIG_TYPECHECK_POINTER 0 -SWIG_TYPECHECK_VOIDPTR 10 -SWIG_TYPECHECK_BOOL 15 -SWIG_TYPECHECK_UINT8 20 -SWIG_TYPECHECK_INT8 25 -SWIG_TYPECHECK_UINT16 30 -SWIG_TYPECHECK_INT16 35 -SWIG_TYPECHECK_UINT32 40 -SWIG_TYPECHECK_INT32 45 -SWIG_TYPECHECK_UINT64 50 -SWIG_TYPECHECK_INT64 55 -SWIG_TYPECHECK_UINT128 60 -SWIG_TYPECHECK_INT128 65 -SWIG_TYPECHECK_INTEGER 70 -SWIG_TYPECHECK_FLOAT 80 -SWIG_TYPECHECK_DOUBLE 90 -SWIG_TYPECHECK_COMPLEX 100 -SWIG_TYPECHECK_UNICHAR 110 -SWIG_TYPECHECK_UNISTRING 120 -SWIG_TYPECHECK_CHAR 130 -SWIG_TYPECHECK_STRING 140 -SWIG_TYPECHECK_BOOL_ARRAY 1015 -SWIG_TYPECHECK_INT8_ARRAY 1025 -SWIG_TYPECHECK_INT16_ARRAY 1035 -SWIG_TYPECHECK_INT32_ARRAY 1045 -SWIG_TYPECHECK_INT64_ARRAY 1055 -SWIG_TYPECHECK_INT128_ARRAY 1065 -SWIG_TYPECHECK_FLOAT_ARRAY 1080 -SWIG_TYPECHECK_DOUBLE_ARRAY 1090 -SWIG_TYPECHECK_CHAR_ARRAY 1130 -SWIG_TYPECHECK_STRING_ARRAY 1140 -*/ - -%typecheck(SWIG_TYPECHECK_BOOL) bool { $1 = 1; }; -%typecheck(SWIG_TYPECHECK_CHAR) char { $1 = 1; }; -%typecheck(SWIG_TYPECHECK_FLOAT) float { $1 = 1; }; -%typecheck(SWIG_TYPECHECK_DOUBLE) double { $1 = 1; }; -%typecheck(SWIG_TYPECHECK_STRING) char * { $1 = 1; }; -%typecheck(SWIG_TYPECHECK_INTEGER) - unsigned char, signed char, - short, signed short, unsigned short, - int, signed int, unsigned int, - long, signed long, unsigned long, - enum SWIGTYPE { $1 = 1; }; -%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, - SWIGTYPE[], SWIGTYPE[ANY], - SWIGTYPE { $1 = 1; }; - -/* This maps C/C++ types to Lisp classes for overload dispatch */ - -%typemap(lispclass) bool "t"; -%typemap(lispclass) char "cl:character"; -%typemap(lispclass) unsigned char, signed char, - short, signed short, unsigned short, - int, signed int, unsigned int, - long, signed long, unsigned long, - enum SWIGTYPE "cl:integer"; -%typemap(lispclass) float "cl:single-float"; -%typemap(lispclass) double "cl:double-float"; -%typemap(lispclass) char * "cl:string"; - -%typemap(out) void ""; -%typemap(out) bool "$result = (int)$1;"; -%typemap(out) char, unsigned char, signed char, - short, signed short, unsigned short, - int, signed int, unsigned int, - long, signed long, unsigned long, - float, double, long double, char *, void *, - enum SWIGTYPE, SWIGTYPE *, - SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE && "$result = $1;"; -#ifdef __cplusplus -%typemap(out) SWIGTYPE "$result = new $1_ltype($1);"; -#else -%typemap(out) SWIGTYPE { - $result = ($&1_ltype) malloc(sizeof($1_type)); - memmove($result, &$1, sizeof($1_type)); -} -#endif - -////////////////////////////////////////////////////////////// -// UCS-2 string conversion - -// should this be SWIG_TYPECHECK_CHAR? -%typecheck(SWIG_TYPECHECK_UNICHAR) wchar_t { $1 = 1; }; - -%typemap(in) wchar_t "$1 = $input;"; -%typemap(lin,numinputs=1) wchar_t "(cl::let (($out (cl:char-code $in)))\n $body)"; -%typemap(lin,numinputs=1) wchar_t * "(excl:with-native-string ($out $in -:external-format #+little-endian :fat-le #-little-endian :fat)\n -$body)" - -%typemap(out) wchar_t "$result = $1;"; -%typemap(lout) wchar_t "(cl::setq ACL_ffresult (cl::code-char $body))"; -%typemap(lout) wchar_t * "(cl::setq ACL_ffresult (excl:native-to-string $body -:external-format #+little-endian :fat-le #-little-endian :fat))"; - -%typemap(ffitype) wchar_t ":unsigned-short"; -%typemap(lisptype) wchar_t ""; -%typemap(ctype) wchar_t "wchar_t"; -%typemap(lispclass) wchar_t "cl:character"; -%typemap(lispclass) wchar_t * "cl:string"; -////////////////////////////////////////////////////////////// - -/* Array reference typemaps */ -%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } -%apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) } - -/* const pointers */ -%apply SWIGTYPE * { SWIGTYPE *const } -%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) } -%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) } - -/* name conversion for overloaded operators. */ -#ifdef __cplusplus -%rename(__add__) *::operator+; -%rename(__pos__) *::operator+(); -%rename(__pos__) *::operator+() const; - -%rename(__sub__) *::operator-; -%rename(__neg__) *::operator-() const; -%rename(__neg__) *::operator-(); - -%rename(__mul__) *::operator*; -%rename(__deref__) *::operator*(); -%rename(__deref__) *::operator*() const; - -%rename(__div__) *::operator/; -%rename(__mod__) *::operator%; -%rename(__logxor__) *::operator^; -%rename(__logand__) *::operator&; -%rename(__logior__) *::operator|; -%rename(__lognot__) *::operator~(); -%rename(__lognot__) *::operator~() const; - -%rename(__not__) *::operator!(); -%rename(__not__) *::operator!() const; - -%rename(__assign__) *::operator=; - -%rename(__add_assign__) *::operator+=; -%rename(__sub_assign__) *::operator-=; -%rename(__mul_assign__) *::operator*=; -%rename(__div_assign__) *::operator/=; -%rename(__mod_assign__) *::operator%=; -%rename(__logxor_assign__) *::operator^=; -%rename(__logand_assign__) *::operator&=; -%rename(__logior_assign__) *::operator|=; - -%rename(__lshift__) *::operator<<; -%rename(__lshift_assign__) *::operator<<=; -%rename(__rshift__) *::operator>>; -%rename(__rshift_assign__) *::operator>>=; - -%rename(__eq__) *::operator==; -%rename(__ne__) *::operator!=; -%rename(__lt__) *::operator<; -%rename(__gt__) *::operator>; -%rename(__lte__) *::operator<=; -%rename(__gte__) *::operator>=; - -%rename(__and__) *::operator&&; -%rename(__or__) *::operator||; - -%rename(__preincr__) *::operator++(); -%rename(__postincr__) *::operator++(int); -%rename(__predecr__) *::operator--(); -%rename(__postdecr__) *::operator--(int); - -%rename(__comma__) *::operator,(); -%rename(__comma__) *::operator,() const; - -%rename(__member_ref__) *::operator->; -%rename(__member_func_ref__) *::operator->*; - -%rename(__funcall__) *::operator(); -%rename(__aref__) *::operator[]; - -%rename(__bool__) *::operator bool(); -%rename(__bool__) *::operator bool() const; -#endif - -%insert("lisphead") %{ -(eval-when (:compile-toplevel :load-toplevel :execute) - - ;; avoid compiling ef-templates at runtime - (excl:find-external-format :fat) - (excl:find-external-format :fat-le) - -;;; You can define your own identifier converter if you want. -;;; Use the -identifier-converter command line argument to -;;; specify its name. - -(eval-when (:compile-toplevel :load-toplevel :execute) - (cl::defparameter *swig-export-list* nil)) - -(cl::defconstant *void* :..void..) - -;; parsers to aid in finding SWIG definitions in files. -(cl::defun scm-p1 (form) - (let* ((info (cl::second form)) - (id (car info)) - (id-args (if (eq (cl::car form) 'swig-dispatcher) - (cl::cdr info) - (cl::cddr info)))) - (cl::apply *swig-identifier-converter* id - (cl::progn (cl::when (cl::eq (cl::car form) 'swig-dispatcher) - (cl::remf id-args :arities)) - id-args)))) - -(cl::defmacro defswig1 (name (&rest args) &body body) - `(cl::progn (cl::defmacro ,name ,args - ,@body) - (excl::define-simple-parser ,name scm-p1)) ) - -(cl::defmacro defswig2 (name (&rest args) &body body) - `(cl::progn (cl::defmacro ,name ,args - ,@body) - (excl::define-simple-parser ,name second))) - -(defun read-symbol-from-string (string) - (cl::multiple-value-bind (result position) - (cl::read-from-string string nil "eof" :preserve-whitespace t) - (cl::if (cl::and (cl::symbolp result) - (cl::eql position (cl::length string))) - result - (cl::multiple-value-bind (sym) - (cl::intern string) - sym)))) - -(cl::defun full-name (id type arity class) - ; We need some kind of a hack here to handle template classes - ; and other synonym types right. We need the original name. - (let*( (sym (read-symbol-from-string - (if (eq *swig-identifier-converter* 'identifier-convert-lispify) - (string-lispify id) - id))) - (sym-class (find-class sym nil)) - (id (cond ( (not sym-class) - id ) - ( (and sym-class - (not (eq (class-name sym-class) - sym))) - (class-name sym-class) ) - ( t - id ))) ) - (cl::case type - (:getter (cl::format nil "~@[~A_~]~A" class id)) - (:constructor (cl::format nil "new_~A~@[~A~]" id arity)) - (:destructor (cl::format nil "delete_~A" id)) - (:type (cl::format nil "ff_~A" id)) - (:slot id) - (:ff-operator (cl::format nil "ffi_~A" id)) - (otherwise (cl::format nil "~@[~A_~]~A~@[~A~]" - class id arity))))) - -(cl::defun identifier-convert-null (id &key type class arity) - (cl::if (cl::eq type :setter) - `(cl::setf ,(identifier-convert-null - id :type :getter :class class :arity arity)) - (read-symbol-from-string (full-name id type arity class)))) - -(cl::defun string-lispify (str) - (cl::let ( (cname (excl::replace-regexp str "_" "-")) - (lastcase :other) - newcase char res ) - (cl::dotimes (n (cl::length cname)) - (cl::setf char (cl::schar cname n)) - (excl::if* (cl::alpha-char-p char) - then - (cl::setf newcase (cl::if (cl::upper-case-p char) :upper :lower)) - (cl::when (cl::and (cl::eq lastcase :lower) - (cl::eq newcase :upper)) - ;; case change... add a dash - (cl::push #\- res) - (cl::setf newcase :other)) - (cl::push (cl::char-downcase char) res) - (cl::setf lastcase newcase) - else - (cl::push char res) - (cl::setf lastcase :other))) - (cl::coerce (cl::nreverse res) 'string))) - -(cl::defun identifier-convert-lispify (cname &key type class arity) - (cl::assert (cl::stringp cname)) - (cl::when (cl::eq type :setter) - (cl::return-from identifier-convert-lispify - `(cl::setf ,(identifier-convert-lispify - cname :type :getter :class class :arity arity)))) - (cl::setq cname (full-name cname type arity class)) - (cl::if (cl::eq type :constant) - (cl::setf cname (cl::format nil "*~A*" cname))) - (read-symbol-from-string (string-lispify cname))) - -(cl::defun id-convert-and-export (name &rest kwargs) - (cl::multiple-value-bind (symbol package) - (cl::apply *swig-identifier-converter* name kwargs) - (cl::let ((args (cl::list (cl::if (cl::consp symbol) - (cl::cadr symbol) symbol) - (cl::or package cl::*package*)))) - (cl::apply #'cl::export args) - (cl::pushnew args *swig-export-list*)) - symbol)) - -(cl::defmacro swig-insert-id (name namespace &key (type :type) class) - `(cl::let ((cl::*package* (cl::find-package ,(package-name-for-namespace namespace)))) - (id-convert-and-export ,name :type ,type :class ,class))) - -(defswig2 swig-defconstant (string value) - (cl::let ((symbol (id-convert-and-export string :type :constant))) - `(cl::eval-when (:compile-toplevel :load-toplevel :execute) - (cl::defconstant ,symbol ,value)))) - -(cl::defun maybe-reorder-args (funcname arglist) - ;; in the foreign setter function the new value will be the last argument - ;; in Lisp it needs to be the first - (cl::if (cl::consp funcname) - (cl::append (cl::last arglist) (cl::butlast arglist)) - arglist)) - -(cl::defun maybe-return-value (funcname arglist) - ;; setf functions should return the new value - (cl::when (cl::consp funcname) - `(,(cl::if (cl::consp (cl::car arglist)) - (cl::caar arglist) - (cl::car arglist))))) - -(cl::defun swig-anyvarargs-p (arglist) - (cl::member :SWIG__varargs_ arglist)) - -(defswig1 swig-defun ((name &optional (mangled-name name) - &key (type :operator) class arity) - arglist kwargs - &body body) - (cl::let* ((symbol (id-convert-and-export name :type type - :arity arity :class class)) - (mangle (excl::if* (cl::string-equal name mangled-name) - then (id-convert-and-export - (cl::cond - ((cl::eq type :setter) (cl::format nil "~A-set" name)) - ((cl::eq type :getter) (cl::format nil "~A-get" name)) - (t name)) - :type :ff-operator :arity arity :class class) - else (cl::intern mangled-name))) - (defun-args (maybe-reorder-args - symbol - (cl::mapcar #'cl::car (cl::and (cl::not (cl::equal arglist '(:void))) - (cl::loop as i in arglist - when (cl::eq (cl::car i) :p+) - collect (cl::cdr i)))))) - (ffargs (cl::if (cl::equal arglist '(:void)) - arglist - (cl::mapcar #'cl::cdr arglist))) - ) - (cl::when (swig-anyvarargs-p ffargs) - (cl::setq ffargs '())) - `(cl::eval-when (:compile-toplevel :load-toplevel :execute) - (excl::compiler-let ((*record-xref-info* nil)) - (ff:def-foreign-call (,mangle ,mangled-name) ,ffargs ,@kwargs)) - (cl::macrolet ((swig-ff-call (&rest args) - (cl::cons ',mangle args))) - (cl::defun ,symbol ,defun-args - ,@body - ,@(maybe-return-value symbol defun-args)))))) - -(defswig1 swig-defmethod ((name &optional (mangled-name name) - &key (type :operator) class arity) - ffargs kwargs - &body body) - (cl::let* ((symbol (id-convert-and-export name :type type - :arity arity :class class)) - (mangle (cl::intern mangled-name)) - (defmethod-args (maybe-reorder-args - symbol - (cl::unless (cl::equal ffargs '(:void)) - (cl::loop for (lisparg name dispatch) in ffargs - when (eq lisparg :p+) - collect `(,name ,dispatch))))) - (ffargs (cl::if (cl::equal ffargs '(:void)) - ffargs - (cl::loop for (nil name nil . ffi) in ffargs - collect `(,name ,@ffi))))) - `(cl::eval-when (:compile-toplevel :load-toplevel :execute) - (excl::compiler-let ((*record-xref-info* nil)) - (ff:def-foreign-call (,mangle ,mangled-name) ,ffargs ,@kwargs)) - (cl::macrolet ((swig-ff-call (&rest args) - (cl::cons ',mangle args))) - (cl::defmethod ,symbol ,defmethod-args - ,@body - ,@(maybe-return-value symbol defmethod-args)))))) - -(defswig1 swig-dispatcher ((name &key (type :operator) class arities)) - (cl::let ((symbol (id-convert-and-export name - :type type :class class))) - `(cl::eval-when (:compile-toplevel :load-toplevel :execute) - (cl::defun ,symbol (&rest args) - (cl::case (cl::length args) - ,@(cl::loop for arity in arities - for symbol-n = (id-convert-and-export name - :type type :class class :arity arity) - collect `(,arity (cl::apply #',symbol-n args))) - (t (cl::error "No applicable wrapper-methods for foreign call ~a with args ~a of classes ~a" ',symbol args (cl::mapcar #'(cl::lambda (x) (cl::class-name (cl::class-of x))) args))) - ))))) - -(defswig2 swig-def-foreign-stub (name) - (cl::let ((lsymbol (id-convert-and-export name :type :class)) - (symbol (id-convert-and-export name :type :type))) - `(cl::eval-when (:compile-toplevel :load-toplevel :execute) - (ff:def-foreign-type ,symbol (:class )) - (cl::defclass ,lsymbol (ff:foreign-pointer) ())))) - -(defswig2 swig-def-foreign-class (name supers &rest rest) - (cl::let ((lsymbol (id-convert-and-export name :type :class)) - (symbol (id-convert-and-export name :type :type))) - `(cl::eval-when (:compile-toplevel :load-toplevel :execute) - (ff:def-foreign-type ,symbol ,@rest) - (cl::defclass ,lsymbol ,supers - ((foreign-type :initform ',symbol :initarg :foreign-type - :accessor foreign-pointer-type)))))) - -(defswig2 swig-def-foreign-type (name &rest rest) - (cl::let ((symbol (id-convert-and-export name :type :type))) - `(cl::eval-when (:compile-toplevel :load-toplevel :execute) - (ff:def-foreign-type ,symbol ,@rest)))) - -(defswig2 swig-def-synonym-type (synonym of ff-synonym) - `(cl::eval-when (:compile-toplevel :load-toplevel :execute) - (cl::setf (cl::find-class ',synonym) (cl::find-class ',of)) - (ff:def-foreign-type ,ff-synonym (:struct )))) - -(cl::defun package-name-for-namespace (namespace) - (excl::list-to-delimited-string - (cl::cons *swig-module-name* - (cl::mapcar #'(cl::lambda (name) - (cl::string - (cl::funcall *swig-identifier-converter* - name - :type :namespace))) - namespace)) - ".")) - -(cl::defmacro swig-defpackage (namespace) - (cl::let* ((parent-namespaces (cl::maplist #'cl::reverse (cl::cdr (cl::reverse namespace)))) - (parent-strings (cl::mapcar #'package-name-for-namespace - parent-namespaces)) - (string (package-name-for-namespace namespace))) - `(cl::eval-when (:compile-toplevel :load-toplevel :execute) - (cl::defpackage ,string - (:use :swig :ff #+ignore '(:common-lisp :ff :excl) - ,@parent-strings ,*swig-module-name*) - (:import-from :cl :* :nil :t))))) - -(cl::defmacro swig-in-package (namespace) - `(cl::eval-when (:compile-toplevel :load-toplevel :execute) - (cl::in-package ,(package-name-for-namespace namespace)))) - -(defswig2 swig-defvar (name mangled-name &key type (ftype :unsigned-natural)) - (cl::let ((symbol (id-convert-and-export name :type type))) - `(cl::eval-when (:compile-toplevel :load-toplevel :execute) - (ff:def-foreign-variable (,symbol ,mangled-name) :type ,ftype)))) - -) ;; eval-when - -(cl::eval-when (:compile-toplevel :execute) - (cl::flet ((starts-with-p (str prefix) - (cl::and (cl::>= (cl::length str) (cl::length prefix)) - (cl::string= str prefix :end1 (cl::length prefix))))) - (cl::export (cl::loop for sym being each present-symbol of cl::*package* - when (cl::or (starts-with-p (cl::symbol-name sym) (cl::symbol-name :swig-)) - (starts-with-p (cl::symbol-name sym) (cl::symbol-name :identifier-convert-))) - collect sym)))) - -%} - -typedef void *__SWIGACL_FwdReference; - -%{ - -#ifdef __cplusplus -# define EXTERN extern "C" -#else -# define EXTERN extern -#endif - -#define EXPORT EXTERN SWIGEXPORT - -typedef void *__SWIGACL_FwdReference; - -#include -#include -%} diff --git a/Lib/allegrocl/inout_typemaps.i b/Lib/allegrocl/inout_typemaps.i deleted file mode 100644 index d8d61feed..000000000 --- a/Lib/allegrocl/inout_typemaps.i +++ /dev/null @@ -1,111 +0,0 @@ -/* inout_typemaps.i - - Support for INPUT, OUTPUT, and INOUT typemaps. OUTPUT variables are returned - as multiple values. - -*/ - - -/* Note that this macro automatically adds a pointer to the type passed in. - As a result, INOUT typemaps for char are for 'char *'. The definition - of typemaps for 'char' takes advantage of this, believing that it's more - likely to see an INOUT argument for strings, than a single char. */ -%define INOUT_TYPEMAP(type_, OUTresult_, INbind_) -// OUTPUT map. -%typemap(lin,numinputs=0) type_ *OUTPUT, type_ &OUTPUT -%{(cl::let (($out (ff:allocate-fobject '$*in_fftype :c))) - $body - OUTresult_ - (ff:free-fobject $out)) %} - -// INPUT map. -%typemap(in) type_ *INPUT, type_ &INPUT -%{ $1 = &$input; %} - -%typemap(ctype) type_ *INPUT, type_ &INPUT "$*1_ltype"; - - -// INOUT map. -// careful here. the input string is converted to a C string -// with length equal to the input string. This should be large -// enough to contain whatever OUTPUT value will be stored in it. -%typemap(lin,numinputs=1) type_ *INOUT, type_ &INOUT -%{(cl::let (($out (ff:allocate-fobject '$*in_fftype :c))) - INbind_ - $body - OUTresult_ - (ff:free-fobject $out)) %} - -%enddef - -// $in, $out, $lclass, -// $in_fftype, $*in_fftype - -INOUT_TYPEMAP(int, - (cl::push (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) ACL_result), - (cl::setf (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) $in)); -INOUT_TYPEMAP(short, - (cl::push (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) ACL_result), - (cl::setf (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) $in)); -INOUT_TYPEMAP(long, - (cl::push (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) ACL_result), - (cl::setf (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) $in)); -INOUT_TYPEMAP(unsigned int, - (cl::push (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) ACL_result), - (cl::setf (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) $in)); -INOUT_TYPEMAP(unsigned short, - (cl::push (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) ACL_result), - (cl::setf (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) $in)); -INOUT_TYPEMAP(unsigned long, - (cl::push (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) ACL_result), - (cl::setf (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) $in)); -// char * mapping for passing strings. didn't quite work -// INOUT_TYPEMAP(char, -// (cl::push (excl:native-to-string $out) ACL_result), -// (cl::setf (ff:fslot-value-typed (cl::quote $in_fftype) :c $out) -// (excl:string-to-native $in))) -INOUT_TYPEMAP(float, - (cl::push (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) ACL_result), - (cl::setf (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) $in)); -INOUT_TYPEMAP(double, - (cl::push (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) ACL_result), - (cl::setf (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) $in)); -INOUT_TYPEMAP(bool, - (cl::push (not (zerop (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out))) - ACL_result), - (cl::setf (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) (if $in 1 0))); - -%typemap(lisptype) bool *INPUT, bool &INPUT "boolean"; - -// long long support not yet complete -// INOUT_TYPEMAP(long long); -// INOUT_TYPEMAP(unsigned long long); - -// char *OUTPUT map. -// for this to work, swig needs to know how large an array to allocate. -// you can fake this by -// %typemap(ffitype) char *myarg "(:array :char 30)"; -// %apply char *OUTPUT { char *myarg }; -%typemap(lin,numinputs=0) char *OUTPUT, char &OUTPUT -%{(cl::let (($out (ff:allocate-fobject '$*in_fftype :c))) - $body - (cl::push (excl:native-to-string $out) ACL_result) - (ff:free-fobject $out)) %} - -// char *INPUT map. -%typemap(in) char *INPUT, char &INPUT -%{ $1 = &$input; %} -%typemap(ctype) char *INPUT, char &INPUT "$*1_ltype"; - -// char *INOUT map. -%typemap(lin,numinputs=1) char *INOUT, char &INOUT -%{(cl::let (($out (excl:string-to-native $in))) - $body - (cl::push (excl:native-to-string $out) ACL_result) - (ff:free-fobject $out)) %} - -// uncomment this if you want INOUT mappings for chars instead of strings. -// INOUT_TYPEMAP(char, -// (cl::push (code-char (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out)) -// ACL_result), -// (cl::setf (ff:fslot-value-typed (cl::quote $*in_fftype) :c $out) $in)); diff --git a/Lib/allegrocl/longlongs.i b/Lib/allegrocl/longlongs.i deleted file mode 100644 index a15adcdda..000000000 --- a/Lib/allegrocl/longlongs.i +++ /dev/null @@ -1,49 +0,0 @@ -/* ----------------------------------------------------------------------------- - * longlongs.i - * - * Typemap addition for support of 'long long' type and 'unsigned long long - * Makes use of swig-def-foreign-class, so this header should be loaded - * after allegrocl.swg and after any custom user identifier-conversion - * functions have been defined. - * ----------------------------------------------------------------------------- */ - -#ifdef Acl64Bit -%typemap(ctype) long long, unsigned long long "$1_ltype"; -%typemap(out) long long, unsigned long long "$result = $1;"; - -%typemap(ffitype) long long ":nat"; -%typemap(ffitype) unsigned long long ":unsigned-nat"; - -%typemap(lout) long long, unsigned long long " #+64bit (cl::setq ACL_ffresult $body)"; - -#else -%typemap(out) long long, unsigned long long "$result = &$1;"; -%typemap(ffitype) long long "(:struct (l1 :long) (l2 :long))"; - -%typemap(ffitype) unsigned long long "(:struct (l1 :unsigned-long) (l2 :unsigned-long))"; - -%typemap(lout) long long -" (cl::setq ACL_ffresult (make-instance '#.(swig-insert-id \"longlong\" () :type :class) - :foreign-address $body))"; - -%typemap(lout) unsigned long long -" (cl:setq ACL_ffresult (make-instance '#.(swig-insert-id \"ulonglong\" () :type :class) - :foreign-address $body))"; - -#endif - -%typemap(in) long long, unsigned long long "$1 = $input;"; - - -%insert("lisphead") %{ - -#-64bit -(swig-def-foreign-class "longlong" - (ff:foreign-pointer) - (:struct (l1 :long) (l2 :long))) - -#-64bit -(swig-def-foreign-class "ulonglong" - (ff:foreign-pointer) - (:struct (l1 :unsigned-long) (l2 :unsigned-long))) -%} diff --git a/Lib/allegrocl/std_list.i b/Lib/allegrocl/std_list.i deleted file mode 100644 index a3660c9f7..000000000 --- a/Lib/allegrocl/std_list.i +++ /dev/null @@ -1,230 +0,0 @@ -/* ----------------------------------------------------------------------------- - * std_list.i - * - * SWIG typemaps for std::list types - * - * To use, add: - * - * %include "std_list.i" - * - * to your interface file. You will also need to include a template directive - * for each instance of the list container you want to use in your application. - * e.g. - * - * %template (intlist) std::list; - * %template (floatlist) std::list; - * ----------------------------------------------------------------------------- */ - -%module std_list -%warnfilter(468) std::list; - -%{ -#include -#include -%} - - -namespace std{ - template class list - { - 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; - typedef T &iterator; - typedef const T& const_iterator; - - list(); - list(unsigned int size, const T& value = T()); - list(const list& other); - - void assign(unsigned int n, const T& value); - void swap(list &x); - - const_reference front(); - const_reference back(); - const_iterator begin(); - const_iterator end(); - - void resize(unsigned int n, T c = T()); - bool empty() const; - - void push_front(const T& INPUT); - void push_back(const T& INPUT); - - void pop_front(); - void pop_back(); - void clear(); - unsigned int size() const; - unsigned int max_size() const; - void resize(unsigned int n, const T& INPUT); - - void remove(const T& INPUT); - void unique(); - void reverse(); - void sort(); - - %extend - { - %typemap(lout) T &__getitem__ "(cl::setq ACL_ffresult (ff:fslot-value-typed '$*out_fftype :c $body))"; - %typemap(lout) T *__getitem__ "(cl::setq ACL_ffresult (make-instance '$lclass :foreign-address $body))"; - - const_reference __getitem__(int i) throw (std::out_of_range) - { - std::list::iterator first = self->begin(); - int size = int(self->size()); - if (i<0) i += size; - if (i>=0 && i::iterator first = self->begin(); - int size = int(self->size()); - if (i<0) i += size; - if (i>=0 && i::iterator first = self->begin(); - int size = int(self->size()); - if (i<0) i += size; - if (i>=0 && ierase(first); - } - else throw std::out_of_range("list index out of range"); - } - std::list __getslice__(int i,int j) - { - std::list::iterator first = self->begin(); - std::list::iterator end = self->end(); - - int size = int(self->size()); - if (i<0) i += size; - if (j<0) j += size; - if (i<0) i = 0; - if (j>size) j = size; - if (i>=j) i=j; - if (i>=0 && i=0) - { - for (int k=0;k tmp(j-i); - if (j>i) std::copy(first,end,tmp.begin()); - return tmp; - } - else throw std::out_of_range("list index out of range"); - } - void __delslice__(int i,int j) - { - std::list::iterator first = self->begin(); - std::list::iterator end = self->end(); - - int size = int(self->size()); - if (i<0) i += size; - if (j<0) j += size; - if (i<0) i = 0; - if (j>size) j = size; - - for (int k=0;kerase(first,end); - } - void __setslice__(int i,int j, const std::list& v) - { - std::list::iterator first = self->begin(); - std::list::iterator end = self->end(); - - int size = int(self->size()); - if (i<0) i += size; - if (j<0) j += size; - if (i<0) i = 0; - if (j>size) j = size; - - for (int k=0;kerase(first,end); - if (i+1 <= int(self->size())) - { - first = self->begin(); - for (int k=0;kinsert(first,v.begin(),v.end()); - } - else self->insert(self->end(),v.begin(),v.end()); - } - } - unsigned int __len__() - { - return self->size(); - } - bool __nonzero__() - { - return !(self->empty()); - } - void append(const T& INPUT) - { - self->push_back(INPUT); - } - void pop() - { - self->pop_back(); - } - } - }; -} - - - - - - diff --git a/Lib/allegrocl/std_string.i b/Lib/allegrocl/std_string.i deleted file mode 100644 index cbcd250a9..000000000 --- a/Lib/allegrocl/std_string.i +++ /dev/null @@ -1,209 +0,0 @@ -/* ----------------------------------------------------------------------------- - * std_string.i - * - * SWIG typemaps for std::string - * ----------------------------------------------------------------------------- */ - -// ------------------------------------------------------------------------ -// std::string is typemapped by value -// This can prevent exporting methods which return a string -// in order for the user to modify it. -// However, I think I'll wait until someone asks for it... -// ------------------------------------------------------------------------ - -// %include -%warnfilter(404) std::string; -%warnfilter(404) std::wstring; - -%{ -#include -%} - -// %include - -// %naturalvar std::string; -// %naturalvar std::wstring; - -namespace std { - typedef unsigned long size_t; - typedef signed long ptrdiff_t; - - template class basic_string { - public: - typedef charT *pointer; - typedef charT &reference; - typedef const charT &const_reference; - typedef size_t size_type; - typedef ptrdiff_t difference_type; - basic_string(); - basic_string( charT *str ); - size_type size(); - charT operator []( int pos ) const; - charT *c_str() const; - basic_string &operator = ( const basic_string &ws ); - basic_string &operator = ( const charT *str ); - basic_string &append( const basic_string &other ); - basic_string &append( const charT *str ); - void push_back( charT c ); - void clear(); - void reserve( size_type t ); - void resize( size_type n, charT c = charT() ); - int compare( const basic_string &other ) const; - int compare( const charT *str ) const; - basic_string &insert( size_type pos, - const basic_string &str ); - size_type find( const basic_string &other, int pos = 0 ) const; - size_type find( charT c, int pos = 0 ) const; - %extend { - bool operator == ( const basic_string &other ) const { - return self->compare( other ) == 0; - } - bool operator != ( const basic_string &other ) const { - return self->compare( other ) != 0; - } - bool operator < ( const basic_string &other ) const { - return self->compare( other ) == -1; - } - bool operator > ( const basic_string &other ) const { - return self->compare( other ) == 1; - } - bool operator <= ( const basic_string &other ) const { - return self->compare( other ) != 1; - } - bool operator >= ( const basic_string &other ) const { - return self->compare( other ) != -1; - } - - } - }; - - %template(string) basic_string; - %template(wstring) basic_string; - - %apply char * { string }; - %apply wchar_t * { wstring }; - - typedef basic_string string; - typedef basic_string wstring; - - // automatically convert constant std::strings to cl:strings - %typemap(ctype) string "char *"; - %typemap(in) string "$1.assign($input);"; - %typemap(out) string "$result = (char *)(&$1)->c_str();"; - %typemap(lisptype) string "cl:string"; - %typemap(lout) string "(cl::setq ACL_ffresult $body)"; - - %typemap(ctype) const string *"char *"; - %typemap(in) const string * "$1.assign($input);"; - %typemap(out) const string * "$result = (char *)($1)->c_str();"; - %typemap(lisptype) const string * "cl:string"; - %typemap(lout) const string * "(cl::setq ACL_ffresult $body)"; - - %typemap(ctype) wstring "wchar_t *"; - %typemap(in) wstring "$1.assign($input);"; - %typemap(out) wstring "$result = (wchar_t *)(&$1)->c_str();"; - %typemap(lisptype) wstring "cl:string"; - %typemap(lout) wstring "(cl::setq ACL_ffresult (excl:native-to-string $body -:external-format #+little-endian :fat-le #-little-endian :fat))"; - - %typemap(ctype) const wstring *"char *"; - %typemap(in) const wstring * "$1.assign($input);"; - %typemap(out) const wstring * "$result = (char *)($1)->c_str();"; - %typemap(lisptype) const wstring * "cl:string"; - %typemap(lout) const wstring * "(cl::setq ACL_ffresult $body)"; - - /* Overloading check */ -// %typemap(in) string { -// if (caml_ptr_check($input)) -// $1.assign((char *)caml_ptr_val($input,0), -// caml_string_len($input)); -// else -// SWIG_exception(SWIG_TypeError, "string expected"); -// } - -// %typemap(in) const string & ($*1_ltype temp) { -// if (caml_ptr_check($input)) { -// temp.assign((char *)caml_ptr_val($input,0), -// caml_string_len($input)); -// $1 = &temp; -// } else { -// SWIG_exception(SWIG_TypeError, "string expected"); -// } -// } - -// %typemap(in) string & ($*1_ltype temp) { -// if (caml_ptr_check($input)) { -// temp.assign((char *)caml_ptr_val($input,0), -// caml_string_len($input)); -// $1 = &temp; -// } else { -// SWIG_exception(SWIG_TypeError, "string expected"); -// } -// } - -// %typemap(in) string * ($*1_ltype *temp) { -// if (caml_ptr_check($input)) { -// temp = new $*1_ltype((char *)caml_ptr_val($input,0), -// caml_string_len($input)); -// $1 = temp; -// } else { -// SWIG_exception(SWIG_TypeError, "string expected"); -// } -// } - -// %typemap(free) string * ($*1_ltype *temp) { -// delete temp; -// } - -// %typemap(argout) string & { -// caml_list_append(swig_result,caml_val_string_len((*$1).c_str(), -// (*$1).size())); -// } - -// %typemap(directorout) string { -// $result.assign((char *)caml_ptr_val($input,0), -// caml_string_len($input)); -// } - -// %typemap(out) string { -// $result = caml_val_string_len($1.c_str(),$1.size()); -// } - -// %typemap(out) string * { -// $result = caml_val_string_len((*$1).c_str(),(*$1).size()); -// } -} - -// #ifdef ENABLE_CHARPTR_ARRAY -// char **c_charptr_array( const std::vector &str_v ); - -// %{ -// SWIGEXT char **c_charptr_array( const std::vector &str_v ) { -// char **out = new char *[str_v.size() + 1]; -// out[str_v.size()] = 0; -// for( int i = 0; i < str_v.size(); i++ ) { -// out[i] = (char *)str_v[i].c_str(); -// } -// return out; -// } -// %} -// #endif - -// #ifdef ENABLE_STRING_VECTOR -// %template (StringVector) std::vector; - -// %insert(ml) %{ -// (* Some STL convenience items *) - -// let string_array_to_vector sa = -// let nv = _new_StringVector C_void in -// array_to_vector nv (fun x -> C_string x) sa ; nv - -// let c_string_array ar = -// _c_charptr_array (string_array_to_vector ar) -// %} - -// %insert(mli) %{ -// val c_string_array: string array -> c_obj -// %} -// #endif diff --git a/Lib/allegrocl/typemaps.i b/Lib/allegrocl/typemaps.i deleted file mode 100644 index 293d1cd34..000000000 --- a/Lib/allegrocl/typemaps.i +++ /dev/null @@ -1,4 +0,0 @@ -/* Unused for Allegro CL module */ - -%include "inout_typemaps.i" -%include "longlongs.i" -- cgit v1.2.1 From 84ff84f4fbee16e92f5fa98bfbe91090eca4a23f Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Tue, 11 May 2021 14:50:31 +0100 Subject: [Python] Fix memory leaks. --- Lib/python/pyerrors.swg | 8 +++-- Lib/python/pyrun.swg | 85 +++++++++++++++++++++++++++++++++---------------- 2 files changed, 64 insertions(+), 29 deletions(-) (limited to 'Lib') diff --git a/Lib/python/pyerrors.swg b/Lib/python/pyerrors.swg index dcd99c939..2628de8e6 100644 --- a/Lib/python/pyerrors.swg +++ b/Lib/python/pyerrors.swg @@ -95,8 +95,12 @@ SWIG_Python_RaiseOrModifyTypeError(const char *message) #else newvalue = PyString_FromFormat("%s\nAdditional information:\n%s", PyString_AsString(value), message); #endif - Py_XDECREF(value); - PyErr_Restore(type, newvalue, traceback); + if (newvalue) { + Py_XDECREF(value); + PyErr_Restore(type, newvalue, traceback); + } else { + PyErr_Restore(type, value, traceback); + } } else { /* Raise TypeError using given message */ PyErr_SetString(PyExc_TypeError, message); diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 63ff82ff8..f32afb07e 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -127,7 +127,11 @@ SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) { if (!PyList_Check(result)) { PyObject *o2 = result; result = PyList_New(1); - PyList_SetItem(result, 0, o2); + if (result) { + PyList_SET_ITEM(result, 0, o2); + } else { + return o2; + } } PyList_Append(result,obj); Py_DECREF(obj); @@ -279,18 +283,26 @@ SwigPyClientData_New(PyObject* obj) /* the newraw method and newargs arguments used to create a new raw instance */ if (PyClass_Check(obj)) { data->newraw = 0; - data->newargs = obj; Py_INCREF(obj); + data->newargs = obj; } else { data->newraw = PyObject_GetAttrString(data->klass, "__new__"); if (data->newraw) { - Py_INCREF(data->newraw); - data->newargs = PyTuple_New(1); - PyTuple_SetItem(data->newargs, 0, obj); + data->newargs = PyTuple_New(1); + if (data->newargs) { + Py_INCREF(obj); + PyTuple_SET_ITEM(data->newargs, 0, obj); + } else { + Py_DECREF(data->newraw); + Py_DECREF(data->klass); + free(data); + PyErr_NoMemory(); + return 0; + } } else { - data->newargs = obj; + Py_INCREF(obj); + data->newargs = obj; } - Py_INCREF(data->newargs); } /* the destroy method, aka as the C++ delete method */ data->destroy = PyObject_GetAttrString(data->klass, "__swig_destroy__"); @@ -299,10 +311,7 @@ SwigPyClientData_New(PyObject* obj) data->destroy = 0; } if (data->destroy) { - int flags; - Py_INCREF(data->destroy); - flags = PyCFunction_GET_FLAGS(data->destroy); - data->delargs = !(flags & (METH_O)); + data->delargs = !(PyCFunction_GET_FLAGS(data->destroy) & METH_O); } else { data->delargs = 0; } @@ -313,10 +322,13 @@ SwigPyClientData_New(PyObject* obj) } SWIGRUNTIME void -SwigPyClientData_Del(SwigPyClientData *data) { +SwigPyClientData_Del(SwigPyClientData *data) +{ + Py_XDECREF(data->klass); Py_XDECREF(data->newraw); Py_XDECREF(data->newargs); Py_XDECREF(data->destroy); + free(data); } /* =============== SwigPyObject =====================*/ @@ -343,6 +355,9 @@ SwigPyObject_get___dict__(PyObject *v, PyObject *SWIGUNUSEDPARM(args)) if (!sobj->dict) sobj->dict = PyDict_New(); + if (!sobj->dict) + return PyErr_NoMemory(); + Py_INCREF(sobj->dict); return sobj->dict; } @@ -361,18 +376,21 @@ SwigPyObject_format(const char* fmt, SwigPyObject *v) PyObject *res = NULL; PyObject *args = PyTuple_New(1); if (args) { - if (PyTuple_SetItem(args, 0, SwigPyObject_long(v)) == 0) { - PyObject *ofmt = SWIG_Python_str_FromChar(fmt); + PyObject *val = SwigPyObject_long(v); + if (val) { + PyObject *ofmt; + PyTuple_SET_ITEM(args, 0, val); + ofmt = SWIG_Python_str_FromChar(fmt); if (ofmt) { #if PY_VERSION_HEX >= 0x03000000 - res = PyUnicode_Format(ofmt,args); + res = PyUnicode_Format(ofmt,args); #else - res = PyString_Format(ofmt,args); + res = PyString_Format(ofmt,args); #endif - Py_DECREF(ofmt); + Py_DECREF(ofmt); } - Py_DECREF(args); } + Py_DECREF(args); } return res; } @@ -523,6 +541,9 @@ SwigPyObject_dealloc(PyObject *v) #endif } Py_XDECREF(next); +#ifdef SWIGPYTHON_BUILTIN + Py_XDECREF(sobj->dict); +#endif PyObject_DEL(v); } @@ -582,6 +603,7 @@ SwigPyObject_own(PyObject *v, PyObject *args) } else { SwigPyObject_disown(v,args); } + Py_DECREF(Py_None); } return obj; } @@ -740,6 +762,9 @@ SwigPyObject_New(void *ptr, swig_type_info *ty, int own) sobj->ty = ty; sobj->own = own; sobj->next = 0; +#ifdef SWIGPYTHON_BUILTIN + sobj->dict = 0; +#endif } return (PyObject *)sobj; } @@ -1310,7 +1335,9 @@ SWIG_Python_NewPointerObj(PyObject *self, void *ptr, swig_type_info *type, int f } else { newobj = PyObject_New(SwigPyObject, clientdata->pytype); #ifdef SWIGPYTHON_BUILTIN - newobj->dict = 0; + if (newobj) { + newobj->dict = 0; + } #endif } if (newobj) { @@ -1349,6 +1376,13 @@ SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { void *SWIG_ReturnGlobalTypeList(void *); #endif +/* The python cached type query */ +SWIGRUNTIME PyObject * +SWIG_Python_TypeCache(void) { + static PyObject *SWIG_STATIC_POINTER(cache) = PyDict_New(); + return cache; +} + SWIGRUNTIME swig_module_info * SWIG_Python_GetModule(void *SWIGUNUSEDPARM(clientdata)) { static void *type_pointer = (void *)0; @@ -1377,11 +1411,13 @@ SWIG_Python_DestroyModule(PyObject *obj) swig_type_info *ty = types[i]; if (ty->owndata) { SwigPyClientData *data = (SwigPyClientData *) ty->clientdata; + ty->clientdata = 0; if (data) SwigPyClientData_Del(data); } } Py_DECREF(SWIG_This()); Swig_This_global = NULL; + Py_DECREF(SWIG_Python_TypeCache()); } SWIGRUNTIME void @@ -1395,19 +1431,14 @@ SWIG_Python_SetModule(swig_module_info *swig_module) { #endif PyObject *pointer = PyCapsule_New((void *) swig_module, SWIGPY_CAPSULE_NAME, SWIG_Python_DestroyModule); if (pointer && module) { - PyModule_AddObject(module, "type_pointer_capsule" SWIG_TYPE_TABLE_NAME, pointer); + if (PyModule_AddObject(module, "type_pointer_capsule" SWIG_TYPE_TABLE_NAME, pointer) < 0) { + Py_DECREF(pointer); + } } else { Py_XDECREF(pointer); } } -/* The python cached type query */ -SWIGRUNTIME PyObject * -SWIG_Python_TypeCache(void) { - static PyObject *SWIG_STATIC_POINTER(cache) = PyDict_New(); - return cache; -} - SWIGRUNTIME swig_type_info * SWIG_Python_TypeQuery(const char *type) { -- cgit v1.2.1 From 5f38f9cc78b44cbc3266011490613c8134cbd3a3 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 13 May 2021 10:54:04 +1200 Subject: [Chicken] Remove code for Chicken We dropped support for it in SWIG 4.0.0 and nobody has stepped forward to revive it in over 2 years. See #2009. --- Lib/chicken/chicken.swg | 809 ------------------------------- Lib/chicken/chickenkw.swg | 31 -- Lib/chicken/chickenrun.swg | 375 -------------- Lib/chicken/extra-install.list | 3 - Lib/chicken/multi-generic.scm | 152 ------ Lib/chicken/std_string.i | 96 ---- Lib/chicken/swigclosprefix.scm | 31 -- Lib/chicken/tinyclos-multi-generic.patch | 150 ------ Lib/chicken/typemaps.i | 314 ------------ 9 files changed, 1961 deletions(-) delete mode 100644 Lib/chicken/chicken.swg delete mode 100644 Lib/chicken/chickenkw.swg delete mode 100644 Lib/chicken/chickenrun.swg delete mode 100644 Lib/chicken/extra-install.list delete mode 100644 Lib/chicken/multi-generic.scm delete mode 100644 Lib/chicken/std_string.i delete mode 100644 Lib/chicken/swigclosprefix.scm delete mode 100644 Lib/chicken/tinyclos-multi-generic.patch delete mode 100644 Lib/chicken/typemaps.i (limited to 'Lib') diff --git a/Lib/chicken/chicken.swg b/Lib/chicken/chicken.swg deleted file mode 100644 index f42fd27b9..000000000 --- a/Lib/chicken/chicken.swg +++ /dev/null @@ -1,809 +0,0 @@ -/* ----------------------------------------------------------------------------- - * chicken.swg - * - * CHICKEN configuration module. - * ----------------------------------------------------------------------------- */ - -/* chicken.h has to appear first. */ - -%insert(runtime) %{ -#include -#include -%} - -%insert(runtime) "swigrun.swg" // Common C API type-checking code -%insert(runtime) "swigerrors.swg" // SWIG errors -%insert(runtime) "chickenrun.swg" // CHICKEN run-time code - -/* ----------------------------------------------------------------------------- - * standard typemaps - * ----------------------------------------------------------------------------- */ - -/* - CHICKEN: C - ---------- - - fixnum: int, short, unsigned int, unsigned short, unsigned char, - signed char - - char: char - - bool: bool - - flonum: float, double, long, long long, unsigned long, unsigned long - long - */ - -/* --- Primitive types --- */ - -%define SIMPLE_TYPEMAP(type_, from_scheme, to_scheme, checker, convtype, storage_) - -%typemap(in) type_ -%{ if (!checker ($input)) { - swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument #$argnum is not of type 'type_'"); - } - $1 = ($1_ltype) from_scheme ($input); %} - -/* Const primitive references. Passed by value */ - -%typemap(in) const type_ & ($*1_ltype temp) -%{ if (!checker ($input)) { - swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument #$argnum is not of type 'type_'"); - } - temp = ($*1_ltype) from_scheme ($input); - $1 = &temp; %} - -/* --- Variable input --- */ -%typemap(varin) type_ -%{ if (!checker ($input)) { - swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Cannot use '$1_ltype' for variable '$name' of type 'type_'"); - } - $1 = ($1_ltype) from_scheme ($input); %} - -#if "storage_" == "0" - -%typemap(out) type_ -%{ - $result = to_scheme (convtype ($1)); -%} - -/* References to primitive types. Return by value */ - -%typemap(out) const type_ & -%{ - $result = to_scheme (convtype (*$1)); -%} - -/* --- Variable output --- */ -%typemap(varout) type_ -%{ - $result = to_scheme (convtype ($varname)); -%} - -%typemap(throws) type_ -%{ - SWIG_Chicken_ThrowException(to_scheme ( convtype ($1))); -%} - -#else - -%typemap(out) type_ -%{ - { - C_word *space = C_alloc(storage_); - $result = to_scheme (&space, convtype ($1)); - } -%} - -/* References to primitive types. Return by value */ - -%typemap(out) const type_ & -%{ - { - C_word *space = C_alloc(storage_); - $result = to_scheme (&space, convtype (*$1)); - } -%} - -/* --- Variable output --- */ -%typemap(varout) type_ -%{ - { - C_word *space = C_alloc(storage_); - $result = to_scheme (&space, convtype ($varname)); - } -%} - -%typemap(throws) type_ -%{ - { - C_word *space = C_alloc(storage_); - SWIG_Chicken_ThrowException(to_scheme (&space, convtype ($1))); - } -%} - -#endif - -/* --- Constants --- */ - -%typemap(constcode) type_ -"static const $1_type $result = $value;" - -%enddef - -SIMPLE_TYPEMAP(int, C_num_to_int, C_fix, C_swig_is_number, (int), 0); -//SIMPLE_TYPEMAP(enum SWIGTYPE, C_unfix, C_fix, C_swig_is_fixnum, (int), 0); -SIMPLE_TYPEMAP(short, C_num_to_int, C_fix, C_swig_is_number, (int), 0); -SIMPLE_TYPEMAP(long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM); -SIMPLE_TYPEMAP(long long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM); -SIMPLE_TYPEMAP(unsigned int, C_num_to_unsigned_int, C_unsigned_int_to_num, C_swig_is_number, (unsigned int), C_SIZEOF_FLONUM); -SIMPLE_TYPEMAP(unsigned short, C_num_to_unsigned_int, C_fix, C_swig_is_number, (unsigned int), 0); -SIMPLE_TYPEMAP(unsigned long, C_num_to_unsigned_long, C_unsigned_long_to_num, C_swig_is_long, (unsigned long), C_SIZEOF_FLONUM); -SIMPLE_TYPEMAP(unsigned long long, C_num_to_unsigned_long, C_unsigned_long_to_num, C_swig_is_long, (unsigned long), C_SIZEOF_FLONUM); -SIMPLE_TYPEMAP(unsigned char, C_character_code, C_make_character, C_swig_is_char, (unsigned int), 0); -SIMPLE_TYPEMAP(signed char, C_character_code, C_make_character, C_swig_is_char, (int), 0); -SIMPLE_TYPEMAP(char, C_character_code, C_make_character, C_swig_is_char, (char), 0); -SIMPLE_TYPEMAP(bool, C_truep, C_mk_bool, C_swig_is_bool, (bool), 0); -SIMPLE_TYPEMAP(float, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEOF_FLONUM); -SIMPLE_TYPEMAP(double, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEOF_FLONUM); - -/* enum SWIGTYPE */ -%apply int { enum SWIGTYPE }; -%apply const int& { const enum SWIGTYPE& }; -%apply const int& { const enum SWIGTYPE&& }; - -%typemap(varin) enum SWIGTYPE -{ - if (!C_swig_is_fixnum($input) && sizeof(int) != sizeof($1)) { - swig_barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, "enum variable '$name' can not be set"); - } - *((int *)(void *)&$1) = C_unfix($input); -} - - -/* --- Input arguments --- */ - -/* Strings */ - -%typemap(in) char * -{ if ($input == C_SCHEME_FALSE) { - $1 = NULL; - } - else { - if (!C_swig_is_string ($input)) { - swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument #$argnum is not of type 'char *'"); - } - $1 = ($ltype) SWIG_MakeString ($input); - } -} - -%typemap(freearg) char * "if ($1 != NULL) { free ($1); }" - -/* Pointers, references, and arrays */ -%typemap(in,closcode="(slot-ref $input 'swig-this)") SWIGTYPE *, SWIGTYPE [], SWIGTYPE &, SWIGTYPE && { - $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, $disown); -} - -%typemap(in,closcode="(slot-ref $input 'swig-this)") SWIGTYPE *DISOWN { - $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, SWIG_POINTER_DISOWN); -} - -/* Void pointer. Accepts any kind of pointer */ -%typemap(in) void * { - $1 = ($1_ltype)SWIG_MustGetPtr($input, NULL, $argnum, 0); -} - -%typemap(varin,closcode="(slot-ref $input 'swig-this)") SWIGTYPE * { - $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, 1, SWIG_POINTER_DISOWN); -} - -%typemap(varin,closcode="(slot-ref $input 'swig-this)") SWIGTYPE & { - $1 = *(($1_ltype)SWIG_MustGetPtr($input, $descriptor, 1, 0)); -} - -%typemap(varin,closcode="(slot-ref $input 'swig-this)") SWIGTYPE && { - $1 = *(($1_ltype)SWIG_MustGetPtr($input, $descriptor, 1, 0)); -} - -%typemap(varin) SWIGTYPE [] { - SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, "Type error"); -} - -%typemap(varin) SWIGTYPE [ANY] { - void *temp; - int ii; - $1_basetype *b = 0; - temp = SWIG_MustGetPtr($input, $1_descriptor, 1, 0); - b = ($1_basetype *) $1; - for (ii = 0; ii < $1_size; ii++) b[ii] = *(($1_basetype *) temp + ii); -} - -%typemap(varin) void * { - $1 = SWIG_MustGetPtr($input, NULL, 1, 0); -} - -%typemap(out) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] { - C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER); - $result = SWIG_NewPointerObj($1, $descriptor, $owner); -} - -%typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC { - C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER); - swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor,(void **) &$1); - $result = SWIG_NewPointerObj($1, ty, $owner); -} - -%typemap(varout) SWIGTYPE *, SWIGTYPE [] { - C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER); - $result = SWIG_NewPointerObj($varname, $descriptor, 0); -} - -%typemap(varout) SWIGTYPE & { - C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER); - $result = SWIG_NewPointerObj((void *) &$varname, $1_descriptor, 0); -} - -%typemap(varout) SWIGTYPE && { - C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER); - $result = SWIG_NewPointerObj((void *) &$varname, $1_descriptor, 0); -} - -/* special typemaps for class pointers */ -%typemap(in) SWIGTYPE (CLASS::*) { - char err_msg[256]; - - if (C_swig_is_pair($input)) { - /* try and convert pointer object */ - void *result; - if (!SWIG_ConvertPtr(C_block_item($input,1), &result, $descriptor, 0)) { - C_word ptr = C_block_item($input,0); - if (C_swig_is_string(ptr)) { - SWIG_UnpackData(C_c_string(ptr), (void *) &$1, sizeof($1)); - } else { - snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", $argnum, ($descriptor->str ? $descriptor->str : $descriptor->name)); - SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg); - } - } else { - snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", $argnum, ($descriptor->str ? $descriptor->str : $descriptor->name)); - SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg); - } - } else { - snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", $argnum, ($descriptor->str ? $descriptor->str : $descriptor->name)); - SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg); - } -} - -%typemap(out) SWIGTYPE (CLASS::*) { - size_t ptr_size = sizeof($type); - C_word *known_space = C_alloc(C_SIZEOF_PAIR + C_SIZEOF_STRING(2*ptr_size) + C_SIZEOF_SWIG_POINTER); - char *temp = (char *)malloc(2*ptr_size); - C_word ptr = SWIG_NewPointerObj((void *) known_space, $descriptor, 0); - - SWIG_PackData(temp, (void *) &$1, ptr_size); - $result = C_pair(&known_space, C_string(&known_space, 2*ptr_size, temp), ptr); - free(temp); -} - -%typemap(varin) SWIGTYPE (CLASS::*) { - char err_msg[256]; - - if (C_swig_is_pair($input)) { - /* try and convert pointer object */ - void *result; - if (!SWIG_ConvertPtr(C_block_item($input,1), &result, $descriptor, 0)) { - C_word ptr = C_block_item($input,0); - if (C_swig_is_string(ptr)) { - SWIG_UnpackData(C_c_string(ptr), (void *) &$1, sizeof($1)); - } else { - snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", 1, ($descriptor->str ? $descriptor->str : $descriptor->name)); - SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg); - } - } else { - snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", 1, ($descriptor->str ? $descriptor->str : $descriptor->name)); - SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg); - } - } else { - snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", 1, ($descriptor->str ? $descriptor->str : $descriptor->name)); - SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg); - } -} - -%typemap(varout) SWIGTYPE (CLASS::*) { - size_t ptr_size = sizeof($type); - C_word *known_space = C_alloc(C_SIZEOF_PAIR + C_SIZEOF_STRING(2*ptr_size) + C_SIZEOF_SWIG_POINTER); - char *temp = (char *)malloc(2*ptr_size); - C_word ptr = SWIG_NewPointerObj((void *) known_space, $descriptor, 0); - - SWIG_PackData(temp, (void *) &$varname, ptr_size); - $result = C_pair(&known_space, C_string(&known_space, 2*ptr_size, temp), ptr); - free(temp); -} - - - -/* Pass-by-value */ - -%typemap(in,closcode="(slot-ref $input 'swig-this)") SWIGTYPE($&1_ltype argp) { - argp = ($&1_ltype)SWIG_MustGetPtr($input, $&1_descriptor, $argnum, 0); - $1 = *argp; -} - -%typemap(varin,closcode="(slot-ref $input 'swig-this)") SWIGTYPE { - $&1_ltype argp; - argp = ($&1_ltype)SWIG_MustGetPtr($input, $&1_descriptor, 1, 0); - $1 = *argp; -} - -%typemap(out) SWIGTYPE -#ifdef __cplusplus -{ - $&1_ltype resultptr; - C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER); - resultptr = new $1_ltype((const $1_ltype &) $1); - $result = SWIG_NewPointerObj(resultptr, $&1_descriptor, 1); -} -#else -{ - $&1_ltype resultptr; - C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER); - resultptr = ($&1_ltype) malloc(sizeof($1_type)); - memmove(resultptr, &$1, sizeof($1_type)); - $result = SWIG_NewPointerObj(resultptr, $&1_descriptor, 1); -} -#endif - -%typemap(varout) SWIGTYPE -#ifdef __cplusplus -{ - $&1_ltype resultptr; - C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER); - resultptr = new $1_ltype((const $1_ltype&) $1); - $result = SWIG_NewPointerObj(resultptr, $&1_descriptor, 0); -} -#else -{ - $&1_ltype resultptr; - C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER); - resultptr = ($&1_ltype) malloc(sizeof($1_type)); - memmove(resultptr, &$1, sizeof($1_type)); - $result = SWIG_NewPointerObj(resultptr, $&1_descriptor, 0); -} -#endif - -/* --- Output values --- */ - -/* Strings */ - -%typemap(out) - char * -{ char *s = (char*) $1; - if ($1 == NULL) { - $result = C_SCHEME_FALSE; - } - else { - int string_len = strlen ((char *) ($1)); - C_word *string_space = C_alloc (C_SIZEOF_STRING (string_len)); - $result = C_string (&string_space, string_len, s); - } -} - -%typemap(varout) - char * -{ char *s = (char*) $varname; - if ($varname == NULL) { - $result = C_SCHEME_FALSE; - } - else { - int string_len = strlen ($varname); - C_word *string_space = C_alloc (C_SIZEOF_STRING (string_len)); - $result = C_string (&string_space, string_len, s); - } -} - -%typemap(throws) char * -{ - if ($1 == NULL) { - SWIG_Chicken_ThrowException(C_SCHEME_FALSE); - } else { - int string_len = strlen($1); - C_word *string_space = C_alloc(C_SIZEOF_STRING(string_len)); - SWIG_Chicken_ThrowException(C_string(&string_space, string_len, (char *) $1)); - } -} - -/* Void */ -%typemap(out) void -%{ -$result = C_SCHEME_UNDEFINED; -%} - -/* Special typemap for character array return values */ - -%typemap(out) - char [ANY], const char [ANY] -%{ if ($1 == NULL) { - $result = C_SCHEME_FALSE; - } - else { - const int string_len = strlen ($1); - C_word *string_space = C_alloc (C_SIZEOF_STRING (string_len)); - $result = C_string (&string_space, string_len, $1); - } %} - -/* Primitive types--return by value */ - -/* --- Variable input --- */ - -/* A string */ -#ifdef __cplusplus -%typemap(varin) char * { - if ($input == C_SCHEME_FALSE) { - $1 = NULL; - } - else if (!C_swig_is_string ($input)) { - swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "C variable '$name ($1_ltype)'"); - } - else { - char *temp = C_c_string ($input); - int len = C_header_size ($input); - if ($1) delete [] $1; - $1 = ($type) new char[len+1]; - strncpy((char*)$1, temp, len); - ((char*)$1) [len] = 0; - } -} -%typemap(varin,warning="451:Setting const char * variable may leak memory") const char * { - if ($input == C_SCHEME_FALSE) { - $1 = NULL; - } - else if (!C_swig_is_string ($input)) { - swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "C variable '$name ($1_ltype)'"); - } - else { - char *temp = C_c_string ($input); - int len = C_header_size ($input); - $1 = ($type) new char[len+1]; - strncpy((char*)$1,temp,len); - ((char*)$1) [len] = 0; - } -} -#else -%typemap(varin) char * { - if ($input == C_SCHEME_FALSE) { - $1 = NULL; - } - else if (!C_swig_is_string ($input)) { - swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "C variable '$name ($1_ltype)'"); - } - else { - char *temp = C_c_string ($input); - int len = C_header_size ($input); - if ($1) free((char*) $1); - $1 = ($type) malloc(len+1); - strncpy((char*)$1,temp,len); - ((char*)$1) [len] = 0; - } -} -%typemap(varin,warning="451:Setting const char * variable may leak memory") const char * { - if ($input == C_SCHEME_FALSE) { - $1 = NULL; - } - else if (!C_swig_is_string ($input)) { - swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "C variable '$name ($1_ltype)'"); - } - else { - char *temp = C_c_string ($input); - int len = C_header_size ($input); - $1 = ($type) malloc(len+1); - strncpy((char*)$1,temp,len); - ((char*)$1) [len] = 0; - } -} -#endif - -%typemap(varin) char [] { - swig_barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, "C/C++ variable '$name' is read-only"); -} - -/* Special case for string array variables */ -%typemap(varin) char [ANY] { - if ($input == C_SCHEME_FALSE) { - memset($1,0,$1_dim0*sizeof(char)); - } - else if (!C_swig_is_string ($input)) { - swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "C variable '$name ($1_ltype)'"); - } - else { - char *temp = C_c_string ($input); - strncpy($1,temp,$1_dim0*sizeof(char)); - } -} - -/* --- Variable output --- */ - -/* Void */ -%typemap(varout) void "$result = C_SCHEME_UNDEFINED;"; - -/* Special typemap for character array return values */ -%typemap(varout) char [ANY], const char [ANY] -%{ if ($varname == NULL) { - $result = C_SCHEME_FALSE; - } - else { - const int string_len = strlen ($varname); - C_word *string_space = C_alloc (C_SIZEOF_STRING (string_len)); - $result = C_string (&string_space, string_len, (char *) $varname); - } -%} - - -/* --- Constants --- */ - -%typemap(constcode) char * -"static const char *$result = $value;" - -%typemap(constcode) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] -"static const void *$result = (void*) $value;" - -/* ------------------------------------------------------------ - * String & length - * ------------------------------------------------------------ */ - -%typemap(in) (char *STRING, int LENGTH), (char *STRING, size_t LENGTH) { - if ($input == C_SCHEME_FALSE) { - swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Cannot use a null/#f string for a char*, int arguments"); - } - else if (C_swig_is_string ($input)) { - $1 = ($1_ltype) C_c_string ($input); - $2 = ($2_ltype) C_header_size ($input); - } - else { - swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument #$argnum is not of type 'string'"); - } -} - -/* ------------------------------------------------------------ - * CHICKEN types - * ------------------------------------------------------------ */ - -%typemap(in) C_word "$1 = $input;"; -%typemap(out) C_word "$result = $1;"; - -/* ------------------------------------------------------------ - * Typechecking rules - * ------------------------------------------------------------ */ - -%typecheck(SWIG_TYPECHECK_INTEGER) - bool, const bool & -{ - $1 = C_swig_is_bool ($input); -} - -%typecheck(SWIG_TYPECHECK_INTEGER) - int, short, - unsigned int, unsigned short, - signed char, unsigned char, - const int &, const short &, - const unsigned int &, const unsigned short &, - enum SWIGTYPE -{ - $1 = C_swig_is_fixnum ($input); -} - -%typecheck(SWIG_TYPECHECK_INTEGER) - long, - unsigned long, - long long, unsigned long long, - const long &, - const unsigned long &, - const long long &, const unsigned long long & -{ - $1 = (C_swig_is_bool ($input) || - C_swig_is_fixnum ($input) || - C_swig_is_flonum ($input)) ? 1 : 0; -} - -%typecheck(SWIG_TYPECHECK_DOUBLE) - float, double, - const float &, const double & -{ - $1 = C_swig_is_flonum ($input); -} - -%typecheck(SWIG_TYPECHECK_CHAR) char { - $1 = C_swig_is_string ($input); -} - -%typecheck(SWIG_TYPECHECK_STRING) char * { - $1 = C_swig_is_string ($input); -} - -%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE [] { - void *ptr; - $1 = !SWIG_ConvertPtr($input, &ptr, $1_descriptor, 0); -} - -%typecheck(SWIG_TYPECHECK_VOIDPTR) void * { - void *ptr; - $1 = !SWIG_ConvertPtr($input, &ptr, 0, 0); -} - -%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE & -{ - void *ptr = 0; - if (SWIG_ConvertPtr($input, &ptr, $descriptor, SWIG_POINTER_NO_NULL)) { - $1 = 0; - } else { - $1 = 1; - } -} - -%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE && -{ - void *ptr = 0; - if (SWIG_ConvertPtr($input, &ptr, $descriptor, SWIG_POINTER_NO_NULL)) { - $1 = 0; - } else { - $1 = 1; - } -} - -%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE -{ - void *ptr = 0; - if (SWIG_ConvertPtr($input, &ptr, $&descriptor, SWIG_POINTER_NO_NULL)) { - $1 = 0; - } else { - $1 = 1; - } -} - - -/* ------------------------------------------------------------ - * Exception handling - * ------------------------------------------------------------ */ - -/* ------------------------------------------------------------ - * --- Exception handling --- - * ------------------------------------------------------------ */ - -%typemap(throws) SWIGTYPE { - $<ype temp = new $ltype($1); - C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER); - C_word ptr = SWIG_NewPointerObj(temp, $&descriptor,1); - SWIG_Chicken_ThrowException(ptr); -} - -%typemap(throws) SWIGTYPE * { - C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER); - C_word ptr = SWIG_NewPointerObj((void *) $1, $descriptor, 0); - SWIG_Chicken_ThrowException(ptr); -} - -%typemap(throws) SWIGTYPE [ANY] { - C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER); - C_word ptr = SWIG_NewPointerObj((void *) $1, $descriptor, 0); - SWIG_Chicken_ThrowException(ptr); -} - -%typemap(throws) SWIGTYPE & { - C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER); - C_word ptr = SWIG_NewPointerObj((void *)&($1),$descriptor,0); - SWIG_Chicken_ThrowException(ptr); -} - -%typemap(throws) SWIGTYPE && { - C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER); - C_word ptr = SWIG_NewPointerObj((void *)&($1),$descriptor,0); - SWIG_Chicken_ThrowException(ptr); -} - -/* ------------------------------------------------------------ - * ANSI C typemaps - * ------------------------------------------------------------ */ - -%apply unsigned long { size_t }; - -/* ------------------------------------------------------------ - * Various - * ------------------------------------------------------------ */ - -/* Array reference typemaps */ -%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } -%apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) } - -/* const pointers */ -%apply SWIGTYPE * { SWIGTYPE *const } -%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) } -%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) } - -/* ------------------------------------------------------------ - * Overloaded operator support - * ------------------------------------------------------------ */ - -#ifdef __cplusplus -%rename(__add__) *::operator+; -%rename(__pos__) *::operator+(); -%rename(__pos__) *::operator+() const; -%rename(__sub__) *::operator-; -%rename(__neg__) *::operator-(); -%rename(__neg__) *::operator-() const; -%rename(__mul__) *::operator*; -%rename(__div__) *::operator/; -%rename(__mod__) *::operator%; -%rename(__lshift__) *::operator<<; -%rename(__rshift__) *::operator>>; -%rename(__and__) *::operator&; -%rename(__or__) *::operator|; -%rename(__xor__) *::operator^; -%rename(__invert__) *::operator~; -%rename(__iadd__) *::operator+=; -%rename(__isub__) *::operator-=; -%rename(__imul__) *::operator*=; -%rename(__idiv__) *::operator/=; -%rename(__imod__) *::operator%=; -%rename(__ilshift__) *::operator<<=; -%rename(__irshift__) *::operator>>=; -%rename(__iand__) *::operator&=; -%rename(__ior__) *::operator|=; -%rename(__ixor__) *::operator^=; -%rename(__lt__) *::operator<; -%rename(__le__) *::operator<=; -%rename(__gt__) *::operator>; -%rename(__ge__) *::operator>=; -%rename(__eq__) *::operator==; -%rename(__ne__) *::operator!=; - -/* Special cases */ -%rename(__call__) *::operator(); - -#endif -/* Warnings for certain CHICKEN keywords */ -%include - -/* TinyCLOS <--> Low-level CHICKEN */ - -%typemap("clos_in") SIMPLE_CLOS_OBJECT * "(slot-ref $input (quote this))" -%typemap("clos_out") SIMPLE_CLOS_OBJECT * "(make $class (quote this) $1)" - -%insert(header) %{ -#ifdef __cplusplus -extern "C" { -#endif -/* Chicken initialization function */ -SWIGEXPORT void SWIG_init(C_word, C_word, C_word) C_noret; -#ifdef __cplusplus -} -#endif -%} - -%insert(closprefix) "swigclosprefix.scm" - -%insert(init) "swiginit.swg" - -%insert(init) %{ -/* CHICKEN initialization function */ -#ifdef __cplusplus -extern "C" { -#endif -SWIGEXPORT void SWIG_init(C_word argc, C_word closure, C_word continuation) { - int i; - C_word sym; - C_word tmp; - C_word *a; - C_word ret; - C_word *return_vec; - - SWIG_InitializeModule(0); - SWIG_PropagateClientData(); - ret = C_SCHEME_TRUE; - -#if $veclength - return_vec = C_alloc(C_SIZEOF_VECTOR($veclength)); - ret = (C_word) return_vec; - *(return_vec++) = C_VECTOR_TYPE | $veclength; -#endif - - a = C_alloc(2*$nummethods$symsize); - -%} diff --git a/Lib/chicken/chickenkw.swg b/Lib/chicken/chickenkw.swg deleted file mode 100644 index d2c26c74c..000000000 --- a/Lib/chicken/chickenkw.swg +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef CHICKEN_CHICKENKW_SWG_ -#define CHICKEN_CHICKENKW_SWG_ - -/* Warnings for certain CHICKEN keywords. From Section 7.1.1 of - Revised^5 Report on the Algorithmic Language Scheme */ -#define CHICKENKW(x) %namewarn("314: '" #x "' is a R^5RS syntatic keyword") #x - -CHICKENKW(else); -CHICKENKW(=>); -CHICKENKW(define); -CHICKENKW(unquote); -CHICKENKW(unquote-splicing); -CHICKENKW(quote); -CHICKENKW(lambda); -CHICKENKW(if); -CHICKENKW(set!); -CHICKENKW(begin); -CHICKENKW(cond); -CHICKENKW(and); -CHICKENKW(or); -CHICKENKW(case); -CHICKENKW(let); -CHICKENKW(let*); -CHICKENKW(letrec); -CHICKENKW(do); -CHICKENKW(delay); -CHICKENKW(quasiquote); - -#undef CHICKENKW - -#endif //CHICKEN_CHICKENKW_SWG_ diff --git a/Lib/chicken/chickenrun.swg b/Lib/chicken/chickenrun.swg deleted file mode 100644 index bb14b4bc9..000000000 --- a/Lib/chicken/chickenrun.swg +++ /dev/null @@ -1,375 +0,0 @@ -/* ----------------------------------------------------------------------------- - * chickenrun.swg - * ----------------------------------------------------------------------------- */ - -#include -#include -#include -#include -#include -#if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__BORLANDC__) || defined(_WATCOM) -# ifndef snprintf -# define snprintf _snprintf -# endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#define SWIG_malloc(size) \ - malloc(size) -#define SWIG_free(mem) \ - free(mem) -#define SWIG_MakeString(c) \ - SWIG_Chicken_MakeString(c) -#define SWIG_ConvertPtr(s, result, type, flags) \ - SWIG_Chicken_ConvertPtr(s, result, type, flags) -#define SWIG_MustGetPtr(s, type, argnum, flags) \ - SWIG_Chicken_MustGetPtr(s, type, argnum, flags) -#define SWIG_NewPointerObj(ptr, type, owner) \ - SWIG_Chicken_NewPointerObj((void*)ptr, type, owner, &known_space) -#define swig_barf SWIG_Chicken_Barf -#define SWIG_ThrowException(val) SWIG_Chicken_ThrowException(val) - -#define SWIG_contract_assert(expr, message) if (!(expr)) { \ - SWIG_Chicken_Barf(SWIG_BARF1_CONTRACT_ASSERT, C_text(message)); } else - -/* Runtime API */ -#define SWIG_GetModule(clientdata) SWIG_Chicken_GetModule(clientdata) -#define SWIG_SetModule(clientdata, pointer) SWIG_Chicken_SetModule(pointer) - -#define C_swig_is_bool(x) C_truep (C_booleanp (x)) -#define C_swig_is_char(x) C_truep (C_charp (x)) -#define C_swig_is_fixnum(x) C_truep (C_fixnump (x)) -#define C_swig_is_flonum(x) (C_truep (C_blockp (x)) && C_truep (C_flonump (x))) -#define C_swig_is_string(x) (C_truep (C_blockp (x)) && C_truep (C_stringp (x))) -#define C_swig_is_vector(x) (C_truep (C_blockp (x)) && C_truep (C_vectorp (x))) -#define C_swig_is_list(x) (C_truep (C_i_listp (x))) -#define C_swig_is_pair(x) (C_truep (C_blockp(x)) && C_truep (C_pairp(x))) -#define C_swig_is_ptr(x) (C_truep (C_blockp (x)) && C_truep (C_pointerp (x))) -#define C_swig_is_swigpointer(x) (C_truep (C_blockp(x)) && C_truep (C_swigpointerp(x))) -#define C_swig_is_closurep(x) (C_truep (C_blockp(x)) && C_truep(C_closurep(x))) -#define C_swig_is_number(x) (C_swig_is_fixnum(x) || C_swig_is_flonum(x)) -#define C_swig_is_long(x) C_swig_is_number(x) - -#define C_swig_sizeof_closure(num) (num+1) - -#define SWIG_Chicken_SetupArgout { \ - C_word *a = C_alloc(C_swig_sizeof_closure(2)); \ - C_word *closure = a; \ - *(a++)=C_CLOSURE_TYPE|2; \ - *(a++)=(C_word)SWIG_Chicken_ApplyResults; \ - *(a++)=continuation; \ - continuation=(C_word)closure; \ -} - -#define SWIG_APPEND_VALUE(obj) { \ - C_word val = (C_word)(obj); \ - if (val != C_SCHEME_UNDEFINED) { \ - C_word *a = C_alloc(C_swig_sizeof_closure(3)); \ - C_word *closure = a; \ - *(a++)=C_CLOSURE_TYPE|3; \ - *(a++)=(C_word)SWIG_Chicken_MultiResultBuild; \ - *(a++)=(C_word)continuation; \ - *(a++)=val; \ - continuation=(C_word)closure; \ - } } - -#define SWIG_Chicken_FindCreateProxy(func,obj) \ - if (C_swig_is_swigpointer(obj)) { \ - swig_type_info *t = (swig_type_info *) C_block_item(obj, 1); \ - if (t && t->clientdata && ((swig_chicken_clientdata *)t->clientdata)->gc_proxy_create) { \ - func = CHICKEN_gc_root_ref( ((swig_chicken_clientdata *)t->clientdata)->gc_proxy_create); \ - } else { \ - func = C_SCHEME_FALSE; \ - } \ - } else { \ - func = C_SCHEME_FALSE; \ - } - - -enum { - SWIG_BARF1_BAD_ARGUMENT_TYPE /* 1 arg */, - SWIG_BARF1_ARGUMENT_NULL /* 1 arg */, - SWIG_BARF1_CONTRACT_ASSERT /* 1 arg */, -}; - -typedef C_word (*swig_chicken_destructor)(C_word,C_word,C_word,C_word); -typedef struct swig_chicken_clientdata { - void *gc_proxy_create; - swig_chicken_destructor destroy; -} swig_chicken_clientdata; - -static char * -SWIG_Chicken_MakeString(C_word str) { - char *ret; - size_t l; - - l = C_header_size(str); - ret = (char *) SWIG_malloc( (l + 1) * sizeof(char)); - if (!ret) return NULL; - - memcpy(ret, C_c_string(str), l); - ret[l] = '\0'; - return ret; -} - -static C_word SWIG_Chicken_LookupSymbol(char *name, C_SYMBOL_TABLE *stable) { - C_word *a = C_alloc(C_SIZEOF_STRING (strlen (name))); - C_word n = C_string2(&a, name); - C_word sym = C_find_symbol(n, stable); - if (C_truep(sym)) { - return C_symbol_value(sym); - } else { - return C_SCHEME_FALSE; - } -} - -/* Just a helper function. Do not export it */ -static void SWIG_Chicken_Panic (C_char *) C_noret; -static void SWIG_Chicken_Panic (C_char *msg) -{ - C_word *a = C_alloc (C_SIZEOF_STRING (strlen (msg))); - C_word scmmsg = C_string2 (&a, msg); - C_halt (scmmsg); - exit (5); /* should never get here */ -} - -static void -SWIG_Chicken_Barf(int code, C_char *msg, ...) C_noret; -static void -SWIG_Chicken_Barf(int code, C_char *msg, ...) -{ - char *errorhook = C_text("\003syserror-hook"); - C_word *a = C_alloc (C_SIZEOF_STRING (strlen (errorhook))); - C_word err = C_intern2 (&a, errorhook); - int c = -1; - int i, barfval; - va_list v; - - - C_temporary_stack = C_temporary_stack_bottom; - err = C_block_item(err, 0); - - if(C_immediatep (err)) - SWIG_Chicken_Panic (C_text ("`##sys#error-hook' is not defined")); - - switch (code) { - case SWIG_BARF1_BAD_ARGUMENT_TYPE: - barfval = C_BAD_ARGUMENT_TYPE_ERROR; - c = 1; - break; - case SWIG_BARF1_ARGUMENT_NULL: - barfval = C_BAD_ARGUMENT_TYPE_ERROR; - c = 1; - break; - case SWIG_BARF1_CONTRACT_ASSERT: - barfval = C_BAD_ARGUMENT_TYPE_ERROR; - c = 1; - break; - default: - SWIG_Chicken_Panic (C_text (msg)); - }; - - if(c > 0 && !C_immediatep (err)) { - C_save (C_fix (barfval)); - - i = c; - if (i) { - C_word *b = C_alloc (C_SIZEOF_STRING (strlen (msg))); - C_word scmmsg = C_string2 (&b, msg); - C_save (scmmsg); - i--; - } - - va_start (v, msg); - - while(i--) - C_save (va_arg (v, C_word)); - - va_end (v); - C_do_apply (c + 1, err, - C_SCHEME_UNDEFINED); /* <- no continuation is passed: - '##sys#error-hook' may not - return! */ - } - else if (msg) { - SWIG_Chicken_Panic (msg); - } - else { - SWIG_Chicken_Panic (C_text ("unspecified panic")); - } -} - -static void SWIG_Chicken_ThrowException(C_word value) C_noret; -static void SWIG_Chicken_ThrowException(C_word value) -{ - char *aborthook = C_text("\003sysabort"); - C_word *a = C_alloc(C_SIZEOF_STRING(strlen(aborthook))); - C_word abort = C_intern2(&a, aborthook); - - abort = C_block_item(abort, 0); - if (C_immediatep(abort)) - SWIG_Chicken_Panic(C_text("`##sys#abort' is not defined")); - - C_save(value); - C_do_apply(1, abort, C_SCHEME_UNDEFINED); -} - -static void -SWIG_Chicken_Finalizer(C_word argc, C_word closure, C_word continuation, C_word s) -{ - swig_type_info *type; - swig_chicken_clientdata *cdata; - - if (argc == 3 && s != C_SCHEME_FALSE && C_swig_is_swigpointer(s)) { - type = (swig_type_info *) C_block_item(s, 1); - if (type) { - cdata = (swig_chicken_clientdata *) type->clientdata; - if (cdata && cdata->destroy) { - /* this will not return, but will continue correctly */ - cdata->destroy(3,closure,continuation,s); - } - } - } - C_kontinue(continuation, C_SCHEME_UNDEFINED); -} -static C_word finalizer_obj[2] = {(C_word) (C_CLOSURE_TYPE|1), (C_word) SWIG_Chicken_Finalizer}; - -static C_word -SWIG_Chicken_NewPointerObj(void *ptr, swig_type_info *type, int owner, C_word **data) -{ - swig_chicken_clientdata *cdata = (swig_chicken_clientdata *) type->clientdata; - - if (ptr == NULL) - return C_SCHEME_FALSE; - else { - C_word cptr = C_swigmpointer(data, ptr, type); - /* add finalizer to object */ - #ifndef SWIG_CHICKEN_NO_COLLECTION - if (owner) - C_do_register_finalizer(cptr, (C_word) finalizer_obj); - #endif - - return cptr; - } -} - -/* Return 0 if successful. */ -static int -SWIG_Chicken_ConvertPtr(C_word s, void **result, swig_type_info *type, int flags) -{ - swig_cast_info *cast; - swig_type_info *from; - - if (s == C_SCHEME_FALSE) { - *result = NULL; - return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK; - } else if (C_swig_is_swigpointer(s)) { - /* try and convert type */ - from = (swig_type_info *) C_block_item(s, 1); - if (!from) return 1; - if (type) { - cast = SWIG_TypeCheckStruct(from, type); - if (cast) { - int newmemory = 0; - *result = SWIG_TypeCast(cast, (void *) C_block_item(s, 0), &newmemory); - assert(!newmemory); /* newmemory handling not yet implemented */ - } else { - return 1; - } - } else { - *result = (void *) C_block_item(s, 0); - } - - /* check if we are disowning this object */ - if (flags & SWIG_POINTER_DISOWN) { - C_do_unregister_finalizer(s); - } - } else { - return 1; - } - - return 0; -} - -static SWIGINLINE void * -SWIG_Chicken_MustGetPtr (C_word s, swig_type_info *type, int argnum, int flags) -{ - void *result; - char err_msg[256]; - if (SWIG_Chicken_ConvertPtr(s, &result, type, flags)) { - /* type mismatch */ - snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", argnum, (type->str ? type->str : type->name)); - SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg); - } - return result; -} - -static char *chicken_runtimevar_name = "type_pointer" SWIG_TYPE_TABLE_NAME; - -static swig_module_info * -SWIG_Chicken_GetModule(void *SWIGUNUSEDPARM(clientdata)) { - swig_module_info *ret = 0; - C_word sym; - - /* lookup the type pointer... it is stored in its own symbol table */ - C_SYMBOL_TABLE *stable = C_find_symbol_table("swig_runtime_data" SWIG_RUNTIME_VERSION); - if (stable != NULL) { - sym = SWIG_Chicken_LookupSymbol(chicken_runtimevar_name, stable); - if (C_truep(sym) && C_swig_is_ptr(sym)) { - ret = (swig_module_info *) C_block_item(sym, 0); - } - } - - return ret; -} - -static void -SWIG_Chicken_SetModule(swig_module_info *module) { - C_word *a; - C_SYMBOL_TABLE *stable; - C_word sym; - C_word pointer; - static C_word *space = 0; - - /* type pointer is stored in its own symbol table */ - stable = C_find_symbol_table("swig_runtime_data" SWIG_RUNTIME_VERSION); - if (stable == NULL) { - stable = C_new_symbol_table("swig_runtime_data" SWIG_RUNTIME_VERSION, 16); - } - - if (!space) { - space = (C_word *) C_malloc((C_SIZEOF_POINTER + C_SIZEOF_INTERNED_SYMBOL(C_strlen(chicken_runtimevar_name))) * sizeof(C_word)); - } - a = space; - pointer = C_mpointer(&a, (void *) module); - sym = C_intern_in(&a, C_strlen(chicken_runtimevar_name), chicken_runtimevar_name, stable); - C_set_block_item(sym, 0, pointer); -} - -static C_word SWIG_Chicken_MultiResultBuild(C_word num, C_word closure, C_word lst) { - C_word cont = C_block_item(closure,1); - C_word obj = C_block_item(closure,2); - C_word func; - - SWIG_Chicken_FindCreateProxy(func,obj); - - if (C_swig_is_closurep(func)) { - ((C_proc4)(void *)C_block_item(func, 0))(4,func,cont,obj,lst); - } else { - C_word *a = C_alloc(C_SIZEOF_PAIR); - C_kontinue(cont,C_pair(&a,obj,lst)); - } - return C_SCHEME_UNDEFINED; /* never reached */ -} - -static C_word SWIG_Chicken_ApplyResults(C_word num, C_word closure, C_word result) { - C_apply_values(3,C_SCHEME_UNDEFINED,C_block_item(closure,1),result); - return C_SCHEME_UNDEFINED; /* never reached */ -} - -#ifdef __cplusplus -} -#endif diff --git a/Lib/chicken/extra-install.list b/Lib/chicken/extra-install.list deleted file mode 100644 index 48721cee0..000000000 --- a/Lib/chicken/extra-install.list +++ /dev/null @@ -1,3 +0,0 @@ -swigclosprefix.scm -multi-generic.scm -tinyclos-multi-generic.patch diff --git a/Lib/chicken/multi-generic.scm b/Lib/chicken/multi-generic.scm deleted file mode 100644 index 9d2e31d34..000000000 --- a/Lib/chicken/multi-generic.scm +++ /dev/null @@ -1,152 +0,0 @@ -;; This file is no longer necessary with Chicken versions above 1.92 -;; -;; This file overrides two functions inside TinyCLOS to provide support -;; for multi-argument generics. There are many ways of linking this file -;; into your code... all that needs to happen is this file must be -;; executed after loading TinyCLOS but before any SWIG modules are loaded -;; -;; something like the following -;; (require 'tinyclos) -;; (load "multi-generic") -;; (declare (uses swigmod)) -;; -;; An alternative to loading this scheme code directly is to add a -;; (declare (unit multi-generic)) to the top of this file, and then -;; compile this into the final executable or something. Or compile -;; this into an extension. - -;; Lastly, to override TinyCLOS method creation, two functions are -;; overridden: see the end of this file for which two are overridden. -;; You might want to remove those two lines and then exert more control over -;; which functions are used when. - -;; Comments, bugs, suggestions: send either to chicken-users@nongnu.org or to -;; Most code copied from TinyCLOS - -(define (make - 'name "multi-generic" - 'direct-supers (list ) - 'direct-slots '())) - -(letrec ([applicable? - (lambda (c arg) - (memq c (class-cpl (class-of arg))))] - - [more-specific? - (lambda (c1 c2 arg) - (memq c2 (memq c1 (class-cpl (class-of arg)))))] - - [filter-in - (lambda (f l) - (if (null? l) - '() - (let ([h (##sys#slot l 0)] - [r (##sys#slot l 1)] ) - (if (f h) - (cons h (filter-in f r)) - (filter-in f r) ) ) ) )]) - -(add-method compute-apply-generic - (make-method (list ) - (lambda (call-next-method generic) - (lambda args - (let ([cam (let ([x (compute-apply-methods generic)] - [y ((compute-methods generic) args)] ) - (lambda (args) (x y args)) ) ] ) - (cam args) ) ) ) ) ) - - - -(add-method compute-methods - (make-method (list ) - (lambda (call-next-method generic) - (lambda (args) - (let ([applicable - (filter-in (lambda (method) - (let check-applicable ([list1 (method-specializers method)] - [list2 args]) - (cond ((null? list1) #t) - ((null? list2) #f) - (else - (and (applicable? (##sys#slot list1 0) (##sys#slot list2 0)) - (check-applicable (##sys#slot list1 1) (##sys#slot list2 1))))))) - (generic-methods generic) ) ] ) - (if (or (null? applicable) (null? (##sys#slot applicable 1))) - applicable - (let ([cmms (compute-method-more-specific? generic)]) - (sort applicable (lambda (m1 m2) (cmms m1 m2 args))) ) ) ) ) ) ) ) - -(add-method compute-method-more-specific? - (make-method (list ) - (lambda (call-next-method generic) - (lambda (m1 m2 args) - (let loop ((specls1 (method-specializers m1)) - (specls2 (method-specializers m2)) - (args args)) - (cond-expand - [unsafe - (let ((c1 (##sys#slot specls1 0)) - (c2 (##sys#slot specls2 0)) - (arg (##sys#slot args 0))) - (if (eq? c1 c2) - (loop (##sys#slot specls1 1) - (##sys#slot specls2 1) - (##sys#slot args 1)) - (more-specific? c1 c2 arg))) ] - [else - (cond ((and (null? specls1) (null? specls2)) - (##sys#error "two methods are equally specific" generic)) - ;((or (null? specls1) (null? specls2)) - ; (##sys#error "two methods have different number of specializers" generic)) - ((null? specls1) #f) - ((null? specls2) #t) - ((null? args) - (##sys#error "fewer arguments than specializers" generic)) - (else - (let ((c1 (##sys#slot specls1 0)) - (c2 (##sys#slot specls2 0)) - (arg (##sys#slot args 0))) - (if (eq? c1 c2) - (loop (##sys#slot specls1 1) - (##sys#slot specls2 1) - (##sys#slot args 1)) - (more-specific? c1 c2 arg)))) ) ] ) ) ) ) ) ) - -) ;; end of letrec - -(define multi-add-method - (lambda (generic method) - (slot-set! - generic - 'methods - (let filter-in-method ([methods (slot-ref generic 'methods)]) - (if (null? methods) - (list method) - (let ([l1 (length (method-specializers method))] - [l2 (length (method-specializers (##sys#slot methods 0)))]) - (cond ((> l1 l2) - (cons (##sys#slot methods 0) (filter-in-method (##sys#slot methods 1)))) - ((< l1 l2) - (cons method methods)) - (else - (let check-method ([ms1 (method-specializers method)] - [ms2 (method-specializers (##sys#slot methods 0))]) - (cond ((and (null? ms1) (null? ms2)) - (cons method (##sys#slot methods 1))) ;; skip the method already in the generic - ((eq? (##sys#slot ms1 0) (##sys#slot ms2 0)) - (check-method (##sys#slot ms1 1) (##sys#slot ms2 1))) - (else - (cons (##sys#slot methods 0) (filter-in-method (##sys#slot methods 1)))))))))))) - - (##sys#setslot (##sys#slot generic (- (##sys#size generic) 2)) 1 (compute-apply-generic generic)) )) - -(define (multi-add-global-method val sym specializers proc) - (let ((generic (if (procedure? val) val (make 'name (##sys#symbol->string sym))))) - (multi-add-method generic (make-method specializers proc)) - generic)) - -;; Might want to remove these, or perhaps do something like -;; (define old-add-method ##tinyclos#add-method) -;; and then you can switch between creating multi-generics and TinyCLOS generics. -(set! ##tinyclos#add-method multi-add-method) -(set! ##tinyclos#add-global-method multi-add-global-method) diff --git a/Lib/chicken/std_string.i b/Lib/chicken/std_string.i deleted file mode 100644 index fa77c1533..000000000 --- a/Lib/chicken/std_string.i +++ /dev/null @@ -1,96 +0,0 @@ -/* ----------------------------------------------------------------------------- - * std_string.i - * - * SWIG typemaps for std::string - * ----------------------------------------------------------------------------- */ - -%{ -#include -%} - -namespace std { - %naturalvar string; - - - %insert(closprefix) %{ (declare (hide )) %} - %nodefault string; - %rename("std-string") string; - class string { - public: - ~string() {} - }; - %extend string { - char *str; - } - %{ - #define std_string_str_get(s) ((char *)((s)->c_str())) - #define std_string_str_set(s,v) (s->assign((char *)(v))) - %} - - %typemap(typecheck) string = char *; - %typemap(typecheck) const string & = char *; - - %typemap(in) string (char * tempptr) { - if ($input == C_SCHEME_FALSE) { - $1.resize(0); - } else { - if (!C_swig_is_string ($input)) { - swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, - "Argument #$argnum is not a string"); - } - tempptr = SWIG_MakeString($input); - $1.assign(tempptr); - if (tempptr) SWIG_free(tempptr); - } - } - - %typemap(in) const string& ($*1_ltype temp, char *tempptr) { - - if ($input == C_SCHEME_FALSE) { - temp.resize(0); - $1 = &temp; - } else { - if (!C_swig_is_string ($input)) { - swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, - "Argument #$argnum is not a string"); - } - tempptr = SWIG_MakeString($input); - temp.assign(tempptr); - if (tempptr) SWIG_free(tempptr); - $1 = &temp; - } - } - - %typemap(out) string { - int size = $1.size(); - C_word *space = C_alloc (C_SIZEOF_STRING (size)); - $result = C_string (&space, size, (char *) $1.c_str()); - } - - %typemap(out) const string& { - int size = $1->size(); - C_word *space = C_alloc (C_SIZEOF_STRING (size)); - $result = C_string (&space, size, (char *) $1->c_str()); - } - - %typemap(varin) string { - if ($input == C_SCHEME_FALSE) { - $1.resize(0); - } else { - char *tempptr; - if (!C_swig_is_string ($input)) { - swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, - "Argument #$argnum is not a string"); - } - tempptr = SWIG_MakeString($input); - $1.assign(tempptr); - if (tempptr) SWIG_free(tempptr); - } - } - - %typemap(varout) string { - int size = $1.size(); - C_word *space = C_alloc (C_SIZEOF_STRING (size)); - $result = C_string (&space, size, (char *) $1.c_str()); - } -} diff --git a/Lib/chicken/swigclosprefix.scm b/Lib/chicken/swigclosprefix.scm deleted file mode 100644 index e4bd72b71..000000000 --- a/Lib/chicken/swigclosprefix.scm +++ /dev/null @@ -1,31 +0,0 @@ -(declare (hide swig-initialize)) - -(define (swig-initialize obj initargs create) - (slot-set! obj 'swig-this - (if (memq 'swig-this initargs) - (cadr initargs) - (let ((ret (apply create initargs))) - (if (instance? ret) - (slot-ref ret 'swig-this) - ret))))) - -(define-class () (void)) - -(define-method (compute-getter-and-setter (class ) slot allocator) - (if (not (memq ':swig-virtual slot)) - (call-next-method) - (let ((getter (let search-get ((lst slot)) - (if (null? lst) - #f - (if (eq? (car lst) ':swig-get) - (cadr lst) - (search-get (cdr lst)))))) - (setter (let search-set ((lst slot)) - (if (null? lst) - #f - (if (eq? (car lst) ':swig-set) - (cadr lst) - (search-set (cdr lst))))))) - (values - (lambda (o) (getter (slot-ref o 'swig-this))) - (lambda (o new) (setter (slot-ref o 'swig-this) new) new))))) diff --git a/Lib/chicken/tinyclos-multi-generic.patch b/Lib/chicken/tinyclos-multi-generic.patch deleted file mode 100644 index 2e585960e..000000000 --- a/Lib/chicken/tinyclos-multi-generic.patch +++ /dev/null @@ -1,150 +0,0 @@ -# This patch is against chicken 1.92, but it should work just fine -# with older versions of chicken. It adds support for mulit-argument -# generics, that is, generics now correctly handle adding methods -# with different lengths of specializer lists - -# This patch has been committed into the CHICKEN darcs repository, -# so chicken versions above 1.92 work fine. - -# Comments, bugs, suggestions send to chicken-users@nongnu.org - -# Patch written by John Lenz - ---- tinyclos.scm.old 2005-04-05 01:13:56.000000000 -0500 -+++ tinyclos.scm 2005-04-11 16:37:23.746181489 -0500 -@@ -37,8 +37,10 @@ - - (include "parameters") - -+(cond-expand [(not chicken-compile-shared) (declare (unit tinyclos))] -+ [else] ) -+ - (declare -- (unit tinyclos) - (uses extras) - (usual-integrations) - (fixnum) -@@ -234,7 +236,10 @@ - y = C_block_item(y, 1); - } - } -- return(C_block_item(v, i + 1)); -+ if (x == C_SCHEME_END_OF_LIST && y == C_SCHEME_END_OF_LIST) -+ return(C_block_item(v, i + 1)); -+ else -+ goto mismatch; - } - else if(free_index == -1) free_index = i; - mismatch: -@@ -438,7 +443,7 @@ - (define hash-arg-list - (foreign-lambda* unsigned-int ((scheme-object args) (scheme-object svector)) " - C_word tag, h, x; -- int n, i, j; -+ int n, i, j, len = 0; - for(i = 0; args != C_SCHEME_END_OF_LIST; args = C_block_item(args, 1)) { - x = C_block_item(args, 0); - if(C_immediatep(x)) { -@@ -481,8 +486,9 @@ - default: i += 255; - } - } -+ ++len; - } -- return(i & (C_METHOD_CACHE_SIZE - 1));") ) -+ return((i + len) & (C_METHOD_CACHE_SIZE - 1));") ) - - - ; -@@ -868,13 +874,27 @@ - (##tinyclos#slot-set! - generic - 'methods -- (cons method -- (filter-in -- (lambda (m) -- (let ([ms1 (method-specializers m)] -- [ms2 (method-specializers method)] ) -- (not (every2 (lambda (x y) (eq? x y)) ms1 ms2) ) ) ) -- (##tinyclos#slot-ref generic 'methods)))) -+ (let* ([ms1 (method-specializers method)] -+ [l1 (length ms1)] ) -+ (let filter-in-method ([methods (##tinyclos#slot-ref generic 'methods)]) -+ (if (null? methods) -+ (list method) -+ (let* ([mm (##sys#slot methods 0)] -+ [ms2 (method-specializers mm)] -+ [l2 (length ms2)]) -+ (cond ((> l1 l2) -+ (cons mm (filter-in-method (##sys#slot methods 1)))) -+ ((< l1 l2) -+ (cons method methods)) -+ (else -+ (let check-method ([ms1 ms1] -+ [ms2 ms2]) -+ (cond ((and (null? ms1) (null? ms2)) -+ (cons method (##sys#slot methods 1))) ;; skip the method already in the generic -+ ((eq? (##sys#slot ms1 0) (##sys#slot ms2 0)) -+ (check-method (##sys#slot ms1 1) (##sys#slot ms2 1))) -+ (else -+ (cons mm (filter-in-method (##sys#slot methods 1))))))))))))) - (if (memq generic generic-invocation-generics) - (set! method-cache-tag (vector)) - (%entity-cache-set! generic #f) ) -@@ -925,11 +945,13 @@ - (memq (car args) generic-invocation-generics)) - (let ([proc - (method-procedure -+ ; select the first method of one argument - (let lp ([lis (generic-methods generic)]) -- (let ([tail (##sys#slot lis 1)]) -- (if (null? tail) -- (##sys#slot lis 0) -- (lp tail)) ) ) ) ] ) -+ (if (null? lis) -+ (##sys#error "Unable to find original compute-apply-generic") -+ (if (= (length (method-specializers (##sys#slot lis 0))) 1) -+ (##sys#slot lis 0) -+ (lp (##sys#slot lis 1)))))) ] ) - (lambda (args) (apply proc #f args)) ) - (let ([x (compute-apply-methods generic)] - [y ((compute-methods generic) args)] ) -@@ -946,9 +968,13 @@ - (lambda (args) - (let ([applicable - (filter-in (lambda (method) -- (every2 applicable? -- (method-specializers method) -- args)) -+ (let check-applicable ([list1 (method-specializers method)] -+ [list2 args]) -+ (cond ((null? list1) #t) -+ ((null? list2) #f) -+ (else -+ (and (applicable? (##sys#slot list1 0) (##sys#slot list2 0)) -+ (check-applicable (##sys#slot list1 1) (##sys#slot list2 1))))))) - (generic-methods generic) ) ] ) - (if (or (null? applicable) (null? (##sys#slot applicable 1))) - applicable -@@ -975,8 +1001,10 @@ - [else - (cond ((and (null? specls1) (null? specls2)) - (##sys#error "two methods are equally specific" generic)) -- ((or (null? specls1) (null? specls2)) -- (##sys#error "two methods have different number of specializers" generic)) -+ ;((or (null? specls1) (null? specls2)) -+ ; (##sys#error "two methods have different number of specializers" generic)) -+ ((null? specls1) #f) -+ ((null? specls2) #t) - ((null? args) - (##sys#error "fewer arguments than specializers" generic)) - (else -@@ -1210,7 +1238,7 @@ - (define (make-primitive-class "structure")) - (define (make-primitive-class "procedure" )) - (define (make-primitive-class "end-of-file")) --(define (make-primitive-class "environment" )) ; (Benedikt insisted on this) -+(define (make-primitive-class "environment" )) - (define (make-primitive-class "hash-table" )) - (define (make-primitive-class "promise" )) - (define (make-primitive-class "queue" )) diff --git a/Lib/chicken/typemaps.i b/Lib/chicken/typemaps.i deleted file mode 100644 index fd587fd68..000000000 --- a/Lib/chicken/typemaps.i +++ /dev/null @@ -1,314 +0,0 @@ -/* ----------------------------------------------------------------------------- - * typemaps.i - * - * Pointer handling - * - * These mappings provide support for input/output arguments and - * common uses for C/C++ pointers. INOUT mappings allow for C/C++ - * pointer variables in addition to input/output arguments. - * ----------------------------------------------------------------------------- */ - -// INPUT typemaps. -// These remap a C pointer to be an "INPUT" value which is passed by value -// instead of reference. - -/* -The following methods can be applied to turn a pointer into a simple -"input" value. That is, instead of passing a pointer to an object, -you would use a real value instead. - - int *INPUT - short *INPUT - long *INPUT - long long *INPUT - unsigned int *INPUT - unsigned short *INPUT - unsigned long *INPUT - unsigned long long *INPUT - unsigned char *INPUT - char *INPUT - bool *INPUT - float *INPUT - double *INPUT - -To use these, suppose you had a C function like this : - - double fadd(double *a, double *b) { - return *a+*b; - } - -You could wrap it with SWIG as follows : - - %include - double fadd(double *INPUT, double *INPUT); - -or you can use the %apply directive : - - %include - %apply double *INPUT { double *a, double *b }; - double fadd(double *a, double *b); - -*/ - -// OUTPUT typemaps. These typemaps are used for parameters that -// are output only. The output value is appended to the result as -// a list element. - -/* -The following methods can be applied to turn a pointer into an "output" -value. When calling a function, no input value would be given for -a parameter, but an output value would be returned. In the case of -multiple output values, they are returned in the form of a Scheme list. - - int *OUTPUT - short *OUTPUT - long *OUTPUT - long long *OUTPUT - unsigned int *OUTPUT - unsigned short *OUTPUT - unsigned long *OUTPUT - unsigned long long *OUTPUT - unsigned char *OUTPUT - char *OUTPUT - bool *OUTPUT - float *OUTPUT - double *OUTPUT - -For example, suppose you were trying to wrap the modf() function in the -C math library which splits x into integral and fractional parts (and -returns the integer part in one of its parameters).K: - - double modf(double x, double *ip); - -You could wrap it with SWIG as follows : - - %include - double modf(double x, double *OUTPUT); - -or you can use the %apply directive : - - %include - %apply double *OUTPUT { double *ip }; - double modf(double x, double *ip); - -*/ - -//---------------------------------------------------------------------- -// -// T_OUTPUT typemap (and helper function) to return multiple argouts as -// a tuple instead of a list. -// -//---------------------------------------------------------------------- - -// Simple types - -%define INOUT_TYPEMAP(type_, from_scheme, to_scheme, checker, convtype, storage_) - -%typemap(in) type_ *INPUT($*1_ltype temp), type_ &INPUT($*1_ltype temp) -%{ if (!checker ($input)) { - swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument #$argnum is not of type 'type_'"); - } - temp = ($*1_ltype) from_scheme ($input); - $1 = &temp; %} - -%typemap(typecheck) type_ *INPUT = type_; -%typemap(typecheck) type_ &INPUT = type_; - -%typemap(in, numinputs=0) type_ *OUTPUT($*1_ltype temp), type_ &OUTPUT($*1_ltype temp) -" $1 = &temp;" - -#if "storage_" == "0" - -%typemap(argout) type_ *OUTPUT, type_ &OUTPUT -%{ - if ($1 == NULL) { - swig_barf (SWIG_BARF1_ARGUMENT_NULL, "Argument #$argnum must be non-null"); - } - SWIG_APPEND_VALUE(to_scheme (convtype (*$1))); -%} - -#else - -%typemap(argout) type_ *OUTPUT, type_ &OUTPUT -%{ - { - C_word *known_space = C_alloc(storage_); - if ($1 == NULL) { - swig_barf (SWIG_BARF1_ARGUMENT_NULL, "Variable '$1' must be non-null"); - } - SWIG_APPEND_VALUE(to_scheme (&known_space, convtype (*$1))); - } -%} - -#endif - -%enddef - -INOUT_TYPEMAP(int, C_num_to_int, C_fix, C_swig_is_number, (int), 0); -INOUT_TYPEMAP(enum SWIGTYPE, C_num_to_int, C_fix, C_swig_is_number, (int), 0); -INOUT_TYPEMAP(short, C_num_to_int, C_fix, C_swig_is_number, (int), 0); -INOUT_TYPEMAP(long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM); -INOUT_TYPEMAP(long long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM); -INOUT_TYPEMAP(unsigned int, C_num_to_unsigned_int, C_unsigned_int_to_num, C_swig_is_number, (int), C_SIZEOF_FLONUM); -INOUT_TYPEMAP(unsigned short, C_num_to_unsigned_int, C_fix, C_swig_is_number, (unsigned int), 0); -INOUT_TYPEMAP(unsigned long, C_num_to_unsigned_long, C_unsigned_long_to_num, C_swig_is_long, (unsigned long), C_SIZEOF_FLONUM); -INOUT_TYPEMAP(unsigned long long, C_num_to_unsigned_long, C_unsigned_long_to_num, C_swig_is_long, (unsigned long), C_SIZEOF_FLONUM); -INOUT_TYPEMAP(unsigned char, C_character_code, C_make_character, C_swig_is_char, (unsigned int), 0); -INOUT_TYPEMAP(signed char, C_character_code, C_make_character, C_swig_is_char, (int), 0); -INOUT_TYPEMAP(char, C_character_code, C_make_character, C_swig_is_char, (char), 0); -INOUT_TYPEMAP(bool, C_truep, C_mk_bool, C_swig_is_bool, (bool), 0); -INOUT_TYPEMAP(float, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEOF_FLONUM); -INOUT_TYPEMAP(double, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEOF_FLONUM); - -// INOUT -// Mappings for an argument that is both an input and output -// parameter - -/* -The following methods can be applied to make a function parameter both -an input and output value. This combines the behavior of both the -"INPUT" and "OUTPUT" methods described earlier. Output values are -returned in the form of a CHICKEN tuple. - - int *INOUT - short *INOUT - long *INOUT - long long *INOUT - unsigned int *INOUT - unsigned short *INOUT - unsigned long *INOUT - unsigned long long *INOUT - unsigned char *INOUT - char *INOUT - bool *INOUT - float *INOUT - double *INOUT - -For example, suppose you were trying to wrap the following function : - - void neg(double *x) { - *x = -(*x); - } - -You could wrap it with SWIG as follows : - - %include - void neg(double *INOUT); - -or you can use the %apply directive : - - %include - %apply double *INOUT { double *x }; - void neg(double *x); - -As well, you can wrap variables with : - - %include - %apply double *INOUT { double *y }; - extern double *y; - -Unlike C, this mapping does not directly modify the input value (since -this makes no sense in CHICKEN). Rather, the modified input value shows -up as the return value of the function. Thus, to apply this function -to a CHICKEN variable you might do this : - - x = neg(x) - -Note : previous versions of SWIG used the symbol 'BOTH' to mark -input/output arguments. This is still supported, but will be slowly -phased out in future releases. - -*/ - -%typemap(in) int *INOUT = int *INPUT; -%typemap(in) enum SWIGTYPE *INOUT = enum SWIGTYPE *INPUT; -%typemap(in) short *INOUT = short *INPUT; -%typemap(in) long *INOUT = long *INPUT; -%typemap(in) long long *INOUT = long long *INPUT; -%typemap(in) unsigned *INOUT = unsigned *INPUT; -%typemap(in) unsigned short *INOUT = unsigned short *INPUT; -%typemap(in) unsigned long *INOUT = unsigned long *INPUT; -%typemap(in) unsigned long long *INOUT = unsigned long long *INPUT; -%typemap(in) unsigned char *INOUT = unsigned char *INPUT; -%typemap(in) char *INOUT = char *INPUT; -%typemap(in) bool *INOUT = bool *INPUT; -%typemap(in) float *INOUT = float *INPUT; -%typemap(in) double *INOUT = double *INPUT; - -%typemap(in) int &INOUT = int &INPUT; -%typemap(in) enum SWIGTYPE &INOUT = enum SWIGTYPE &INPUT; -%typemap(in) short &INOUT = short &INPUT; -%typemap(in) long &INOUT = long &INPUT; -%typemap(in) long long &INOUT = long long &INPUT; -%typemap(in) unsigned &INOUT = unsigned &INPUT; -%typemap(in) unsigned short &INOUT = unsigned short &INPUT; -%typemap(in) unsigned long &INOUT = unsigned long &INPUT; -%typemap(in) unsigned long long &INOUT = unsigned long long &INPUT; -%typemap(in) unsigned char &INOUT = unsigned char &INPUT; -%typemap(in) char &INOUT = char &INPUT; -%typemap(in) bool &INOUT = bool &INPUT; -%typemap(in) float &INOUT = float &INPUT; -%typemap(in) double &INOUT = double &INPUT; - -%typemap(argout) int *INOUT = int *OUTPUT; -%typemap(argout) enum SWIGTYPE *INOUT = enum SWIGTYPE *OUTPUT; -%typemap(argout) short *INOUT = short *OUTPUT; -%typemap(argout) long *INOUT = long *OUTPUT; -%typemap(argout) long long *INOUT = long long *OUTPUT; -%typemap(argout) unsigned *INOUT = unsigned *OUTPUT; -%typemap(argout) unsigned short *INOUT = unsigned short *OUTPUT; -%typemap(argout) unsigned long *INOUT = unsigned long *OUTPUT; -%typemap(argout) unsigned long long *INOUT = unsigned long long *OUTPUT; -%typemap(argout) unsigned char *INOUT = unsigned char *OUTPUT; -%typemap(argout) bool *INOUT = bool *OUTPUT; -%typemap(argout) float *INOUT = float *OUTPUT; -%typemap(argout) double *INOUT = double *OUTPUT; - -%typemap(argout) int &INOUT = int &OUTPUT; -%typemap(argout) enum SWIGTYPE &INOUT = enum SWIGTYPE &OUTPUT; -%typemap(argout) short &INOUT = short &OUTPUT; -%typemap(argout) long &INOUT = long &OUTPUT; -%typemap(argout) long long &INOUT = long long &OUTPUT; -%typemap(argout) unsigned &INOUT = unsigned &OUTPUT; -%typemap(argout) unsigned short &INOUT = unsigned short &OUTPUT; -%typemap(argout) unsigned long &INOUT = unsigned long &OUTPUT; -%typemap(argout) unsigned long long &INOUT = unsigned long long &OUTPUT; -%typemap(argout) unsigned char &INOUT = unsigned char &OUTPUT; -%typemap(argout) char &INOUT = char &OUTPUT; -%typemap(argout) bool &INOUT = bool &OUTPUT; -%typemap(argout) float &INOUT = float &OUTPUT; -%typemap(argout) double &INOUT = double &OUTPUT; - -/* Overloading information */ - -%typemap(typecheck) double *INOUT = double; -%typemap(typecheck) bool *INOUT = bool; -%typemap(typecheck) char *INOUT = char; -%typemap(typecheck) signed char *INOUT = signed char; -%typemap(typecheck) unsigned char *INOUT = unsigned char; -%typemap(typecheck) unsigned long *INOUT = unsigned long; -%typemap(typecheck) unsigned long long *INOUT = unsigned long long; -%typemap(typecheck) unsigned short *INOUT = unsigned short; -%typemap(typecheck) unsigned int *INOUT = unsigned int; -%typemap(typecheck) long *INOUT = long; -%typemap(typecheck) long long *INOUT = long long; -%typemap(typecheck) short *INOUT = short; -%typemap(typecheck) int *INOUT = int; -%typemap(typecheck) enum SWIGTYPE *INOUT = enum SWIGTYPE; -%typemap(typecheck) float *INOUT = float; - -%typemap(typecheck) double &INOUT = double; -%typemap(typecheck) bool &INOUT = bool; -%typemap(typecheck) char &INOUT = char; -%typemap(typecheck) signed char &INOUT = signed char; -%typemap(typecheck) unsigned char &INOUT = unsigned char; -%typemap(typecheck) unsigned long &INOUT = unsigned long; -%typemap(typecheck) unsigned long long &INOUT = unsigned long long; -%typemap(typecheck) unsigned short &INOUT = unsigned short; -%typemap(typecheck) unsigned int &INOUT = unsigned int; -%typemap(typecheck) long &INOUT = long; -%typemap(typecheck) long long &INOUT = long long; -%typemap(typecheck) short &INOUT = short; -%typemap(typecheck) int &INOUT = int; -%typemap(typecheck) enum SWIGTYPE &INOUT = enum SWIGTYPE; -%typemap(typecheck) float &INOUT = float; -- cgit v1.2.1 From f3ba54c3bbc717cebb8716779aa676fa62d8b68c Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 13 May 2021 10:58:50 +1200 Subject: [CLISP] Remove code for GNU Common Lisp We dropped support for it in SWIG 4.0.0 and nobody has stepped forward to revive it in over 2 years. See #2009. --- Lib/clisp/clisp.swg | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 Lib/clisp/clisp.swg (limited to 'Lib') diff --git a/Lib/clisp/clisp.swg b/Lib/clisp/clisp.swg deleted file mode 100644 index e1d330cb3..000000000 --- a/Lib/clisp/clisp.swg +++ /dev/null @@ -1,32 +0,0 @@ -/* ----------------------------------------------------------------------------- - * clisp.swg - * ----------------------------------------------------------------------------- */ - -/* Define a C preprocessor symbol that can be used in interface files - to distinguish between the SWIG language modules. */ - -#define SWIG_CLISP - -/* Typespecs for basic types. */ - -%typemap(in) void "NIL"; - -%typemap(in) char "character"; -%typemap(in) char * "ffi:c-string"; -%typemap(in) unsigned char "ffi:uchar"; -%typemap(in) signed char "ffi:char"; - -%typemap(in) short "ffi:short"; -%typemap(in) signed short "ffi:short"; -%typemap(in) unsigned short "ffi:ushort"; - -%typemap(in) int "ffi:int"; -%typemap(in) signed int "ffi:int"; -%typemap(in) unsigned int "ffi:uint"; - -%typemap(in) long "ffi:long"; -%typemap(in) signed long "ffi:long"; -%typemap(in) unsigned long "ffi:ulong"; - -%typemap(in) float "SINGLE-FLOAT"; -%typemap(in) double "DOUBLE-FLOAT"; -- cgit v1.2.1 From 12f3a859166cb02eedb5e5f9aa17f52d72324d83 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 13 May 2021 11:08:39 +1200 Subject: [Modula3] Remove code for Modula3 We dropped support for it in SWIG 4.0.0 and nobody has stepped forward to revive it in over 2 years. See #2009. --- Lib/modula3/modula3.swg | 787 -------------------------------------------- Lib/modula3/modula3head.swg | 64 ---- Lib/modula3/typemaps.i | 74 ----- 3 files changed, 925 deletions(-) delete mode 100644 Lib/modula3/modula3.swg delete mode 100644 Lib/modula3/modula3head.swg delete mode 100644 Lib/modula3/typemaps.i (limited to 'Lib') diff --git a/Lib/modula3/modula3.swg b/Lib/modula3/modula3.swg deleted file mode 100644 index 13d06e9c6..000000000 --- a/Lib/modula3/modula3.swg +++ /dev/null @@ -1,787 +0,0 @@ -/* ----------------------------------------------------------------------------- - * modula3.swg - * - * Modula3 typemaps - * ----------------------------------------------------------------------------- */ - -%include - -/* The ctype, m3rawtype and m3wraptype typemaps work together and so there should be one of each. - * The ctype typemap contains the C type used in the signature of C wrappers for C++ functions. - * The m3rawtype typemap contains the M3 type used in the raw interface. - * The m3rawintype typemap contains the M3 type used as function argument. - * The m3rawrettype typemap contains the M3 type used as return value. - * The m3wraptype typemap contains the M3 type used in the M3 type wrapper classes and module class. */ - -/* Primitive types */ -%typemap(ctype) bool, const bool & "bool" -%typemap(ctype) char, const char & "char" -%typemap(ctype) signed char, const signed char & "signed char" -%typemap(ctype) unsigned char, const unsigned char & "unsigned short" -%typemap(ctype) short, const short & "short" -%typemap(ctype) unsigned short, const unsigned short & "unsigned short" -%typemap(ctype) int, const int & "int" -%typemap(ctype) unsigned int, const unsigned int & "unsigned int" -%typemap(ctype) long, const long & "long" -%typemap(ctype) unsigned long, const unsigned long & "unsigned long" -%typemap(ctype) long long, const long long & "long long" -%typemap(ctype) unsigned long long, const unsigned long long & "unsigned long long" -%typemap(ctype) float, const float & "float" -%typemap(ctype) double, const double & "double" -%typemap(ctype) char * "char *" -%typemap(ctype) void "void" - -%typemap(m3rawtype) bool, const bool & "BOOLEAN" -%typemap(m3rawtype) char, const char & "C.char" -%typemap(m3rawtype) signed char, const signed char & "C.signed_char" -%typemap(m3rawtype) unsigned char, const unsigned char & "C.unsigned_char" -%typemap(m3rawtype) short, const short & "C.short" -%typemap(m3rawtype) unsigned short, const unsigned short & "C.unsigned_short" -%typemap(m3rawtype) int, const int & "C.int" -%typemap(m3rawtype) unsigned int, const unsigned int & "C.unsigned_int" -%typemap(m3rawtype) long, const long & "C.long" -%typemap(m3rawtype) unsigned long, const unsigned long & "C.unsigned_long" -%typemap(m3rawtype) long long, const long long & "C.long_long" -%typemap(m3rawtype) unsigned long long, const unsigned long long & "C.unsigned_long_long" -%typemap(m3rawtype) float, const float & "C.float" -%typemap(m3rawtype) double, const double & "C.double" -%typemap(m3rawtype) long double, const long double & "C.long_double" -%typemap(m3rawtype) char * "C.char_star" -%typemap(m3rawtype) void "" -%typemap(m3rawtype) FILE "Cstdio.FILE"; -%typemap(m3rawtype) FILE * "Cstdio.FILE_star"; - - -%typemap(m3rawintype) bool *, bool &, bool "BOOLEAN" -%typemap(m3rawintype) char *, char &, char "C.char" -%typemap(m3rawintype) signed char *, signed char &, signed char "C.signed_char" -%typemap(m3rawintype) unsigned char *, unsigned char &, unsigned char "C.unsigned_char" -%typemap(m3rawintype) short *, short &, short "C.short" -%typemap(m3rawintype) unsigned short *, unsigned short &, unsigned short "C.unsigned_short" -%typemap(m3rawintype) int *, int &, int "C.int" -%typemap(m3rawintype) unsigned int *, unsigned int &, unsigned int "C.unsigned_int" -%typemap(m3rawintype) long *, long &, long "C.long" -%typemap(m3rawintype) unsigned long *, unsigned long &, unsigned long "C.unsigned_long" -%typemap(m3rawintype) long long *, long long &, long long "C.long_long" -%typemap(m3rawintype) unsigned long long *, unsigned long long &, unsigned long long "C.unsigned_long_long" -%typemap(m3rawintype) float *, float &, float "C.float" -%typemap(m3rawintype) double *, double &, double "C.double" -%typemap(m3rawintype) long double *, long double &, long double "C.long_double" -%typemap(m3rawintype) char * "C.char_star" -%typemap(m3rawintype) void "" -%typemap(m3rawintype) void * "ADDRESS" -%typemap(m3rawintype) FILE "Cstdio.FILE"; -%typemap(m3rawintype) FILE * "Cstdio.FILE_star"; - -%typemap(m3rawinmode) char *, void *, FILE * "" - - -%typemap(m3rawrettype) bool, const bool & "BOOLEAN" -%typemap(m3rawrettype) char, const char & "C.char" -%typemap(m3rawrettype) signed char, const signed char & "C.signed_char" -%typemap(m3rawrettype) unsigned char, const unsigned char & "C.unsigned_char" -%typemap(m3rawrettype) short, const short & "C.short" -%typemap(m3rawrettype) unsigned short, const unsigned short & "C.unsigned_short" -%typemap(m3rawrettype) int, const int & "C.int" -%typemap(m3rawrettype) unsigned int, const unsigned int & "C.unsigned_int" -%typemap(m3rawrettype) long, const long & "C.long" -%typemap(m3rawrettype) unsigned long, const unsigned long & "C.unsigned_long" -%typemap(m3rawrettype) long long, const long long & "C.long_long" -%typemap(m3rawrettype) unsigned long long, const unsigned long long & "C.unsigned_long_long" -%typemap(m3rawrettype) float, const float & "C.float" -%typemap(m3rawrettype) double, const double & "C.double" -%typemap(m3rawrettype) long double, const long double & "C.long_double" -%typemap(m3rawrettype) char * "C.char_star" -%typemap(m3rawrettype) void "" -%typemap(m3rawrettype) void * "ADDRESS" -%typemap(m3rawrettype) FILE "Cstdio.FILE"; -%typemap(m3rawrettype) FILE * "Cstdio.FILE_star"; - - -%typemap("m3rawtype:import") - char, const char &, - signed char, const signed char &, - unsigned char, const unsigned char &, - short, const short &, - unsigned short, const unsigned short &, - int, const int &, - unsigned int, const unsigned int &, - long, const long &, - unsigned long, const unsigned long &, - long long, const long long &, - unsigned long long, const unsigned long long &, - float, const float &, - double, const double &, - long double, const long double &, - char * - "Ctypes AS C" - -%typemap("m3rawintype:import") - char, const char &, - signed char, const signed char &, - unsigned char, const unsigned char &, - short, const short &, - unsigned short, const unsigned short &, - int, const int &, - unsigned int, const unsigned int &, - long, const long &, - unsigned long, const unsigned long &, - long long, const long long &, - unsigned long long, const unsigned long long &, - float, const float &, - double, const double &, - long double, const long double &, - char * - "Ctypes AS C" - -%typemap("m3rawrettype:import") - char, const char &, - signed char, const signed char &, - unsigned char, const unsigned char &, - short, const short &, - unsigned short, const unsigned short &, - int, const int &, - unsigned int, const unsigned int &, - long, const long &, - unsigned long, const unsigned long &, - long long, const long long &, - unsigned long long, const unsigned long long &, - float, const float &, - double, const double &, - long double, const long double &, - char * - "Ctypes AS C" - -%typemap("m3rawtype:import") - FILE, FILE * - "Cstdio"; - -%typemap("m3rawintype:import") - FILE, FILE * - "Cstdio"; - -%typemap("m3rawrettype:import") - FILE, FILE * - "Cstdio"; - -%typemap(m3wraptype) bool, const bool & "BOOLEAN" -%typemap(m3wraptype) char, const char & "CHAR" -%typemap(m3wraptype) signed char, const signed char & "CHAR" -%typemap(m3wraptype) unsigned char, const unsigned char & "CHAR" -%typemap(m3wraptype) short, const short & "Integer16.T" -%typemap(m3wraptype) unsigned short, const unsigned short & "Cardinal16.T" -%typemap(m3wraptype) int, const int & "INTEGER" -%typemap(m3wraptype) unsigned int, const unsigned int & "CARDINAL" -%typemap(m3wraptype) long, const long & "Integer32.T" -%typemap(m3wraptype) unsigned long, const unsigned long & "Cardinal32.T" -%typemap(m3wraptype) long long, const long long & "Integer64.T" -%typemap(m3wraptype) unsigned long long, const unsigned long long & "Cardinal64.T" -%typemap(m3wraptype) float, const float & "REAL" -%typemap(m3wraptype) double, const double & "LONGREAL" -%typemap(m3wraptype) long double, const long double & "EXTENDED" -%typemap(m3wraptype) char * "TEXT" -%typemap(m3wraptype) void "" -%typemap(m3wraptype) FILE "Cstdio.FILE"; -%typemap(m3wraptype) FILE * "Cstdio.FILE_star"; - -%typemap(m3wrapintype) bool, const bool *, const bool & "BOOLEAN" -%typemap(m3wrapintype) char, const char *, const char & "CHAR" -%typemap(m3wrapintype) signed char, const signed char *, const signed char & "CHAR" -%typemap(m3wrapintype) unsigned char, const unsigned char *, const unsigned char & "CHAR" -%typemap(m3wrapintype) short, const short *, const short & "INTEGER" -%typemap(m3wrapintype) unsigned short, const unsigned short *, const unsigned short & "CARDINAL" -%typemap(m3wrapintype) int, const int *, const int & "INTEGER" -%typemap(m3wrapintype) unsigned int, const unsigned int *, const unsigned int & "CARDINAL" -%typemap(m3wrapintype) long, const long *, const long & "INTEGER" -%typemap(m3wrapintype) unsigned long, const unsigned long *, const unsigned long & "CARDINAL" -%typemap(m3wrapintype) long long, const long long *, const long long & "INTEGER" -%typemap(m3wrapintype) unsigned long long, const unsigned long long *, const unsigned long long & "CARDINAL" -%typemap(m3wrapintype) float, const float *, const float & "REAL" -%typemap(m3wrapintype) double, const double *, const double & "LONGREAL" -%typemap(m3wrapintype) long double, const long double *, const long double & "EXTENDED" -%typemap(m3wrapintype) const char *, const char [] "TEXT" -%typemap(m3wrapintype,numinputs=0) void "" -%typemap(m3wrapintype) FILE "Cstdio.FILE"; -%typemap(m3wrapintype) FILE * "Cstdio.FILE_star"; - - -%typemap(m3wrapouttype) bool, bool *, bool & "BOOLEAN" -%typemap(m3wrapouttype) char, char *, char & "CHAR" -%typemap(m3wrapouttype) signed char, signed char *, signed char & "CHAR" -%typemap(m3wrapouttype) unsigned char, unsigned char *, unsigned char & "CHAR" -%typemap(m3wrapouttype) short, short *, short & "INTEGER" -%typemap(m3wrapouttype) unsigned short, unsigned short *, unsigned short & "CARDINAL" -%typemap(m3wrapouttype) int, int *, int & "INTEGER" -%typemap(m3wrapouttype) unsigned int, unsigned int *, unsigned int & "CARDINAL" -%typemap(m3wrapouttype) long, long *, long & "INTEGER" -%typemap(m3wrapouttype) unsigned long, unsigned long *, unsigned long & "CARDINAL" -%typemap(m3wrapouttype) long long, long long *, long long & "INTEGER" -%typemap(m3wrapouttype) unsigned long long, unsigned long long *, unsigned long long & "CARDINAL" -%typemap(m3wrapouttype) float, float *, float & "REAL" -%typemap(m3wrapouttype) double, double *, double & "LONGREAL" -%typemap(m3wrapouttype) long double, long double *, long double & "EXTENDED" -%typemap(m3wrapouttype) char *, char [] "TEXT" -%typemap(m3wrapouttype,numinputs=0) void "" - -%typemap(m3wraprettype) bool, const bool & "BOOLEAN" -%typemap(m3wraprettype) char, const char & "CHAR" -%typemap(m3wraprettype) signed char, const signed char & "CHAR" -%typemap(m3wraprettype) unsigned char, const unsigned char & "CHAR" -%typemap(m3wraprettype) short, const short & "INTEGER" -%typemap(m3wraprettype) unsigned short, const unsigned short & "CARDINAL" -%typemap(m3wraprettype) int, const int & "INTEGER" -%typemap(m3wraprettype) unsigned int, const unsigned int & "CARDINAL" -%typemap(m3wraprettype) long, const long & "INTEGER" -%typemap(m3wraprettype) unsigned long, const unsigned long & "CARDINAL" -%typemap(m3wraprettype) long long, const long long & "INTEGER" -%typemap(m3wraprettype) unsigned long long, const unsigned long long & "CARDINAL" -%typemap(m3wraprettype) float, const float & "REAL" -%typemap(m3wraprettype) double, const double & "LONGREAL" -%typemap(m3wraprettype) long double, const long double & "EXTENDED" -%typemap(m3wraprettype) char * "TEXT" -%typemap(m3wraprettype) void "" -%typemap(m3wraprettype) FILE "Cstdio.FILE"; -%typemap(m3wraprettype) FILE * "Cstdio.FILE_star"; - - -%typemap(ctype) char[ANY] "char *" -%typemap(m3rawtype) char[ANY] "C.char_star" -%typemap(m3rawintype) char[ANY] "C.char_star" -%typemap(m3rawrettype) char[ANY] "C.char_star" -%typemap(m3wraptype) char[ANY] "TEXT" -%typemap(m3wrapintype) char[ANY] "TEXT" -%typemap(m3wrapouttype) char[ANY] "TEXT" -%typemap(m3wraprettype) char[ANY] "TEXT" - -%typemap(m3wrapinmode) const char * %{%} -%typemap(m3wrapargvar) const char * %{$1 : C.char_star;%} -%typemap(m3wrapinconv) const char * %{$1 := M3toC.SharedTtoS($1_name);%} -%typemap(m3wrapfreearg) const char * %{M3toC.FreeSharedS($1_name,$1);%} -%typemap(m3wrapargraw) const char * %{$1%} -%typemap("m3wrapargvar:import") const char * "Ctypes AS C" -%typemap("m3wrapinconv:import") const char * "M3toC" -%typemap("m3wrapfreearg:import") const char * "M3toC" - -%typemap(m3wrapretvar) char * %{result : C.char_star;%} -%typemap(m3wrapretraw) char * %{result%} -%typemap(m3wrapretconv) char * %{M3toC.CopyStoT(result)%} -%typemap("m3wrapretvar:import") char * "Ctypes AS C" -%typemap("m3wrapretconv:import") char * "M3toC" - -%typemap(m3wrapinmode) FILE * %{%} - - -%typemap("m3wraptype:import") - FILE, FILE * - "Cstdio"; - -%typemap("m3wrapintype:import") - FILE, FILE * - "Cstdio"; - -%typemap("m3wraprettype:import") - FILE, FILE * - "Cstdio"; - - -/* Composed types */ -%typemap(ctype) SWIGTYPE "$1_type" -%typemap(m3rawtype) SWIGTYPE "$1_basetype" -%typemap(m3rawrettype) SWIGTYPE "UNTRACED REF $1_basetype" -%typemap(m3wraptype) SWIGTYPE "$1_basetype" -%typemap(m3wrapintype) SWIGTYPE "$1_basetype" -%typemap(m3wrapouttype) SWIGTYPE "$1_basetype" -%typemap(m3wraprettype) SWIGTYPE "$1_basetype" - -%typemap(ctype) SWIGTYPE [] "$1_type" -%typemap(m3rawtype) const SWIGTYPE [] "UNTRACED REF ARRAY INTEGER OF $1_basetype" -%typemap(m3rawtype) SWIGTYPE [] "UNTRACED REF ARRAY INTEGER OF $1_basetype" -%typemap(m3rawintype) const SWIGTYPE [] "(*ARRAY OF*) $1_basetype" -%typemap(m3rawinmode) const SWIGTYPE [] "READONLY" -%typemap(m3rawintype) SWIGTYPE [] "(*ARRAY OF*) $1_basetype" -%typemap(m3rawinmode) SWIGTYPE [] "VAR" -%typemap(m3rawrettype) const SWIGTYPE [] "UNTRACED REF ARRAY INTEGER OF $1_basetype" -%typemap(m3rawrettype) SWIGTYPE [] "UNTRACED REF ARRAY INTEGER OF $1_basetype" -%typemap(m3wraptype) SWIGTYPE [] "$1_basetype" -%typemap(m3wrapintype) const SWIGTYPE [] "ARRAY OF $1_basetype" -%typemap(m3wrapinmode) const SWIGTYPE [] "READONLY" -%typemap(m3wrapintype) SWIGTYPE [] "ARRAY OF $1_basetype" -%typemap(m3wrapinmode) SWIGTYPE [] "VAR" -%typemap(m3wrapouttype) SWIGTYPE [] "ARRAY OF $1_basetype" -%typemap(m3wraprettype) SWIGTYPE [] "REF ARRAY OF $1_basetype" - -%typemap(ctype) SWIGTYPE * "$1_type" -%typemap(m3rawtype) const SWIGTYPE * "UNTRACED REF $1_basetype" -%typemap(m3rawtype) SWIGTYPE * "UNTRACED REF $1_basetype" -%typemap(m3rawintype) const SWIGTYPE * "$1_basetype" -%typemap(m3rawinmode) const SWIGTYPE * "READONLY" -%typemap(m3rawintype) SWIGTYPE * "$1_basetype" -%typemap(m3rawinmode) SWIGTYPE * "VAR" -%typemap(m3rawrettype) const SWIGTYPE * "UNTRACED REF $1_basetype" -%typemap(m3rawrettype) SWIGTYPE * "UNTRACED REF $1_basetype" -%typemap(m3wraptype) SWIGTYPE * "$1_basetype" -%typemap(m3wrapintype) const SWIGTYPE * "$1_basetype" -%typemap(m3wrapinmode) const SWIGTYPE * "READONLY" -%typemap(m3wrapintype) SWIGTYPE * "$1_basetype" -%typemap(m3wrapinmode) SWIGTYPE * "VAR" -%typemap(m3wrapouttype) SWIGTYPE * "$1_basetype" -%typemap(m3wraprettype) SWIGTYPE * "UNTRACED REF $1_basetype" - -%typemap(ctype) SWIGTYPE & "$1_type" -%typemap(m3rawtype) const SWIGTYPE & "UNTRACED REF $1_basetype" -%typemap(m3rawtype) SWIGTYPE & "UNTRACED REF $1_basetype" -%typemap(m3rawintype) const SWIGTYPE & "$1_basetype" -%typemap(m3rawinmode) const SWIGTYPE & "READONLY" -%typemap(m3rawintype) SWIGTYPE & "$1_basetype" -%typemap(m3rawinmode) SWIGTYPE & "VAR" -%typemap(m3rawrettype) const SWIGTYPE & "UNTRACED REF $1_basetype" -%typemap(m3rawrettype) SWIGTYPE & "UNTRACED REF $1_basetype" -%typemap(m3wraptype) SWIGTYPE & "$1_basetype" -%typemap(m3wrapintype) const SWIGTYPE & "$1_basetype" -%typemap(m3wrapinmode) const SWIGTYPE & "READONLY" -%typemap(m3wrapintype) SWIGTYPE & "$1_basetype" -%typemap(m3wrapinmode) SWIGTYPE & "VAR" -%typemap(m3wrapouttype) SWIGTYPE & "$1_basetype" -%typemap(m3wraprettype) SWIGTYPE & "UNTRACED REF $1_basetype" - -%typemap(ctype) SWIGTYPE && "$1_type" -%typemap(m3rawtype) const SWIGTYPE && "UNTRACED REF $1_basetype" -%typemap(m3rawtype) SWIGTYPE && "UNTRACED REF $1_basetype" -%typemap(m3rawintype) const SWIGTYPE && "$1_basetype" -%typemap(m3rawinmode) const SWIGTYPE && "READONLY" -%typemap(m3rawintype) SWIGTYPE && "$1_basetype" -%typemap(m3rawinmode) SWIGTYPE && "VAR" -%typemap(m3rawrettype) const SWIGTYPE && "UNTRACED REF $1_basetype" -%typemap(m3rawrettype) SWIGTYPE && "UNTRACED REF $1_basetype" -%typemap(m3wraptype) SWIGTYPE && "$1_basetype" -%typemap(m3wrapintype) const SWIGTYPE && "$1_basetype" -%typemap(m3wrapinmode) const SWIGTYPE && "READONLY" -%typemap(m3wrapintype) SWIGTYPE && "$1_basetype" -%typemap(m3wrapinmode) SWIGTYPE && "VAR" -%typemap(m3wrapouttype) SWIGTYPE && "$1_basetype" -%typemap(m3wraprettype) SWIGTYPE && "UNTRACED REF $1_basetype" - -%typemap(ctype) enum SWIGTYPE "$1_type" -%typemap(m3rawtype) enum SWIGTYPE "C.int" -%typemap(m3rawintype) enum SWIGTYPE "C.int (* $1_type *)" -%typemap(m3rawrettype) enum SWIGTYPE "C.int" -%typemap(m3wraptype) enum SWIGTYPE "$*1_type" -%typemap(m3wrapintype) enum SWIGTYPE "$1_type" -%typemap(m3wrapouttype) enum SWIGTYPE "$1_type" -%typemap(m3wraprettype) enum SWIGTYPE "$*1_type" - -/* pointer to a class member */ -%typemap(ctype) SWIGTYPE (CLASS::*) "$1_type" -%typemap(m3rawtype) SWIGTYPE (CLASS::*) "REFANY" -%typemap(m3wraptype) SWIGTYPE (CLASS::*) "$1_basetype" - -/* The following are the in, out, freearg, argout typemaps. - These are the PInvoke code generating typemaps for converting from C# to C and visa versa. */ - -/* primitive types */ -%typemap(in) bool -%{ $1 = $input ? true : false; %} - -%typemap(in) char, - signed char, - unsigned char, - short, - unsigned short, - int, - unsigned int, - long, - unsigned long, - long long, - unsigned long long, - float, - double, - enum SWIGTYPE -%{ $1 = ($1_ltype)$input; %} - -%typemap(out) bool %{ $result = $1; %} -%typemap(out) char %{ $result = $1; %} -%typemap(out) signed char %{ $result = $1; %} -%typemap(out) unsigned char %{ $result = $1; %} -%typemap(out) short %{ $result = $1; %} -%typemap(out) unsigned short %{ $result = $1; %} -%typemap(out) int %{ $result = $1; %} -%typemap(out) unsigned int %{ $result = $1; %} -%typemap(out) long %{ $result = $1; %} -%typemap(out) unsigned long %{ $result = $1; %} -%typemap(out) long long %{ $result = $1; %} -%typemap(out) unsigned long long %{ $result = $1; %} -%typemap(out) float %{ $result = $1; %} -%typemap(out) double %{ $result = $1; %} -%typemap(out) enum SWIGTYPE %{ $result = $1; %} - -/* char * - treat as String */ -%typemap(in) char * { - $1 = $input; -} -//%typemap(freearg) char * { if ($1) JCALL2(ReleaseStringUTFChars, jenv, $input, $1); } -//%typemap(out) char * { if($1) $result = JCALL1(NewStringUTF, jenv, $1); } - -%typemap(out) void "" - -/* primitive types by const reference */ -%typemap(in) const bool & (bool temp) -%{ temp = $input ? true : false; - $1 = &temp; %} - -%typemap(in) const char & (char temp), - const signed char & (signed char temp), - const unsigned char & (unsigned char temp), - const short & (short temp), - const unsigned short & (unsigned short temp), - const int & (int temp), - const unsigned int & (unsigned int temp), - const long & (long temp), - const unsigned long & (unsigned long temp), - const long long & ($*1_ltype temp), - const unsigned long long & ($*1_ltype temp), - const float & (float temp), - const double & (double temp) -%{ temp = ($*1_ltype)$input; -$1 = &temp; %} - -%typemap(out) const bool & %{ $result = *$1; %} -%typemap(out) const char & %{ $result = *$1; %} -%typemap(out) const signed char & %{ $result = *$1; %} -%typemap(out) const unsigned char & %{ $result = *$1; %} -%typemap(out) const short & %{ $result = *$1; %} -%typemap(out) const unsigned short & %{ $result = *$1; %} -%typemap(out) const int & %{ $result = *$1; %} -%typemap(out) const unsigned int & %{ $result = *$1; %} -%typemap(out) const long & %{ $result = *$1; %} -%typemap(out) const unsigned long & %{ $result = *$1; %} -%typemap(out) const long long & %{ $result = *$1; %} -%typemap(out) const unsigned long long & %{ $result = *$1; %} -%typemap(out) const float & %{ $result = *$1; %} -%typemap(out) const double & %{ $result = *$1; %} - -/* Default handling. Object passed by value. Convert to a pointer */ -%typemap(in) SWIGTYPE ($&1_type argp) -%{ argp = *($&1_ltype*)&$input; - if (!argp) { -// SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null $1_type"); - RETURN $null; - } - $1 = *argp; %} -%typemap(out) SWIGTYPE -#ifdef __cplusplus -%{*($&1_ltype*)&$result = new $1_ltype((const $1_ltype &)$1); %} -#else -{ - $&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype)); - memmove($1ptr, &$1, sizeof($1_type)); - *($&1_ltype*)&$result = $1ptr; -} -#endif - -/* Generic pointers and references */ -%typemap(in) SWIGTYPE *, SWIGTYPE (CLASS::*) %{ $1 = *($&1_ltype)&$input; %} -%typemap(in) SWIGTYPE & %{ $1 = *($&1_ltype)&$input; - if(!$1) { - //SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null"); - RETURN $null; - } %} -%typemap(in) SWIGTYPE && %{ $1 = *($&1_ltype)&$input; - if(!$1) { - //SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null"); - RETURN $null; - } %} -%typemap(out) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE (CLASS::*) %{ *($&1_ltype)&$result = $1; %} - - -/* Default array handling */ -%typemap(in) SWIGTYPE [] %{ $1 = *($&1_ltype)&$input; %} -%typemap(out) SWIGTYPE [] %{ *($&1_ltype)&$result = $1; %} - -/* char[ANY] - treat as String */ -%typemap(in) char[ANY] { - $1 = $input; -} - -%typemap(argout) char[ANY] "" -%typemap(freearg) char[ANY] ""//{ if ($1) JCALL2(ReleaseStringUTFChars, jenv, $input, $1); } -%typemap(out) char[ANY] { if($1) $result = $1; } - - -/* Typecheck typemaps - The purpose of these is merely to issue a warning for overloaded C++ functions - * that cannot be overloaded in C# as more than one C++ type maps to a single C# type */ - -%typecheck(SWIG_TYPECHECK_BOOL) /* Java boolean */ - bool, - const bool & - "" - -%typecheck(SWIG_TYPECHECK_CHAR) /* Java char */ - char, - const char & - "" - -%typecheck(SWIG_TYPECHECK_INT8) /* Java byte */ - signed char, - const signed char & - "" - -%typecheck(SWIG_TYPECHECK_INT16) /* Java short */ - unsigned char, - short, - const unsigned char &, - const short & - "" - -%typecheck(SWIG_TYPECHECK_INT32) /* Java int */ - unsigned short, - int, - long, - const unsigned short &, - const int &, - const long &, - enum SWIGTYPE - "" - -%typecheck(SWIG_TYPECHECK_INT64) /* Java long */ - unsigned int, - unsigned long, - long long, - const unsigned int &, - const unsigned long &, - const long long & - "" - -%typecheck(SWIG_TYPECHECK_INT128) /* Java BigInteger */ - unsigned long long - "" - -%typecheck(SWIG_TYPECHECK_FLOAT) /* Java float */ - float, - const float & - "" - -%typecheck(SWIG_TYPECHECK_DOUBLE) /* Java double */ - double, - const double & - "" - -%typecheck(SWIG_TYPECHECK_STRING) /* Java String */ - char *, - char[ANY] - "" - -%typecheck(SWIG_TYPECHECK_POINTER) /* Default */ - SWIGTYPE, - SWIGTYPE *, - SWIGTYPE &, - SWIGTYPE &&, - SWIGTYPE [], - SWIGTYPE (CLASS::*) - "" - -/* Exception handling */ - -%typemap(throws) int, - long, - short, - unsigned int, - unsigned long, - unsigned short { - char error_msg[256]; - sprintf(error_msg, "C++ $1_type exception thrown, value: %d", $1); - SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, error_msg); - RETURN $null; -} - -%typemap(throws) SWIGTYPE { - (void)$1; - SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "C++ $1_type exception thrown"); - RETURN $null; -} - -%typemap(throws) char * { - SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1); - RETURN $null; -} - - -/* Typemaps for code generation in proxy classes and C# type wrapper classes */ - -/* The in typemap is used for converting function parameter types from the type - * used in the proxy, module or type wrapper class to the type used in the PInvoke class. */ -%typemap(m3in) bool, const bool &, - char, const char &, - signed char, const signed char &, - unsigned char, const unsigned char &, - short, const short &, - unsigned short, const unsigned short &, - int, const int &, - unsigned int, const unsigned int &, - long, const long &, - unsigned long, const unsigned long &, - long long, const long long &, - unsigned long long, const unsigned long long &, - float, const float &, - double, const double &, - char *, - char[ANY], - enum SWIGTYPE - "$input" -%typemap(m3in) SWIGTYPE "$&*1_type.getCPtr($input)" -%typemap(m3in) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "$1_basetype.getCPtr($input)" - -/* The m3out typemap is used for converting function return types from the return type - * used in the PInvoke class to the type returned by the proxy, module or type wrapper class. */ -%typemap(m3out) bool, const bool &, - char, const char &, - signed char, const signed char &, - unsigned char, const unsigned char &, - short, const short &, - unsigned short, const unsigned short &, - int, const int &, - unsigned int, const unsigned int &, - long, const long &, - unsigned long, const unsigned long &, - long long, const long long &, - unsigned long long, const unsigned long long &, - float, const float &, - double, const double &, - char *, - char[ANY], - enum SWIGTYPE -%{$imcall%} - -%typemap(m3out) void %{$imcall%} - -%typemap(m3out) SWIGTYPE %{ - RETURN NEW(REF $1_basetype, $imcall); -%} -%typemap(m3out) SWIGTYPE & %{ - RETURN NEW($1_basetype, $imcall, $owner); -%} -%typemap(m3out) SWIGTYPE && %{ - RETURN NEW($1_basetype, $imcall, $owner); -%} -%typemap(m3out) SWIGTYPE *, SWIGTYPE [], SWIGTYPE (CLASS::*) %{ - cPtr := $imcall; - RETURN (cPtr = IntPtr.Zero) ? null : NEW($1_basetype, cPtr, $owner); -%} - -/* Properties */ -%typemap(m3varin) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) %{ -PROCEDURE Set$var (value: $vartype) = - BEGIN - $imcall; - END Set$var; -%} - -%typemap(m3varout) bool, const bool &, - char, const char &, - signed char, const signed char &, - unsigned char, const unsigned char &, - short, const short &, - unsigned short, const unsigned short &, - int, const int &, - unsigned int, const unsigned int &, - long, const long &, - unsigned long, const unsigned long &, - long long, const long long &, - unsigned long long, const unsigned long long &, - float, const float &, - double, const double &, - char *, - char[ANY], - enum SWIGTYPE %{ -PROCEDURE Get$var (): $vartype = - BEGIN - RETURN $imcall; - END Get$var; -%} - -%typemap(m3varout) void %{ - get { - $imcall; - } %} -%typemap(m3varout) SWIGTYPE %{ - get { - RETURN new $&*1_mangle($imcall, true); - } %} -%typemap(m3varout) SWIGTYPE & %{ - get { - RETURN new $1_basetype($imcall, $owner); - } %} -%typemap(m3varout) SWIGTYPE && %{ - get { - RETURN new $1_basetype($imcall, $owner); - } %} -%typemap(m3varout) SWIGTYPE *, SWIGTYPE [], SWIGTYPE (CLASS::*) %{ - get { - IntPtr cPtr = $imcall; - RETURN (cPtr == IntPtr.Zero) ? null : new $1_basetype(cPtr, $owner); - } %} - -/* Typemaps used for the generation of proxy and type wrapper class code */ -%typemap(m3base) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" -%typemap(m3classmodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "public" -%typemap(m3code) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" -%typemap(m3imports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "using System;" -%typemap(m3interfaces) SWIGTYPE "IDisposable" -%typemap(m3interfaces_derived) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" -%typemap(m3ptrconstructormodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) "internal" - -%typemap(m3finalize) SWIGTYPE %{ - ~$1_basetype() { - Dispose(); - } -%} - -%typemap(m3destruct, methodname="Dispose") SWIGTYPE { - if(swigCPtr != IntPtr.Zero && swigCMemOwn) { - $imcall; - swigCMemOwn = false; - } - swigCPtr = IntPtr.Zero; - GC.SuppressFinalize(this); - } - -%typemap(m3destruct_derived, methodname="Dispose") SWIGTYPE { - if(swigCPtr != IntPtr.Zero && swigCMemOwn) { - $imcall; - swigCMemOwn = false; - } - swigCPtr = IntPtr.Zero; - GC.SuppressFinalize(this); - base.Dispose(); - } - -%typemap(m3getcptr) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [], SWIGTYPE (CLASS::*) %{ - internal static IntPtr getCPtr($1_basetype obj) { - RETURN (obj == null) ? IntPtr.Zero : obj.swigCPtr; - } -%} - -/* M3 specific directives */ -#define %m3multiretval %feature("modula3:multiretval") -#define %constnumeric(num) %feature("constnumeric","num") - -%pragma(modula3) moduleimports=%{ -IMPORT BlaBla; -%} - -%pragma(modula3) imclassimports=%{ -FROM BlaBla IMPORT Bla; -%} - -/* Some ANSI C typemaps */ - -%apply unsigned long { size_t }; - -/* Array reference typemaps */ -%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } -%apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) } - -/* const pointers */ -%apply SWIGTYPE * { SWIGTYPE *const } -%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) } -%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) } - diff --git a/Lib/modula3/modula3head.swg b/Lib/modula3/modula3head.swg deleted file mode 100644 index af96a78d1..000000000 --- a/Lib/modula3/modula3head.swg +++ /dev/null @@ -1,64 +0,0 @@ -/* ----------------------------------------------------------------------------- - * modula3head.swg - * - * Modula3 support code - * ----------------------------------------------------------------------------- */ - -%insert(runtime) %{ - -#include -#include -#include -%} - -#if 0 -%insert(runtime) %{ -/* Support for throwing Modula3 exceptions */ -typedef enum { - SWIG_JavaOutOfMemoryError = 1, - SWIG_JavaIOException, - SWIG_JavaRuntimeException, - SWIG_JavaIndexOutOfBoundsException, - SWIG_JavaArithmeticException, - SWIG_JavaIllegalArgumentException, - SWIG_JavaNullPointerException, - SWIG_JavaUnknownError -} SWIG_JavaExceptionCodes; - -typedef struct { - SWIG_JavaExceptionCodes code; - const char *java_exception; -} SWIG_JavaExceptions_t; - -#if defined(SWIG_NOINCLUDE) -void SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg); -#else -%} -%insert(runtime) { -void SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg) { - jclass excep; - static const SWIG_JavaExceptions_t java_exceptions[] = { - { SWIG_JavaOutOfMemoryError, "java/lang/OutOfMemoryError" }, - { SWIG_JavaIOException, "java/io/IOException" }, - { SWIG_JavaRuntimeException, "java/lang/RuntimeException" }, - { SWIG_JavaIndexOutOfBoundsException, "java/lang/IndexOutOfBoundsException" }, - { SWIG_JavaArithmeticException, "java/lang/ArithmeticException" }, - { SWIG_JavaIllegalArgumentException, "java/lang/IllegalArgumentException" }, - { SWIG_JavaNullPointerException, "java/lang/NullPointerException" }, - { SWIG_JavaUnknownError, "java/lang/UnknownError" }, - { (SWIG_JavaExceptionCodes)0, "java/lang/UnknownError" } }; - const SWIG_JavaExceptions_t *except_ptr = java_exceptions; - - while (except_ptr->code != code && except_ptr->code) - except_ptr++; - - JCALL0(ExceptionClear, jenv); - excep = JCALL1(FindClass, jenv, except_ptr->java_exception); - if (excep) - JCALL2(ThrowNew, jenv, excep, msg); -} -} -%insert(runtime) %{ -#endif -%} -#endif diff --git a/Lib/modula3/typemaps.i b/Lib/modula3/typemaps.i deleted file mode 100644 index 1d76ab5e0..000000000 --- a/Lib/modula3/typemaps.i +++ /dev/null @@ -1,74 +0,0 @@ -/* ----------------------------------------------------------------------------- - * typemaps.i - * - * Pointer and reference handling typemap library - * - * These mappings provide support for input/output arguments and common - * uses for C/C++ pointers and C++ references. - * ----------------------------------------------------------------------------- */ - -/* These typemaps will eventually probably maybe make their way into named typemaps - * OUTPUT * and OUTPUT & as they currently break functions that return a pointer or - * reference. */ - -%typemap(ctype) bool *, bool & "bool *" -%typemap(ctype) char & "char *" -%typemap(ctype) signed char *, signed char & "signed char *" -%typemap(ctype) unsigned char *, unsigned char & "unsigned short *" -%typemap(ctype) short *, short & "short *" -%typemap(ctype) unsigned short *, unsigned short & "unsigned short *" -%typemap(ctype) int *, int & "int *" -%typemap(ctype) unsigned int *, unsigned int & "unsigned int *" -%typemap(ctype) long *, long & "long *" -%typemap(ctype) unsigned long *, unsigned long & "unsigned long *" -%typemap(ctype) long long *, long long & "long long *" -%typemap(ctype) unsigned long long *, unsigned long long & "unsigned long long *" -%typemap(ctype) float *, float & "float *" -%typemap(ctype) double *, double & "double *" - -%typemap(imtype) bool *, bool & "ref bool" -%typemap(imtype) char & "ref char" -%typemap(imtype) signed char *, signed char & "ref sbyte" -%typemap(imtype) unsigned char *, unsigned char & "ref byte" -%typemap(imtype) short *, short & "ref short" -%typemap(imtype) unsigned short *, unsigned short & "ref ushort" -%typemap(imtype) int *, int & "ref int" -%typemap(imtype) unsigned int *, unsigned int & "ref uint" -%typemap(imtype) long *, long & "ref int" -%typemap(imtype) unsigned long *, unsigned long & "ref uint" -%typemap(imtype) long long *, long long & "ref long" -%typemap(imtype) unsigned long long *, unsigned long long & "ref ulong" -%typemap(imtype) float *, float & "ref float" -%typemap(imtype) double *, double & "ref double" - -%typemap(cstype) bool *, bool & "ref bool" -%typemap(cstype) char & "ref char" -%typemap(cstype) signed char *, signed char & "ref sbyte" -%typemap(cstype) unsigned char *, unsigned char & "ref byte" -%typemap(cstype) short *, short & "ref short" -%typemap(cstype) unsigned short *, unsigned short & "ref ushort" -%typemap(cstype) int *, int & "ref int" -%typemap(cstype) unsigned int *, unsigned int & "ref uint" -%typemap(cstype) long *, long & "ref int" -%typemap(cstype) unsigned long *, unsigned long & "ref uint" -%typemap(cstype) long long *, long long & "ref long" -%typemap(cstype) unsigned long long *, unsigned long long & "ref ulong" -%typemap(cstype) float *, float & "ref float" -%typemap(cstype) double *, double & "ref double" - -%typemap(csin) bool *, bool &, - char &, - signed char *, signed char &, - unsigned char *, unsigned char &, - short *, short &, - unsigned short *, unsigned short &, - int *, int &, - unsigned int *, unsigned int &, - long *, long &, - unsigned long *, unsigned long &, - long long *, long long &, - unsigned long long *, unsigned long long &, - float *, float &, - double *, double & - "ref $csinput" - -- cgit v1.2.1 From 11bb422bd33524fbeb215b5108c881f6ecaf3c4f Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 13 May 2021 11:11:40 +1200 Subject: [Pike] Remove code for Pike We dropped support for it in SWIG 4.0.0 and nobody has stepped forward to revive it in over 2 years. See #2009. --- Lib/pike/pike.swg | 326 -------------------------------------------------- Lib/pike/pikekw.swg | 55 --------- Lib/pike/pikerun.swg | 71 ----------- Lib/pike/std_string.i | 60 ---------- 4 files changed, 512 deletions(-) delete mode 100644 Lib/pike/pike.swg delete mode 100644 Lib/pike/pikekw.swg delete mode 100644 Lib/pike/pikerun.swg delete mode 100644 Lib/pike/std_string.i (limited to 'Lib') diff --git a/Lib/pike/pike.swg b/Lib/pike/pike.swg deleted file mode 100644 index a36bf3ad2..000000000 --- a/Lib/pike/pike.swg +++ /dev/null @@ -1,326 +0,0 @@ -/* ----------------------------------------------------------------------------- - * pike.swg - * - * Pike configuration module. - * ----------------------------------------------------------------------------- */ - -%insert(runtime) "swigrun.swg"; // Common C API type-checking code -%insert(runtime) "pikerun.swg"; // Pike run-time code - -%insert(runtime) %{ -#ifdef __cplusplus -extern "C" { -#endif -#include -#include -#include -#ifdef __cplusplus -} -#endif -%} - -/* ----------------------------------------------------------------------------- - * standard typemaps - * ----------------------------------------------------------------------------- */ - -/* --- Input arguments --- */ - -/* Primitive datatypes. */ - -%typemap(in, pikedesc="tInt") - int, unsigned int, short, unsigned short, - long, unsigned long, char, signed char, unsigned char, - bool, enum SWIGTYPE, long long, unsigned long long -{ - if ($input.type != T_INT) - Pike_error("Bad argument: Expected an integer.\n"); - $1 = ($1_ltype) $input.u.integer; -} - -%typemap(in, pikedesc="tFloat") float, double { - if ($input.type != T_FLOAT) - Pike_error("Bad argument: Expected a float.\n"); - $1 = ($1_ltype) $input.u.float_number; -} - -%typemap(in, pikedesc="tStr") char *, char [ANY] { - if ($input.type != T_STRING) - Pike_error("Bad argument: Expected a string.\n"); - $1 = ($1_ltype) STR0($input.u.string); -} - -/* Pointers, references and arrays */ - -%typemap(in) SWIGTYPE *, - SWIGTYPE &, - SWIGTYPE &&, - SWIGTYPE [] - "SWIG_ConvertPtr($input.u.object, (void **) &$1, $1_descriptor, 1);" - -/* Void pointer. Accepts any kind of pointer */ -%typemap(in) void * "/* FIXME */"; - -/* Object passed by value. Convert to a pointer */ -%typemap(in) SWIGTYPE ($&1_ltype argp) "/* FIXME */"; - -/* Pointer to a class member */ -%typemap(in) SWIGTYPE (CLASS::*) "/* FIXME */"; - -/* Const primitive references. Passed by value */ - -%typemap(in, pikedesc="tInt") const int & (int temp), - const short & (short temp), - const long & (long temp), - const unsigned int & (unsigned int temp), - const unsigned short & (unsigned short temp), - const unsigned long & (unsigned long temp), - const char & (char temp), - const signed char & (signed char temp), - const unsigned char & (unsigned char temp), - const bool & (bool temp), - const long long & ($*1_ltype temp), - const unsigned long long & ($*1_ltype temp), - const enum SWIGTYPE & ($*1_ltype temp), - const enum SWIGTYPE && ($*1_ltype temp) -{ - if ($input.type != T_INT) - Pike_error("Bad argument: Expected an integer.\n"); - temp = ($*1_ltype) $input.u.integer; - $1 = &temp; -} - -%typemap(in, pikedesc="tFloat") const float & (float temp), - const double & (double temp) -{ - if ($input.type != T_FLOAT) - Pike_error("Bad argument: Expected a float.\n"); - temp = ($*1_ltype) $input.u.float_number; - $1 = &temp; -} - -/* ----------------------------------------------------------------------------- - * Output Typemaps - * ----------------------------------------------------------------------------- */ -%typemap(out, pikedesc="tInt") - int, unsigned int, - short, unsigned short, - long, unsigned long, - char, signed char, unsigned char, - bool, enum SWIGTYPE - "push_int($1);"; - -%typemap(out, pikedesc="tInt") long long "push_int64($1);"; -%typemap(out, pikedesc="tInt") unsigned long long "push_int64($1);"; -%typemap(out, pikedesc="tFloat") float, double "push_float($1);"; -%typemap(out, pikedesc="tStr") char * "push_text($1);"; - -/* Pointers, references, and arrays */ -%typemap(out, pikedesc="tObj") SWIGTYPE*, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] "push_object(SWIG_NewPointerObj((void *) $1, $1_descriptor, $owner));"; - -/* Void return value; don't push anything */ -%typemap(out, pikedesc="tVoid") void ""; - -/* Dynamic casts */ - -%typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC "/* FIXME */"; - -/* Member pointer */ -%typemap(out) SWIGTYPE (CLASS::*) "/* FIXME */"; - -/* Special typemap for character array return values */ -%typemap(out, pikedesc="tStr") char [ANY], const char [ANY] "push_text($1);"; - -/* Primitive types--return by value */ -%typemap(out, pikedesc="tObj") SWIGTYPE -#ifdef __cplusplus -{ - $&1_ltype resultptr; - resultptr = new $1_ltype((const $1_ltype &) $1); - push_object(SWIG_NewPointerObj((void *) resultptr, $&1_descriptor, 1)); -} -#else -{ - $&1_ltype resultptr; - resultptr = ($&1_ltype) malloc(sizeof($1_type)); - memmove(resultptr, &$1, sizeof($1_type)); - push_object(SWIG_NewPointerObj((void *) resultptr, $&1_descriptor, 1)); -} -#endif - -/* References to primitive types. Return by value */ - -%typemap(out, pikedesc="tInt") const int &, const unsigned int &, - const short &, const unsigned short &, - const long &, const unsigned long &, - const char &, const signed char &, const unsigned char &, - const bool &, - const long long &, const unsigned long long &, - const enum SWIGTYPE & ($*1_ltype temp), - const enum SWIGTYPE && ($*1_ltype temp) - "push_int(*($1));"; - -%typemap(out, pikedesc="tFloat") const float &, const double & "push_float(*($1));"; - -/************************ Constant Typemaps *****************************/ - -%typemap(constant) - int, unsigned int, - short, unsigned short, - long, unsigned long, - signed char, unsigned char, - bool, enum SWIGTYPE, - long long, unsigned long long - "add_integer_constant(\"$symname\", $1, 0);"; - -%typemap(constant) char - "add_integer_constant(\"$symname\", '$1', 0);"; - -%typemap(constant) long long, unsigned long long - "add_integer_constant(\"$symname\", $1, 0);"; - -%typemap(constant) float, double - "add_float_constant(\"$symname\", $1, 0);"; - -%typemap(constant) char * - "add_string_constant(\"$symname\", \"$1\", 0);"; - -/* ------------------------------------------------------------ - * String & length - * ------------------------------------------------------------ */ - -%typemap(in) (char *STRING, int LENGTH), (char *STRING, size_t LENGTH) { - if ($input.type != T_STRING) - Pike_error("Bad argument: Expected a string.\n"); - $1 = ($1_ltype) STR0($input.u.string); - $2 = ($2_ltype) $input.u.string->length; -} - -/* ------------------------------------------------------------ - * ANSI C typemaps - * ------------------------------------------------------------ */ - -%typemap(in, pikedesc="tInt") size_t { - if ($input.type != T_INT) - Pike_error("Bad argument: Expected an integer.\n"); - $1 = ($1_ltype) $input.u.integer; -} - -%typemap(out) size_t = long; - -/* ------------------------------------------------------------ - * Typechecking rules - * ------------------------------------------------------------ */ - -%typecheck(SWIG_TYPECHECK_INTEGER) - int, short, long, - unsigned int, unsigned short, unsigned long, - signed char, unsigned char, - long long, unsigned long long, - const int &, const short &, const long &, - const unsigned int &, const unsigned short &, const unsigned long &, - const long long &, const unsigned long long &, - enum SWIGTYPE, enum SWIGTYPE &, SWIGTYPE &&, - bool, const bool & -{ - $1 = ($input.type == T_INT) ? 1 : 0; -} - -%typecheck(SWIG_TYPECHECK_DOUBLE) - float, double, - const float &, const double & -{ - $1 = (($input.type == T_FLOAT) || ($input.type == T_INT)) ? 1 : 0; -} - -%typecheck(SWIG_TYPECHECK_CHAR) char { - $1 = ($input.type == T_INT) ? 1 : 0; -} - -%typecheck(SWIG_TYPECHECK_STRING) char * { - $1 = ($input.type == T_STRING) ? 1 : 0; -} - -%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] { - void *ptr; - if (SWIG_ConvertPtr($input.u.object, (void **) &ptr, $1_descriptor, 0) == -1) { - $1 = 0; - } else { - $1 = 1; - } -} - -%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE { - void *ptr; - if (SWIG_ConvertPtr($input.u.object, (void **) &ptr, $&1_descriptor, 0) == -1) { - $1 = 0; - } else { - $1 = 1; - } -} - -%typecheck(SWIG_TYPECHECK_VOIDPTR) void * { - void *ptr; - if (SWIG_ConvertPtr($input.u.object, (void **) &ptr, 0, 0) == -1) { - $1 = 0; - } else { - $1 = 1; - } -} - -/* Array reference typemaps */ -%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } -%apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) } - -/* const pointers */ -%apply SWIGTYPE * { SWIGTYPE *const } -%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) } -%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) } - -/* ------------------------------------------------------------ - * Overloaded operator support - * ------------------------------------------------------------ */ - -#ifdef __cplusplus -%rename("`+") *::operator+; -%rename("`-") *::operator-; -%rename("`*") *::operator*; -%rename("`/") *::operator/; -%rename("`%") *::operator%; -%rename("`<<") *::operator<<; -%rename("`>>") *::operator>>; -%rename("`&") *::operator&; -%rename("`|") *::operator|; -%rename("`^") *::operator^; -%rename("`~") *::operator~; -%rename("`<") *::operator<; -%rename("`>") *::operator>; -%rename("`==") *::operator==; - -/* Special cases */ -%rename("`()") *::operator(); - -#endif - -/* ------------------------------------------------------------ - * The start of the Pike initialization function - * ------------------------------------------------------------ */ - -%init "swiginit.swg" - -%init %{ -#ifdef __cplusplus -extern "C" -#endif -PIKE_MODULE_EXIT {} - -#ifdef __cplusplus -extern "C" -#endif -PIKE_MODULE_INIT -{ - struct program *pr; - SWIG_InitializeModule(0); -%} - -/* pike keywords */ -%include diff --git a/Lib/pike/pikekw.swg b/Lib/pike/pikekw.swg deleted file mode 100644 index 844b1f189..000000000 --- a/Lib/pike/pikekw.swg +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef PIKE_PIKEKW_SWG_ -#define PIKE_PIKEKW_SWG_ - -/* Warnings for Pike keywords */ -#define PIKEKW(x) %namewarn("314: '" #x "' is a pike keyword") #x - -/* - from - http://www.http://docs.linux.cz/pike/tutorial_C.html - -*/ - - -PIKEKW(array); -PIKEKW(break); -PIKEKW(case); -PIKEKW(catch); -PIKEKW(continue); -PIKEKW(default); -PIKEKW(do); -PIKEKW(else); -PIKEKW(float); -PIKEKW(for); -PIKEKW(foreach); -PIKEKW(function); -PIKEKW(gauge); -PIKEKW(if); -PIKEKW(inherit); -PIKEKW(inline); -PIKEKW(int); -PIKEKW(lambda); -PIKEKW(mapping); -PIKEKW(mixed); -PIKEKW(multiset); -PIKEKW(nomask); -PIKEKW(object); -PIKEKW(predef); -PIKEKW(private); -PIKEKW(program); -PIKEKW(protected); -PIKEKW(public); -PIKEKW(return); -PIKEKW(sscanf); -PIKEKW(static); -PIKEKW(string); -PIKEKW(switch); -PIKEKW(typeof); -PIKEKW(varargs); -PIKEKW(void); -PIKEKW(while); - - -#undef PIKEKW - -#endif //PIKE_PIKEKW_SWG_ diff --git a/Lib/pike/pikerun.swg b/Lib/pike/pikerun.swg deleted file mode 100644 index 6ec1143cf..000000000 --- a/Lib/pike/pikerun.swg +++ /dev/null @@ -1,71 +0,0 @@ -/* ----------------------------------------------------------------------------- - * pikerun.swg - * - * This file contains the runtime support for Pike modules - * and includes code for managing global variables and pointer - * type checking. - * ----------------------------------------------------------------------------- */ - -#ifdef __cplusplus -extern "C" { -#endif -#include "pike/object.h" -#include "pike/program.h" -#ifdef __cplusplus -} -#endif -#include - -/* Stores information about a wrapped object */ -typedef struct swig_object_wrapper { - void *self; - swig_type_info *type; -} swig_object_wrapper; - -#ifdef THIS -#undef THIS -#endif -#define THIS (((swig_object_wrapper *) Pike_fp->current_storage)->self) - -#define SWIG_ConvertPtr SWIG_Pike_ConvertPtr -#define SWIG_NewPointerObj SWIG_Pike_NewPointerObj -#define SWIG_GetModule(clientdata) SWIG_Pike_GetModule(clientdata) -#define SWIG_SetModule(clientdata, pointer) SWIG_Pike_SetModule(pointer) - -/* These need to be filled in before type sharing between modules will work */ -static swig_module_info *SWIG_Pike_GetModule(void *SWIGUNUSEDPARM(clientdata)) { - return 0; -} - -static void SWIG_Pike_SetModule(swig_module_info *pointer) { - -} - -/* Convert a pointer value */ -static int -SWIG_Pike_ConvertPtr(struct object *obj, void **ptr, swig_type_info *ty, int flags) { - struct program *pr; - swig_cast_info *tc; - swig_object_wrapper *obj_wrapper; - - if (ty) { - pr = (struct program *) ty->clientdata; - obj_wrapper = (swig_object_wrapper *) get_storage(obj, pr); - if (obj_wrapper && obj_wrapper->type) { - tc = SWIG_TypeCheckStruct(obj_wrapper->type, ty); - if (tc) { - int newmemory = 0; - *ptr = SWIG_TypeCast(tc, obj_wrapper->self, &newmemory); - assert(!newmemory); /* newmemory handling not yet implemented */ - return 0; - } - } - } - return -1; -} - -/* Create a new pointer object */ -static struct object * -SWIG_Pike_NewPointerObj(void *ptr, swig_type_info *type, int own) { - return 0; -} diff --git a/Lib/pike/std_string.i b/Lib/pike/std_string.i deleted file mode 100644 index b32b3c112..000000000 --- a/Lib/pike/std_string.i +++ /dev/null @@ -1,60 +0,0 @@ -/* ----------------------------------------------------------------------------- - * std_string.i - * - * SWIG typemaps for std::string - * ----------------------------------------------------------------------------- */ - -%{ -#include -%} - -namespace std { - - %naturalvar string; - - class string; - - /* Overloading check */ - - %typemap(typecheck) string = char *; - %typemap(typecheck) const string & = char *; - - %typemap(in, pikedesc="tStr") string { - if ($input.type != T_STRING) - Pike_error("Bad argument: Expected a string.\n"); - $1.assign(STR0($input.u.string)); - } - - %typemap(in, pikedesc="tStr") const string & ($*1_ltype temp) { - if ($input.type != T_STRING) - Pike_error("Bad argument: Expected a string.\n"); - temp.assign(STR0($input.u.string)); - $1 = &temp; - } - - %typemap(out, pikedesc="tStr") string "push_text($1.c_str());"; - - %typemap(out, pikedesc="tStr") const string & "push_text($1->c_str());"; - - %typemap(directorin) string, const string &, string & "$1.c_str()"; - - %typemap(directorin) string *, const string * "$1->c_str()"; - - %typemap(directorout) string { - if ($input.type == T_STRING) - $result.assign(STR0($input.u.string)); - else - throw Swig::DirectorTypeMismatchException("string expected"); - } - - %typemap(directorout) const string & ($*1_ltype temp) { - if ($input.type == T_STRING) { - temp.assign(STR0($input.u.string)); - $result = &temp; - } else { - throw Swig::DirectorTypeMismatchException("string expected"); - } - } - -} - -- cgit v1.2.1 From a54d62b22e70428a68452c172520d153ffde931c Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 13 May 2021 11:39:21 +1200 Subject: [UFFI] Remove code for Common Lisp UFFI We dropped support for it in SWIG 4.0.0 and nobody has stepped forward to revive it in over 2 years. See #2009. --- Lib/uffi/uffi.swg | 101 ------------------------------------------------------ 1 file changed, 101 deletions(-) delete mode 100644 Lib/uffi/uffi.swg (limited to 'Lib') diff --git a/Lib/uffi/uffi.swg b/Lib/uffi/uffi.swg deleted file mode 100644 index 41b085998..000000000 --- a/Lib/uffi/uffi.swg +++ /dev/null @@ -1,101 +0,0 @@ -/* Define a C preprocessor symbol that can be used in interface files - to distinguish between the SWIG language modules. */ - -#define SWIG_UFFI - -/* Typespecs for basic types. */ - -%typemap(ffitype) char ":char"; -%typemap(ffitype) unsigned char ":unsigned-char"; -%typemap(ffitype) signed char ":char"; -%typemap(ffitype) short ":short"; -%typemap(ffitype) signed short ":short"; -%typemap(ffitype) unsigned short ":unsigned-short"; -%typemap(ffitype) int ":int"; -%typemap(ffitype) signed int ":int"; -%typemap(ffitype) unsigned int ":unsigned-int"; -%typemap(ffitype) long ":long"; -%typemap(ffitype) signed long ":long"; -%typemap(ffitype) unsigned long ":unsigned-long"; -%typemap(ffitype) float ":float"; -%typemap(ffitype) double ":double"; -%typemap(ffitype) char * ":cstring"; -%typemap(ffitype) void * ":pointer-void"; -%typemap(ffitype) void ":void"; - -// FIXME: This is guesswork -typedef long size_t; - -%wrapper %{ -(eval-when (compile eval) - -;;; You can define your own identifier converter if you want. -;;; Use the -identifier-converter command line argument to -;;; specify its name. - -(defun identifier-convert-null (id &key type) - (declare (ignore type)) - (read-from-string id)) - -(defun identifier-convert-lispify (cname &key type) - (assert (stringp cname)) - (if (eq type :constant) - (setf cname (format nil "*~A*" cname))) - (setf cname (replace-regexp cname "_" "-")) - (let ((lastcase :other) - newcase char res) - (dotimes (n (length cname)) - (setf char (schar cname n)) - (if* (alpha-char-p char) - then - (setf newcase (if (upper-case-p char) :upper :lower)) - - (when (or (and (eq lastcase :upper) (eq newcase :lower)) - (and (eq lastcase :lower) (eq newcase :upper))) - ;; case change... add a dash - (push #\- res) - (setf newcase :other)) - - (push (char-downcase char) res) - - (setf lastcase newcase) - - else - (push char res) - (setf lastcase :other))) - (read-from-string (coerce (nreverse res) 'string)))) - -(defun identifier-convert-low-level (cname &key type) - (assert (stringp cname)) - (if (eq type :constant) - (setf cname (format nil "+~A+" cname))) - (setf cname (substitute #\- #\_ cname)) - (if (eq type :operator) - (setf cname (format nil "%~A" cname))) - (if (eq type :constant-function) - nil) - (read-from-string cname)) - - - -(defmacro swig-defconstant (string value &key (export T)) - (let ((symbol (funcall *swig-identifier-converter* string :type :constant))) - `(eval-when (compile load eval) - (uffi:def-constant ,symbol ,value ,export)))) - -(defmacro swig-defun (name &rest rest) - (let ((symbol (funcall *swig-identifier-converter* name :type :operator))) - `(eval-when (compile load eval) - (uffi:def-function (,name ,symbol) ,@rest) - (export (quote ,symbol))))) - -(defmacro swig-def-struct (name &rest fields) - "Declare a struct object" - (let ((symbol (funcall *swig-identifier-converter* name :type :type))) - `(eval-when (compile load eval) - (uffi:def-struct ,symbol ,@fields) - (export (quote ,symbol))))) - - -) ;; eval-when -%} -- cgit v1.2.1 From 4f453e0cde3ce1ec854b22eab7b46e2c38fcdd1f Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Mon, 17 May 2021 22:50:52 +0100 Subject: Tidy up handling of OOM exceptions - Py*_New will call PyErr_NoMemory() internally, so there is no need to call it again here, just correctly handle the NULL return value --- Lib/python/pyrun.swg | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'Lib') diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index f32afb07e..83060484f 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -296,7 +296,6 @@ SwigPyClientData_New(PyObject* obj) Py_DECREF(data->newraw); Py_DECREF(data->klass); free(data); - PyErr_NoMemory(); return 0; } } else { @@ -355,10 +354,7 @@ SwigPyObject_get___dict__(PyObject *v, PyObject *SWIGUNUSEDPARM(args)) if (!sobj->dict) sobj->dict = PyDict_New(); - if (!sobj->dict) - return PyErr_NoMemory(); - - Py_INCREF(sobj->dict); + Py_XINCREF(sobj->dict); return sobj->dict; } -- cgit v1.2.1 From 16123466f46cb6b5540a73059692381a32d64f0e Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Tue, 18 May 2021 13:05:51 +0100 Subject: Update tests for failing Python API calls to all use '!= 0' --- Lib/python/pyrun.swg | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Lib') diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 83060484f..086e84b2d 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -743,7 +743,7 @@ SwigPyObject_TypeOnce(void) { }; swigpyobject_type = tmp; type_init = 1; - if (PyType_Ready(&swigpyobject_type) < 0) + if (PyType_Ready(&swigpyobject_type) != 0) return NULL; } return &swigpyobject_type; @@ -913,7 +913,7 @@ SwigPyPacked_TypeOnce(void) { }; swigpypacked_type = tmp; type_init = 1; - if (PyType_Ready(&swigpypacked_type) < 0) + if (PyType_Ready(&swigpypacked_type) != 0) return NULL; } return &swigpypacked_type; @@ -1427,7 +1427,7 @@ SWIG_Python_SetModule(swig_module_info *swig_module) { #endif PyObject *pointer = PyCapsule_New((void *) swig_module, SWIGPY_CAPSULE_NAME, SWIG_Python_DestroyModule); if (pointer && module) { - if (PyModule_AddObject(module, "type_pointer_capsule" SWIG_TYPE_TABLE_NAME, pointer) < 0) { + if (PyModule_AddObject(module, "type_pointer_capsule" SWIG_TYPE_TABLE_NAME, pointer) != 0) { Py_DECREF(pointer); } } else { @@ -1593,7 +1593,7 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { } if (!tp->tp_dict) { - if (PyType_Ready(tp) < 0) + if (PyType_Ready(tp) != 0) goto done; } -- cgit v1.2.1 From 448e8d57bd49d7a714712f96f4566f86d67703ba Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Tue, 18 May 2021 13:07:48 +0100 Subject: Further leak fixes --- Lib/python/pyrun.swg | 66 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 23 deletions(-) (limited to 'Lib') diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 086e84b2d..0025184d1 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -130,6 +130,7 @@ SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) { if (result) { PyList_SET_ITEM(result, 0, o2); } else { + Py_DECREF(obj); return o2; } } @@ -408,18 +409,23 @@ SwigPyObject_repr(SwigPyObject *v) { const char *name = SWIG_TypePrettyName(v->ty); PyObject *repr = SWIG_Python_str_FromFormat("", (name ? name : "unknown"), (void *)v); - if (v->next) { + if (repr && v->next) { PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next); + if (nrep) { # if PY_VERSION_HEX >= 0x03000000 - PyObject *joined = PyUnicode_Concat(repr, nrep); - Py_DecRef(repr); - Py_DecRef(nrep); - repr = joined; + PyObject *joined = PyUnicode_Concat(repr, nrep); + Py_DecRef(repr); + Py_DecRef(nrep); + repr = joined; # else - PyString_ConcatAndDel(&repr,nrep); + PyString_ConcatAndDel(&repr,nrep); # endif + } else { + Py_DecRef(repr); + repr = NULL; + } } - return repr; + return repr; } /* We need a version taking two PyObject* parameters so it's a valid @@ -515,8 +521,12 @@ SwigPyObject_dealloc(PyObject *v) if (data->delargs) { /* we need to create a temporary object to carry the destroy operation */ PyObject *tmp = SwigPyObject_New(sobj->ptr, ty, 0); - res = SWIG_Python_CallFunctor(destroy, tmp); - Py_DECREF(tmp); + if (tmp) { + res = SWIG_Python_CallFunctor(destroy, tmp); + } else { + res = 0; + } + Py_XDECREF(tmp); } else { PyCFunction meth = PyCFunction_GET_FUNCTION(destroy); PyObject *mself = PyCFunction_GET_SELF(destroy); @@ -595,11 +605,10 @@ SwigPyObject_own(PyObject *v, PyObject *args) PyObject *obj = PyBool_FromLong(sobj->own); if (val) { if (PyObject_IsTrue(val)) { - SwigPyObject_acquire(v,args); + Py_DECREF(SwigPyObject_acquire(v,args)); } else { - SwigPyObject_disown(v,args); + Py_DECREF(SwigPyObject_disown(v,args)); } - Py_DECREF(Py_None); } return obj; } @@ -1221,12 +1230,17 @@ SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this) #if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) PyObject **dictptr = _PyObject_GetDictPtr(inst); if (dictptr != NULL) { - PyObject *dict = *dictptr; - if (dict == NULL) { - dict = PyDict_New(); - *dictptr = dict; - PyDict_SetItem(dict, SWIG_This(), swig_this); - } + PyObject *dict = *dictptr; + if (dict == NULL) { + dict = PyDict_New(); + *dictptr = dict; + } + if (dict) { + PyDict_SetItem(dict, SWIG_This(), swig_this); + } else{ + Py_DECREF(inst); + inst = 0; + } } #else if (PyObject_SetAttr(inst, SWIG_This(), swig_this) == -1) { @@ -1277,7 +1291,11 @@ SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this) dict = PyDict_New(); *dictptr = dict; } - return PyDict_SetItem(dict, SWIG_This(), swig_this); + if (dict) { + return PyDict_SetItem(dict, SWIG_This(), swig_this); + } else{ + return -1; + } } #endif return PyObject_SetAttr(inst, SWIG_This(), swig_this); @@ -1292,7 +1310,7 @@ SWIG_Python_InitShadowInstance(PyObject *args) { } else { SwigPyObject *sthis = SWIG_Python_GetSwigThis(obj[0]); if (sthis) { - SwigPyObject_append((PyObject*) sthis, obj[1]); + Py_DECREF(SwigPyObject_append((PyObject*) sthis, obj[1])); } else { if (SWIG_Python_SetSwigThis(obj[0], obj[1]) != 0) return NULL; @@ -1449,8 +1467,10 @@ SWIG_Python_TypeQuery(const char *type) descriptor = SWIG_TypeQueryModule(swig_module, swig_module, type); if (descriptor) { obj = PyCapsule_New((void*) descriptor, NULL, NULL); - PyDict_SetItem(cache, key, obj); - Py_DECREF(obj); + if (obj) { + PyDict_SetItem(cache, key, obj); + Py_DECREF(obj); + } } } Py_DECREF(key); @@ -1608,7 +1628,7 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { } else { encoded_name = PyUnicode_AsUTF8String(name); if (!encoded_name) - return -1; + goto done; } PyErr_Format(PyExc_AttributeError, "'%.100s' object has no attribute '%.200s'", tp->tp_name, PyString_AsString(encoded_name)); Py_DECREF(encoded_name); -- cgit v1.2.1 From 3c168ef332ed66929c404cbf8c02ec04bfd02780 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 5 May 2021 12:02:38 +1200 Subject: Map known PHP interfaces to zend_class_entry* Most pre-defined interfaces are accessible via zend_class_entry* variables declared in the PHP C API - we can use these to add an interface at MINIT time (rather than having to wait until RINIT to look up by name) by having a mapping from PHP interface name to them. This will also be a little faster than looking up by name. Closes #2013 --- Lib/php/php.swg | 3 +++ Lib/php/phpinterfaces.i | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ Lib/php/phprun.swg | 2 ++ 3 files changed, 67 insertions(+) create mode 100644 Lib/php/phpinterfaces.i (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 468c7bb55..42985eac7 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -547,3 +547,6 @@ /* php keywords */ %include + +/* PHP known interfaces */ +%include diff --git a/Lib/php/phpinterfaces.i b/Lib/php/phpinterfaces.i new file mode 100644 index 000000000..dda219d91 --- /dev/null +++ b/Lib/php/phpinterfaces.i @@ -0,0 +1,62 @@ +/* ----------------------------------------------------------------------------- + * phpinterfaces.i + * + * Define "known" PHP interfaces. + * + * These can be added at MINIT time (which is when PHP loads the extension + * module). + * + * Any interface can be added via phpinterfaces, but looking up the + * zend_class_entry by name has to wait until RINIT time, which means it + * happens for every request. + * ----------------------------------------------------------------------------- */ + +// Note: Abstract interfaces such as "Traversable" can't be used in +// "implements" so are not relevant here. + +%insert(header) %{ + +#define SWIG_PHP_INTERFACE_Iterator_CE zend_ce_iterator +#define SWIG_PHP_INTERFACE_Iterator_HEADER "zend_interfaces.h" + +#define SWIG_PHP_INTERFACE_IteratorAggregate_CE zend_ce_aggregate +#define SWIG_PHP_INTERFACE_IteratorAggregate_HEADER "zend_interfaces.h" + +#define SWIG_PHP_INTERFACE_ArrayAccess_CE zend_ce_arrayaccess +#define SWIG_PHP_INTERFACE_ArrayAccess_HEADER "zend_interfaces.h" + +#define SWIG_PHP_INTERFACE_Serializable_CE zend_ce_serializable +#define SWIG_PHP_INTERFACE_Serializable_HEADER "zend_interfaces.h" + +#define SWIG_PHP_INTERFACE_Countable_CE zend_ce_countable +#define SWIG_PHP_INTERFACE_Countable_HEADER "zend_interfaces.h" + +#define SWIG_PHP_INTERFACE_OuterIterator_CE spl_ce_OuterIterator +#define SWIG_PHP_INTERFACE_OuterIterator_HEADER "ext/spl/spl_iterators.h" + +#define SWIG_PHP_INTERFACE_RecursiveIterator_CE spl_ce_RecursiveIterator +#define SWIG_PHP_INTERFACE_RecursiveIterator_HEADER "ext/spl/spl_iterators.h" + +#define SWIG_PHP_INTERFACE_SeekableIterator_CE spl_ce_SeekableIterator +#define SWIG_PHP_INTERFACE_SeekableIterator_HEADER "ext/spl/spl_iterators.h" + +#define SWIG_PHP_INTERFACE_SplObserver_CE spl_ce_SplObserver +#define SWIG_PHP_INTERFACE_SplObserver_HEADER "ext/spl/spl_observer.h" + +#define SWIG_PHP_INTERFACE_SplSubject_CE spl_ce_SplSubject +#define SWIG_PHP_INTERFACE_SplSubject_HEADER "ext/spl/spl_observer.h" + +#define SWIG_PHP_INTERFACE_DateTimeInterface_CE php_date_get_interface_ce() +#define SWIG_PHP_INTERFACE_DateTimeInterface_HEADER "ext/date/php_date.h" + +// The "json" extension needs to be loaded earlier that us for this to work. +#define SWIG_PHP_INTERFACE_JsonSerializable_CE php_json_serializable_ce +#define SWIG_PHP_INTERFACE_JsonSerializable_HEADER "ext/json/php_json.h" + +// New in PHP 8.0. +#if PHP_MAJOR >= 8 +# define SWIG_PHP_INTERFACE_Stringable_CE zend_ce_stringable +# define SWIG_PHP_INTERFACE_Stringable_HEADER "zend_interfaces.h" +#endif + +%} diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index b0376314e..880c98f41 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -16,7 +16,9 @@ extern "C" { # error These bindings need PHP 7 or later - to generate PHP5 bindings use: SWIG < 4.0.0 and swig -php5 #endif +#include "zend_inheritance.h" #include "zend_exceptions.h" +#include "zend_inheritance.h" #include /* for abort(), used in generated code. */ -- cgit v1.2.1 From 8fb25b6a38e41d8147d5f0767d64ab269f0fdc66 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 25 May 2021 16:33:01 +1200 Subject: php: SWIG_exception now maps code to exception class This now determines the class of the exception object where a suitable pre-defined PHP exception class exists - for example, SWIG_TypeError -> PHP exception class TypeError. Exception codes which don't naturally map to a pre-defined PHP exception class are thrown as PHP class Exception (like all PHP exceptions raised by SWIG_exception were before this change.) --- Lib/exception.i | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'Lib') diff --git a/Lib/exception.i b/Lib/exception.i index 9bf3a19d4..020ee1150 100644 --- a/Lib/exception.i +++ b/Lib/exception.i @@ -14,7 +14,18 @@ #ifdef SWIGPHP %{ -#define SWIG_exception(code, msg) do { zend_throw_exception(NULL, (char*)msg, code); goto thrown; } while (0) +#if PHP_MAJOR >= 8 +# define SWIG_HANDLE_VALUE_ERROR_FOR_PHP8 code == SWIG_ValueError ? zend_ce_value_error : +#else +# define SWIG_HANDLE_VALUE_ERROR_FOR_PHP8 +#endif +#define SWIG_exception(code, msg) do { zend_throw_exception( \ + code == SWIG_TypeError ? zend_ce_type_error : \ + SWIG_HANDLE_VALUE_ERROR_FOR_PHP8 \ + code == SWIG_DivisionByZero ? zend_ce_division_by_zero_error : \ + code == SWIG_SyntaxError ? zend_ce_parse_error : \ + code == SWIG_OverflowError ? zend_ce_arithmetic_error : \ + NULL, msg, code); goto thrown; } while (0) %} #endif -- cgit v1.2.1 From cdc69f9843a9b153a91109a493702e089f48602f Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 25 May 2021 16:37:21 +1200 Subject: php: Throw exceptions instead of using errors Parameter type errors and some other cases in SWIG-generated wrappers now throw a PHP exception, which is how PHP's native parameter handling deals with similar situations. See #2014, but not closing yet as there may be more cases to convert. --- Lib/php/php.swg | 35 +++++++++++++++++++++++------------ Lib/php/phppointers.i | 2 +- Lib/php/typemaps.i | 3 ++- 3 files changed, 26 insertions(+), 14 deletions(-) (limited to 'Lib') diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 42985eac7..3b579b9fc 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -86,7 +86,8 @@ %typemap(in) SWIGTYPE ($&1_ltype tmp) %{ if (SWIG_ConvertPtr(&$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); + zend_type_error("Expected $&1_descriptor for argument $argnum of $symname"); + return; } $1 = *tmp; %} @@ -94,7 +95,8 @@ %typemap(directorout) SWIGTYPE ($&1_ltype tmp) %{ if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor"); + zend_type_error("Expected $&1_descriptor for argument $argnum of $symname"); + goto thrown; } $result = *tmp; %} @@ -103,7 +105,8 @@ SWIGTYPE [] %{ if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + zend_type_error("Expected $1_descriptor for argument $argnum of $symname"); + return; } %} @@ -111,7 +114,8 @@ SWIGTYPE [] (swig_owntype own) %{ if (SWIG_ConvertPtrAndOwn($input, (void **)&$result, $1_descriptor, SWIG_POINTER_DISOWN, &own) < 0) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + zend_type_error("Expected $1_descriptor for argument $argnum of $symname"); + goto thrown; } swig_acquire_ownership_obj((void*)$result, own); %} @@ -120,7 +124,8 @@ SWIGTYPE && %{ if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + zend_type_error("Expected $1_descriptor for argument $argnum of $symname"); + return; } %} @@ -128,7 +133,8 @@ SWIGTYPE && ($1_ltype tmp) %{ if (SWIG_ConvertPtr($input, (void **) &tmp, $1_descriptor, 0) < 0 || tmp == NULL) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + zend_type_error("Expected $1_descriptor for argument $argnum of $symname"); + goto thrown; } $result = tmp; %} @@ -136,7 +142,8 @@ %typemap(in) SWIGTYPE *const& ($*ltype temp) %{ if (SWIG_ConvertPtr(&$input, (void **) &temp, $*1_descriptor, 0) < 0) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $*1_descriptor"); + zend_type_error("Expected $*1_descriptor for argument $argnum of $symname"); + return; } $1 = ($1_ltype)&temp; %} @@ -144,7 +151,8 @@ %typemap(in) SWIGTYPE *DISOWN %{ if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN) < 0) { - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + zend_type_error("Expected $1_descriptor for argument $argnum of $symname"); + return; } %} @@ -157,10 +165,12 @@ %{ if (SWIG_ConvertPtr(&$input, (void **) &$1, 0, 0) < 0) { /* Allow NULL from php for void* */ - if (Z_ISNULL($input)) + if (Z_ISNULL($input)) { $1=0; - else - SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor"); + } else { + zend_type_error("Expected $1_descriptor for argument $argnum of $symname"); + return; + } } %} @@ -175,7 +185,8 @@ /* So... we didn't get a ref or ptr, but we'll accept NULL by reference */ if (!(Z_ISREF($input) && Z_ISNULL_P(Z_REFVAL($input)))) { /* wasn't a pre/ref/thing, OR anything like an int thing */ - SWIG_PHP_Error(E_ERROR, "Type error in argument $arg of $symname."); + zend_throw_exception(zend_ce_type_error, "Type error in argument $arg of $symname", 0); + return; } } force=0; diff --git a/Lib/php/phppointers.i b/Lib/php/phppointers.i index 14756837c..8b4e75e60 100644 --- a/Lib/php/phppointers.i +++ b/Lib/php/phppointers.i @@ -6,7 +6,7 @@ CONVERT_IN(tmp, $*1_ltype, $input); $1 = &tmp; } else { - SWIG_PHP_Error(E_ERROR, SWIG_PHP_Arg_Error_Msg($argnum, Expected a reference)); + zend_type_error(SWIG_PHP_Arg_Error_Msg($argnum, Expected a reference)); } %} %typemap(argout) TYPE *REF, diff --git a/Lib/php/typemaps.i b/Lib/php/typemaps.i index c248a588e..aaea0a26a 100644 --- a/Lib/php/typemaps.i +++ b/Lib/php/typemaps.i @@ -276,7 +276,8 @@ INT_TYPEMAP(unsigned long long); /* So... we didn't get a ref or ptr, but we'll accept NULL by reference */ if (!(Z_ISREF($input) && Z_ISNULL_P(Z_REFVAL($input)))) { /* wasn't a pre/ref/thing, OR anything like an int thing */ - SWIG_PHP_Error(E_ERROR, "Type error in argument $arg of $symname."); + zend_type_error("Expected reference or NULL for argument $arg of $symname"); + SWIG_FAIL; } } force=0; -- cgit v1.2.1 From 17a294cec4bb99d37ed01b99787fad483326792f Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 26 May 2021 08:56:41 +1200 Subject: Replace remaining PHP errors with PHP exceptions `SWIG_ErrorCode()`, `SWIG_ErrorMsg()`, `SWIG_FAIL()` and `goto thrown;` are no longer supported (these are really all internal implementation details and none are documented aside from brief mentions in CHANGES for the first three). I wasn't able to find any uses at least in FOSS code via code search tools. If you are using these: Use `SWIG_PHP_Error(code,msg);` instead of `SWIG_ErrorCode(code); SWIG_ErrorMsg(msg);` (which will throw a PHP exception in SWIG >= 4.1 and do the same as the individual calls in older SWIG). `SWIG_FAIL();` and `goto thrown;` can typically be replaced with `SWIG_fail;`. This will probably also work with older SWIG, but please test with your wrappers if this is important to you. Fixes #2014 --- Lib/exception.i | 2 +- Lib/php/director.swg | 4 ++-- Lib/php/php.swg | 6 +++--- Lib/php/phprun.swg | 7 ++----- Lib/php/typemaps.i | 2 +- 5 files changed, 9 insertions(+), 12 deletions(-) (limited to 'Lib') diff --git a/Lib/exception.i b/Lib/exception.i index 020ee1150..7508b409b 100644 --- a/Lib/exception.i +++ b/Lib/exception.i @@ -25,7 +25,7 @@ code == SWIG_DivisionByZero ? zend_ce_division_by_zero_error : \ code == SWIG_SyntaxError ? zend_ce_parse_error : \ code == SWIG_OverflowError ? zend_ce_arithmetic_error : \ - NULL, msg, code); goto thrown; } while (0) + NULL, msg, code); SWIG_fail; } while (0) %} #endif diff --git a/Lib/php/director.swg b/Lib/php/director.swg index ead731a48..68be6a3ba 100644 --- a/Lib/php/director.swg +++ b/Lib/php/director.swg @@ -137,8 +137,8 @@ namespace Swig { swig_msg += " "; swig_msg += msg; } - SWIG_ErrorCode() = code; - SWIG_ErrorMsg() = swig_msg.c_str(); + // Don't replace an already active PHP exception. + if (!EG(exception)) zend_throw_exception(NULL, swig_msg.c_str(), code); } virtual ~DirectorException() throw() { diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 3b579b9fc..6e4ee2d2f 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -96,7 +96,7 @@ %{ if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) { zend_type_error("Expected $&1_descriptor for argument $argnum of $symname"); - goto thrown; + SWIG_fail; } $result = *tmp; %} @@ -115,7 +115,7 @@ %{ if (SWIG_ConvertPtrAndOwn($input, (void **)&$result, $1_descriptor, SWIG_POINTER_DISOWN, &own) < 0) { zend_type_error("Expected $1_descriptor for argument $argnum of $symname"); - goto thrown; + SWIG_fail; } swig_acquire_ownership_obj((void*)$result, own); %} @@ -134,7 +134,7 @@ %{ if (SWIG_ConvertPtr($input, (void **) &tmp, $1_descriptor, 0) < 0 || tmp == NULL) { zend_type_error("Expected $1_descriptor for argument $argnum of $symname"); - goto thrown; + SWIG_fail; } $result = tmp; %} diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 880c98f41..a3569a783 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -58,15 +58,12 @@ static zend_always_inline void *zend_object_alloc(size_t obj_size, zend_class_en #define SWIG_fail goto fail -// If there's an active PHP exception, just return so it can propagate. -#define SWIG_FAIL() do { if (!EG(exception)) zend_error_noreturn(SWIG_ErrorCode(), "%s", SWIG_ErrorMsg()); goto thrown; } while (0) - static const char *default_error_msg = "Unknown error occurred"; static int default_error_code = E_ERROR; #define SWIG_PHP_Arg_Error_Msg(argnum,extramsg) "Error in argument " #argnum " "#extramsg -#define SWIG_PHP_Error(code,msg) do { SWIG_ErrorCode() = code; SWIG_ErrorMsg() = msg; SWIG_fail; } while (0) +#define SWIG_PHP_Error(code,msg) do { zend_throw_exception(NULL, msg, code); SWIG_fail; } while (0) #define SWIG_contract_assert(expr,msg) \ do { if (!(expr)) zend_printf("Contract Assert Failed %s\n", msg); } while (0) @@ -102,7 +99,7 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) { } if (!type->clientdata) { - zend_error(E_ERROR, "Type: %s not registered with zend", type->name); + zend_type_error("Type: %s not registered with zend", type->name); return; } diff --git a/Lib/php/typemaps.i b/Lib/php/typemaps.i index aaea0a26a..94b351113 100644 --- a/Lib/php/typemaps.i +++ b/Lib/php/typemaps.i @@ -277,7 +277,7 @@ INT_TYPEMAP(unsigned long long); if (!(Z_ISREF($input) && Z_ISNULL_P(Z_REFVAL($input)))) { /* wasn't a pre/ref/thing, OR anything like an int thing */ zend_type_error("Expected reference or NULL for argument $arg of $symname"); - SWIG_FAIL; + return; } } force=0; -- cgit v1.2.1 From 4461c443cf86493851b25c5052dc01800371cef6 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 14 Sep 2021 13:59:21 -0700 Subject: remove Go -no-cgo option It only worked for Go versions before 1.5, which is more than five years ago and long-unsupported. --- Lib/go/goruntime.swg | 146 --------------------------------------------------- 1 file changed, 146 deletions(-) (limited to 'Lib') diff --git a/Lib/go/goruntime.swg b/Lib/go/goruntime.swg index 269a4eefd..667cc35ca 100644 --- a/Lib/go/goruntime.swg +++ b/Lib/go/goruntime.swg @@ -23,46 +23,38 @@ static void* Swig_malloc(int c) { %} -#if SWIGGO_CGO %insert(cgo_comment_typedefs) %{ #include %} -#endif #if SWIGGO_INTGO_SIZE == 32 %insert(runtime) %{ typedef int intgo; typedef unsigned int uintgo; %} -#if SWIGGO_CGO %insert(cgo_comment_typedefs) %{ typedef int intgo; typedef unsigned int uintgo; %} -#endif #elif SWIGGO_INTGO_SIZE == 64 %insert(runtime) %{ typedef long long intgo; typedef unsigned long long uintgo; %} -#if SWIGGO_CGO %insert(cgo_comment_typedefs) %{ typedef long long intgo; typedef unsigned long long uintgo; %} -#endif #else %insert(runtime) %{ typedef ptrdiff_t intgo; typedef size_t uintgo; %} -#if SWIGGO_CGO %insert(cgo_comment_typedefs) %{ typedef ptrdiff_t intgo; typedef size_t uintgo; %} #endif -#endif #ifndef SWIGGO_GCCGO // Set the host compiler struct attribute that will be @@ -89,8 +81,6 @@ typedef struct { void* array; intgo len; intgo cap; } _goslice_; %} -#ifdef SWIGGO_CGO - %insert(cgo_comment_typedefs) %{ typedef struct { char *p; intgo n; } _gostring_; @@ -98,8 +88,6 @@ typedef struct { void* array; intgo len; intgo cap; } _goslice_; %} -#endif - #ifndef SWIGGO_GCCGO /* Boilerplate for C/C++ code when using 6g/8g. This code is compiled with gcc. */ @@ -145,43 +133,6 @@ static void _swig_gopanic(const char *p) { %} -#if !SWIGGO_CGO - -/* This is here for backward compatibility, but it will not work - with Go 1.5 or later. Do not use it in new code. */ -%insert(runtime) %{ - -static void *_swig_goallocate(size_t len) { - struct { - size_t len; - void *ret; - } SWIGSTRUCTPACKED a; - a.len = len; - crosscall2(_cgo_allocate, &a, (int) sizeof a); - return a.ret; -} - -%} - -#endif - -#if !SWIGGO_CGO - -/* Boilerplate for C code when using 6g/8g. This code is compiled - with 6c/8c. */ -%insert(gc_header) %{ -#include "runtime.h" -#include "cgocall.h" - -#pragma dataflag 16 -static void *cgocall = runtime·cgocall; -#pragma dataflag 16 -void *·_cgo_runtime_cgocall = &cgocall; - -%} - -#endif - #else /* Boilerplate for C/C++ code when using gccgo. */ @@ -201,97 +152,6 @@ extern void _cgo_panic(const char *); #define _swig_gopanic _cgo_panic %} -#if !SWIGGO_CGO - -%insert(runtime) %{ - -/* Implementations of SwigCgocall and friends for different versions - of gccgo. The Go code will call these functions using C names with - a prefix of the module name. The implementations here call the - routine in libgo. The routines to call vary depending on the gccgo - version. We assume that the version of gcc used to compile this - file is the same as the version of gccgo. */ - -#ifdef __cplusplus -extern "C" { -#endif - -#define SWIG_GCC_VERSION \ - (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) - -#if SWIG_GCC_VERSION < 40700 -#define SwigDoCgocall() -#define SwigDoCgocallDone() -#define SwigDoCgocallBack() -#define SwigDoCgocallBackDone() -#elif SWIG_GCC_VERSION == 40700 -void SwigDoCgocall(void) __asm__("libgo_syscall.syscall.Entersyscall"); -void SwigDoCgocallDone(void) __asm__("libgo_syscall.syscall.Exitsyscall"); -void SwigDoCgocallBack(void) __asm__("libgo_syscall.syscall.Exitsyscall"); -void SwigDoCgocallBackDone(void) __asm__("libgo_syscall.syscall.Entersyscall"); -#else -void SwigDoCgocall(void) __asm__("syscall.Cgocall"); -void SwigDoCgocallDone(void) __asm__("syscall.CgocallDone"); -void SwigDoCgocallBack(void) __asm__("syscall.CgocallBack"); -void SwigDoCgocallBackDone(void) __asm__("syscall.CgocallBackDone"); -#endif - -#define SWIGSTRINGIFY2(s) #s -#define SWIGSTRINGIFY(s) SWIGSTRINGIFY2(s) - -void SwigCgocall() - __asm__(SWIGSTRINGIFY(SWIGGO_PREFIX) ".SwigCgocall"); -void SwigCgocall() { - SwigDoCgocall(); -} - -void SwigCgocallDone() - __asm__(SWIGSTRINGIFY(SWIGGO_PREFIX) ".SwigCgocallDone"); -void SwigCgocallDone() { - SwigDoCgocallDone(); -} - -void SwigCgocallBack() - __asm__(SWIGSTRINGIFY(SWIGGO_PREFIX) ".SwigCgocallBack"); -void SwigCgocallBack() { - SwigDoCgocallBack(); -} - -void SwigCgocallBackDone() - __asm__(SWIGSTRINGIFY(SWIGGO_PREFIX) ".SwigCgocallBackDone"); -void SwigCgocallBackDone() { - SwigDoCgocallBackDone(); -} - -#undef SWIGSTRINGIFY -#undef SWIGSTRINGIFY2 - -#ifdef __cplusplus -} -#endif - -%} - -#endif - -#endif - -#if !SWIGGO_CGO - -%insert(runtime) %{ - -/* This is here for backward compatibility, but it will not work - with Go 1.5 or later. Do not use it in new code. */ -static _gostring_ _swig_makegostring(const char *p, size_t l) { - _gostring_ ret; - ret.p = (char*)_swig_goallocate(l + 1); - memcpy(ret.p, p, l); - ret.n = l; - return ret; -} - -%} - #endif %insert(runtime) %{ @@ -304,12 +164,6 @@ static _gostring_ _swig_makegostring(const char *p, size_t l) { %go_import("unsafe", _ "runtime/cgo") -#if !SWIGGO_CGO -%insert(go_header) %{ -var _cgo_runtime_cgocall func(unsafe.Pointer, uintptr) -%} -#endif - #else %go_import("syscall", "unsafe") -- cgit v1.2.1 From 6ca5d5d722b07977cd2865337d4a9e6cf6d75d5f Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 15 Sep 2021 17:56:01 -0700 Subject: swig -go: don't use crosscall2 for panicking Instead rely only on documented and exported interfaces. --- Lib/go/goruntime.swg | 53 +--------------------------------------------------- 1 file changed, 1 insertion(+), 52 deletions(-) (limited to 'Lib') diff --git a/Lib/go/goruntime.swg b/Lib/go/goruntime.swg index 667cc35ca..c3401b1a8 100644 --- a/Lib/go/goruntime.swg +++ b/Lib/go/goruntime.swg @@ -88,52 +88,7 @@ typedef struct { void* array; intgo len; intgo cap; } _goslice_; %} -#ifndef SWIGGO_GCCGO -/* Boilerplate for C/C++ code when using 6g/8g. This code is compiled - with gcc. */ -%insert(runtime) %{ - -#define swiggo_size_assert_eq(x, y, name) typedef char name[(x-y)*(x-y)*-2+1]; -#define swiggo_size_assert(t, n) swiggo_size_assert_eq(sizeof(t), n, swiggo_sizeof_##t##_is_not_##n) - -swiggo_size_assert(char, 1) -swiggo_size_assert(short, 2) -swiggo_size_assert(int, 4) -typedef long long swiggo_long_long; -swiggo_size_assert(swiggo_long_long, 8) -swiggo_size_assert(float, 4) -swiggo_size_assert(double, 8) - -#ifdef __cplusplus -extern "C" { -#endif -extern void crosscall2(void (*fn)(void *, int), void *, int); -extern char* _cgo_topofstack(void) __attribute__ ((weak)); -extern void _cgo_allocate(void *, int); -extern void _cgo_panic(void *, int); -#ifdef __cplusplus -} -#endif - -static char *_swig_topofstack() { - if (_cgo_topofstack) { - return _cgo_topofstack(); - } else { - return 0; - } -} - -static void _swig_gopanic(const char *p) { - struct { - const char *p; - } SWIGSTRUCTPACKED a; - a.p = p; - crosscall2(_cgo_panic, &a, (int) sizeof a); -} - -%} - -#else +#ifdef SWIGGO_GCCGO /* Boilerplate for C/C++ code when using gccgo. */ %insert(runtime) %{ @@ -154,12 +109,6 @@ extern void _cgo_panic(const char *); #endif -%insert(runtime) %{ - -#define SWIG_contract_assert(expr, msg) \ - if (!(expr)) { _swig_gopanic(msg); } else -%} - #ifndef SWIGGO_GCCGO %go_import("unsafe", _ "runtime/cgo") -- cgit v1.2.1 From 6c59cae7996f83e0340145ed989b72c7eee68246 Mon Sep 17 00:00:00 2001 From: Anthony Heading Date: Mon, 30 Aug 2021 20:40:12 -0400 Subject: Avoid gcc 11 misleading indentation warning in generated code Closes https://github.com/swig/swig/pull/2074 --- Lib/perl5/perltypemaps.swg | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Lib') diff --git a/Lib/perl5/perltypemaps.swg b/Lib/perl5/perltypemaps.swg index bab3d7acd..42f8887be 100644 --- a/Lib/perl5/perltypemaps.swg +++ b/Lib/perl5/perltypemaps.swg @@ -56,7 +56,9 @@ %define %set_output(obj) $result = obj; argvi++ %enddef /* append output */ -%define %append_output(obj) if (argvi >= items) EXTEND(sp, argvi+1); %set_output(obj) %enddef +%define %append_output(obj) +if (argvi >= items) EXTEND(sp, argvi+1); +%set_output(obj) %enddef /* variable output */ %define %set_varoutput(obj) sv_setsv($result,obj) %enddef -- cgit v1.2.1 From ada739b4a8e71717f9438c0b6d7e34f1b18e3832 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 12 Nov 2021 09:09:14 +0000 Subject: Fix mismatched new char[] and free() - Javascript Javascript - v8 and node only. When wrapping C code char arrays. Now calloc is now used instead of new char[] in SWIG_AsCharPtrAndSize. Fixes gcc-11 warning -Wmismatched-new-delete in arrays and memberin_extend testcases. --- Lib/javascript/v8/javascriptstrings.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib') diff --git a/Lib/javascript/v8/javascriptstrings.swg b/Lib/javascript/v8/javascriptstrings.swg index 42d0b86b5..aaf1b9302 100644 --- a/Lib/javascript/v8/javascriptstrings.swg +++ b/Lib/javascript/v8/javascriptstrings.swg @@ -14,7 +14,7 @@ SWIG_AsCharPtrAndSize(SWIGV8_VALUE valRef, char** cptr, size_t* psize, int *allo %#endif size_t len = SWIGV8_UTF8_LENGTH(js_str) + 1; - char* cstr = new char[len]; + char* cstr = (char*) %new_array(len, char); SWIGV8_WRITE_UTF8(js_str, cstr, len); if(alloc) *alloc = SWIG_NEWOBJ; -- cgit v1.2.1 From 01eb2e0aa99acaace2ebe406ef069cfb3f2420e1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 12 Nov 2021 19:30:53 +0000 Subject: Lua int ref typemap improvements Fixes complex typedefs to const int& and const unsigned int&. Fixes cpp11_type_aliasing testcase --- Lib/lua/luatypemaps.swg | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Lib') diff --git a/Lib/lua/luatypemaps.swg b/Lib/lua/luatypemaps.swg index 6c92e3b59..3f531bd05 100644 --- a/Lib/lua/luatypemaps.swg +++ b/Lib/lua/luatypemaps.swg @@ -39,12 +39,12 @@ $1 = ($type)lua_tonumber(L, $input);%} // SWIG assumes that this code will need a pointer to int to be passed in // (this might be ok for objects by const ref, but not for numeric primitives) // therefore we add a set of typemaps to fix this (for both in & out) -%typemap(in,checkfn="lua_isnumber") const int&($basetype temp) -%{ temp=($basetype)lua_tonumber(L,$input); $1=&temp;%} +%typemap(in,checkfn="lua_isnumber") const int&($*1_ltype temp) +%{ temp=($*1_ltype)lua_tonumber(L,$input); $1=&temp;%} -%typemap(in,checkfn="lua_isnumber") const unsigned int&($basetype temp) +%typemap(in,checkfn="lua_isnumber") const unsigned int&($*1_ltype temp) %{SWIG_contract_assert((lua_tonumber(L,$input)>=0),"number must not be negative") -temp=($basetype)lua_tonumber(L,$input); $1=&temp;%} +temp=($*1_ltype)lua_tonumber(L,$input); $1=&temp;%} %typemap(out) const int&, const unsigned int& %{ lua_pushnumber(L, (lua_Number) *$1); SWIG_arg++;%} -- cgit v1.2.1 From 606491326e50454d26abc8570ee8ad644fe263d1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 15 Nov 2021 20:19:12 +0000 Subject: Scilab compilation fix when wrapping C++11 enum classes --- Lib/scilab/scienum.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib') diff --git a/Lib/scilab/scienum.swg b/Lib/scilab/scienum.swg index 54ec1f85c..cc1f7c977 100644 --- a/Lib/scilab/scienum.swg +++ b/Lib/scilab/scienum.swg @@ -18,7 +18,7 @@ SWIG_Int_AsEnum(void *pvApiCtx, int iVar, int *enumValue, char *fname) { } %fragment(SWIG_From_frag(Enum), "header", fragment="SWIG_Int_FromEnum") { -%#define SWIG_From_Enum(scilabValue) SWIG_Int_FromEnum(pvApiCtx, SWIG_Scilab_GetOutputPosition(), scilabValue, SWIG_Scilab_GetFuncName()) +%#define SWIG_From_Enum(scilabValue) SWIG_Int_FromEnum(pvApiCtx, SWIG_Scilab_GetOutputPosition(), (int)scilabValue, SWIG_Scilab_GetFuncName()) } %fragment("SWIG_Int_FromEnum", "header", fragment="SWIG_SciDouble_FromInt") { SWIGINTERN int -- cgit v1.2.1 From f586d920f72aeedd8d4c9504415f4251005ef4bf Mon Sep 17 00:00:00 2001 From: Dimitris Apostolou Date: Sat, 13 Nov 2021 21:23:08 +0200 Subject: Fix typos --- Lib/d/doperators.swg | 6 +++--- Lib/octave/octcomplex.swg | 2 +- Lib/ruby/rubyautodoc.swg | 4 ++-- Lib/tcl/mactkinit.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'Lib') diff --git a/Lib/d/doperators.swg b/Lib/d/doperators.swg index 0cb63533c..0a82a6cb4 100644 --- a/Lib/d/doperators.swg +++ b/Lib/d/doperators.swg @@ -58,7 +58,7 @@ template SwigOperatorDefinitions() { %rename(opCall) *::operator(); -// !a is not overrideable in D1. +// !a is not overridable in D1. %ignoreoperator(LNOT) operator!; // opCmp is used in D. @@ -71,7 +71,7 @@ template SwigOperatorDefinitions() { // a != b is rewritten as !a.opEquals(b) in D. %ignoreoperator(NOTEQUAL) operator!=; -// The logic operators are not overrideable in D. +// The logic operators are not overridable in D. %ignoreoperator(LAND) operator&&; %ignoreoperator(LOR) operator||; @@ -198,7 +198,7 @@ mixin template SwigOperatorDefinitions() { // a != b is rewritten as !a.opEquals(b) in D. %ignoreoperator(NOTEQUAL) operator!=; -// The logic operators are not overrideable in D. +// The logic operators are not overridable in D. %ignoreoperator(LAND) operator&&; %ignoreoperator(LOR) operator||; diff --git a/Lib/octave/octcomplex.swg b/Lib/octave/octcomplex.swg index 87e77a62e..553c25a3d 100644 --- a/Lib/octave/octcomplex.swg +++ b/Lib/octave/octcomplex.swg @@ -2,7 +2,7 @@ Defines the As/From conversors for double/float complex, you need to provide complex Type, the Name you want to use in the conversors, the complex Constructor method, and the Real and Imag complex - accesor methods. + accessor methods. See the std_complex.i and ccomplex.i for concrete examples. */ diff --git a/Lib/ruby/rubyautodoc.swg b/Lib/ruby/rubyautodoc.swg index 1e6b0d9dc..6b0472ce8 100644 --- a/Lib/ruby/rubyautodoc.swg +++ b/Lib/ruby/rubyautodoc.swg @@ -77,7 +77,7 @@ AUTODOC(operator>, "Higher than comparison operator"); AUTODOC(operator<<, "Left shifting or appending operator"); AUTODOC(operator>>, "Right shifting operator or extracting operator"); AUTODOC(operator+, "Add operator"); -AUTODOC(operator-, "Substraction operator"); +AUTODOC(operator-, "Subtraction operator"); AUTODOC(operator+(), "Positive operator"); AUTODOC(operator-(), "Negation operator"); AUTODOC(operator&, "AND operator"); @@ -93,7 +93,7 @@ AUTODOC(__gt__, "Higher than comparison operator"); AUTODOC(__lshift__, "Left shifting or appending operator"); AUTODOC(__rshift__, "Right shifting operator or extracting operator"); AUTODOC(__add___, "Add operator"); -AUTODOC(__sub__, "Substraction operator"); +AUTODOC(__sub__, "Subtraction operator"); AUTODOC(__pos__, "Positive operator"); AUTODOC(__neg__, "Negation operator"); AUTODOC(__and__, "AND operator"); diff --git a/Lib/tcl/mactkinit.c b/Lib/tcl/mactkinit.c index 8d1420088..18f1f0203 100644 --- a/Lib/tcl/mactkinit.c +++ b/Lib/tcl/mactkinit.c @@ -126,7 +126,7 @@ MacintoshInit() * * This procedure calls initialization routines require a Tcl * interp as an argument. This call effectively makes the passed - * iterpreter the "main" interpreter for the application. + * interpreter the "main" interpreter for the application. * * Results: * Returns TCL_OK if everything went fine. If it didn't the -- cgit v1.2.1