From cecd89f66f7d8e7949323358d37b78ddbf268c76 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 12 Dec 2013 15:39:10 +1300 Subject: [PATCH] [PHP] The usage of $input in PHP directorout typemaps has been changed to be consistent with other languages. The typemaps provided by SWIG have been updated accordingly, but if you have written your own directorout typemaps, you'll need to update $input to &$input (or make equivalent changes). *** POTENTIAL INCOMPATIBILITY *** --- CHANGES.current | 9 +++++++++ Examples/test-suite/typemap_directorout.i | 18 ------------------ Lib/php/php.swg | 2 +- Lib/php/std_string.i | 8 ++++---- Lib/php/utils.i | 4 ++-- Source/Modules/php.cxx | 3 +-- 6 files changed, 17 insertions(+), 27 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index a4d12239d..597a0e853 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,15 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.0 (in progress) ============================ +2013-12-12: olly + [PHP] The usage of $input in PHP directorout typemaps has been + changed to be consistent with other languages. The typemaps + provided by SWIG have been updated accordingly, but if you + have written your own directorout typemaps, you'll need to + update $input to &$input (or make equivalent changes). + + *** POTENTIAL INCOMPATIBILITY *** + 2013-11-27: vadz [C#, Java, Python] Add std_auto_ptr.i defining typemaps for returning std::auto_ptr<>. diff --git a/Examples/test-suite/typemap_directorout.i b/Examples/test-suite/typemap_directorout.i index fb0a6ab81..4a85bd47c 100644 --- a/Examples/test-suite/typemap_directorout.i +++ b/Examples/test-suite/typemap_directorout.i @@ -13,24 +13,6 @@ // Can't use the %typemap(directorout) MyType & = SWIGTYPE & approach as non-director languages don't define any directorout typemaps %typemap(directorout) MyType &Class1::foo2, MyType &foo1 %{ /* special start */ $input = 0; /* special end */ %} -#ifdef SWIGPHP -%typemap(directorout, warning="PHP directorout typemaps need fixing") MyType &Class1::foo2, MyType &foo1 %{ /* special start */ /*$input = 0;*/ /* special end */ %} -/* Patch to make $input work same as other languages. Then $input needs changing to &$input in most (maybe all) typemaps. ---- a/Source/Modules/php.cxx -+++ b/Source/Modules/php.cxx -@@ -2631,8 +2631,7 @@ done: - if (!is_void) { - tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w); - if (tm != 0) { -- static const String *amp_result = NewStringf("&%s", Swig_cresult_name()); -- Replaceall(tm, "$input", amp_result); -+ Replaceall(tm, "$input", Swig_cresult_name()); - char temp[24]; - sprintf(temp, "%d", idx); - Replaceall(tm, "$argnum", temp); -*/ -#endif - #ifdef SWIGCSHARP %typemap(csdirectorout) MyType & %{ WILL_NOT_COMPILE %} diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 325abbcd4..afa047ef6 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -93,7 +93,7 @@ %typemap(directorout) SWIGTYPE ($&1_ltype tmp) { - if(SWIG_ConvertPtr(*$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) { + 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; diff --git a/Lib/php/std_string.i b/Lib/php/std_string.i index 10d7fdd31..aaa5dc9cd 100644 --- a/Lib/php/std_string.i +++ b/Lib/php/std_string.i @@ -33,8 +33,8 @@ namespace std { %} %typemap(directorout) string %{ - convert_to_string_ex($input); - $result.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input)); + convert_to_string_ex(&$input); + $result.assign(Z_STRVAL_P($input), Z_STRLEN_P($input)); %} %typemap(out) string %{ @@ -63,8 +63,8 @@ namespace std { %} %typemap(directorout) string & ($*1_ltype *temp) %{ - convert_to_string_ex($input); - temp = new $*1_ltype(Z_STRVAL_PP($input), Z_STRLEN_PP($input)); + convert_to_string_ex(&$input); + temp = new $*1_ltype(Z_STRVAL_P($input), Z_STRLEN_P($input)); swig_acquire_ownership(temp); $result = temp; %} diff --git a/Lib/php/utils.i b/Lib/php/utils.i index 07ac96900..c3b19a320 100644 --- a/Lib/php/utils.i +++ b/Lib/php/utils.i @@ -80,11 +80,11 @@ %} %typemap(directorout) TYPE %{ - CONVERT_IN($result,$1_ltype,$input); + CONVERT_IN($result,$1_ltype,&$input); %} %typemap(directorout) const TYPE & ($*1_ltype temp) %{ - CONVERT_IN(temp,$*1_ltype,$input); + CONVERT_IN(temp,$*1_ltype,&$input); $result = &temp; %} %enddef diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index def917019..a8659b9f1 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -2626,8 +2626,7 @@ done: if (!is_void) { tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w); if (tm != 0) { - static const String *amp_result = NewStringf("&%s", Swig_cresult_name()); - Replaceall(tm, "$input", amp_result); + Replaceall(tm, "$input", Swig_cresult_name()); char temp[24]; sprintf(temp, "%d", idx); Replaceall(tm, "$argnum", temp);