diff --git a/Examples/test-suite/php/newobject2_runme.php b/Examples/test-suite/php/newobject2_runme.php new file mode 100644 index 000000000..f20a6a4f9 --- /dev/null +++ b/Examples/test-suite/php/newobject2_runme.php @@ -0,0 +1,17 @@ +std);\n"); - // expand %delete typemap instead of SWIG_remove? - Printf(s, " if (obj->newobject)\n"); - Printf(s, " SWIG_remove((%s *)obj->ptr);\n", Getattr(n, "classtype")); + Printf(s, " if (obj->newobject)"); + String * type = Getattr(n, "classtype"); + if (destructor_action) { + Printv(s, + " {\n", + type, " * arg1 = (", type, " *)obj->ptr;\n", + destructor_action, "\n", + " }\n", NIL); + } else if (CPlusPlus) { + Printf(s, "\n delete (%s *)obj->ptr;\n", type); + } else { + Printf(s, "\n free(obj->ptr);\n", type); + } Printf(s, "}\n\n"); } @@ -371,9 +383,6 @@ public: Printf(s_header, "}\n"); Printf(s_header, "#endif\n\n"); - Printf(s_header, "#ifdef __cplusplus\n#define SWIG_remove(PTR) delete PTR\n"); - Printf(s_header, "#else\n#define SWIG_remove(PTR) free(PTR)\n#endif\n\n"); - if (directorsEnabled()) { // Insert director runtime Swig_insert_file("director_common.swg", s_header); @@ -1132,10 +1141,12 @@ public: } } - if (Cmp(nodeType, "destructor") == 0) { + if (wrapperType == destructor) { // We don't explicitly wrap the destructor for PHP - Zend manages the // reference counting, and the user can just do `$obj = null;' or similar // to remove a reference to an object. + Setattr(n, "wrap:name", wname); + (void)emit_action(n); return SWIG_OK; } @@ -1535,6 +1546,7 @@ public: String *base_class = NULL; class_name = symname; + destructor_action = NULL; Printf(all_cs_entry, "static zend_function_entry class_%s_functions[] = {\n", class_name); @@ -1811,8 +1823,13 @@ public: /* ------------------------------------------------------------ * destructorHandler() * ------------------------------------------------------------ */ - //virtual int destructorHandler(Node *n) { - //} + virtual int destructorHandler(Node *n) { + wrapperType = destructor; + Language::destructorHandler(n); + destructor_action = Getattr(n, "wrap:action"); + wrapperType = standard; + return SWIG_OK; + } /* ------------------------------------------------------------ * memberconstantHandler()