Eliminate SWIG_SetZval()

$needNewFlow is now only used for a different hack in a directorout
typemap.
This commit is contained in:
Olly Betts 2021-04-21 17:43:12 +12:00
commit 33feca7527
3 changed files with 16 additions and 32 deletions

View file

@ -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
{
$&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
%{

View file

@ -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);

View file

@ -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);