Skip to content

Commit e91de64

Browse files
fixed the __invoke() and __call() methods: the return value of the C++ function was not passed to php space
1 parent ce70162 commit e91de64

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

zend/classimpl.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,17 @@ void ClassImpl::callMethod(INTERNAL_FUNCTION_PARAMETERS)
106106
// the function could throw an exception
107107
try
108108
{
109-
// wrap the return value
110-
Value result(return_value, true);
111-
112109
// construct parameters
113110
ParametersImpl params(getThis(), ZEND_NUM_ARGS());
114111

115112
// retrieve the base object
116113
Base *base = params.object();
117114

118115
// is this a static, or a non-static call?
119-
if (base) result = meta->callCall(base, name, params);
120-
else result = meta->callCallStatic(name, params);
116+
Php::Value result = base ? meta->callCall(base, name, params) : meta->callCallStatic(name, params);
117+
118+
// return a full copy of the zval, and do not destruct it
119+
RETVAL_ZVAL(result._val, 1, 0);
121120
}
122121
catch (const NotImplemented &exception)
123122
{
@@ -151,17 +150,17 @@ void ClassImpl::callInvoke(INTERNAL_FUNCTION_PARAMETERS)
151150
// the function could throw an exception
152151
try
153152
{
154-
// wrap the return value
155-
Value result(return_value, true);
156-
157153
// construct parameters
158154
ParametersImpl params(getThis(), ZEND_NUM_ARGS());
159155

160156
// retrieve the base object
161157
Base *base = params.object();
162158

163159
// call the actual __invoke method on the base object
164-
result = meta->callInvoke(base, params);
160+
auto result = meta->callInvoke(base, params);
161+
162+
// return a full copy of the zval, and do not destruct it
163+
RETVAL_ZVAL(result._val, 1, 0);
165164
}
166165
catch (const NotImplemented &exception)
167166
{
@@ -212,7 +211,7 @@ zend_function *ClassImpl::getMethod(zend_object **object, zend_string *method, c
212211
auto *function = &data->func;
213212

214213
// set all properties
215-
function->type = ZEND_INTERNAL_FUNCTION;
214+
function->type = ZEND_INTERNAL_FUNCTION;
216215
function->arg_flags[0] = 0;
217216
function->arg_flags[1] = 0;
218217
function->arg_flags[2] = 0;
@@ -256,7 +255,7 @@ zend_function *ClassImpl::getStaticMethod(zend_class_entry *entry, zend_string *
256255
auto *function = &data->func;
257256

258257
// set all properties for the function
259-
function->type = ZEND_INTERNAL_FUNCTION;
258+
function->type = ZEND_INTERNAL_FUNCTION;
260259
function->arg_flags[0] = 0;
261260
function->arg_flags[1] = 0;
262261
function->arg_flags[2] = 0;
@@ -300,7 +299,7 @@ int ClassImpl::getClosure(zval *object, zend_class_entry **entry_ptr, zend_funct
300299
auto *function = &data->func;
301300

302301
// we're going to set all properties of the zend_internal_function struct
303-
function->type = ZEND_INTERNAL_FUNCTION;
302+
function->type = ZEND_INTERNAL_FUNCTION;
304303
function->arg_flags[0] = 0;
305304
function->arg_flags[1] = 0;
306305
function->arg_flags[2] = 0;

zend/classimpl.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* exist for a class.
66
*
77
* @author Emiel Bruijntjes <[email protected]>
8-
* @copyright 2014 Copernica BV
8+
* @copyright 2014 - 2019 Copernica BV
99
*/
1010

1111
/**
@@ -303,10 +303,10 @@ class ClassImpl
303303

304304
/**
305305
* Method that returns information about the __invoke() method
306-
* @param object
307-
* @param entry
308-
* @param func
309-
* @param object_ptr
306+
* @param object The object on which the method is called
307+
* @param entry Class entry holding class properties
308+
* @param func Function to be filled
309+
* @param object_ptr To be filled with the object on which the method is to be called
310310
* @return int
311311
*/
312312
static int getClosure(zval *object, zend_class_entry **entry, zend_function **func, zend_object **object_ptr);

zend/constantimpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Implementation file for the constant class
55
*
66
* @author Emiel Bruijntjes <[email protected]>
7-
* @copyright 2015 Copernica BV
7+
* @copyright 2015 - 2019 Copernica BV
88
*/
99

1010
/**
@@ -188,7 +188,7 @@ class ConstantImpl
188188

189189
// copy the entire namespace name, separator and constant name
190190
::strncpy(ZSTR_VAL(_constant.name), prefix.c_str(), prefix.size());
191-
::strncpy(ZSTR_VAL(_constant.name) + prefix.size(), "\\", 1);
191+
::strcpy (ZSTR_VAL(_constant.name) + prefix.size(), "\\");
192192
::strncpy(ZSTR_VAL(_constant.name) + prefix.size() + 1, _name, namelen + 1);
193193
}
194194
else

0 commit comments

Comments
 (0)