diff options
author | Olly Betts <olly@survex.com> | 2021-03-18 15:50:52 +1300 |
---|---|---|
committer | Olly Betts <olly@survex.com> | 2021-03-19 08:45:33 +1300 |
commit | 71475b0af9677deeaf6fe55c0c5f53fec9f730d2 (patch) | |
tree | 3a03c08c1ddc11e1de7580ac4104c89d24441795 | |
parent | b7dedecfdd708c5323addc1b28e16cc727e01980 (diff) | |
download | swig-71475b0af9677deeaf6fe55c0c5f53fec9f730d2.tar.gz |
Improve PHP object creation
Reportedly the code we were using in the directorin case gave segfaults
in PHP 7.2 and later - we've been unable to reproduce these, but the new
approach is also simpler and should be bit faster too.
Fixes #1527, #1975
-rw-r--r-- | CHANGES.current | 6 | ||||
-rw-r--r-- | Lib/php/phprun.swg | 14 |
2 files changed, 11 insertions, 9 deletions
diff --git a/CHANGES.current b/CHANGES.current index f287e3d60..79d41001f 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,12 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2021-03-19: olly + #1527 [PHP] Improve PHP object creation in directorin case. + Reportedly the code we were using in this case gave segfaults in + PHP 7.2 and later - we've been unable to reproduce these, but the + new approach is also simpler and should be bit faster too. + 2021-03-18: olly #1655 [PHP] Fix char* typecheck typemap to accept PHP Null like the corresponding in typemap does. diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg index a07a1b9f8..f3a4e6ad1 100644 --- a/Lib/php/phprun.swg +++ b/Lib/php/phprun.swg @@ -90,15 +90,13 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) { } else { /* * Wrap the resource in an object, the resource will be accessible - * via the "_cPtr" member. This is currently only used by + * via the "_cPtr" property. This code path is currently only used by * directorin typemaps. */ - zval resource; zend_class_entry *ce = NULL; const char *type_name = type->name+3; /* +3 so: _p_Foo -> Foo */ size_t type_name_len; const char * p; - HashTable * ht; /* Namespace__Foo -> Foo */ /* FIXME: ugly and goes wrong for classes with __ in their names. */ @@ -107,7 +105,6 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) { } type_name_len = strlen(type_name); - ZVAL_RES(&resource, zend_register_resource(value, *(int *)(type->clientdata))); if (SWIG_PREFIX_LEN > 0) { zend_string * classname = zend_string_alloc(SWIG_PREFIX_LEN + type_name_len, 0); memcpy(classname->val, SWIG_PREFIX, SWIG_PREFIX_LEN); @@ -121,13 +118,12 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) { } if (ce == NULL) { /* class does not exist */ - ce = zend_standard_class_def; + object_init(z); + } else { + object_init_ex(z, ce); } - ALLOC_HASHTABLE(ht); - zend_hash_init(ht, 1, NULL, NULL, 0); - zend_hash_str_update(ht, "_cPtr", sizeof("_cPtr") - 1, &resource); - object_and_properties_init(z, ce, ht); + add_property_resource_ex(z, "_cPtr", sizeof("_cPtr") - 1, zend_register_resource(value, *(int *)(type->clientdata))); } return; } |