summaryrefslogtreecommitdiff
path: root/zend/callable.cpp
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-07 10:55:53 +0200
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-07 10:55:53 +0200
commit45a79f33051ed70fd69d3b9943a1e5797402430e (patch)
treef87bacb47b746182367bbb1e9840f5cb32cbb783 /zend/callable.cpp
parente2b543132bdf6cf7c335801139c19cc17dca0c34 (diff)
objects were not destructed correctly (we freed memory that we had allocated ourselves, but the Zend engine seemed to deallocate the same memory too, which caused a crash), and improved returning values from functions, which crashed when one of the own parameters was directly returned (error mentioned in issue #68)
Diffstat (limited to 'zend/callable.cpp')
-rw-r--r--zend/callable.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/zend/callable.cpp b/zend/callable.cpp
index 737b85b..96f5f90 100644
--- a/zend/callable.cpp
+++ b/zend/callable.cpp
@@ -23,7 +23,7 @@ namespace Php {
* @param tsrm_ls
* @return integer
*/
-static void invoke_callable(INTERNAL_FUNCTION_PARAMETERS)
+void Callable::invoke(INTERNAL_FUNCTION_PARAMETERS)
{
// find the function name
const char *name = get_active_function_name(TSRMLS_C);
@@ -31,9 +31,6 @@ static void invoke_callable(INTERNAL_FUNCTION_PARAMETERS)
// uncover the hidden pointer inside the function name
Callable *callable = HiddenPointer<Callable>(name);
- // wrap the return value
- Value result(return_value, true);
-
// construct parameters
ParametersImpl params(this_ptr, ZEND_NUM_ARGS() TSRMLS_CC);
@@ -41,7 +38,15 @@ static void invoke_callable(INTERNAL_FUNCTION_PARAMETERS)
try
{
// get the result
- result = callable->invoke(params);
+ Value result(callable->invoke(params));
+
+ // detach the zval (we don't want it to be destructed)
+ zval *val = result.detach();
+
+ // @todo php 5.6 has a RETVAL_ZVAL_FAST macro that can be used instead (and is faster)
+
+ // return a full copy of the zval, and do not destruct it
+ RETVAL_ZVAL(val, 1, 0);
}
catch (Exception &exception)
{
@@ -64,7 +69,7 @@ void Callable::initialize(zend_function_entry *entry, const char *classname, int
{
// fill the members of the entity, and hide a pointer to the current object in the name
entry->fname = (const char *)_ptr;
- entry->handler = invoke_callable;
+ entry->handler = &Callable::invoke;
entry->arg_info = _argv;
entry->num_args = _argc;
entry->flags = flags;