Improve generated object handlers
Do more initialisation at module load time. Use a shared set of handlers for cases when the C/C++ object is destroyed with free(). Most of the code in the free_obj and create_object handlers is the same for every wrapped class so factor that out into common functions.
This commit is contained in:
parent
5da86a1413
commit
78f5404727
2 changed files with 95 additions and 69 deletions
|
|
@ -206,3 +206,24 @@ static swig_module_info *SWIG_Php_GetModule() {
|
|||
static void SWIG_Php_SetModule(swig_module_info *pointer, int module_number) {
|
||||
REGISTER_LONG_CONSTANT(const_name, (long) pointer, CONST_CS | CONST_PERSISTENT);
|
||||
}
|
||||
|
||||
/* Common parts of the "create_object" object handler. */
|
||||
static zend_object *SWIG_Php_do_create_object(zend_class_entry *ce, zend_object_handlers *handlers) {
|
||||
swig_object_wrapper *obj = (swig_object_wrapper*)zend_object_alloc(sizeof(swig_object_wrapper), ce);
|
||||
zend_object_std_init(&obj->std, ce);
|
||||
object_properties_init(&obj->std, ce);
|
||||
obj->std.handlers = handlers;
|
||||
obj->newobject = 1;
|
||||
return &obj->std;
|
||||
}
|
||||
|
||||
/* Common parts of the "free_obj" object handler.
|
||||
Returns void* pointer if the C/C++ object should be destroyed. */
|
||||
static void* SWIG_Php_free_obj(zend_object *object) {
|
||||
if (object) {
|
||||
swig_object_wrapper *obj = swig_php_fetch_object(object);
|
||||
zend_object_std_dtor(&obj->std);
|
||||
if (obj->newobject) return obj->ptr;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue