diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2015-01-11 14:09:11 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2015-01-11 14:09:11 +0100 |
commit | d31039e6eebedaf4573e99cd11df58c958b82ddb (patch) | |
tree | 2dd1dc60c11643e2e7a2425236265a88433bb473 | |
parent | ae9d580fe7a79052d614b7d48d8feb54836fe334 (diff) |
fixed return value problem in the Php::eval() function (also solved in issue #129)
-rw-r--r-- | zend/eval.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/zend/eval.cpp b/zend/eval.cpp index 4c4bffc..674d39d 100644 --- a/zend/eval.cpp +++ b/zend/eval.cpp @@ -29,8 +29,11 @@ Value eval(const std::string &phpCode) // the current exception zval* oldException = EG(exception); - // the return zval - zval* retval = nullptr; + // the return va + zval *retval = nullptr; + MAKE_STD_ZVAL(retval); + + // evaluate the string if (zend_eval_stringl_ex((char *)phpCode.c_str(), (int32_t)phpCode.length(), retval, (char *)"", 1 TSRMLS_CC) != SUCCESS) { // Do we want to throw an exception here? The original author of this code @@ -57,8 +60,17 @@ Value eval(const std::string &phpCode) // throw a C++ new exception to give the C++ code the chance to catch it if (oldException != EG(exception) && EG(exception)) throw OrigException(EG(exception) TSRMLS_CC); - // no (additional) exception was thrown - return retval ? Value(retval) : nullptr; + // wrap the return value in a value object + Value result(retval); + + // the retval should now have two references: the value object and the + // retval itselves, so we can remove one of it (the zval_ptr_dtor only + // decrements refcount and won't destruct anything because there still + // is one reference left inside the Value object) + zval_ptr_dtor(&retval); + + // done + return result; } } |