swig/swig-4.0.2-Improve-PHP-object-creation.patch

83 lines
3.1 KiB
Diff

From 71475b0af9677deeaf6fe55c0c5f53fec9f730d2 Mon Sep 17 00:00:00 2001
From: Olly Betts <olly@survex.com>
Date: Thu, 18 Mar 2021 15:50:52 +1300
Subject: [PATCH] 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
---
CHANGES.current | 6 ++++++
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;
}
--
2.26.3