summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlly Betts <olly@survex.com>2021-04-21 17:43:12 +1200
committerOlly Betts <olly@survex.com>2021-04-21 18:16:08 +1200
commit33feca7527758466af7b6ffc503cf46fc18d0ee2 (patch)
treeb0a6877452a35ff72d14eeda1b6dedd62edd6c79
parentac676d1a6c98c57a316842abeb92c5d4a8da8cb9 (diff)
downloadswig-33feca7527758466af7b6ffc503cf46fc18d0ee2.tar.gz
Eliminate SWIG_SetZval()
$needNewFlow is now only used for a different hack in a directorout typemap.
-rw-r--r--Lib/php/php.swg15
-rw-r--r--Lib/php/phprun.swg32
-rw-r--r--Source/Modules/php.cxx1
3 files changed, 16 insertions, 32 deletions
diff --git a/Lib/php/php.swg b/Lib/php/php.swg
index 37be5b4a2..8dd613620 100644
--- a/Lib/php/php.swg
+++ b/Lib/php/php.swg
@@ -370,12 +370,12 @@
SWIGTYPE &,
SWIGTYPE &&
%{
- SWIG_SetZval($result, $needNewFlow, $owner, (void *)result, $1_descriptor);
+ SWIG_SetPointerZval($result, (void *)$1, $1_descriptor, $owner);
%}
%typemap(out) SWIGTYPE *const&
%{
- SWIG_SetZval(return_value, $needNewFlow, $owner, (void *)*$1, $*1_descriptor);
+ SWIG_SetPointerZval($result, (void *)*$1, $*1_descriptor, $owner);
%}
%typemap(directorin) SWIGTYPE *,
@@ -403,22 +403,19 @@
SWIGTYPE &DYNAMIC
{
swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor, (void **) &$1);
- SWIG_SetPointerZval(return_value, (void *)$1, ty, $owner);
+ SWIG_SetPointerZval($result, (void *)$1, ty, $owner);
}
%typemap(out) SWIGTYPE
-#ifdef __cplusplus
{
+#ifdef __cplusplus
$&1_ltype resultobj = new $1_ltype((const $1_ltype &) $1);
- SWIG_SetZval(return_value, $needNewFlow, 1, (void *)resultobj, $&1_descriptor);
-}
#else
-{
$&1_ltype resultobj = ($&1_ltype) emalloc(sizeof($1_type));
memcpy(resultobj, &$1, sizeof($1_type));
- SWIG_SetZval(return_value, $needNewFlow, 1, (void *)resultobj, $&1_descriptor);
-}
#endif
+ SWIG_SetPointerZval($result, (void *)resultobj, $&1_descriptor, 1);
+}
%typemap(directorin) SWIGTYPE
%{
diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg
index 2795f5b6a..a1eeb3aae 100644
--- a/Lib/php/phprun.swg
+++ b/Lib/php/phprun.swg
@@ -101,13 +101,20 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) {
}
{
- zend_class_entry *ce = (zend_class_entry*)(type->clientdata);
- zend_object *obj = ce->create_object(ce);
+ zend_object *obj;
+ if (Z_TYPE_P(z) == IS_OBJECT) {
+ /* The PHP object is already initialised - this is the case when wrapping
+ * the return value from a PHP constructor. */
+ obj = Z_OBJ_P(z);
+ } else {
+ zend_class_entry *ce = (zend_class_entry*)(type->clientdata);
+ obj = ce->create_object(ce);
+ ZVAL_OBJ(z, obj);
+ }
swig_object_wrapper *value = php_fetch_object(obj);
value->ptr = ptr;
value->newobject = (newobject & 1);
value->type = type;
- ZVAL_OBJ(z, obj);
}
}
@@ -168,25 +175,6 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) {
return -1;
}
-static void
-SWIG_SetZval(zval *zv, int newFlow, int newobject, void *ptr, swig_type_info *type) {
- if (newFlow > 1) {
- if (!ptr) {
- ZVAL_NULL(zv);
- return;
- }
-
- {
- swig_object_wrapper * obj = SWIG_Z_FETCH_OBJ_P(zv);
- obj->ptr = ptr;
- obj->newobject = newobject;
- obj->type = type;
- }
- } else {
- SWIG_SetPointerZval(zv, ptr, type, newobject);
- }
-}
-
static const char const_name[] = "swig_runtime_data_type_pointer";
static swig_module_info *SWIG_Php_GetModule() {
zval *pointer = zend_get_constant_str(const_name, sizeof(const_name) - 1);
diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx
index ae3ae0c93..b30f57076 100644
--- a/Source/Modules/php.cxx
+++ b/Source/Modules/php.cxx
@@ -1402,7 +1402,6 @@ public:
Replaceall(tm, "$input", Swig_cresult_name());
Replaceall(tm, "$result", php_constructor ? "ZEND_THIS" : "return_value");
Replaceall(tm, "$owner", newobject ? "1" : "0");
- Replaceall(tm, "$needNewFlow", php_constructor && is_class(d) ? "2" : "0");
Printf(f->code, "%s\n", tm);
} else {
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), name);