From 8615adfb07900c653d08a72acec22c791f0ae987 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 10 Aug 2009 21:58:54 +0000 Subject: [PATCH 01/68] Remove memory leak for char ** out typemap example, as per Peter Allen email on swig-user on, ahem, 19 July 2006 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11527 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Perl5.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/Manual/Perl5.html b/Doc/Manual/Perl5.html index 0579cddfd..8f74bd1de 100644 --- a/Doc/Manual/Perl5.html +++ b/Doc/Manual/Perl5.html @@ -2173,7 +2173,7 @@ reference to be used as a char ** datatype. }; myav = av_make(len,svs); free(svs); - $result = newRV((SV*)myav); + $result = newRV_noinc((SV*)myav); sv_2mortal($result); argvi++; } From b61f9da6e6eccbe1dbe2c469b48d5f80666dc017 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 11 Aug 2009 10:19:04 +0000 Subject: [PATCH 02/68] PHP: fix for the template_ref_type testcase git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11528 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/php.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 849ba043b..366425382 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1194,7 +1194,7 @@ public: const char *pname_cstr = GetChar(p, "name"); // Just get rid of the C++ namespace part for now. const char *ptr = NULL; - if ((ptr = strrchr(pname_cstr, ':'))) { + if (pname_cstr && (ptr = strrchr(pname_cstr, ':'))) { pname_cstr = ptr + 1; } if (!pname_cstr) { From abcff1089d4f06eddabd27a03f3c1910a965d282 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 11 Aug 2009 13:56:50 +0000 Subject: [PATCH 03/68] Fix 2 of the 3 warnings under PHP (the remaining one doesn't seem to respond to %warnfilter as I'd expect...) git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11529 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/php_namewarn_rename.i | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Examples/test-suite/php_namewarn_rename.i b/Examples/test-suite/php_namewarn_rename.i index 87877c4f0..cebe93f02 100644 --- a/Examples/test-suite/php_namewarn_rename.i +++ b/Examples/test-suite/php_namewarn_rename.i @@ -1,20 +1,23 @@ %module php_namewarn_rename +#ifdef SWIGPHP +%warnfilter(SWIGWARN_PARSE_KEYWORD) Empty(); +// FIXME: this doesn't work for me: +%warnfilter(SWIGWARN_PARSE_KEYWORD) stdClass; +%warnfilter(SWIGWARN_PARSE_KEYWORD) Hello::empty(); +#endif %inline %{ - void Empty() {}; - + void Empty() {} - class stdClass + class stdClass { }; - struct Hello + struct Hello { - void empty() {} + void empty() {} }; - - %} From 37b9370344a737d6e216f597adf5a50d4dc898fd Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 11 Aug 2009 14:40:51 +0000 Subject: [PATCH 04/68] Eliminate space before "function" when there's no access specifier (just a cosmetic tweak). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11530 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/php.cxx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 366425382..0ea23080f 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1570,6 +1570,9 @@ public: Delete(warnmsg); } } + if (Cmp(acc, "") != 0) { + Append(acc, " "); + } if (constructor) { const char * arg0; if (max_num_of_arguments > 0) { @@ -1581,13 +1584,13 @@ public: } SwigType *t = Getattr(current_class, "classtype"); String *mangled_type = SwigType_manglestr(SwigType_ltype(t)); - Printf(output, "\t%s function %s(%s) {\n", acc, methodname, args); + Printf(output, "\t%sfunction %s(%s) {\n", acc, methodname, args); Printf(output, "\t\tif (is_resource($%s) && get_resource_type($%s) === '_p%s') {\n", arg0, arg0, mangled_type); Printf(output, "\t\t\t$this->%s=$%s;\n", SWIG_PTR, arg0); Printf(output, "\t\t\treturn;\n"); Printf(output, "\t\t}\n"); } else { - Printf(output, "\t%s function %s(%s) {\n", acc, methodname, args); + Printf(output, "\t%sfunction %s(%s) {\n", acc, methodname, args); } Delete(acc); } else { From 741b90763b8945889bd6d3b49a5472149684ed9f Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 11 Aug 2009 14:42:03 +0000 Subject: [PATCH 05/68] Fix to work for classes which aren't called "Foo"... git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11531 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/php.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 0ea23080f..c4c6bab25 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1604,7 +1604,8 @@ public: if (strcmp(methodname, "__construct") == 0) { Printf(output, "\t\t$this->%s=%s;\n", SWIG_PTR, invoke); } else { - Printf(output, "\t\treturn new %s(%s);\n", "Foo", invoke); + String *classname = Swig_class_name(current_class); + Printf(output, "\t\treturn new %s(%s);\n", classname, invoke); } } else { Node *parent = Swig_methodclass(n); From ac8f104d7b6f8cfbafee9657331211e92b03f0e2 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 11 Aug 2009 22:53:32 +0000 Subject: [PATCH 06/68] PHP: Add more comments in SWIG_ZTS_SetPointerZval() git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11536 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/php/phprun.swg | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index 3f762a3e5..f48748914 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -113,8 +113,14 @@ SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject value->ptr=ptr; value->newobject=newobject; if (newobject <= 1) { + /* Just register the pointer as a resource. */ ZEND_REGISTER_RESOURCE(z, value, *(int *)(type->clientdata)); } else { + /* + * Wrap the resource in an object, the resource will be accessible + * via the "_cPtr" member. This is currently only used by + * directorin typemaps. + */ value->newobject = 0; zval *resource; MAKE_STD_ZVAL(resource); From 3076cbcdc0d7b07d3efcbf286e568f3663207161 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 12 Aug 2009 00:22:47 +0000 Subject: [PATCH 07/68] Fix seg fault in SWIG_Python_ConvertFunctionPtr() for invalid values git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11537 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/pyrun.swg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 38632e1ab..21fddb610 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1163,10 +1163,10 @@ SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) { /* here we get the method pointer for callbacks */ const char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc); const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0; - if (desc) { + if (desc) desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0; - if (!desc) return SWIG_ERROR; - } + if (!desc) + return SWIG_ERROR; if (ty) { swig_cast_info *tc = SWIG_TypeCheck(desc,ty); if (tc) { From 889b156afd1c6220f36827cdd49bae3b3618b901 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 12 Aug 2009 11:18:58 +0000 Subject: [PATCH 08/68] PHP: fix for the extend_template testcase The fix is not to handle a %template as a rename by reading the class' sym:name attribute instead of the ctor's name attribute. This has been broken in r11510. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11539 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/php.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index c4c6bab25..44fe032a5 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1027,11 +1027,11 @@ public: if (constructor) { class_has_ctor = true; // Skip the Foo:: prefix. - char *ptr = strrchr(GetChar(n, "name"), ':'); + char *ptr = strrchr(GetChar(Swig_methodclass(n), "sym:name"), ':'); if (ptr) { ptr++; } else { - ptr = GetChar(n, "name"); + ptr = GetChar(Swig_methodclass(n), "sym:name"); } if (strcmp(ptr, GetChar(n, "constructorHandler:sym:name")) == 0) { methodname = "__construct"; From 36c4707c0d3b06ced3056163966daf0f9b811588 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 12 Aug 2009 22:07:49 +0000 Subject: [PATCH 09/68] Correct docs wrt C preprocessor constants with a cast git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11541 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/SWIG.html | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index 1bdc6b4d0..fdbbab6f7 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -667,7 +667,6 @@ enum boolean {NO=0, YES=1}; enum months {JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC}; %constant double BLAH = 42.37; -#define F_CONST (double) 5 // A floating pointer constant with cast #define PI_4 PI/4 #define FLAGS 0x04 | 0x08 | 0x40 @@ -706,8 +705,15 @@ the declaration

defines a constant because PI was already defined as a constant and the value is known. +However, for the same conservative reasons even a constant with a simple cast will be ignored, such as

+
+
+#define F_CONST (double) 5            // A floating pointer constant with cast
+
+
+

The use of constant expressions is allowed, but SWIG does not evaluate them. Rather, it passes them through to the output file and lets the C From ce3d4db364e5ae42c5e260aabb370815fbd1d290 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 13 Aug 2009 03:31:38 +0000 Subject: [PATCH 10/68] Update the list of expected methods for smart_pointer_rename for PHP5 so this testcase now passes. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11543 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/php/smart_pointer_rename_runme.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/php/smart_pointer_rename_runme.php b/Examples/test-suite/php/smart_pointer_rename_runme.php index a1759cb95..c601cce16 100644 --- a/Examples/test-suite/php/smart_pointer_rename_runme.php +++ b/Examples/test-suite/php/smart_pointer_rename_runme.php @@ -5,8 +5,8 @@ require "tests.php"; require "smart_pointer_rename.php"; check::classes(array("Foo","Bar")); -check::classmethods("foo",array("foo","ftest1","ftest2")); -check::classmethods("bar",array("__deref__","bar","test","ftest1","ftest2")); +check::classmethods("foo",array("ftest1","ftest2","__set","__isset","__get","__construct")); +check::classmethods("bar",array("__deref__","test","ftest1","ftest2","__set","__isset","__get","__construct")); $foo=new foo(); check::classname("foo",$foo); $bar=new bar($foo); From 54018f66a2d530a785e7db361d5e604cb94459e4 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 13 Aug 2009 03:35:48 +0000 Subject: [PATCH 11/68] Correct the human-readable messages in 3 assertions. Remove meaningless comment. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11544 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/php/enum_scope_template_runme.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Examples/test-suite/php/enum_scope_template_runme.php b/Examples/test-suite/php/enum_scope_template_runme.php index 7cea23911..e152efca6 100644 --- a/Examples/test-suite/php/enum_scope_template_runme.php +++ b/Examples/test-suite/php/enum_scope_template_runme.php @@ -1,14 +1,12 @@ Date: Thu, 13 Aug 2009 03:58:09 +0000 Subject: [PATCH 12/68] Change class names in test code which clash with PHP reserved words (Interface, Class, and Function - these are case insensitive reserved words in PHP). Fix lists of expected methods in rename_scope_runme.php to match those which we expect with PHP5. With this and the change above, this testcase now passes. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11545 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/php/rename_scope_runme.php | 8 ++++---- Examples/test-suite/rename_scope.i | 10 +++++----- Examples/test-suite/template_default_qualify.i | 6 +++--- Examples/test-suite/template_enum_ns_inherit.i | 14 +++++++------- Examples/test-suite/template_enum_typedef.i | 6 +++--- Examples/test-suite/template_ns4.i | 16 ++++++++-------- Examples/test-suite/valuewrapper_base.i | 8 ++++---- 7 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Examples/test-suite/php/rename_scope_runme.php b/Examples/test-suite/php/rename_scope_runme.php index 6da5c4a5c..6c66906c6 100644 --- a/Examples/test-suite/php/rename_scope_runme.php +++ b/Examples/test-suite/php/rename_scope_runme.php @@ -6,10 +6,10 @@ require "rename_scope.php"; check::classes(array("rename_scope","Interface_UP","Interface_BP","Natural_UP","Natural_BP","Bucket")); -check::classmethods("Interface_UP",array("__construct")); -check::classmethods("Interface_BP",array("__construct")); -check::classmethods("Natural_UP",array("__construct","rtest")); -check::classmethods("Natural_BP",array("__construct","rtest")); +check::classmethods("Interface_UP",array("__construct","__set","__isset","__get")); +check::classmethods("Interface_BP",array("__construct","__set","__isset","__get")); +check::classmethods("Natural_UP",array("__construct","__set","__isset","__get","rtest")); +check::classmethods("Natural_BP",array("__construct","__set","__isset","__get","rtest")); check::classparent("Natural_UP","Interface_UP"); check::classparent("Natural_BP","Interface_BP"); diff --git a/Examples/test-suite/rename_scope.i b/Examples/test-suite/rename_scope.i index 6bea35b0e..9a09949c4 100644 --- a/Examples/test-suite/rename_scope.i +++ b/Examples/test-suite/rename_scope.i @@ -7,7 +7,7 @@ enum Polarization { UnaryPolarization, BinaryPolarization }; template - struct Interface + struct Interface_ { }; } @@ -15,9 +15,9 @@ namespace oss { - // Interface - %template(Interface_UP) Interface; - %template(Interface_BP) Interface; + // Interface_ + %template(Interface_UP) Interface_; + %template(Interface_BP) Interface_; } %inline @@ -27,7 +27,7 @@ namespace oss namespace interfaces { template - struct Natural : Interface

+ struct Natural : Interface_

{ int test(void) { return 1; } }; diff --git a/Examples/test-suite/template_default_qualify.i b/Examples/test-suite/template_default_qualify.i index bcba1a44e..640011b2c 100644 --- a/Examples/test-suite/template_default_qualify.i +++ b/Examples/test-suite/template_default_qualify.i @@ -12,14 +12,14 @@ enum Polarization { UnaryPolarization, BinaryPolarization }; template - struct Interface + struct Interface_ { }; namespace modules { - template > + template > // *** problem here **** struct Module : base { @@ -35,7 +35,7 @@ namespace oss { - %template(Interface_UP) Interface; + %template(Interface_UP) Interface_; namespace modules { %template(Module_etraits) Module; diff --git a/Examples/test-suite/template_enum_ns_inherit.i b/Examples/test-suite/template_enum_ns_inherit.i index 8992eef6d..c617b5716 100644 --- a/Examples/test-suite/template_enum_ns_inherit.i +++ b/Examples/test-suite/template_enum_ns_inherit.i @@ -6,7 +6,7 @@ enum Polarization { UnaryPolarization, BinaryPolarization }; template - struct Interface + struct Interface_ { }; @@ -21,8 +21,8 @@ namespace oss { - %template(Interface_UP) Interface; - %template(Module_UPIUP) Module >; + %template(Interface_UP) Interface_; + %template(Module_UPIUP) Module >; } %inline %{ @@ -31,18 +31,18 @@ namespace oss namespace hello { struct HInterface1 : - Interface // this works (with fullns qualification) + Interface_ // this works (with fullns qualification) { }; struct HInterface2 : - Interface // this doesn't work + Interface_ // this doesn't work { }; - struct HModule1 : Module > { + struct HModule1 : Module > { }; } } -%} \ No newline at end of file +%} diff --git a/Examples/test-suite/template_enum_typedef.i b/Examples/test-suite/template_enum_typedef.i index 9752d0858..38444594e 100644 --- a/Examples/test-suite/template_enum_typedef.i +++ b/Examples/test-suite/template_enum_typedef.i @@ -9,7 +9,7 @@ enum Polarization { UnaryPolarization, BinaryPolarization }; template - struct Interface + struct Interface_ { }; @@ -25,7 +25,7 @@ typedef Traits traits; static const Polarization P = traits::pmode; - void get(Interface

arg) { }; // Here P is only replace by traits::pmode + void get(Interface_

arg) { }; // Here P is only replace by traits::pmode }; } @@ -34,6 +34,6 @@ namespace oss { - %template(Interface_UP) Interface; + %template(Interface_UP) Interface_; %template(Module_UP) Module; } diff --git a/Examples/test-suite/template_ns4.i b/Examples/test-suite/template_ns4.i index 34489c473..f5c134852 100644 --- a/Examples/test-suite/template_ns4.i +++ b/Examples/test-suite/template_ns4.i @@ -8,13 +8,13 @@ }; template - struct Function + struct Function_ { char *test() { return (char *) "test"; } }; template - struct ArithFunction : Function + struct ArithFunction : Function_ { }; @@ -40,7 +40,7 @@ }; template - class Class : public ArithFunction< typename traits::arg_type, + class Class_ : public ArithFunction< typename traits::arg_type, typename traits::res_type > { }; @@ -49,7 +49,7 @@ typename traits::base make_Class() { - return Class(); + return Class_(); } @@ -58,9 +58,9 @@ %{ namespace hello { - template struct Function ; + template struct Function_ ; template struct ArithFunction ; - template class Class ; + template class Class_ ; } %} @@ -69,9 +69,9 @@ // This complains only when using a namespace // %template() traits; - %template(Function_DD) Function ; + %template(Function_DD) Function_ ; %template(ArithFunction_DD) ArithFunction ; - %template(Class_DD) Class ; + %template(Class_DD) Class_ ; %template(make_Class_DD) make_Class ; } diff --git a/Examples/test-suite/valuewrapper_base.i b/Examples/test-suite/valuewrapper_base.i index 1698c3e03..63471bbc8 100644 --- a/Examples/test-suite/valuewrapper_base.i +++ b/Examples/test-suite/valuewrapper_base.i @@ -10,9 +10,9 @@ }; template - struct Interface : Base + struct Interface_ : Base { - Interface(const Base& b) { }; + Interface_(const Base& b) { }; }; template @@ -23,6 +23,6 @@ namespace oss { // Interface - %template(Interface_BP) Interface; - %template(make_Interface_BP) make >; + %template(Interface_BP) Interface_; + %template(make_Interface_BP) make >; } From dd96b09e6884b83f71f79a46959877d35bd0c6a5 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 13 Aug 2009 04:13:35 +0000 Subject: [PATCH 13/68] Fix the list of classes expected. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11546 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/php/li_carrays_runme.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Examples/test-suite/php/li_carrays_runme.php b/Examples/test-suite/php/li_carrays_runme.php index 8972b9fc2..b6d47e926 100644 --- a/Examples/test-suite/php/li_carrays_runme.php +++ b/Examples/test-suite/php/li_carrays_runme.php @@ -1,14 +1,15 @@ Date: Thu, 13 Aug 2009 14:58:27 +0000 Subject: [PATCH 14/68] Just disable SWIGWARN_PARSE_KEYWORD for li_math.i under PHP. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11547 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/li_math.i | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Examples/test-suite/li_math.i b/Examples/test-suite/li_math.i index db39cd3de..3aa3db303 100644 --- a/Examples/test-suite/li_math.i +++ b/Examples/test-suite/li_math.i @@ -1,2 +1,7 @@ %module li_math +#ifdef SWIGPHP +// PHP already provides these functions with the same names, so just kill that +// warning. +%warnfilter(SWIGWARN_PARSE_KEYWORD); +#endif %include math.i From 627d9faffd33e8b945f671478f1b4b1a67aa5640 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 13 Aug 2009 21:41:23 +0000 Subject: [PATCH 15/68] Add PHP const ref typemaps for primitive types git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11549 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 +++ .../test-suite/php/primitive_ref_runme.php | 25 +++++++++++++++ Lib/php/php.swg | 31 +++++++++++++++++++ Lib/php/utils.i | 7 ++++- 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/php/primitive_ref_runme.php diff --git a/CHANGES.current b/CHANGES.current index e3f690daa..30cd03df7 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ Version 1.3.40 (in progress) ============================ +2009-08-13: wsfulton + [PHP] Add const reference typemaps. const reference primitive types are + now passed by value rather than pointer like the other target languages. + 2009-08-08: wsfulton [Python] More user friendly AttributeError is raised when there are no constructors generated for the proxy class in the event that the diff --git a/Examples/test-suite/php/primitive_ref_runme.php b/Examples/test-suite/php/primitive_ref_runme.php new file mode 100644 index 000000000..6a5a3f43d --- /dev/null +++ b/Examples/test-suite/php/primitive_ref_runme.php @@ -0,0 +1,25 @@ + diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 42cb8db4a..09e293e6f 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -184,6 +184,21 @@ ZVAL_LONG(return_value,$1); } +%typemap(out) const int &, + const unsigned int &, + const short &, + const unsigned short &, + const long &, + const unsigned long &, + const signed char &, + const unsigned char &, + const bool &, + const size_t &, + const enum SWIGTYPE & +{ + ZVAL_LONG(return_value,*$1); +} + %typemap(directorin) int, unsigned int, short, @@ -203,6 +218,11 @@ ZVAL_BOOL(return_value,($1)?1:0); } +%typemap(out) const bool & +{ + ZVAL_BOOL(return_value,(*$1)?1:0); +} + %typemap(directorin) bool { ZVAL_BOOL($input,($1_name)?1:0); @@ -214,6 +234,12 @@ ZVAL_DOUBLE(return_value,$1); } +%typemap(out) const float &, + const double & +{ + ZVAL_DOUBLE(return_value,*$1); +} + %typemap(directorin) float, double { @@ -225,6 +251,11 @@ ZVAL_STRINGL(return_value,&$1, 1, 1); } +%typemap(out) const char & +{ + ZVAL_STRINGL(return_value,&*$1, 1, 1); +} + %typemap(out) char *, char [] { diff --git a/Lib/php/utils.i b/Lib/php/utils.i index f6fc2e5d2..69cec1004 100644 --- a/Lib/php/utils.i +++ b/Lib/php/utils.i @@ -33,10 +33,15 @@ %enddef %define %pass_by_val( TYPE, CONVERT_IN ) -%typemap(in) TYPE, const TYPE & +%typemap(in) TYPE %{ CONVERT_IN($1,$1_ltype,$input); %} +%typemap(in) const TYPE &($*1_ltype temp) +%{ + CONVERT_IN(temp,$*1_ltype,$input); + $1 = &temp; +%} %typemap(directorout) TYPE, const TYPE & %{ CONVERT_IN($result,$1_ltype,$input); From d2316a8189728032c32e659daf1f68ce9b0e2344 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 13 Aug 2009 22:07:34 +0000 Subject: [PATCH 16/68] PHP std::vector wrappers overhaul modelling on Java std_vector.i. Work around empty rename warning problem. Add capacity and reserve(). Remove need for specialize_std_vector macro. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11550 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 + Lib/php/std_vector.i | 201 ++++++++++++++++++------------------------- 2 files changed, 90 insertions(+), 115 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 30cd03df7..4c7c2a93f 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ Version 1.3.40 (in progress) ============================ +2009-08-13: wsfulton + [PHP] std::vector wrappers overhaul. They no longer require the + specialize_std_vector() macro. Added wrappers for capacity() and reserve(). + 2009-08-13: wsfulton [PHP] Add const reference typemaps. const reference primitive types are now passed by value rather than pointer like the other target languages. diff --git a/Lib/php/std_vector.i b/Lib/php/std_vector.i index b54181618..74991cc8c 100644 --- a/Lib/php/std_vector.i +++ b/Lib/php/std_vector.i @@ -3,132 +3,103 @@ * of SWIG, and the README file for authors - http://www.swig.org/release.html. * * std_vector.i - * - * SWIG typemaps for std::vector types * ----------------------------------------------------------------------------- */ %include -// ------------------------------------------------------------------------ -// std::vector -// -// The aim of all that follows would be to integrate std::vector with -// PHP as much as possible, namely, to allow the user to pass and -// be returned PHP lists. -// const declarations are used to guess the intent of the function being -// exported; therefore, the following rationale is applied: -// -// -- f(std::vector), f(const std::vector&), f(const std::vector*): -// the parameter being read-only, either a PHP sequence or a -// previously wrapped std::vector can be passed. -// -- f(std::vector&), f(std::vector*): -// the parameter must be modified; therefore, only a wrapped std::vector -// can be passed. -// -- std::vector f(): -// the vector is returned by copy; therefore, a PHP sequence of T:s -// is returned which is most easily used in other PHP functions -// -- std::vector& f(), std::vector* f(), const std::vector& f(), -// const std::vector* f(): -// the vector is returned by reference; therefore, a wrapped std::vector -// is returned -// ------------------------------------------------------------------------ - %{ #include -#include #include %} -// exported class - namespace std { - - template class vector { - // add generic typemaps here - public: - vector(unsigned int size = 0); - unsigned int size() const; - %rename(is_empty) empty; - bool empty() const; - void clear(); - %rename(push) push_back; - void push_back(const T& x); - %extend { - T pop() throw (std::out_of_range) { - if (self->size() == 0) - throw std::out_of_range("pop from empty vector"); - T x = self->back(); - self->pop_back(); - return x; - } - T& get(int i) throw (std::out_of_range) { - int size = int(self->size()); - if (i>=0 && isize()); - if (i>=0 && i class vector { + public: + typedef size_t size_type; + typedef T value_type; + typedef const value_type& const_reference; + vector(); + vector(size_type n); + size_type size() const; + size_type capacity() const; + void reserve(size_type n); + void clear(); + %rename(push) push_back; + void push_back(const value_type& x); + %extend { + bool is_empty() const { + return $self->empty(); + } + T pop() throw (std::out_of_range) { + if (self->size() == 0) + throw std::out_of_range("pop from empty vector"); + T x = self->back(); + self->pop_back(); + return x; + } + const_reference get(int i) throw (std::out_of_range) { + int size = int(self->size()); + if (i>=0 && isize()); + if (i>=0 && i class vector { - // add specialized typemaps here - public: - vector(unsigned int size = 0); - unsigned int size() const; - %rename(is_empty) empty; - bool empty() const; - void clear(); - %rename(push) push_back; - void push_back(T x); - %extend { - T pop() throw (std::out_of_range) { - if (self->size() == 0) - throw std::out_of_range("pop from empty vector"); - T x = self->back(); - self->pop_back(); - return x; - } - T get(int i) throw (std::out_of_range) { - int size = int(self->size()); - if (i>=0 && isize()); - if (i>=0 && i class vector { + public: + typedef size_t size_type; + typedef bool value_type; + typedef bool const_reference; + vector(); + vector(size_type n); + size_type size() const; + size_type capacity() const; + void reserve(size_type n); + void clear(); + %rename(push) push_back; + void push_back(const value_type& x); + %extend { + bool is_empty() const { + return $self->empty(); + } + bool pop() throw (std::out_of_range) { + if (self->size() == 0) + throw std::out_of_range("pop from empty vector"); + bool x = self->back(); + self->pop_back(); + return x; + } + const_reference get(int i) throw (std::out_of_range) { + int size = int(self->size()); + if (i>=0 && isize()); + if (i>=0 && i Date: Thu, 13 Aug 2009 22:39:20 +0000 Subject: [PATCH 17/68] add php typecheck typemaps for const reference for primitives git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11551 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/php/director_string_runme.php | 2 +- Lib/php/php.swg | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Examples/test-suite/php/director_string_runme.php b/Examples/test-suite/php/director_string_runme.php index b239e47fb..5ac583f78 100644 --- a/Examples/test-suite/php/director_string_runme.php +++ b/Examples/test-suite/php/director_string_runme.php @@ -4,7 +4,7 @@ require "tests.php"; require "director_string.php"; // No new functions -check::functions(array(a_get_first,a_call_get_first,a_string_length,a_process_text,a_call_process_func,stringvector_size,stringvector_is_empty,stringvector_clear,stringvector_push,stringvector_pop)); +check::functions(array(a_get_first,a_call_get_first,a_string_length,a_process_text,a_call_process_func,stringvector_size,stringvector_is_empty,stringvector_clear,stringvector_push,stringvector_pop,stringvector_capacity,stringvector_reserve)); // No new classes check::classes(array(A,StringVector)); // now new vars diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 09e293e6f..b41af8968 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -327,7 +327,7 @@ // an argument to be converted from a different PHP type, you must convert // it yourself before passing it (e.g. (string)4.7 or (int)"6"). %define %php_typecheck(_type,_prec,is) -%typemap(typecheck,precedence=_prec) _type +%typemap(typecheck,precedence=_prec) _type, const _type & " $1 = (Z_TYPE_PP($input) == is); " %enddef @@ -342,13 +342,12 @@ %php_typecheck(size_t,SWIG_TYPECHECK_INT16,IS_LONG) %php_typecheck(enum SWIGTYPE,SWIG_TYPECHECK_INT8,IS_LONG) %php_typecheck(bool,SWIG_TYPECHECK_BOOL,IS_BOOL) - -%php_typecheck(char,SWIG_TYPECHECK_CHAR,IS_STRING) -%php_typecheck(char *,SWIG_TYPECHECK_STRING,IS_STRING) -%php_typecheck(char [],SWIG_TYPECHECK_STRING,IS_STRING) - %php_typecheck(float,SWIG_TYPECHECK_FLOAT,IS_DOUBLE) %php_typecheck(double,SWIG_TYPECHECK_BOOL,IS_DOUBLE) +%php_typecheck(char,SWIG_TYPECHECK_CHAR,IS_STRING) + +%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) char *, const char *&, char [] + " $1 = (Z_TYPE_PP($input) == IS_STRING); " %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE { From cc43f20f6d260504582621e1a241461639bd2041 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 13 Aug 2009 23:31:19 +0000 Subject: [PATCH 18/68] PHP fix const char\*\& typemaps and add in char_strings runtime test based on Java version git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11552 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/char_strings.i | 12 +++++ .../test-suite/php/char_strings_runme.php | 44 +++++++++++++++++++ Lib/php/php.swg | 19 ++++++-- Lib/php/utils.i | 2 +- 4 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 Examples/test-suite/php/char_strings_runme.php diff --git a/Examples/test-suite/char_strings.i b/Examples/test-suite/char_strings.i index 12e4b5aa2..2561108c6 100644 --- a/Examples/test-suite/char_strings.i +++ b/Examples/test-suite/char_strings.i @@ -149,6 +149,18 @@ const char global_const_char_array2[sizeof(CPLUSPLUS_MSG)+1] = CPLUSPLUS_MSG; %inline %{ // char *& tests +char *&GetCharPointerRef() { + static char str[] = CPLUSPLUS_MSG; + static char *ptr = str; + return ptr; +} + +bool SetCharPointerRef(char *&str, unsigned int number) { + static char static_str[] = CPLUSPLUS_MSG; + strcpy(static_str, str); + return check(static_str, number); +} + const char *&GetConstCharPointerRef() { static const char str[] = CPLUSPLUS_MSG; static const char *ptr = str; diff --git a/Examples/test-suite/php/char_strings_runme.php b/Examples/test-suite/php/char_strings_runme.php new file mode 100644 index 000000000..ff75afc58 --- /dev/null +++ b/Examples/test-suite/php/char_strings_runme.php @@ -0,0 +1,44 @@ + + diff --git a/Lib/php/php.swg b/Lib/php/php.swg index b41af8968..1a953650f 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -64,6 +64,8 @@ %pass_by_val(double, CONVERT_FLOAT_IN); %pass_by_val(char *, CONVERT_STRING_IN); +%typemap(in) char *& = const char *&; +%typemap(directorout) char *& = const char *&; // char array can be in/out, though the passed string may not be big enough... // so we have to size it @@ -241,7 +243,7 @@ } %typemap(directorin) float, - double + double { ZVAL_DOUBLE($input,$1_name); } @@ -266,6 +268,15 @@ } } +%typemap(out) char *& +{ + if(!*$1) { + ZVAL_NULL(return_value); + } else { + ZVAL_STRING(return_value, (char *)*$1, 1); + } +} + %typemap(out) SWIGTYPE *, SWIGTYPE [], SWIGTYPE & @@ -274,8 +285,8 @@ %} %typemap(directorin) SWIGTYPE *, - SWIGTYPE [], - SWIGTYPE & + SWIGTYPE [], + SWIGTYPE & %{ SWIG_SetPointerZval($input, (void *)&$1_name, $1_descriptor, $owner); %} @@ -346,7 +357,7 @@ %php_typecheck(double,SWIG_TYPECHECK_BOOL,IS_DOUBLE) %php_typecheck(char,SWIG_TYPECHECK_CHAR,IS_STRING) -%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) char *, const char *&, char [] +%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) char *, char *&, char [] " $1 = (Z_TYPE_PP($input) == IS_STRING); " %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE diff --git a/Lib/php/utils.i b/Lib/php/utils.i index 69cec1004..cadba3c2f 100644 --- a/Lib/php/utils.i +++ b/Lib/php/utils.i @@ -37,7 +37,7 @@ %{ CONVERT_IN($1,$1_ltype,$input); %} -%typemap(in) const TYPE &($*1_ltype temp) +%typemap(in) const TYPE & ($*1_ltype temp) %{ CONVERT_IN(temp,$*1_ltype,$input); $1 = &temp; From d1a6d960eb28c42715cb075bd424a27d5ed56644 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 13 Aug 2009 23:37:05 +0000 Subject: [PATCH 19/68] Add non-const char *& runtime tests git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11553 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/csharp/char_strings_runme.cs | 15 +++++++++++++-- Examples/test-suite/java/char_strings_runme.java | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Examples/test-suite/csharp/char_strings_runme.cs b/Examples/test-suite/csharp/char_strings_runme.cs index a8907fb16..59bcc64df 100644 --- a/Examples/test-suite/csharp/char_strings_runme.cs +++ b/Examples/test-suite/csharp/char_strings_runme.cs @@ -120,15 +120,26 @@ public class char_strings_runme { // char *& tests for (i=0; i Date: Fri, 14 Aug 2009 00:15:23 +0000 Subject: [PATCH 20/68] Zap extra blank line after ?> which appears in testsuite output git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11554 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/php/char_strings_runme.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Examples/test-suite/php/char_strings_runme.php b/Examples/test-suite/php/char_strings_runme.php index ff75afc58..e06ee9d2b 100644 --- a/Examples/test-suite/php/char_strings_runme.php +++ b/Examples/test-suite/php/char_strings_runme.php @@ -41,4 +41,3 @@ check::equal(SetConstCharPointerRef($OTHERLAND_MSG_10, 10), true, "failed SetCon check::done(); ?> - From 3675a7baf7dca8e0826f84bda7760f497c18ce97 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 14 Aug 2009 01:00:36 +0000 Subject: [PATCH 21/68] Add min and max as built-in functions. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11555 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/php/phpkw.swg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/php/phpkw.swg b/Lib/php/phpkw.swg index e38f5e6a4..a5f410bc5 100644 --- a/Lib/php/phpkw.swg +++ b/Lib/php/phpkw.swg @@ -13,7 +13,6 @@ #define PHPBN2(x) %builtinwarn("'" `x` "' conflicts with a built-in name in PHP") "::" `x` #define PHPFN(x) %keywordwarn("'" `x` "' is a PHP built-in function, renamed as 'c_" `x` "'",sourcefmt="%(lower)s",%$isfunction,%$not %$ismember,rename="c_%s") `x` - /* From @@ -475,6 +474,8 @@ PHPFN(sqrt); PHPFN(ceil); PHPFN(floor); PHPFN(fmod); +PHPFN(min); +PHPFN(max); #undef PHPKW #undef PHPBN1 From 45359dc12c1caed9374820d576e9dc8746557e74 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 14 Aug 2009 01:14:49 +0000 Subject: [PATCH 22/68] Add SWIGTYPE *& typemaps for PHP git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11556 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../php/pointer_reference_runme.php | 14 +++++++++++++ Lib/php/php.swg | 20 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/php/pointer_reference_runme.php diff --git a/Examples/test-suite/php/pointer_reference_runme.php b/Examples/test-suite/php/pointer_reference_runme.php new file mode 100644 index 000000000..8fc67a134 --- /dev/null +++ b/Examples/test-suite/php/pointer_reference_runme.php @@ -0,0 +1,14 @@ + diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 1a953650f..136326cb7 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -114,6 +114,14 @@ } } +%typemap(in) SWIGTYPE *& ($*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 = &temp; +} + %typemap(in) SWIGTYPE *DISOWN { if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN ) < 0) { @@ -284,6 +292,11 @@ SWIG_SetPointerZval(return_value, (void *)$1, $1_descriptor, $owner); %} +%typemap(out) SWIGTYPE *& +%{ + SWIG_SetPointerZval(return_value, (void *)*$1, $*1_descriptor, $owner); +%} + %typemap(directorin) SWIGTYPE *, SWIGTYPE [], SWIGTYPE & @@ -325,6 +338,10 @@ } #endif +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + + %typemap(out) void ""; %typemap(out) char [ANY] @@ -368,7 +385,8 @@ %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE [], - SWIGTYPE & + SWIGTYPE &, + SWIGTYPE *& { void *tmp; _v = (SWIG_ConvertPtr(*$input, (void**)&tmp, $1_descriptor, 0) >= 0); From 84215444eb3d4ae299d81f028cfa7eff90f8a1ec Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 14 Aug 2009 01:33:23 +0000 Subject: [PATCH 23/68] Rename max() to maximum() as max() is a built-in function in PHP. Testcases overload_template and overload_template_fast now pass for PHP. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11557 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../test-suite/csharp/overload_template_runme.cs | 4 ++-- .../test-suite/java/overload_template_runme.java | 4 ++-- .../test-suite/lua/overload_template_runme.lua | 4 ++-- .../test-suite/octave/overload_template_runme.m | 4 ++-- Examples/test-suite/overload_template.i | 14 ++++---------- .../test-suite/python/overload_template_runme.py | 4 ++-- .../test-suite/ruby/overload_template_runme.rb | 4 ++-- 7 files changed, 16 insertions(+), 22 deletions(-) diff --git a/Examples/test-suite/csharp/overload_template_runme.cs b/Examples/test-suite/csharp/overload_template_runme.cs index e4910161b..e25420169 100644 --- a/Examples/test-suite/csharp/overload_template_runme.cs +++ b/Examples/test-suite/csharp/overload_template_runme.cs @@ -7,8 +7,8 @@ public class runme { int f = overload_template.foo(); - f += overload_template.max(3,4); - double b = overload_template.max(3.4,5.2); + f += overload_template.maximum(3,4); + double b = overload_template.maximum(3.4,5.2); b++; // warning suppression // mix 1 diff --git a/Examples/test-suite/java/overload_template_runme.java b/Examples/test-suite/java/overload_template_runme.java index e76bf63ee..bda1853be 100644 --- a/Examples/test-suite/java/overload_template_runme.java +++ b/Examples/test-suite/java/overload_template_runme.java @@ -16,8 +16,8 @@ public class overload_template_runme { public static void main(String argv[]) { int f = overload_template.foo(); - int a = overload_template.max(3,4); - double b = overload_template.max(3.4,5.2); + int a = overload_template.maximum(3,4); + double b = overload_template.maximum(3.4,5.2); // mix 1 if (overload_template.mix1("hi") != 101) diff --git a/Examples/test-suite/lua/overload_template_runme.lua b/Examples/test-suite/lua/overload_template_runme.lua index c62a42c02..19cc7e9dd 100644 --- a/Examples/test-suite/lua/overload_template_runme.lua +++ b/Examples/test-suite/lua/overload_template_runme.lua @@ -2,12 +2,12 @@ require("import") -- the import fn import("overload_template") -- import code for k,v in pairs(overload_template) do _G[k]=v end -- move to global --- lua has only one numeric type, so max(int,int) and max(double,double) are the same +-- lua has only one numeric type, so maximum(int,int) and maximum(double,double) are the same -- whichever one was wrapper first will be used (which is int) f = foo() -a = max(3,4) +a = maximum(3,4) -- mix 1 assert(mix1("hi") == 101) diff --git a/Examples/test-suite/octave/overload_template_runme.m b/Examples/test-suite/octave/overload_template_runme.m index b38dc73e1..d7b1cbb65 100644 --- a/Examples/test-suite/octave/overload_template_runme.m +++ b/Examples/test-suite/octave/overload_template_runme.m @@ -1,8 +1,8 @@ overload_template f = foo(); -a = max(3,4); -b = max(3.4,5.2); +a = maximum(3,4); +b = maximum(3.4,5.2); # mix 1 if (mix1("hi") != 101) diff --git a/Examples/test-suite/overload_template.i b/Examples/test-suite/overload_template.i index a889dbfda..dee6ab91e 100644 --- a/Examples/test-suite/overload_template.i +++ b/Examples/test-suite/overload_template.i @@ -3,7 +3,7 @@ #ifdef SWIGLUA // lua only has one numeric type, so most of the overloads shadow each other creating warnings %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) foo; -%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) max; +%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) maximum; %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) specialization; %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) overload; %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) space::nsoverload; @@ -11,12 +11,6 @@ %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) barT; #endif -%{ -#ifdef max -#undef max -#endif -%} - %inline %{ int foo() { @@ -29,15 +23,15 @@ template } template - T max(T a, T b) { return (a > b) ? a : b; } + T maximum(T a, T b) { return (a > b) ? a : b; } %} %template(foo) foo; %template(foo) foo; -%template(max) max; -%template(max) max; +%template(maximum) maximum; +%template(maximum) maximum; // Mix template overloading with plain function overload // Mix 1 diff --git a/Examples/test-suite/python/overload_template_runme.py b/Examples/test-suite/python/overload_template_runme.py index 3fd77f339..c1337ba6a 100644 --- a/Examples/test-suite/python/overload_template_runme.py +++ b/Examples/test-suite/python/overload_template_runme.py @@ -1,8 +1,8 @@ from overload_template import * f = foo() -a = max(3,4) -b = max(3.4,5.2) +a = maximum(3,4) +b = maximum(3.4,5.2) # mix 1 if (mix1("hi") != 101): diff --git a/Examples/test-suite/ruby/overload_template_runme.rb b/Examples/test-suite/ruby/overload_template_runme.rb index bcbddf512..b099fd3ea 100755 --- a/Examples/test-suite/ruby/overload_template_runme.rb +++ b/Examples/test-suite/ruby/overload_template_runme.rb @@ -13,5 +13,5 @@ require 'overload_template' f = Overload_template.foo() -a = Overload_template.max(3,4) -b = Overload_template.max(3.4,5.2) +a = Overload_template.maximum(3,4) +b = Overload_template.maximum(3.4,5.2) From 6f80e2f7a69224e7608c2b845537f575f580c572 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 14 Aug 2009 04:22:03 +0000 Subject: [PATCH 24/68] PHP: Add directorout typemap for primitive type const refs git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11559 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/php/utils.i | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Lib/php/utils.i b/Lib/php/utils.i index cadba3c2f..166941585 100644 --- a/Lib/php/utils.i +++ b/Lib/php/utils.i @@ -42,10 +42,15 @@ CONVERT_IN(temp,$*1_ltype,$input); $1 = &temp; %} -%typemap(directorout) TYPE, const TYPE & +%typemap(directorout) TYPE %{ CONVERT_IN($result,$1_ltype,$input); %} +%typemap(directorout) const TYPE & ($*1_ltype temp) +%{ + CONVERT_IN(temp,$*1_ltype,$input); + $result = &temp; +%} %enddef %fragment("t_output_helper","header") %{ From e0683051251aefa3c9aec07cb6c6888e54418b97 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 14 Aug 2009 07:53:38 +0000 Subject: [PATCH 25/68] If there's no prefix, special case to avoid prepending an empty string. Don't calculate $class in the stdClass case when we don't need it. Eliminate an unnecessary else. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11563 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/php.cxx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 44fe032a5..ae4463238 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1651,15 +1651,19 @@ public: * TODO: do this in a more elegant way */ Printf(output, "\t\tif (is_resource($r)) {\n"); - Printf(output, "\t\t\t$class='%s'.substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3));\n", prefix); if (Getattr(classLookup(Getattr(n, "type")), "module")) { + if (Len(prefix) == 0) { + Printf(output, "\t\t\t$class=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3));\n"); + } else { + Printf(output, "\t\t\t$class='%s'.substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3));\n", prefix); + } Printf(output, "\t\t\treturn new $class($r);\n"); } else { Printf(output, "\t\t\t$c = new stdClass();\n"); Printf(output, "\t\t\t$c->_cPtr = $r;\n"); Printf(output, "\t\t\treturn $c;\n"); } - Printf(output, "\t\t}\n\t\telse return $r;\n"); + Printf(output, "\t\t}\n\t\treturn $r;\n"); } else { Printf(output, "\t\t$this->%s = $r;\n", SWIG_PTR); Printf(output, "\t\treturn $this;\n"); From e125ce326db5f53085d9f42fff108f4ebc5b3151 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 14 Aug 2009 08:04:21 +0000 Subject: [PATCH 26/68] If $c would be used as a parameter name, rename it to $c_ to avoid issues if call-time pass-by-reference is enabled and used. Use $c instead of $class to keep down the number of "reserved" parameter names. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11564 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/php.cxx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index ae4463238..0f12bcfc3 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1392,9 +1392,11 @@ public: /* We use $r to store the return value, so disallow that as a parameter * name in case the user uses the "call-time pass-by-reference" feature * (it's deprecated and off by default in PHP5, but we want to be - * maximally portable). + * maximally portable). Similarly we use $c for the classname or new + * stdClass object. */ Setattr(seen, "r", seen); + Setattr(seen, "c", seen); for (int argno = 0; argno < max_num_of_arguments; ++argno) { String *&pname = arg_names[argno]; @@ -1653,11 +1655,11 @@ public: Printf(output, "\t\tif (is_resource($r)) {\n"); if (Getattr(classLookup(Getattr(n, "type")), "module")) { if (Len(prefix) == 0) { - Printf(output, "\t\t\t$class=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3));\n"); + Printf(output, "\t\t\t$c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3));\n"); } else { - Printf(output, "\t\t\t$class='%s'.substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3));\n", prefix); + Printf(output, "\t\t\t$c='%s'.substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3));\n", prefix); } - Printf(output, "\t\t\treturn new $class($r);\n"); + Printf(output, "\t\t\treturn new $c($r);\n"); } else { Printf(output, "\t\t\t$c = new stdClass();\n"); Printf(output, "\t\t\t$c->_cPtr = $r;\n"); From 1b42d9dde1cd722c16f8ac3917f21fdb2670dad0 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 14 Aug 2009 09:01:31 +0000 Subject: [PATCH 27/68] [PHP] Update the PHP "class" example to work with PHP5 and use modern wrapping features. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11565 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Examples/php/class/Makefile | 2 +- Examples/php/class/runme.php | 38 ++++++++++++++++-------------------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 4c7c2a93f..fb98f0d28 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ Version 1.3.40 (in progress) ============================ +2009-08-14: olly + [PHP] Update the PHP "class" example to work with PHP5 and use + modern wrapping features. + 2009-08-13: wsfulton [PHP] std::vector wrappers overhaul. They no longer require the specialize_std_vector() macro. Added wrappers for capacity() and reserve(). diff --git a/Examples/php/class/Makefile b/Examples/php/class/Makefile index 252a72660..1bc0beaab 100644 --- a/Examples/php/class/Makefile +++ b/Examples/php/class/Makefile @@ -4,7 +4,7 @@ CXXSRCS = example.cxx TARGET = example INTERFACE = example.i LIBS = -SWIGOPT = -noproxy +SWIGOPT = all:: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/php/class/runme.php b/Examples/php/class/runme.php index a9ca657dc..12b686052 100644 --- a/Examples/php/class/runme.php +++ b/Examples/php/class/runme.php @@ -1,22 +1,20 @@ x = 20; +$c->y = 30; +$s->x = -10; +$s->y = 5; print "\nHere is their current position:\n"; -print " Circle = (" . Shape_x_get($c) . "," . Shape_y_get($c) . ")\n"; -print " Square = (" . Shape_x_get($s) . "," . Shape_y_get($s) . ")\n"; +print " Circle = ({$c->x},{$c->y})\n"; +print " Square = ({$s->x},{$s->y})\n"; # ----- Call some methods ----- @@ -39,18 +37,16 @@ print " Square = (" . Shape_x_get($s) . "," . Shape_y_get($s) . ")\n"; # invoke the appropriate virtual method on each object. print "\nHere are some properties of the shapes:\n"; foreach (array($c,$s) as $o) { - print " $o\n"; - print " area = " . Shape_area($o) . "\n"; - print " perimeter = " . Shape_perimeter($o) . "\n"; - } + print " ". get_class($o) . "\n"; + print " area = {$o->area()}\n"; + print " perimeter = {$o->perimeter()}\n"; +} # ----- Delete everything ----- print "\nGuess I'll clean up now\n"; # Note: this invokes the virtual destructor -#delete_Shape($c); -#delete_Shape($s); $c = NULL; $s = NULL; @@ -58,7 +54,7 @@ $s = NULL; # the square. $o = NULL; -print nshapes() . " shapes remain\n"; +print Shape::get_nshapes() . " shapes remain\n"; print "Goodbye\n"; ?> From f4e3444ae3d0c5ef233810484b4244f75928146e Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 14 Aug 2009 09:44:15 +0000 Subject: [PATCH 28/68] Use module name instead of hardcoded "example" in __get(). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11567 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/php.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 0f12bcfc3..91d75a046 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -2046,7 +2046,7 @@ public: Printf(s_phpclasses, "\t}\n"); } else { Printf(s_phpclasses, "\n\tfunction __get($var) {\n"); - Printf(s_phpclasses, "\t\tif ($var === 'thisown') return swig_example_get_newobject($this->%s);\n", SWIG_PTR); + Printf(s_phpclasses, "\t\tif ($var === 'thisown') return swig_%s_get_newobject($this->%s);\n", module, SWIG_PTR); Printf(s_phpclasses, "\t\telse return $this->%s[$var];\n", SWIG_DATA); Printf(s_phpclasses, "\t}\n"); } From 57017bd6bc1f5465b0fdc94185a06ece26a549a9 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 14 Aug 2009 16:22:15 +0000 Subject: [PATCH 29/68] [PHP] PHP5 now wraps static member variables as documented. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11570 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 ++ Source/Modules/php.cxx | 104 ++++++++++++++--------------------------- 2 files changed, 39 insertions(+), 68 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index fb98f0d28..da76ebb40 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,9 @@ Version 1.3.40 (in progress) ============================ +2009-08-14: olly + [PHP] PHP5 now wraps static member variables as documented. + 2009-08-14: olly [PHP] Update the PHP "class" example to work with PHP5 and use modern wrapping features. diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 91d75a046..b41ab7b1f 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -9,10 +9,6 @@ */ /* FIXME: PHP5 OO wrapping TODO list: - * - * Short term: - * - * Sort out wrapping of static member variables in OO PHP5. * * Medium term: * @@ -766,8 +762,8 @@ public: String *outarg = NewStringEmpty(); String *cleanup = NewStringEmpty(); - // Not issued for overloaded functions or static member variables. - if (!overloaded && wrapperType != staticmembervar) { + // Not issued for overloaded functions. + if (!overloaded) { create_command(iname, wname); } Printv(f->def, "ZEND_NAMED_FUNCTION(", wname, ") {\n", NIL); @@ -1721,6 +1717,40 @@ public: } free(arg_names); arg_names = NULL; + } else if (wrapperType == staticmembervar) { + // FIXME: this case ought to be folded into the one above so that it + // handles wrapping static members which are themselves objects. + + // Static member variable, wrapped as a function due to PHP limitations. + const char *methodname = 0; + String *output = s_oowrappers; + methodname = Char(Getattr(n, "staticmembervariableHandler:sym:name")); + + // We're called twice for a writable static member variable - first with + // "foo_set" and then with "foo_get" - so generate half the wrapper + // function each time. + // + // For a const static member, we only get called once. + static bool started = false; + const char *p = Char(iname); + if (strlen(p) > 4) { + p += strlen(p) - 4; + if (!started) { + started = true; + Printf(output, "\n\tstatic function %s() {\n", methodname); + if (strcmp(p, "_set") == 0) { + Printf(output, "\t\tif (func_num_args()) {\n"); + Printf(output, "\t\t\t%s(func_get_arg(0));\n", iname); + Printf(output, "\t\t\treturn;\n"); + Printf(output, "\t\t}\n"); + } + } + if (strcmp(p, "_get") == 0) { + started = false; + Printf(output, "\t\treturn %s();\n", iname); + Printf(output, "\t}\n"); + } + } } DelWrapper(f); @@ -2110,68 +2140,6 @@ public: Language::staticmembervariableHandler(n); wrapperType = standard; - SwigType *type = Getattr(n, "type"); - String *name = Getattr(n, "name"); - String *iname = Getattr(n, "sym:name"); - - /* A temporary(!) hack for static member variables. - * PHP currently supports class functions, but not class variables. - * Until it does, we convert a class variable to a class function - * that returns the current value of the variable. E.g. - * - * class Example { - * public: - * static int ncount; - * }; - * - * would be available in PHP as Example::ncount() - */ - - // If the variable is const, then it's wrapped as a constant with set/get - // functions. - if (SwigType_isconst(type)) - return SWIG_OK; - - // This duplicates the logic from Language::variableWrapper() to test if - // the set wrapper is made. - int assignable = is_assignable(n); - if (assignable) { - String *tm = Swig_typemap_lookup("globalin", n, name, 0); - if (!tm && SwigType_isarray(type)) { - assignable = 0; - } - } - - String *class_iname = Swig_name_member(Getattr(current_class, "sym:name"), iname); - String *lclass_iname = NewStringf("%(lower)s", class_iname); - create_command(lclass_iname, Swig_name_wrapper(class_iname)); - Delete(lclass_iname); - - Wrapper *f = NewWrapper(); - - Printv(f->def, "ZEND_NAMED_FUNCTION(", Swig_name_wrapper(class_iname), ") {\n", NIL); - String *mget = Swig_name_wrapper(Swig_name_get(class_iname)); - String *mset = Swig_name_wrapper(Swig_name_set(class_iname)); - - if (assignable) { - Printf(f->code, "if (ZEND_NUM_ARGS() > 0 ) {\n"); - Printf(f->code, " %s( INTERNAL_FUNCTION_PARAM_PASSTHRU );\n", mset); - Printf(f->code, " // need some error checking here?\n"); - Printf(f->code, " // Set the argument count to 0 for the get call\n"); - Printf(f->code, " ht = 0;\n"); - Printf(f->code, "}\n"); - } - - Printf(f->code, "%s( INTERNAL_FUNCTION_PARAM_PASSTHRU );\n", mget); - Printf(f->code, "}\n"); - - Wrapper_print(f, s_wrappers); - - Delete(class_iname); - Delete(mget); - Delete(mset); - DelWrapper(f); - return SWIG_OK; } From ba29cea2b519672a8304f4195c87b263ff242d19 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 14 Aug 2009 17:01:20 +0000 Subject: [PATCH 30/68] Minor cleanups. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11571 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/php.cxx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index b41ab7b1f..bac95bd93 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -979,6 +979,8 @@ public: Replaceall(f->code, "$symname", iname); Wrapper_print(f, s_wrappers); + DelWrapper(f); + f = NULL; if (overloaded && !Getattr(n, "sym:nextSibling")) { dispatchFunction(n); @@ -988,7 +990,6 @@ public: wname = NULL; if (!shadow) { - DelWrapper(f); return SWIG_OK; } @@ -1004,6 +1005,7 @@ public: Setattr(shadow_set_vars, varname, iname); } } + return SWIG_OK; } // Only look at non-overloaded methods and the last entry in each overload // chain (we check the last so that wrap:parms and wrap:name have been set @@ -1013,6 +1015,7 @@ public: if (!s_oowrappers) s_oowrappers = NewStringEmpty(); + if (newobject || wrapperType == memberfn || wrapperType == staticmemberfn || wrapperType == standard) { bool handle_as_overload = false; String **arg_names; @@ -1753,8 +1756,6 @@ public: } } - DelWrapper(f); - return SWIG_OK; } From 10edc69383693bb3d483e996d8d3a92493423413 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 14 Aug 2009 21:05:06 +0000 Subject: [PATCH 31/68] SWIG_ConvertPtrAndOwn() into the runtime for Perl git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11572 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 5 +++++ Lib/perl5/perlrun.swg | 20 +++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index da76ebb40..c4190883e 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,11 @@ Version 1.3.40 (in progress) ============================ +2009-08-14: wsfulton + [Perl] Add SWIG_ConvertPtrAndOwn() method into the runtime for smart pointer + memory ownership control. shared_ptr support still to be added. Patch from + David Fletcher. + 2009-08-14: olly [PHP] PHP5 now wraps static member variables as documented. diff --git a/Lib/perl5/perlrun.swg b/Lib/perl5/perlrun.swg index 6fb2968f0..be788f540 100644 --- a/Lib/perl5/perlrun.swg +++ b/Lib/perl5/perlrun.swg @@ -18,6 +18,7 @@ /* for raw pointers */ #define SWIG_ConvertPtr(obj, pp, type, flags) SWIG_Perl_ConvertPtr(SWIG_PERL_OBJECT_CALL obj, pp, type, flags) +#define SWIG_ConvertPtrAndOwn(obj, pp, type, flags,own) SWIG_Perl_ConvertPtrAndOwn(SWIG_PERL_OBJECT_CALL obj, pp, type, flags, own) #define SWIG_NewPointerObj(p, type, flags) SWIG_Perl_NewPointerObj(SWIG_PERL_OBJECT_CALL p, type, flags) /* for raw packed data */ @@ -234,10 +235,14 @@ SWIG_TypeProxyCheck(const char *c, swig_type_info *ty) { /* Function for getting a pointer value */ SWIGRUNTIME int -SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *_t, int flags) { +SWIG_Perl_ConvertPtrAndOwn(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *_t, int flags, int *own) { swig_cast_info *tc; void *voidptr = (void *)0; SV *tsv = 0; + + if (own) + *own = 0; + /* If magical, apply more magic */ if (SvGMAGICAL(sv)) mg_get(sv); @@ -287,7 +292,11 @@ SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info * { int newmemory = 0; *ptr = SWIG_TypeCast(tc,voidptr,&newmemory); - assert(!newmemory); /* newmemory handling not yet implemented */ + if (newmemory == SWIG_CAST_NEW_MEMORY) { + assert(own); + if (own) + *own = *own | SWIG_CAST_NEW_MEMORY; + } } } else { *ptr = voidptr; @@ -317,9 +326,14 @@ SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info * return SWIG_OK; } +SWIGRUNTIME int +SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *_t, int flags) { + return SWIG_Perl_ConvertPtrAndOwn(sv, ptr, _t, flags, 0); +} + SWIGRUNTIME void SWIG_Perl_MakePtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, swig_type_info *t, int flags) { - if (ptr && (flags & SWIG_SHADOW)) { + if (ptr && (flags & (SWIG_SHADOW | SWIG_POINTER_OWN))) { SV *self; SV *obj=newSV(0); HV *hash=newHV(); From a717dbd10b8d3ee23601aee790c6779abcaa6e22 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 14 Aug 2009 22:11:27 +0000 Subject: [PATCH 32/68] Add some notes about \%extend and constructors git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11573 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/SWIG.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index fdbbab6f7..31964bbe1 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -2388,6 +2388,10 @@ You can make a Vector look a lot like a class by writing a SWIG interfa

Note the usage of the $self special variable. Its usage is identical to a C++ 'this' pointer and should be used whenever access to the struct instance is required. +Also note that C++ constructor and destructor syntax has been used to simulate a constructor and destructor, even for C code. +There is one subtle difference to a normal C++ constructor implementation though and that is although the constructor declaration +is as per a normal C++ constructor, the newly constructed object must be returned as if the constructor declaration +had a return value, a Vector * in this case.

From 265adcae79d495bf3acaf630a4a487c2e025af6b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 14 Aug 2009 22:13:21 +0000 Subject: [PATCH 33/68] Fill in missing bit about the begin section git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11574 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/SWIG.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index 31964bbe1..8705fa182 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -2716,6 +2716,10 @@ initialization code (in that order).

    +
  • Begin section.
    +A placeholder to put code at the beginning of the C/C++ wrapper file. +
  • +
  • Runtime code.
    This code is internal to SWIG and is used to include type-checking and other support functions that are used by the rest of the module. From 06c06f8742720e83f2f615ed84ad3695b93f5df1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 14 Aug 2009 22:47:11 +0000 Subject: [PATCH 34/68] remove redundant if not __cplusplus for directorin typemap - directors are always c++ git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11575 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/php/php.swg | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Lib/php/php.swg b/Lib/php/php.swg index 136326cb7..a604b035b 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -326,17 +326,9 @@ #endif %typemap(directorin) SWIGTYPE -#ifdef __cplusplus { SWIG_SetPointerZval($input, SWIG_as_voidptr(&$1_name), $&1_descriptor, 2); } -#else -{ - $&1_ltype resultobj = ($&1_ltype) emalloc(sizeof($1_type)); - memcpy(resultobj, &$1, sizeof($1_type)); - SWIG_SetPointerZval($input, (void *)resultobj, $&1_descriptor, 2); -} -#endif /* Array reference typemaps */ %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } From 55170f0f88e5df7f28710d50982da5dd40d8fc04 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 15 Aug 2009 00:17:21 +0000 Subject: [PATCH 35/68] Add Ruby missing methods for vector specialization git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11576 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 +++ .../test-suite/ruby/li_std_vector_runme.rb | 7 ++++++ Lib/ruby/rubycontainer.swg | 25 +------------------ 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index c4190883e..c2ce13d66 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ Version 1.3.40 (in progress) ============================ +2009-08-15: wsfulton + [Ruby] Add numerous missing wrapped methods for std::vector specialization + as reported by Youssef Jones. + 2009-08-14: wsfulton [Perl] Add SWIG_ConvertPtrAndOwn() method into the runtime for smart pointer memory ownership control. shared_ptr support still to be added. Patch from diff --git a/Examples/test-suite/ruby/li_std_vector_runme.rb b/Examples/test-suite/ruby/li_std_vector_runme.rb index 484f1888e..8bcad2d19 100755 --- a/Examples/test-suite/ruby/li_std_vector_runme.rb +++ b/Examples/test-suite/ruby/li_std_vector_runme.rb @@ -98,6 +98,13 @@ sv[1] = Li_std_vector::Struct.new EOF +bv = BoolVector.new(2) +[true, false, true, true].each { |i| bv.push(i) } +0.upto(bv.size-1) { |i| bv[i] = !bv[i] } +bv_check = [true, true, false, true, false, false] +for i in 0..bv.size-1 do + swig_assert(bv_check[i] == bv[i], binding, "bv[#{i}]") +end swig_assert_each_line(<<'EOF', binding) lv = LanguageVector.new diff --git a/Lib/ruby/rubycontainer.swg b/Lib/ruby/rubycontainer.swg index 919695ec2..df3f520d8 100644 --- a/Lib/ruby/rubycontainer.swg +++ b/Lib/ruby/rubycontainer.swg @@ -875,31 +875,8 @@ namespace swig } %enddef -// ..I don't think %swig_sequence_methods_val are really used at all anymore... %define %swig_sequence_methods_val(Sequence...) - %swig_sequence_methods_common(%arg(Sequence)) - %extend { - - VALUE __getitem__(difference_type i) { - VALUE r = Qnil; - try { - r = swig::from< Sequence::value_type >( *(swig::cgetpos(self, i)) ); - } - catch( std::out_of_range ) - { - } - return r; - } - - VALUE __setitem__(difference_type i, value_type x) { - std::size_t len = $self->size(); - if ( i < 0 ) i = len - i; - else if ( static_cast(i) >= len ) - $self->resize( i+1, x ); - else *(swig::getpos(self,i)) = x; - return swig::from< Sequence::value_type >( x ); - } - } + %swig_sequence_methods(%arg(Sequence)) %enddef From b81cb3bff9fef536650e415b8d34612a57678c92 Mon Sep 17 00:00:00 2001 From: Xavier Delacour Date: Sat, 15 Aug 2009 01:19:28 +0000 Subject: [PATCH 36/68] try not to require -api option in octave git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11577 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/octave/octrun.swg | 22 ++++++++++++++++++++++ Source/Modules/octave.cxx | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 759cf3c37..a2bf52070 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -1,4 +1,26 @@ +#if OCTAVE_API_VERSION_OPTION>0 +#define USE_OCTAVE_API_VERSION OCTAVE_API_VERSION_OPTION +#else + +#include +#ifdef OCTAVE_API_VERSION_N +#define USE_OCTAVE_API_VERSION OCTAVE_API_VERSION_N + +#else // Interim hack to distinguish between Octave 3.2 and earlier versions. + +#define ComplexLU __ignore +#include +#undef ComplexLU +#ifdef octave_Complex_LU_h +#define USE_OCTAVE_API_VERSION 36 +#else +#define USE_OCTAVE_API_VERSION 37 +#endif + +#endif + +#endif SWIGRUNTIME bool SWIG_check_num_args(const char *func_name, int num_args, int max_args, int min_args, int varargs) { if (num_args > max_args && !varargs) diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx index 9f924332d..aeb72f77a 100644 --- a/Source/Modules/octave.cxx +++ b/Source/Modules/octave.cxx @@ -56,7 +56,7 @@ public: director_multiple_inheritance = 1; director_language = 1; docs = NewHash(); - api_version = 37; + api_version = 0; } virtual void main(int argc, char *argv[]) { @@ -138,7 +138,7 @@ public: Printf(f_runtime, "#define SWIGOCTAVE\n"); Printf(f_runtime, "#define SWIG_name_d \"%s\"\n", module); Printf(f_runtime, "#define SWIG_name %s\n", module); - Printf(f_runtime, "#define USE_OCTAVE_API_VERSION %i\n", api_version); + Printf(f_runtime, "#define OCTAVE_API_VERSION_OPTION %i\n", api_version); if (directorsEnabled()) { Printf(f_runtime, "#define SWIG_DIRECTORS\n"); From f3d0ebbf1809dfd1ca6170e23b72701039700be5 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 15 Aug 2009 05:33:05 +0000 Subject: [PATCH 37/68] Refactor the recent support for wrapping static member variables for PHP5 so it works for static members which are themselves classes. With this and the previous patch, li_std_string now passes and all other tests pass/fail as before. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11578 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/php.cxx | 67 +++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index bac95bd93..dc7f863e3 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -118,8 +118,7 @@ static enum { membervar, staticmembervar, constructor, - directorconstructor, - destructor + directorconstructor } wrapperType = standard; extern "C" { @@ -1007,6 +1006,7 @@ public: } return SWIG_OK; } + // Only look at non-overloaded methods and the last entry in each overload // chain (we check the last so that wrap:parms and wrap:name have been set // for them all). @@ -1016,7 +1016,7 @@ public: if (!s_oowrappers) s_oowrappers = NewStringEmpty(); - if (newobject || wrapperType == memberfn || wrapperType == staticmemberfn || wrapperType == standard) { + if (newobject || wrapperType == memberfn || wrapperType == staticmemberfn || wrapperType == standard || wrapperType == staticmembervar) { bool handle_as_overload = false; String **arg_names; String **arg_values; @@ -1043,6 +1043,9 @@ public: methodname = Char(Getattr(n, "memberfunctionHandler:sym:name")); } else if (wrapperType == staticmemberfn) { methodname = Char(Getattr(n, "staticmemberfunctionHandler:sym:name")); + } else if (wrapperType == staticmembervar) { + // Static member variable, wrapped as a function due to PHP limitations. + methodname = Char(Getattr(n, "staticmembervariableHandler:sym:name")); } else { // wrapperType == standard methodname = Char(iname); if (!s_fakeoowrappers) @@ -1053,6 +1056,7 @@ public: bool really_overloaded = overloaded ? true : false; int min_num_of_arguments = emit_num_required(l); int max_num_of_arguments = emit_num_arguments(l); + // For a function with default arguments, we end up with the fullest // parmlist in full_parmlist. ParmList *full_parmlist = l; @@ -1515,6 +1519,7 @@ public: Printf(prepare, "$this->%s=", SWIG_PTR); } } + if (!directorsEnabled() || !Swig_directorclass(n) || !newobject) { Printf(prepare, "%s(%s);\n", iname, invoke_args); } else { @@ -1594,6 +1599,26 @@ public: Printf(output, "\t%sfunction %s(%s) {\n", acc, methodname, args); } Delete(acc); + } else if (wrapperType == staticmembervar) { + // We're called twice for a writable static member variable - first + // with "foo_set" and then with "foo_get" - so generate half the + // wrapper function each time. + // + // For a const static member, we only get called once. + static bool started = false; + if (!started) { + Printf(output, "\tstatic function %s() {\n", methodname); + if (max_num_of_arguments) { + // Setter. + Printf(output, "\t\tif (func_num_args()) {\n"); + Printf(output, "\t\t\t%s(func_get_arg(0));\n", iname); + Printf(output, "\t\t\treturn;\n"); + Printf(output, "\t\t}\n"); + started = true; + goto done; + } + } + started = false; } else { Printf(output, "\tstatic function %s(%s) {\n", methodname, args); } @@ -1708,6 +1733,8 @@ public: Printf(output, "\t\treturn %s;\n", invoke); } Printf(output, "\t}\n"); + +done: Delete(prepare); Delete(invoke); free(arg_values); @@ -1720,40 +1747,6 @@ public: } free(arg_names); arg_names = NULL; - } else if (wrapperType == staticmembervar) { - // FIXME: this case ought to be folded into the one above so that it - // handles wrapping static members which are themselves objects. - - // Static member variable, wrapped as a function due to PHP limitations. - const char *methodname = 0; - String *output = s_oowrappers; - methodname = Char(Getattr(n, "staticmembervariableHandler:sym:name")); - - // We're called twice for a writable static member variable - first with - // "foo_set" and then with "foo_get" - so generate half the wrapper - // function each time. - // - // For a const static member, we only get called once. - static bool started = false; - const char *p = Char(iname); - if (strlen(p) > 4) { - p += strlen(p) - 4; - if (!started) { - started = true; - Printf(output, "\n\tstatic function %s() {\n", methodname); - if (strcmp(p, "_set") == 0) { - Printf(output, "\t\tif (func_num_args()) {\n"); - Printf(output, "\t\t\t%s(func_get_arg(0));\n", iname); - Printf(output, "\t\t\treturn;\n"); - Printf(output, "\t\t}\n"); - } - } - if (strcmp(p, "_get") == 0) { - started = false; - Printf(output, "\t\treturn %s();\n", iname); - Printf(output, "\t}\n"); - } - } } return SWIG_OK; From 719df6b10a089fbf5c6518f59e6f73a0fa0dfba7 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 15 Aug 2009 06:08:28 +0000 Subject: [PATCH 38/68] Fix pointer_reference_runme.php for PHP5 - now passes. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11579 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/php/pointer_reference_runme.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Examples/test-suite/php/pointer_reference_runme.php b/Examples/test-suite/php/pointer_reference_runme.php index 8fc67a134..782760a37 100644 --- a/Examples/test-suite/php/pointer_reference_runme.php +++ b/Examples/test-suite/php/pointer_reference_runme.php @@ -3,12 +3,13 @@ require "tests.php"; require "pointer_reference.php"; -$s = get(); -check::equal(Struct_value_get($s), 10, "pointer_reference.get failed"); +$s = pointer_reference::get(); +check::equal($s->value, 10, "pointer_reference::get() failed"); -$ss = new_Struct(20); -set($ss); -check::equal(Struct_value_get(Struct_instance()), 20, "pointer_reference.set failed"); +$ss = new Struct(20); +pointer_reference::set($ss); +$i = Struct::instance(); +check::equal($i->value, 20, "pointer_reference::set() failed"); check::done(); ?> From 5118c399f0516890267ba72b2b74cbade1bfba83 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 15 Aug 2009 07:39:56 +0000 Subject: [PATCH 39/68] Fix valuewrapper_base_runme.php for PHP5. Still fails though. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11580 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/php/valuewrapper_base_runme.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/php/valuewrapper_base_runme.php b/Examples/test-suite/php/valuewrapper_base_runme.php index aff88486e..50de67f2e 100644 --- a/Examples/test-suite/php/valuewrapper_base_runme.php +++ b/Examples/test-suite/php/valuewrapper_base_runme.php @@ -7,7 +7,7 @@ require "valuewrapper_base.php"; check::classes(array("valuewrapper_base","Base","Interface_BP")); check::functions("make_interface_bp"); -$ibp=make_interface_bp(); +$ibp=valuewrapper_base::make_interface_bp(); check::classname("interface_bp",$ibp); check::done(); From d74b680a79ee9cd68b4c92f882d68693d18bac28 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 15 Aug 2009 10:40:19 +0000 Subject: [PATCH 40/68] Fix %template seg fault on some cases of overloading the templated method. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11582 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ .../java/template_methods_runme.java | 7 ++++++ Examples/test-suite/template_methods.i | 22 +++++++++++++++++++ Source/CParse/parser.y | 2 +- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index c2ce13d66..70914fb2f 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ Version 1.3.40 (in progress) ============================ +2009-08-15: wsfulton + Fix %template seg fault on some cases of overloading the templated method. + Bug reported by Jan Kupec. + 2009-08-15: wsfulton [Ruby] Add numerous missing wrapped methods for std::vector specialization as reported by Youssef Jones. diff --git a/Examples/test-suite/java/template_methods_runme.java b/Examples/test-suite/java/template_methods_runme.java index cc179aa49..14256b6be 100644 --- a/Examples/test-suite/java/template_methods_runme.java +++ b/Examples/test-suite/java/template_methods_runme.java @@ -32,6 +32,13 @@ public class template_methods_runme { k.KlassTMethodBool(); b = Klass.KlassStaticTMethodBoolRenamed(true); Klass.KlassStaticTMethodBool(); + + + // + ComponentProperties cp = new ComponentProperties(); + cp.adda("key1", "val1", "key2", 22.2); + cp.adda("key1", "val1", "key2", "val2", "key3", "val3"); + cp.adda("key1", 1, "key2", 2, "key3", 3); } } diff --git a/Examples/test-suite/template_methods.i b/Examples/test-suite/template_methods.i index efd7e3707..8524d5b44 100644 --- a/Examples/test-suite/template_methods.i +++ b/Examples/test-suite/template_methods.i @@ -5,6 +5,8 @@ %warnfilter(SWIGWARN_LANG_TEMPLATE_METHOD_IGNORE) convolve1(); %warnfilter(SWIGWARN_LANG_TEMPLATE_METHOD_IGNORE) convolve3(); +%include + /////////////////// %ignore convolve1(float a); @@ -76,3 +78,23 @@ struct Klass { %template(KlassTMethodBool) Klass::tmethod; %template(KlassStaticTMethodBool) Klass::statictmethod; +//////////////////////////////////////////////////////////////////////////// + +%inline %{ + class ComponentProperties{ + public: + ComponentProperties() {} + ~ComponentProperties() {} + + template void adda(std::string key, T1 val) {} + template void adda(std::string key1, T1 val1, std::string key2, T2 val2) {} + template void adda(std::string key1, T1 val1, std::string key2, T2 val2, std::string key3, T3 val3) {} + }; +%} + +%extend ComponentProperties { + %template(adda) adda; + %template(adda) adda; // ERROR OCCURS HERE + %template(adda) adda; +} + diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index a4787bf4a..7c33e5459 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -2726,7 +2726,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va Parm *ti = targs; String *tv = Getattr(tp,"value"); if (!tv) tv = Getattr(tp,"type"); - while(pi != tp) { + while(pi != tp && ti && pi) { String *name = Getattr(ti,"name"); String *value = Getattr(pi,"value"); if (!value) value = Getattr(pi,"type"); From 4516c1d3f363a1e75b5f1548ae5e5ef199f37cec Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 15 Aug 2009 23:22:20 +0000 Subject: [PATCH 41/68] Fix exception handling when %catches is used in C# git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11583 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 7 +- Examples/test-suite/catches.i | 33 ++++++++++ Examples/test-suite/common.mk | 1 + Examples/test-suite/csharp/catches_runme.cs | 66 +++++++++++++++++++ .../csharp/exception_order_runme.cs | 48 ++++++++++++++ Lib/exception.i | 6 ++ Source/Modules/allocate.cxx | 3 +- Source/Modules/csharp.cxx | 22 +------ 8 files changed, 163 insertions(+), 23 deletions(-) create mode 100644 Examples/test-suite/catches.i create mode 100644 Examples/test-suite/csharp/catches_runme.cs create mode 100644 Examples/test-suite/csharp/exception_order_runme.cs diff --git a/CHANGES.current b/CHANGES.current index 70914fb2f..6e6295378 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,9 @@ Version 1.3.40 (in progress) ============================ +2009-08-16: wsfulton + [C#] Fix exception handling when %catches is used, reported by Juan Manuel Alvarez. + 2009-08-15: wsfulton Fix %template seg fault on some cases of overloading the templated method. Bug reported by Jan Kupec. @@ -128,8 +131,8 @@ Version 1.3.40 (in progress) Fix -Wallkw option as reported by Solomon Gibbs. 2009-07-02: wsfulton - Fix syntax error when a nested struct contains a comment containing a * followed eventually by a /. - Regression from 1.3.37, reported by Solomon Gibbs. + Fix syntax error when a nested struct contains a comment containing a * followed + eventually by a /. Regression from 1.3.37, reported by Solomon Gibbs. 2009-07-01: vmiklos [PHP] Unknown properties are no longer ignored in proxy diff --git a/Examples/test-suite/catches.i b/Examples/test-suite/catches.i new file mode 100644 index 000000000..8f09ae24c --- /dev/null +++ b/Examples/test-suite/catches.i @@ -0,0 +1,33 @@ +%module catches + +%{ +#if defined(_MSC_VER) + #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) +#endif +%} + +%include // for throws(...) typemap + +%catches(int, const char *, const ThreeException&) test_catches(int i); +%catches(int, ...) test_exception_specification(int i); // override the exception specification +%catches(...) test_catches_all(int i); + +%inline %{ +struct ThreeException {}; +void test_catches(int i) { + if (i == 1) { + throw int(1); + } else if (i == 2) { + throw (const char *)"two"; + } else if (i == 3) { + throw ThreeException(); + } +} +void test_exception_specification(int i) throw(int, const char *, const ThreeException&) { + test_catches(i); +} +void test_catches_all(int i) { + test_catches(i); +} +%} + diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 9987f3c0f..492378b16 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -117,6 +117,7 @@ CPP_TEST_CASES += \ arrays_scope \ bloody_hell \ bools \ + catches \ cast_operator \ casts \ char_strings \ diff --git a/Examples/test-suite/csharp/catches_runme.cs b/Examples/test-suite/csharp/catches_runme.cs new file mode 100644 index 000000000..2b5290eac --- /dev/null +++ b/Examples/test-suite/csharp/catches_runme.cs @@ -0,0 +1,66 @@ +using System; +using catchesNamespace; + +public class runme { + static void Main() { + // test_catches() + try { + catches.test_catches(1); + throw new Exception("missed exception"); + } catch (ApplicationException e) { + if (e.Message != "C++ int exception thrown, value: 1") + throw new ApplicationException("bad exception order: " + e.Message); + } + + try { + catches.test_catches(2); + throw new Exception("missed exception"); + } catch (ApplicationException e) { + if (e.Message != "two") + throw new ApplicationException("bad exception order: " + e.Message); + } + + try { + catches.test_catches(3); + throw new Exception("missed exception"); + } catch (ApplicationException e) { + if (e.Message != "C++ ThreeException const & exception thrown") + throw new ApplicationException("bad exception order: " + e.Message); + } + + // test_exception_specification() + try { + catches.test_exception_specification(1); + throw new Exception("missed exception"); + } catch (ApplicationException e) { + if (e.Message != "C++ int exception thrown, value: 1") + throw new ApplicationException("bad exception order: " + e.Message); + } + + try { + catches.test_exception_specification(2); + throw new Exception("missed exception"); + } catch (ApplicationException e) { + if (e.Message != "unknown exception") + throw new ApplicationException("bad exception order: " + e.Message); + } + + try { + catches.test_exception_specification(3); + throw new Exception("missed exception"); + } catch (ApplicationException e) { + if (e.Message != "unknown exception") + throw new ApplicationException("bad exception order: " + e.Message); + } + + // test_catches_all() + try { + catches.test_catches_all(1); + throw new Exception("missed exception"); + } catch (ApplicationException e) { + if (e.Message != "unknown exception") + throw new ApplicationException("bad exception order: " + e.Message); + } + + } +} diff --git a/Examples/test-suite/csharp/exception_order_runme.cs b/Examples/test-suite/csharp/exception_order_runme.cs new file mode 100644 index 000000000..16b32983f --- /dev/null +++ b/Examples/test-suite/csharp/exception_order_runme.cs @@ -0,0 +1,48 @@ +using System; +using exception_orderNamespace; + +public class runme { + static void Main() { + A a = new A(); + + try { + a.foo(); + throw new Exception("missed exception"); + } catch (ApplicationException e) { + if (e.Message != "C++ E1 exception thrown") + throw new ApplicationException("bad exception order: " + e.Message); + } + + try { + a.bar(); + throw new Exception("missed exception"); + } catch (ApplicationException e) { + if (e.Message != "C++ E2 exception thrown") + throw new ApplicationException("bad exception order: " + e.Message); + } + + try { + a.foobar(); + throw new Exception("missed exception"); + } catch (ApplicationException e) { + if (e.Message != "postcatch unknown") + throw new ApplicationException("bad exception order: " + e.Message); + } + + try { + a.barfoo(1); + throw new Exception("missed exception"); + } catch (ApplicationException e) { + if (e.Message != "C++ E1 exception thrown") + throw new ApplicationException("bad exception order: " + e.Message); + } + + try { + a.barfoo(2); + throw new Exception("missed exception"); + } catch (ApplicationException e) { + if (e.Message != "C++ E2 * exception thrown") + throw new ApplicationException("bad exception order: " + e.Message); + } + } +} diff --git a/Lib/exception.i b/Lib/exception.i index e30ac1a5d..a1a47554e 100644 --- a/Lib/exception.i +++ b/Lib/exception.i @@ -262,9 +262,15 @@ SWIGINTERN void SWIG_CSharpException(int code, const char *msg) { /* rethrow the unknown exception */ +#ifdef SWIGCSHARP +%typemap(throws,noblock=1, canthrow=1) (...) { + SWIG_exception(SWIG_RuntimeError,"unknown exception"); +} +#else %typemap(throws,noblock=1) (...) { SWIG_exception(SWIG_RuntimeError,"unknown exception"); } +#endif #endif /* __cplusplus */ diff --git a/Source/Modules/allocate.cxx b/Source/Modules/allocate.cxx index e8397e6a6..d78dd13d7 100644 --- a/Source/Modules/allocate.cxx +++ b/Source/Modules/allocate.cxx @@ -527,8 +527,7 @@ class Allocate:public Dispatcher { } ParmList *throws = Getattr(n, "throws"); if (throws) { - /* if there is no an explicit catchlist, - we catch everything in the throwlist */ + /* if there is no explicit catchlist, we catch everything in the throws list */ if (!catchlist) { Setattr(n, "catchlist", throws); } diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index fa76e42c8..b5444d4b4 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -898,9 +898,9 @@ public: } } - // Get any C# exception classes in the throws typemap + // Look for usage of throws typemap and the canthrow flag ParmList *throw_parm_list = NULL; - if ((throw_parm_list = Getattr(n, "throws"))) { + if ((throw_parm_list = Getattr(n, "catchlist"))) { Swig_typemap_attach_parms("throws", throw_parm_list, f); for (p = throw_parm_list; p; p = nextSibling(p)) { if ((tm = Getattr(p, "tmap:throws"))) { @@ -3063,13 +3063,6 @@ public: return tm; } - /* ----------------------------------------------------------------------------- - * addThrows() - // TODO: remove - * ----------------------------------------------------------------------------- */ - void addThrows(Node *, const String *, Node *) { - } - /* ----------------------------------------------------------------------------- * canThrow() * Determine whether the code in the typemap can throw a C# exception. @@ -3417,10 +3410,6 @@ public: Printf(arg, "j%s", ln); - /* Add various typemap's 'throws' clauses */ - addThrows(n, "tmap:directorin", p); - addThrows(n, "tmap:out", p); - /* And add to the upcall args */ if (gencomma > 0) Printf(jupcall_args, ", "); @@ -3549,9 +3538,8 @@ public: Printf(declaration, " virtual %s", target); Delete(target); - // Get any Java exception classes in the throws typemap + // Add any exception specifications to the methods in the director class ParmList *throw_parm_list = NULL; - if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) { int gencomma = 0; @@ -3562,13 +3550,10 @@ public: Swig_typemap_attach_parms("throws", throw_parm_list, 0); for (p = throw_parm_list; p; p = nextSibling(p)) { if ((tm = Getattr(p, "tmap:throws"))) { - addThrows(n, "tmap:throws", p); - if (gencomma++) { Append(w->def, ", "); Append(declaration, ", "); } - Printf(w->def, "%s", SwigType_str(Getattr(p, "type"), 0)); Printf(declaration, "%s", SwigType_str(Getattr(p, "type"), 0)); } @@ -3621,7 +3606,6 @@ public: /* Copy jresult into c_result... */ if ((tm = Swig_typemap_lookup("directorout", tp, result_str, w))) { - addThrows(n, "tmap:directorout", tp); Replaceall(tm, "$input", jresult_str); Replaceall(tm, "$result", result_str); Printf(w->code, "%s\n", tm); From c7b7078dd02589e5722189f5a1f52494288ef6dc Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Aug 2009 00:04:29 +0000 Subject: [PATCH 42/68] Fix classes not being added into Java method's throws clause when %catches is used git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11584 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Examples/test-suite/java/java_throws_runme.java | 10 ++++++++++ Examples/test-suite/java_throws.i | 6 +++++- Source/Modules/java.cxx | 3 ++- Source/Modules/modula3.cxx | 2 +- 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 6e6295378..25c5a80c3 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ Version 1.3.40 (in progress) ============================ +2009-08-16: wsfulton + [Java] When %catches is used, fix so that any classes specified in the "throws" + attribute of the "throws" typemap are generated into the Java method's throws clause. + 2009-08-16: wsfulton [C#] Fix exception handling when %catches is used, reported by Juan Manuel Alvarez. diff --git a/Examples/test-suite/java/java_throws_runme.java b/Examples/test-suite/java/java_throws_runme.java index 6a73ea563..370173e50 100644 --- a/Examples/test-suite/java/java_throws_runme.java +++ b/Examples/test-suite/java/java_throws_runme.java @@ -40,6 +40,16 @@ public class java_throws_runme { if (!pass) throw new RuntimeException("Test 2 failed"); + // Check the exception class in the throw typemap + pass = false; + try { + java_throws.catches_function(100); + } + catch (IllegalAccessException e) { pass = true; } + + if (!pass) + throw new RuntimeException("Test 3 failed"); + // Check newfree typemap throws attribute try { TestClass tc = java_throws.makeTestClass(); diff --git a/Examples/test-suite/java_throws.i b/Examples/test-suite/java_throws.i index b020fefcb..48a0eeabc 100644 --- a/Examples/test-suite/java_throws.i +++ b/Examples/test-suite/java_throws.i @@ -42,12 +42,16 @@ short full_of_exceptions(int num) { #if defined(_MSC_VER) #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) #endif -void throw_spec_function(int value) throw (int) { throw (int)0; } +bool throw_spec_function(int value) throw (int) { throw (int)0; } #if defined(_MSC_VER) #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) #endif %} +%catches(int) catches_function(int value); +%inline %{ +bool catches_function(int value) { throw (int)0; } +%} // Check newfree typemap throws attribute %newobject makeTestClass; diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 7ed4df636..9af6fc214 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -980,7 +980,7 @@ public: // Get any Java exception classes in the throws typemap ParmList *throw_parm_list = NULL; - if ((throw_parm_list = Getattr(n, "throws"))) { + if ((throw_parm_list = Getattr(n, "catchlist"))) { Swig_typemap_attach_parms("throws", throw_parm_list, f); for (p = throw_parm_list; p; p = nextSibling(p)) { if ((tm = Getattr(p, "tmap:throws"))) { @@ -3679,6 +3679,7 @@ public: Printf(declaration, " virtual %s", target); Delete(target); + // Add any exception specifications to the methods in the director class // Get any Java exception classes in the throws typemap ParmList *throw_parm_list = NULL; diff --git a/Source/Modules/modula3.cxx b/Source/Modules/modula3.cxx index b9eb840f6..b14dddd22 100644 --- a/Source/Modules/modula3.cxx +++ b/Source/Modules/modula3.cxx @@ -1404,7 +1404,7 @@ MODULA3(): // Get any Modula 3 exception classes in the throws typemap ParmList *throw_parm_list = NULL; - if ((throw_parm_list = Getattr(n, "throws"))) { + if ((throw_parm_list = Getattr(n, "catchlist"))) { Swig_typemap_attach_parms("throws", throw_parm_list, f); Parm *p; for (p = throw_parm_list; p; p = nextSibling(p)) { From 26cc9252d948596a9e7f34817d536a611e555c0e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Aug 2009 00:09:43 +0000 Subject: [PATCH 43/68] Fix testcase comment git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11585 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/java/java_throws_runme.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/test-suite/java/java_throws_runme.java b/Examples/test-suite/java/java_throws_runme.java index 370173e50..0365b69ed 100644 --- a/Examples/test-suite/java/java_throws_runme.java +++ b/Examples/test-suite/java/java_throws_runme.java @@ -40,7 +40,7 @@ public class java_throws_runme { if (!pass) throw new RuntimeException("Test 2 failed"); - // Check the exception class in the throw typemap + // Check the exception class is used with %catches pass = false; try { java_throws.catches_function(100); From db7ed25900d305c505fe0f9163ec9c9cd22f3731 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Aug 2009 19:40:29 +0000 Subject: [PATCH 44/68] fix lextype testcase when compiled as c++ as is the case with octave git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11590 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/lextype.i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/lextype.i b/Examples/test-suite/lextype.i index 0c0ef66fe..083fb589d 100644 --- a/Examples/test-suite/lextype.i +++ b/Examples/test-suite/lextype.i @@ -30,13 +30,13 @@ code is not functioning properly it will fail to compile. %typemap(in) Animal () { void *space_needed = malloc(HEIGHT_$1_lextype * WIDTH_$1_lextype); - $1 = space_needed; + $1 = ($1_ltype)space_needed; } %typemap(in) Animal[2] () { void *space_needed = malloc(2 * HEIGHT_$1_lextype * WIDTH_$1_lextype); - $1 = space_needed; + $1 = ($1_ltype)space_needed; } %inline %{ From b5de6aabe57021c341c39fd2201367d16fbbd0e8 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Aug 2009 20:02:22 +0000 Subject: [PATCH 45/68] more efficient python test-suite clean git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11591 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/python/Makefile.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in index cfb02cf2d..274d53f1d 100644 --- a/Examples/test-suite/python/Makefile.in +++ b/Examples/test-suite/python/Makefile.in @@ -139,13 +139,13 @@ endif # Clean: remove the generated .py file %.clean: - @rm -f hugemod.h hugemod_a.i hugemod_b.i hugemod_a.py hugemod_b.py hugemod_runme.py @rm -f $*.py; @#We only remove the _runme3.py if it is generated by 2to3 from a _runme.py. @if [ -f $(py2_runme) ]; then rm -f $(py3_runme) $(py3_runme).bak; fi clean: $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile python_clean + rm -f hugemod.h hugemod_a.i hugemod_b.i hugemod_a.py hugemod_b.py hugemod_runme.py cvsignore: @echo '*wrap* *.pyc *.so *.dll *.exp *.lib' @@ -168,3 +168,4 @@ hugemod: $(MAKE) hugemod_b.cpptest sh -c "time $(PYTHON) $(hugemod_runme)" sh -c "time $(PYTHON) $(hugemod_runme)" + From 8ec652b7cf990488791dfa7e5eb995af4236e5de Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Aug 2009 20:32:42 +0000 Subject: [PATCH 46/68] Suppress g++ warning when compiled as c++ (for Octave) git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11592 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/enums.i | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Examples/test-suite/enums.i b/Examples/test-suite/enums.i index 3ea48b90e..00499f800 100644 --- a/Examples/test-suite/enums.i +++ b/Examples/test-suite/enums.i @@ -32,8 +32,14 @@ bar3(foo3 x) {} enum sad { boo, hoo = 5 }; +#ifdef __cplusplus /* For Octave and g++ which compiles C test code as C++ */ +extern "C" { +#endif /* Unnamed enum instance */ enum { globalinstance1, globalinstance2, globalinstance3 = 30 } GlobalInstance; +#ifdef __cplusplus +} +#endif /* Anonymous enum */ enum { AnonEnum1, AnonEnum2 = 100 }; From b5c49c20fd7eb79bc5cee6dc9b8691842362f071 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sun, 16 Aug 2009 21:44:05 +0000 Subject: [PATCH 47/68] PHP: fix for the valuewrapper_base testcase The problem is the following: before director support, the return class type of a function was hardwired. That was bad, as factory functions wanted to instantiate abstract classes, so we switched to detecting the class type based on the PHP resource type. That was good, but broke the case when for example %template(make_Interface_BP) make >; was used, as the cheap parser had no idea how to turn 'Interface_T_oss__BinaryPolarization_t' to 'make_Interface_BP'. This patch still uses the resource type detection, but in case that would result in a non-existing class, we just use the hardwired name. NOTE: This still does not fix the case when abstract classes are used with templates. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11593 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/php.cxx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index dc7f863e3..72ba4d4eb 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1683,6 +1683,9 @@ public: } else { Printf(output, "\t\t\t$c='%s'.substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3));\n", prefix); } + Printf(output, "\t\t\tif (!class_exists($c)) {\n"); + Printf(output, "\t\t\t\t$c = '%s';\n", Getattr(classLookup(d), "sym:name")); + Printf(output, "\t\t\t}\n"); Printf(output, "\t\t\treturn new $c($r);\n"); } else { Printf(output, "\t\t\t$c = new stdClass();\n"); From 8da18d336e91d7b76affb0539249b3b311bc3999 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sun, 16 Aug 2009 21:47:24 +0000 Subject: [PATCH 48/68] PHP: Optimize the previous commit a bit. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11594 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/php.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 72ba4d4eb..3c975d18b 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1684,7 +1684,7 @@ public: Printf(output, "\t\t\t$c='%s'.substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3));\n", prefix); } Printf(output, "\t\t\tif (!class_exists($c)) {\n"); - Printf(output, "\t\t\t\t$c = '%s';\n", Getattr(classLookup(d), "sym:name")); + Printf(output, "\t\t\t\treturn new %s($r);\n", Getattr(classLookup(d), "sym:name")); Printf(output, "\t\t\t}\n"); Printf(output, "\t\t\treturn new $c($r);\n"); } else { From fc68afcf7351e3d9853533a237133ad815c9970a Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Aug 2009 22:05:47 +0000 Subject: [PATCH 49/68] Octave: Caught exceptions display the type of the C++ exception instead of the generic 'c++-side threw an exception' message git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11595 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ .../test-suite/octave/exception_order_runme.m | 21 +++++++++---------- Lib/octave/octtypemaps.swg | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 25c5a80c3..a2cf82f4c 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ Version 1.3.40 (in progress) ============================ +2009-08-16: wsfulton + [Octave] Caught exceptions display the type of the C++ exception instead of the + generic "c++-side threw an exception" message. + 2009-08-16: wsfulton [Java] When %catches is used, fix so that any classes specified in the "throws" attribute of the "throws" typemap are generated into the Java method's throws clause. diff --git a/Examples/test-suite/octave/exception_order_runme.m b/Examples/test-suite/octave/exception_order_runme.m index a5914f822..3fb2b9a50 100644 --- a/Examples/test-suite/octave/exception_order_runme.m +++ b/Examples/test-suite/octave/exception_order_runme.m @@ -6,40 +6,39 @@ a = A(); try a.foo() catch - if (!strcmp(raised(),"E1")) - error, "bad exception order" + if (!strcmp(lasterror.message, "error: C++ side threw an exception of type E1\n")) + error("bad exception order") endif end_try_catch try a.bar() catch - if (!strcmp(raised(),"E2")) - error, "bad exception order" + if (!strcmp(lasterror.message, "error: C++ side threw an exception of type E2\n")) + error("bad exception order") endif end_try_catch try a.foobar() catch - [t,e]=raised(); - if (!strcmp(e.args(0),"postcatch unknown")) - error + if (!strcmp(lasterror.message, "error: postcatch unknown (SWIG_RuntimeError)\n")) + error("bad exception order") endif end_try_catch try a.barfoo(1) catch - if (!strcmp(raised(),"E1")) - error, "bad exception order" + if (!strcmp(lasterror.message, "error: C++ side threw an exception of type E1\n")) + error("bad exception order") endif end_try_catch try a.barfoo(2) catch - if (!strcmp(raised(),"E2")) - error, "bad exception order" + if (!strcmp(lasterror.message, "error: C++ side threw an exception of type E2 *\n")) + error("bad exception order") endif end_try_catch diff --git a/Lib/octave/octtypemaps.swg b/Lib/octave/octtypemaps.swg index 7934f90bd..26a52197f 100644 --- a/Lib/octave/octtypemaps.swg +++ b/Lib/octave/octtypemaps.swg @@ -32,7 +32,7 @@ #define SWIG_SetConstant(name, obj) SWIG_Octave_SetConstant(module_ns,name,obj) // raise -#define SWIG_Octave_Raise(obj, type, desc) error("c++-side threw an exception") +#define SWIG_Octave_Raise(OBJ, TYPE, DESC) error("C++ side threw an exception of type " TYPE) #define SWIG_Raise(obj, type, desc) SWIG_Octave_Raise(obj, type, desc) // Include the unified typemap library From 4050e5e6f66b6fb71218cae2f759931c32a988ac Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Aug 2009 22:09:33 +0000 Subject: [PATCH 50/68] Add missing commit message for Xavier's Octave 3.2 support git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11596 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index a2cf82f4c..bc810f7fd 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -120,6 +120,9 @@ Version 1.3.40 (in progress) different name to the class, as such constructors can still take parameters. +2009-07-12: xavier99 + [Octave] Add support for Octave 3.2 API + 2009-07-05: olly [PHP] Update the list of PHP keywords - "cfunction" is no longer a keyword in PHP5 and PHP 5.3 added "goto", "namespace", "__DIR__", From 3cabcd05537d361cbe6d216e223f08d6979f4895 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Aug 2009 22:14:06 +0000 Subject: [PATCH 51/68] remove debug print statements git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11597 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/octave/empty_runme.m | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/Examples/test-suite/octave/empty_runme.m b/Examples/test-suite/octave/empty_runme.m index 373c7b0dd..e7b64f1cd 100644 --- a/Examples/test-suite/octave/empty_runme.m +++ b/Examples/test-suite/octave/empty_runme.m @@ -1,17 +1,2 @@ empty -printf("begin\n"); -who global - -printf("after load\n"); -who global - -#clear -g -printf("after clear\n"); -who global - -#clear empty -printf("after clear specific\n"); -who global - -printf("before shutdown\n"); From 82df087b8b6855294d903650feed73167b13aff4 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sun, 16 Aug 2009 22:23:32 +0000 Subject: [PATCH 52/68] PHP: remove '// Sample test file' comments from runme files Those are cut&pasted from skel.php, but that comment makes sense only in skel.php itself. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11598 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/php/add_link_runme.php | 1 - Examples/test-suite/php/arrayptr_runme.php | 1 - Examples/test-suite/php/arrays_global_runme.php | 1 - Examples/test-suite/php/arrays_global_twodim_runme.php | 1 - Examples/test-suite/php/arrays_runme.php | 1 - Examples/test-suite/php/arrays_scope_runme.php | 1 - Examples/test-suite/php/casts_runme.php | 1 - Examples/test-suite/php/class_ignore_runme.php | 1 - Examples/test-suite/php/conversion_namespace_runme.php | 1 - Examples/test-suite/php/conversion_runme.php | 1 - Examples/test-suite/php/cpp_static_runme.php | 1 - Examples/test-suite/php/director_nested_runme.php | 1 - Examples/test-suite/php/evil_diamond_ns_runme.php | 1 - Examples/test-suite/php/evil_diamond_prop_runme.php | 1 - Examples/test-suite/php/evil_diamond_runme.php | 1 - Examples/test-suite/php/extend_template_ns_runme.php | 1 - Examples/test-suite/php/extend_template_runme.php | 1 - Examples/test-suite/php/grouping_runme.php | 1 - Examples/test-suite/php/ignore_parameter_runme.php | 1 - Examples/test-suite/php/li_std_string_runme.php | 1 - Examples/test-suite/php/newobject1_runme.php | 1 - Examples/test-suite/php/prefix_runme.php | 1 - Examples/test-suite/php/rename_scope_runme.php | 1 - Examples/test-suite/php/smart_pointer_rename_runme.php | 1 - Examples/test-suite/php/sym_runme.php | 1 - Examples/test-suite/php/template_arg_typename_runme.php | 1 - Examples/test-suite/php/valuewrapper_base_runme.php | 1 - 27 files changed, 27 deletions(-) diff --git a/Examples/test-suite/php/add_link_runme.php b/Examples/test-suite/php/add_link_runme.php index 4d8c31d5e..7523bd604 100644 --- a/Examples/test-suite/php/add_link_runme.php +++ b/Examples/test-suite/php/add_link_runme.php @@ -1,5 +1,4 @@ Date: Sun, 16 Aug 2009 23:23:49 +0000 Subject: [PATCH 53/68] Fix testcase to minimal testing, most of it contained test code not relevant to std_vector.i git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11599 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../test-suite/octave/li_std_vector_runme.m | 155 +----------------- 1 file changed, 3 insertions(+), 152 deletions(-) diff --git a/Examples/test-suite/octave/li_std_vector_runme.m b/Examples/test-suite/octave/li_std_vector_runme.m index b9f33ee02..83d1f2cb0 100644 --- a/Examples/test-suite/octave/li_std_vector_runme.m +++ b/Examples/test-suite/octave/li_std_vector_runme.m @@ -1,160 +1,11 @@ li_std_vector iv = IntVector(4); -for i=0:4, +for i=0:3, iv(i) = i; endfor - x = average(iv); -y = average([1,2,3,4]); -a = half([10,10.5,11,11.5]); - -dv = DoubleVector(10); -for i=0:10, - dv(i) = i/2.0; -endfor - -halve_in_place(dv); - - -bv = BoolVector(4); -bv(0)= 1; -bv(1)= 0; -bv(2)= 4; -bv(3)= 0; - -if (bv(0) != bv(2)) - error("bad std::vector mapping") +if (x != 1.5) + error("average failed"); endif - -b = B(5); -va = VecA([b,None,b,b]); - -if (va(0).f(1) != 6) - error("bad std::vector mapping") -endif - -if (vecAptr(va) != 6) - error("bad std::vector mapping") -endif - -b.val = 7; -if (va(3).f(1) != 8) - error("bad std::vector mapping") -endif - - -ip = PtrInt(); -ap = new_ArrInt(10); - -ArrInt_setitem(ip,0,123); -ArrInt_setitem(ap,2,123); - -vi = IntPtrVector((ip,ap,None)); -if (ArrInt_getitem(vi[0],0) != ArrInt_getitem(vi[1],2)) - error("bad std::vector mapping") -endif - -delete_ArrInt(ap); - - -a = halfs([10,8,4,3]); - -v = IntVector(); -v(0:2) = [1,2]; -if (v(0) != 1 || v[1] != 2) - error("bad setslice") -endif - -if (v(0:-1)(0) != 1) - error("bad getslice") -endif - -if (v(0:-2).size() != 0) - error("bad getslice") - -v(0:1) = [2]; -if (v(0) != 2) - error("bad setslice") -endif - -v(1:) = [3]; -if (v(1) != 3) - error("bad setslice") -endif - -v(2:) = [3] -if (v(2) != 3) - error("bad setslice") -endif - -if (v(0:)(0) != v(0)) - error("bad getslice") -endif - - -v.erase(:) -if (v.size() != 0) - error("bad getslice") -endif - -v.erase(:) -if (v.size() != 0) - error("bad getslice") -endif - - - -v = vecStr({"hello ", "world"}); -if (v(0) != 'hello world') - error,"bad std::string+std::vector" -endif - - -pv = pyvector({1, "hello", (1,2)}); - -if (pv(1) != "hello") - error -endif - - -iv = IntVector(5); -for i=0:5, - iv(i) = i -endif - -iv(1:3) = []; -if (iv(1) != 3) - error -endif - -# Overloading checks -if (overloaded1(iv) != "vector") - error -endif - -if (overloaded1(dv) != "vector") - error -endif - -if (overloaded2(iv) != "vector") - error -endif - -if (overloaded2(dv) != "vector") - error -endif - -if (overloaded3(iv) != "vector *") - error -endif - -if (overloaded3(None) != "vector *") - error -endif - -if (overloaded3(100) != "int") - error -endif - From 3283728cf5fbd454b5b8dc8b4841511e0cf71fe1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 16 Aug 2009 23:25:42 +0000 Subject: [PATCH 54/68] Add semicolons to remove unwanted statement output git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11600 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/octave/imports_runme.m | 4 ++-- Examples/test-suite/octave/multi_import_runme.m | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Examples/test-suite/octave/imports_runme.m b/Examples/test-suite/octave/imports_runme.m index 3964552ab..be9db5919 100644 --- a/Examples/test-suite/octave/imports_runme.m +++ b/Examples/test-suite/octave/imports_runme.m @@ -1,7 +1,7 @@ # This is the import runtime testcase. -imports_b -imports_a +imports_b; +imports_a; x = imports_b.B(); x.hello(); diff --git a/Examples/test-suite/octave/multi_import_runme.m b/Examples/test-suite/octave/multi_import_runme.m index a6138736c..08149aae4 100644 --- a/Examples/test-suite/octave/multi_import_runme.m +++ b/Examples/test-suite/octave/multi_import_runme.m @@ -1,5 +1,5 @@ -multi_import_a -multi_import_b +multi_import_a; +multi_import_b; x = multi_import_b.XXX(); if (x.testx() != 0) From 3141dfd599f1a89c87fb71abdfe5c8b0320fd2e5 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 17 Aug 2009 01:08:23 +0000 Subject: [PATCH 55/68] Convert to use proxy classes. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11601 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/php/reference/Makefile | 2 +- Examples/php/reference/example.cxx | 3 +-- Examples/php/reference/example.h | 2 +- Examples/php/reference/example.i | 3 +-- Examples/php/reference/runme.php | 43 +++++++++++++++--------------- 5 files changed, 25 insertions(+), 28 deletions(-) diff --git a/Examples/php/reference/Makefile b/Examples/php/reference/Makefile index 252a72660..1bc0beaab 100644 --- a/Examples/php/reference/Makefile +++ b/Examples/php/reference/Makefile @@ -4,7 +4,7 @@ CXXSRCS = example.cxx TARGET = example INTERFACE = example.i LIBS = -SWIGOPT = -noproxy +SWIGOPT = all:: $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ diff --git a/Examples/php/reference/example.cxx b/Examples/php/reference/example.cxx index 3e13841d2..13e47eade 100644 --- a/Examples/php/reference/example.cxx +++ b/Examples/php/reference/example.cxx @@ -17,7 +17,7 @@ Vector operator+(const Vector &a, const Vector &b) { return r; } -char *Vector::print() { +char *Vector::as_string() { static char temp[512]; sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z); return temp; @@ -47,4 +47,3 @@ int VectorArray::size() { printf("VectorArray: size %d self=%p\n",maxsize,this); return maxsize; } - diff --git a/Examples/php/reference/example.h b/Examples/php/reference/example.h index 4915adb1b..1b88cbf5c 100644 --- a/Examples/php/reference/example.h +++ b/Examples/php/reference/example.h @@ -7,7 +7,7 @@ public: Vector() : x(0), y(0), z(0) { }; Vector(double x, double y, double z) : x(x), y(y), z(z) { }; friend Vector operator+(const Vector &a, const Vector &b); - char *print(); + char *as_string(); }; class VectorArray { diff --git a/Examples/php/reference/example.i b/Examples/php/reference/example.i index 55d1828a8..5502a4420 100644 --- a/Examples/php/reference/example.i +++ b/Examples/php/reference/example.i @@ -12,7 +12,7 @@ class Vector { public: Vector(double x, double y, double z); ~Vector(); - char *print(); + char *as_string(); }; /* This helper function calls an overloaded operator */ @@ -41,4 +41,3 @@ public: } } }; - diff --git a/Examples/php/reference/runme.php b/Examples/php/reference/runme.php index 00aaa5298..14578cd92 100644 --- a/Examples/php/reference/runme.php +++ b/Examples/php/reference/runme.php @@ -1,18 +1,17 @@ as_string()}\n"; +print " Created b: {$b->as_string()}\n"; # ----- Call an overloaded operator ----- @@ -23,8 +22,8 @@ print " Created b: $b " . Vector_print($b) . "\n"; # It returns a new allocated object. print "Adding a+b\n"; -$c = addv($a,$b); -print " a+b =". Vector_print($c)."\n"; +$c = example::addv($a,$b); +print " a+b ={$c->as_string()}\n"; # Note: Unless we free the result, a memory leak will occur $c = None; @@ -33,46 +32,46 @@ $c = None; # Note: Using the high-level interface here print "Creating an array of vectors\n"; -$va = new_VectorArray(10); +$va = new VectorArray(10); -print " va: $va size=".VectorArray_size($va)."\n"; +print " va: size={$va->size()}\n"; # ----- Set some values in the array ----- # These operators copy the value of $a and $b to the vector array -VectorArray_set($va,0,$a); -VectorArray_set($va,1,$b); +$va->set(0,$a); +$va->set(1,$b); -VectorArray_get($va,0); +$va->get(0); # This will work, but it will cause a memory leak! -VectorArray_set($va,2,addv($a,$b)); +$va->set(2,addv($a,$b)); # The non-leaky way to do it $c = addv($a,$b); -VectorArray_set($va,3,$c); -$c = None; +$va->set(3,$c); +$c = NULL; # Get some values from the array print "Getting some array values\n"; for ($i = 0; $i < 5; $i++) { -print "do $i\n"; - print " va($i) = ". Vector_print(VectorArray_get($va,$i)). "\n"; + print "do $i\n"; + print " va($i) = {$va->get($i)->as_string()}\n"; } # Watch under resource meter to check on this #print "Making sure we don't leak memory.\n"; #for ($i = 0; $i < 1000000; $i++) { -# $c = VectorArray_get($va,$i % 10); +# $c = $va->get($i % 10); #} # ----- Clean up ----- print "Cleaning up\n"; # wants fixing FIXME -$va = None; -$a = None; -$b = None; +$va = NULL; +$a = NULL; +$b = NULL; ?> From cd6eb83d612b5103947ed087243993fc542509f5 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 17 Aug 2009 01:10:04 +0000 Subject: [PATCH 56/68] Fix #2797485 After doing a 'make clean', install fails if yodl2man or yodl2html is not available. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11602 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CCache/Makefile.in | 4 ++-- CHANGES.current | 4 ++++ Makefile.in | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CCache/Makefile.in b/CCache/Makefile.in index ec55ccaf5..29cf8db1b 100644 --- a/CCache/Makefile.in +++ b/CCache/Makefile.in @@ -53,7 +53,7 @@ uninstall: $(PACKAGE_NAME)$(EXEEXT) $(PACKAGE_NAME).1 clean: /bin/rm -f $(OBJS) *~ $(PACKAGE_NAME)$(EXEEXT) -clean-docs: +distclean-docs: rm -f $(PACKAGE_NAME).1 web/ccache-man.html check : test @@ -63,7 +63,7 @@ test: test.sh check: test -distclean: clean +distclean: clean distclean-docs /bin/rm -f Makefile config.h config.sub config.log build-stamp config.status configure config.h # FIXME: To fix this, test.sh needs to be able to take ccache from the diff --git a/CHANGES.current b/CHANGES.current index bc810f7fd..39ef5427a 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ Version 1.3.40 (in progress) ============================ +2009-08-17: wsfulton + Fix #2797485 After doing a 'make clean', install fails if yodl2man or yodl2html + is not available. + 2009-08-16: wsfulton [Octave] Caught exceptions display the type of the C++ exception instead of the generic "c++-side threw an exception" message. diff --git a/Makefile.in b/Makefile.in index ec8cdb8be..19d37dc3b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -377,7 +377,7 @@ clean-docs-main: @test -d $(DOCS) || exit 0; cd $(DOCS) && $(MAKE) clean clean-docs-ccache: - @test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) clean-docs) + @# Use distclean-docs-ccache, else a user requires the yodl tools to generate the docs after a clean maintainer-clean: clean-libfiles @cd $(SOURCE) && $(MAKE) maintainer-clean @@ -404,6 +404,9 @@ distclean-test-suite: distclean-ccache: test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) -s distclean) +distclean-docs-ccache: + @test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) distclean-docs) + distclean-dead: rm -f $(DISTCLEAN-DEAD) From 089b226b8045582c54c0467a225e7aacc7623fea Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 17 Aug 2009 01:27:31 +0000 Subject: [PATCH 57/68] Rename the "extend" example to "directors" as it tests directors not %extend. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11603 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/php/{extend => directors}/Makefile | 0 Examples/php/{extend => directors}/example.cxx | 0 Examples/php/{extend => directors}/example.h | 0 Examples/php/{extend => directors}/example.i | 0 Examples/php/{extend => directors}/index.html | 0 Examples/php/{extend => directors}/runme.php | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename Examples/php/{extend => directors}/Makefile (100%) rename Examples/php/{extend => directors}/example.cxx (100%) rename Examples/php/{extend => directors}/example.h (100%) rename Examples/php/{extend => directors}/example.i (100%) rename Examples/php/{extend => directors}/index.html (100%) rename Examples/php/{extend => directors}/runme.php (100%) diff --git a/Examples/php/extend/Makefile b/Examples/php/directors/Makefile similarity index 100% rename from Examples/php/extend/Makefile rename to Examples/php/directors/Makefile diff --git a/Examples/php/extend/example.cxx b/Examples/php/directors/example.cxx similarity index 100% rename from Examples/php/extend/example.cxx rename to Examples/php/directors/example.cxx diff --git a/Examples/php/extend/example.h b/Examples/php/directors/example.h similarity index 100% rename from Examples/php/extend/example.h rename to Examples/php/directors/example.h diff --git a/Examples/php/extend/example.i b/Examples/php/directors/example.i similarity index 100% rename from Examples/php/extend/example.i rename to Examples/php/directors/example.i diff --git a/Examples/php/extend/index.html b/Examples/php/directors/index.html similarity index 100% rename from Examples/php/extend/index.html rename to Examples/php/directors/index.html diff --git a/Examples/php/extend/runme.php b/Examples/php/directors/runme.php similarity index 100% rename from Examples/php/extend/runme.php rename to Examples/php/directors/runme.php From c9635d6255ac6260bd0f7589a00c2e74547d2c62 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 17 Aug 2009 01:30:42 +0000 Subject: [PATCH 58/68] Remove bogus stuff about memory leaks - nothing in this testcase leaks. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11604 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/php/reference/example.i | 2 +- Examples/php/reference/runme.php | 42 ++++++-------------------------- 2 files changed, 8 insertions(+), 36 deletions(-) diff --git a/Examples/php/reference/example.i b/Examples/php/reference/example.i index 5502a4420..3710aed91 100644 --- a/Examples/php/reference/example.i +++ b/Examples/php/reference/example.i @@ -1,6 +1,6 @@ /* File : example.i */ -/* This file has a few "typical" uses of C++ references. */ +/* This file shows how to use %extend. */ %module example diff --git a/Examples/php/reference/runme.php b/Examples/php/reference/runme.php index 14578cd92..5d264ee43 100644 --- a/Examples/php/reference/runme.php +++ b/Examples/php/reference/runme.php @@ -7,8 +7,8 @@ require "example.php"; # ----- Object creation ----- print "Creating some objects:\n"; -$a = new Vector(3,4,5); -$b = new Vector(10,11,12); +$a = new Vector(3, 4, 5); +$b = new Vector(10, 11, 12); print " Created a: {$a->as_string()}\n"; print " Created b: {$b->as_string()}\n"; @@ -22,15 +22,11 @@ print " Created b: {$b->as_string()}\n"; # It returns a new allocated object. print "Adding a+b\n"; -$c = example::addv($a,$b); +$c = example::addv($a, $b); print " a+b ={$c->as_string()}\n"; -# Note: Unless we free the result, a memory leak will occur -$c = None; - # ----- Create a vector array ----- -# Note: Using the high-level interface here print "Creating an array of vectors\n"; $va = new VectorArray(10); @@ -39,39 +35,15 @@ print " va: size={$va->size()}\n"; # ----- Set some values in the array ----- # These operators copy the value of $a and $b to the vector array -$va->set(0,$a); -$va->set(1,$b); - -$va->get(0); -# This will work, but it will cause a memory leak! - -$va->set(2,addv($a,$b)); - -# The non-leaky way to do it - -$c = addv($a,$b); -$va->set(3,$c); -$c = NULL; +$va->set(0, $a); +$va->set(1, $b); +$va->set(2, addv($a, $b)); # Get some values from the array print "Getting some array values\n"; for ($i = 0; $i < 5; $i++) { - print "do $i\n"; - print " va($i) = {$va->get($i)->as_string()}\n"; + print " va[$i] = {$va->get($i)->as_string()}\n"; } -# Watch under resource meter to check on this -#print "Making sure we don't leak memory.\n"; -#for ($i = 0; $i < 1000000; $i++) { -# $c = $va->get($i % 10); -#} - -# ----- Clean up ----- -print "Cleaning up\n"; -# wants fixing FIXME -$va = NULL; -$a = NULL; -$b = NULL; - ?> From c8f64ccc2e2c9e59c85614ced23a19461c901381 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 17 Aug 2009 01:34:26 +0000 Subject: [PATCH 59/68] Explain the poor name. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11605 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/php/reference/example.i | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Examples/php/reference/example.i b/Examples/php/reference/example.i index 3710aed91..d6122866b 100644 --- a/Examples/php/reference/example.i +++ b/Examples/php/reference/example.i @@ -1,6 +1,10 @@ /* File : example.i */ -/* This file shows how to use %extend. */ +/* This example has nothing to do with references but the name is used by all + * the other languages so it's hard to rename to something more meaningful. + * + * Mostly it shows how to use %extend. + */ %module example From ea560a73a444478ac955de50e84a03c68e5e387e Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 17 Aug 2009 01:37:18 +0000 Subject: [PATCH 60/68] Rename back - William wants this consistent across all the languages and it's too much work to test a global renaming. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11606 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/php/{directors => extend}/Makefile | 0 Examples/php/{directors => extend}/example.cxx | 0 Examples/php/{directors => extend}/example.h | 0 Examples/php/{directors => extend}/example.i | 0 Examples/php/{directors => extend}/index.html | 0 Examples/php/{directors => extend}/runme.php | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename Examples/php/{directors => extend}/Makefile (100%) rename Examples/php/{directors => extend}/example.cxx (100%) rename Examples/php/{directors => extend}/example.h (100%) rename Examples/php/{directors => extend}/example.i (100%) rename Examples/php/{directors => extend}/index.html (100%) rename Examples/php/{directors => extend}/runme.php (100%) diff --git a/Examples/php/directors/Makefile b/Examples/php/extend/Makefile similarity index 100% rename from Examples/php/directors/Makefile rename to Examples/php/extend/Makefile diff --git a/Examples/php/directors/example.cxx b/Examples/php/extend/example.cxx similarity index 100% rename from Examples/php/directors/example.cxx rename to Examples/php/extend/example.cxx diff --git a/Examples/php/directors/example.h b/Examples/php/extend/example.h similarity index 100% rename from Examples/php/directors/example.h rename to Examples/php/extend/example.h diff --git a/Examples/php/directors/example.i b/Examples/php/extend/example.i similarity index 100% rename from Examples/php/directors/example.i rename to Examples/php/extend/example.i diff --git a/Examples/php/directors/index.html b/Examples/php/extend/index.html similarity index 100% rename from Examples/php/directors/index.html rename to Examples/php/extend/index.html diff --git a/Examples/php/directors/runme.php b/Examples/php/extend/runme.php similarity index 100% rename from Examples/php/directors/runme.php rename to Examples/php/extend/runme.php From af6c65c7e6ff93b62ac5e60aee89f1940adf10bd Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 17 Aug 2009 01:41:16 +0000 Subject: [PATCH 61/68] Add callback and extend; fix error in alphabetical ordering. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11607 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/php/check.list | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Examples/php/check.list b/Examples/php/check.list index 9daad455b..28c7a619f 100644 --- a/Examples/php/check.list +++ b/Examples/php/check.list @@ -1,16 +1,18 @@ # see top-level Makefile.in # (see also top-level configure.in kludge) +callback class constants cpointer disown enum +extend funcptr overloading pointer pragmas -reference proxy +reference simple sync value From c3f61e8881bdfd0d9a52e53dad881ebe5544f1c2 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 17 Aug 2009 02:06:43 +0000 Subject: [PATCH 62/68] Add note that a previous change fixed SF#2524029. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11608 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.current b/CHANGES.current index 39ef5427a..1ca1fc818 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -43,6 +43,7 @@ Version 1.3.40 (in progress) 2009-08-13: wsfulton [PHP] Add const reference typemaps. const reference primitive types are now passed by value rather than pointer like the other target languages. + Fixes SF#2524029. 2009-08-08: wsfulton [Python] More user friendly AttributeError is raised when there are From ea578fcc8f3ea60330cabac941f6d39ea65da15d Mon Sep 17 00:00:00 2001 From: Xavier Delacour Date: Mon, 17 Aug 2009 02:49:35 +0000 Subject: [PATCH 63/68] remove failing runtime tests director_exception_runme.m and director_finalizer_runme.m git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11609 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 2 +- .../octave/director_exception_runme.m | 57 ------------------- .../octave/director_finalizer_runme.m | 56 ------------------ 3 files changed, 1 insertion(+), 114 deletions(-) delete mode 100644 Examples/test-suite/octave/director_exception_runme.m delete mode 100644 Examples/test-suite/octave/director_finalizer_runme.m diff --git a/CHANGES.current b/CHANGES.current index 1ca1fc818..cf0c4a63f 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -125,7 +125,7 @@ Version 1.3.40 (in progress) different name to the class, as such constructors can still take parameters. -2009-07-12: xavier99 +2009-07-12: xavier98 [Octave] Add support for Octave 3.2 API 2009-07-05: olly diff --git a/Examples/test-suite/octave/director_exception_runme.m b/Examples/test-suite/octave/director_exception_runme.m deleted file mode 100644 index 3e0b23064..000000000 --- a/Examples/test-suite/octave/director_exception_runme.m +++ /dev/null @@ -1,57 +0,0 @@ -director_exception - -MyFoo=@() subclass(Foo(), - 'ping',@(self) raise(NotImplementedError("MyFoo::ping() EXCEPTION"))); - -MyFoo2=@() subclass(Foo(), - 'ping',@(self) true); - -ok = 0; - -a = MyFoo(); -b = launder(a); - -try - b.pong(); -catch - [etype,e]=raised(); - if (etype=="NotImplementedError") - ok=1; - endif -end_try_catch - -if (!ok) - error -endif - -ok = 0; - -a = MyFoo2(); -b = launder(a); - -try - b.pong(); -catch - ok = 1; -end_try_catch - -if (!ok) - error -endif - - -try - raise(Exception2()); -catch - if (!strcmp(raised,"Exception2")) - rethrow(lasterr); - endif -end_try_catch - -try - raise(Exception1()); -catch - if (!strcmp(raised,"Exception1")) - rethrow(lasterr); - endif -end_try_catch diff --git a/Examples/test-suite/octave/director_finalizer_runme.m b/Examples/test-suite/octave/director_finalizer_runme.m deleted file mode 100644 index 3781a0f77..000000000 --- a/Examples/test-suite/octave/director_finalizer_runme.m +++ /dev/null @@ -1,56 +0,0 @@ -director_finalizer - -MyFoo=@() subclass(Foo(),'__del__',@delete_MyFoo); -function delete_MyFoo(self) - self.orStatus(2); - try - Foo.__del__(self); - catch - end_try_catch -endfunction - -resetStatus(); - -a = MyFoo(); -clear a; - -if (getStatus() != 3) - error -endif - -resetStatus(); - -a = MyFoo(); -launder(a); - -if (getStatus() != 0) - error -endif - -clear a; - -if (getStatus() != 3) - error -endif - -resetStatus(); - -a = MyFoo().__disown__(); -deleteFoo(a); - -if (getStatus() != 3) - error -endif - -resetStatus(); - -a = MyFoo().__disown__(); -deleteFoo(launder(a)); - -if (getStatus() != 3) - error -endif - -resetStatus(); - - From c4f5f22f679d304e76990031f5f201434539c491 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 17 Aug 2009 03:19:14 +0000 Subject: [PATCH 64/68] Remove some superfluous "else"s in generated PHP code. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11610 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/php.cxx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 3c975d18b..242f99c1e 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -2022,7 +2022,7 @@ done: Printf(s_phpclasses, "\t\tif (function_exists($func)) return call_user_func($func,$this->%s,$value);\n", SWIG_PTR); } Printf(s_phpclasses, "\t\tif ($var === 'thisown') return swig_%s_alter_newobject($this->%s,$value);\n", module, SWIG_PTR); - Printf(s_phpclasses, "\t\telse $this->%s[$var] = $value;\n", SWIG_DATA); + Printf(s_phpclasses, "\t\t$this->%s[$var] = $value;\n", SWIG_DATA); if (baseclass) { Printf(s_phpclasses, "\t\treturn %s%s::__set($var,$value);\n", prefix, baseclass); } @@ -2032,16 +2032,16 @@ done: Printf(s_phpclasses, "\n\tfunction __isset($var) {\n"); Printf(s_phpclasses, "\t\tif (function_exists('%s_'.$var.'_set')) return true;\n", shadow_classname); Printf(s_phpclasses, "\t\tif ($var === 'thisown') return true;\n"); - Printf(s_phpclasses, "\t\telse return array_key_exists($var, $this->%s);\n", SWIG_DATA); + Printf(s_phpclasses, "\t\treturn array_key_exists($var, $this->%s);\n", SWIG_DATA); Printf(s_phpclasses, "\t}\n"); } else { Printf(s_phpclasses, "\n\tfunction __set($var,$value) {\n"); Printf(s_phpclasses, "\t\tif ($var === 'thisown') return swig_%s_alter_newobject($this->%s,$value);\n", module, SWIG_PTR); - Printf(s_phpclasses, "\t\telse $this->%s[$var] = $value;\n", SWIG_DATA); + Printf(s_phpclasses, "\t\t$this->%s[$var] = $value;\n", SWIG_DATA); Printf(s_phpclasses, "\t}\n"); Printf(s_phpclasses, "\n\tfunction __isset($var) {\n"); Printf(s_phpclasses, "\t\tif ($var === 'thisown') return true;\n"); - Printf(s_phpclasses, "\t\telse return array_key_exists($var, $this->%s);\n", SWIG_DATA); + Printf(s_phpclasses, "\t\treturn array_key_exists($var, $this->%s);\n", SWIG_DATA); Printf(s_phpclasses, "\t}\n"); } // Write property GET handlers @@ -2062,19 +2062,19 @@ done: Printf(s_phpclasses, "\t\t$func = '%s_'.$var.'_get';\n", shadow_classname); Printf(s_phpclasses, "\t\tif (function_exists($func)) return call_user_func($func,$this->%s);\n", SWIG_PTR); } - Printf(s_phpclasses, "\t\telse if ($var === 'thisown') return swig_%s_get_newobject($this->%s);\n", module, SWIG_PTR); - Printf(s_phpclasses, "\t\telse if(array_key_exists($var, $this->%s)) return $this->%s[$var];\n", SWIG_DATA, SWIG_DATA); - // Reading an unknown property name gives null in PHP. + Printf(s_phpclasses, "\t\tif ($var === 'thisown') return swig_%s_get_newobject($this->%s);\n", module, SWIG_PTR); + Printf(s_phpclasses, "\t\tif (array_key_exists($var, $this->%s)) return $this->%s[$var];\n", SWIG_DATA, SWIG_DATA); if (base.item) { Printf(s_phpclasses, "\t\treturn %s%s::__get($var);\n", prefix, baseclass); } else { + // Reading an unknown property name gives null in PHP. Printf(s_phpclasses, "\t\treturn null;\n"); } Printf(s_phpclasses, "\t}\n"); } else { Printf(s_phpclasses, "\n\tfunction __get($var) {\n"); Printf(s_phpclasses, "\t\tif ($var === 'thisown') return swig_%s_get_newobject($this->%s);\n", module, SWIG_PTR); - Printf(s_phpclasses, "\t\telse return $this->%s[$var];\n", SWIG_DATA); + Printf(s_phpclasses, "\t\treturn $this->%s[$var];\n", SWIG_DATA); Printf(s_phpclasses, "\t}\n"); } From 47e404ba5b3bac3d5567038409bd885c4654ec5f Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 17 Aug 2009 05:24:17 +0000 Subject: [PATCH 65/68] Only have an array for properties in the base class, not in derived classes. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11611 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/php.cxx | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 242f99c1e..2e3f53ecf 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -2001,7 +2001,11 @@ done: Append(s_phpclasses, "extends Exception "); } Printf(s_phpclasses, "{\n\tpublic $%s=null;\n", SWIG_PTR); - Printf(s_phpclasses, "\tprotected $%s=array();\n", SWIG_DATA); + if (!baseclass) { + // Only store this in the base class (NB !baseclass means we *are* + // a base class...) + Printf(s_phpclasses, "\tprotected $%s=array();\n", SWIG_DATA); + } // Write property SET handlers ki = First(shadow_set_vars); @@ -2022,9 +2026,10 @@ done: Printf(s_phpclasses, "\t\tif (function_exists($func)) return call_user_func($func,$this->%s,$value);\n", SWIG_PTR); } Printf(s_phpclasses, "\t\tif ($var === 'thisown') return swig_%s_alter_newobject($this->%s,$value);\n", module, SWIG_PTR); - Printf(s_phpclasses, "\t\t$this->%s[$var] = $value;\n", SWIG_DATA); if (baseclass) { - Printf(s_phpclasses, "\t\treturn %s%s::__set($var,$value);\n", prefix, baseclass); + Printf(s_phpclasses, "\t\t%s%s::__set($var,$value);\n", prefix, baseclass); + } else { + Printf(s_phpclasses, "\t\t$this->%s[$var] = $value;\n", SWIG_DATA); } Printf(s_phpclasses, "\t}\n"); @@ -2032,16 +2037,28 @@ done: Printf(s_phpclasses, "\n\tfunction __isset($var) {\n"); Printf(s_phpclasses, "\t\tif (function_exists('%s_'.$var.'_set')) return true;\n", shadow_classname); Printf(s_phpclasses, "\t\tif ($var === 'thisown') return true;\n"); - Printf(s_phpclasses, "\t\treturn array_key_exists($var, $this->%s);\n", SWIG_DATA); + if (baseclass) { + Printf(s_phpclasses, "\t\treturn %s%s::__isset($var);\n", prefix, baseclass); + } else { + Printf(s_phpclasses, "\t\treturn array_key_exists($var, $this->%s);\n", SWIG_DATA); + } Printf(s_phpclasses, "\t}\n"); } else { Printf(s_phpclasses, "\n\tfunction __set($var,$value) {\n"); Printf(s_phpclasses, "\t\tif ($var === 'thisown') return swig_%s_alter_newobject($this->%s,$value);\n", module, SWIG_PTR); - Printf(s_phpclasses, "\t\t$this->%s[$var] = $value;\n", SWIG_DATA); + if (baseclass) { + Printf(s_phpclasses, "\t\t%s%s::__set($var,$value);\n", prefix, baseclass); + } else { + Printf(s_phpclasses, "\t\t$this->%s[$var] = $value;\n", SWIG_DATA); + } Printf(s_phpclasses, "\t}\n"); Printf(s_phpclasses, "\n\tfunction __isset($var) {\n"); Printf(s_phpclasses, "\t\tif ($var === 'thisown') return true;\n"); - Printf(s_phpclasses, "\t\treturn array_key_exists($var, $this->%s);\n", SWIG_DATA); + if (baseclass) { + Printf(s_phpclasses, "\t\treturn %s%s::__isset($var);\n", prefix, baseclass); + } else { + Printf(s_phpclasses, "\t\treturn array_key_exists($var, $this->%s);\n", SWIG_DATA); + } Printf(s_phpclasses, "\t}\n"); } // Write property GET handlers @@ -2063,18 +2080,21 @@ done: Printf(s_phpclasses, "\t\tif (function_exists($func)) return call_user_func($func,$this->%s);\n", SWIG_PTR); } Printf(s_phpclasses, "\t\tif ($var === 'thisown') return swig_%s_get_newobject($this->%s);\n", module, SWIG_PTR); - Printf(s_phpclasses, "\t\tif (array_key_exists($var, $this->%s)) return $this->%s[$var];\n", SWIG_DATA, SWIG_DATA); - if (base.item) { + if (baseclass) { Printf(s_phpclasses, "\t\treturn %s%s::__get($var);\n", prefix, baseclass); } else { // Reading an unknown property name gives null in PHP. - Printf(s_phpclasses, "\t\treturn null;\n"); + Printf(s_phpclasses, "\t\treturn $this->%s[$var];\n", SWIG_DATA); } Printf(s_phpclasses, "\t}\n"); } else { Printf(s_phpclasses, "\n\tfunction __get($var) {\n"); Printf(s_phpclasses, "\t\tif ($var === 'thisown') return swig_%s_get_newobject($this->%s);\n", module, SWIG_PTR); - Printf(s_phpclasses, "\t\treturn $this->%s[$var];\n", SWIG_DATA); + if (baseclass) { + Printf(s_phpclasses, "\t\treturn %s%s::__get($var);\n", prefix, baseclass); + } else { + Printf(s_phpclasses, "\t\treturn $this->%s[$var];\n", SWIG_DATA); + } Printf(s_phpclasses, "\t}\n"); } From 4540717c39dcbfac35c052147244cc6f9aedb54a Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 17 Aug 2009 08:47:30 +0000 Subject: [PATCH 66/68] [PHP] Fix to wrap a resource returned by __get() in a PHP object (SF#2549217). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11619 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 3 +++ Source/Modules/php.cxx | 23 +++++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index cf0c4a63f..2dca20083 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,9 @@ Version 1.3.40 (in progress) ============================ +2009-08-17: olly + [PHP] Fix to wrap a resource returned by __get() in a PHP object (SF#2549217). + 2009-08-17: wsfulton Fix #2797485 After doing a 'make clean', install fails if yodl2man or yodl2html is not available. diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 2e3f53ecf..bae922e90 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -2067,18 +2067,21 @@ done: if (ki.key) { // This class has getters. Printf(s_phpclasses, "\n\tfunction __get($var) {\n"); - // FIXME: tune this threshold... - if (Len(shadow_get_vars) <= 2) { - // Not many getters, so avoid call_user_func. - while (ki.key) { - key = ki.key; - Printf(s_phpclasses, "\t\tif ($var === '%s') return %s($this->%s);\n", key, ki.item, SWIG_PTR); - ki = Next(ki); - } + // FIXME: Currently we always use call_user_func for __get, so we can + // check and wrap the result. This is needless if all the properties + // are primitive types. Also this doesn't handle all the cases which + // a method returning an object does. + Printf(s_phpclasses, "\t\t$func = '%s_'.$var.'_get';\n", shadow_classname); + Printf(s_phpclasses, "\t\tif (function_exists($func)) {\n"); + Printf(s_phpclasses, "\t\t\t$r = call_user_func($func,$this->%s);\n", SWIG_PTR); + Printf(s_phpclasses, "\t\t\tif (!is_resource($r)) return $r;\n"); + if (Len(prefix) == 0) { + Printf(s_phpclasses, "\t\t\t$c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3));\n"); } else { - Printf(s_phpclasses, "\t\t$func = '%s_'.$var.'_get';\n", shadow_classname); - Printf(s_phpclasses, "\t\tif (function_exists($func)) return call_user_func($func,$this->%s);\n", SWIG_PTR); + Printf(s_phpclasses, "\t\t\t$c='%s'.substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3));\n", prefix); } + Printf(s_phpclasses, "\t\t\treturn new $c($r);\n"); + Printf(s_phpclasses, "\t\t}\n"); Printf(s_phpclasses, "\t\tif ($var === 'thisown') return swig_%s_get_newobject($this->%s);\n", module, SWIG_PTR); if (baseclass) { Printf(s_phpclasses, "\t\treturn %s%s::__get($var);\n", prefix, baseclass); From 2b4c96235905e0d8e206f64ac34d25fdc299877d Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 17 Aug 2009 12:06:08 +0000 Subject: [PATCH 67/68] [Perl] Add "#undef do_exec" to our clean up of Perl global namespace pollution. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11620 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Lib/perl5/noembed.h | 3 +++ 2 files changed, 7 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 2dca20083..1021106f1 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ Version 1.3.40 (in progress) ============================ +2009-08-17: olly + [Perl] Add "#undef do_exec" to our clean up of Perl global + namespace pollution. + 2009-08-17: olly [PHP] Fix to wrap a resource returned by __get() in a PHP object (SF#2549217). diff --git a/Lib/perl5/noembed.h b/Lib/perl5/noembed.h index 55c3752aa..572465490 100644 --- a/Lib/perl5/noembed.h +++ b/Lib/perl5/noembed.h @@ -7,6 +7,9 @@ #ifdef do_close #undef do_close #endif +#ifdef do_exec + #undef do_exec +#endif #ifdef scalar #undef scalar #endif From dddec445fddf3bd3cceeac77c82725e8c323734a Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 17 Aug 2009 12:14:32 +0000 Subject: [PATCH 68/68] Start "What's New?" list for 1.3.40. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11621 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- README | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README b/README index 5fde83996..6ee379786 100644 --- a/README +++ b/README @@ -92,6 +92,10 @@ A SWIG FAQ and other hints can be found on the SWIG Wiki: What's New? =========== +SWIG-1.3.40 summary: +- SWIG now supports directors for PHP. +- PHP support improved in general. + SWIG-1.3.39 summary: - Some new small feature enhancements. - Improved C# std::vector wrappers.