Only emit custom free_obj handler if needed
If has_destructor isn't set then the default zend_object_std_dtor does everything necessary.
This commit is contained in:
parent
837dfa1e7e
commit
3c4342e66a
1 changed files with 14 additions and 12 deletions
|
|
@ -129,29 +129,31 @@ static void print_creation_free_wrapper(Node *n) {
|
|||
Printf(s, "/* class object handlers for %s */\n",class_name);
|
||||
Printf(s, "zend_object_handlers %s_object_handlers;\n\n",class_name);
|
||||
|
||||
Printf(s, "/* Garbage Collection Method for class %s */\n",class_name);
|
||||
Printf(s, "void %s_free_storage(zend_object *object) {\n",class_name);
|
||||
Printf(s, " swig_object_wrapper *obj = 0;\n");
|
||||
Printf(s, " if (!object)\n");
|
||||
Printf(s, " return;\n");
|
||||
Printf(s, " obj = php_fetch_object(object);\n");
|
||||
|
||||
// expand %delete typemap instead of SWIG_remove?
|
||||
if (Getattr(n, "has_destructor")) {
|
||||
Printf(s, "/* Garbage Collection Method for class %s */\n",class_name);
|
||||
Printf(s, "void %s_free_storage(zend_object *object) {\n",class_name);
|
||||
Printf(s, " swig_object_wrapper *obj = 0;\n");
|
||||
Printf(s, " if (!object)\n");
|
||||
Printf(s, " return;\n");
|
||||
Printf(s, " obj = php_fetch_object(object);\n");
|
||||
|
||||
Printf(s, " zend_object_std_dtor(&obj->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, "}\n\n");
|
||||
}
|
||||
|
||||
Printf(s, " zend_object_std_dtor(&obj->std);\n");
|
||||
Printf(s, "}\n\n");
|
||||
|
||||
Printf(s, "/* Object Creation Method for class %s */\n",class_name);
|
||||
Printf(s, "zend_object * %s_object_new(zend_class_entry *ce) {\n",class_name);
|
||||
Printf(s, " swig_object_wrapper *obj = (swig_object_wrapper*)zend_object_alloc(sizeof(swig_object_wrapper), ce);\n");
|
||||
Printf(s, " zend_object_std_init(&obj->std, ce);\n");
|
||||
Printf(s, " object_properties_init(&obj->std, ce);\n");
|
||||
Printf(s, " %s_object_handlers.offset = XtOffsetOf(swig_object_wrapper, std);\n", class_name);
|
||||
Printf(s, " %s_object_handlers.free_obj = %s_free_storage;\n", class_name, class_name);
|
||||
if (Getattr(n, "has_destructor")) {
|
||||
Printf(s, " %s_object_handlers.free_obj = %s_free_storage;\n", class_name, class_name);
|
||||
}
|
||||
Printf(s, " obj->std.handlers = &%s_object_handlers;\n obj->newobject = 1;\n return &obj->std;\n}\n\n\n",class_name);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue