summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartijn Otto <martijn.otto@copernica.com>2016-05-20 13:38:56 +0200
committerMartijn Otto <martijn.otto@copernica.com>2016-05-20 13:38:56 +0200
commit252870d4a85f942107e7b51f9bdf5fae4e88f728 (patch)
tree0b4d9108c0f75bcbe6a9a8a5ba51bb73eeb6a28a
parent8308b984cc61cb2464b9192961abaae4fe750591 (diff)
Fix exception catching and properly handle casting functions returning something other than a Php::Value
-rw-r--r--include/class.h8
-rw-r--r--include/exception.h4
-rw-r--r--zend/opcodes.h3
-rw-r--r--zend/origexception.h11
-rw-r--r--zend/value.cpp5
5 files changed, 14 insertions, 17 deletions
diff --git a/include/class.h b/include/class.h
index 371595e..26cc610 100644
--- a/include/class.h
+++ b/include/class.h
@@ -462,7 +462,7 @@ private:
T *obj = (T *)base;
// retrieve the casted value and convert it if necessary
- auto result = obj->__toString();
+ Value result{ obj->__toString() };
result.setType(Type::String);
// return the converted result
@@ -480,7 +480,7 @@ private:
T *obj = (T *)base;
// retrieve the casted value and convert it if necessary
- auto result = obj->__toInteger();
+ Value result{ obj->__toInteger() };
result.setType(Type::Numeric);
// return the converted result
@@ -498,7 +498,7 @@ private:
T *obj = (T *)base;
// retrieve the casted value and convert it if necessary
- auto result = obj->__toFloat();
+ Value result{ obj->__toFloat() };
result.setType(Type::Float);
// return the converted result
@@ -516,7 +516,7 @@ private:
T *obj = (T *)base;
// retrieve the casted value and convert it if necessary
- auto result = obj->__toBool();
+ Value result{ obj->__toBool() };
result.setType(Type::Bool);
// return the converted result
diff --git a/include/exception.h b/include/exception.h
index 55601c2..235529f 100644
--- a/include/exception.h
+++ b/include/exception.h
@@ -41,12 +41,12 @@ public:
* Constructor
* @param &string
*/
- Exception(const std::string &message, int code = 0) : std::exception(), _message(message), _code(code) {}
+ Exception(std::string message, int code = 0) : std::exception(), _message(std::move(message)), _code(code) {}
/**
* Destructor
*/
- virtual ~Exception() throw() {}
+ virtual ~Exception() = default;
/**
* Overridden what method
diff --git a/zend/opcodes.h b/zend/opcodes.h
index 1901f1f..0a79b97 100644
--- a/zend/opcodes.h
+++ b/zend/opcodes.h
@@ -93,8 +93,7 @@ public:
// was an exception thrown inside the eval()'ed code? In that case we
// throw a C++ new exception to give the C++ code the chance to catch it
- // todo: OrigException with constructor for zend_object
- // if (oldException != EG(exception) && EG(exception)) throw OrigException(EG(exception) TSRMLS_CC);
+ if (oldException != EG(exception) && EG(exception)) throw OrigException(EG(exception) TSRMLS_CC);
// we're ready if there is no return value
if (ZVAL_IS_NULL(&retval)) return nullptr;
diff --git a/zend/origexception.h b/zend/origexception.h
index f997608..fb873bd 100644
--- a/zend/origexception.h
+++ b/zend/origexception.h
@@ -16,7 +16,7 @@ namespace Php {
/**
* Class definition
*/
-class OrigException : public Value, public Exception
+class OrigException : public Exception
{
private:
/**
@@ -42,10 +42,9 @@ private:
public:
/**
* Constructor
- * @param val
+ * @param object The object that was thrown
*/
- OrigException(zval *val TSRMLS_DC) :
- Value(val), Exception("OrigException")
+ OrigException(zend_object *object) : Exception(std::string{ ZSTR_VAL(object->ce->name), ZSTR_LEN(object->ce->name) })
{
#ifdef ZTS
// copy tsrm_ls
@@ -58,7 +57,7 @@ public:
* @param exception
*/
OrigException(const OrigException &exception) :
- Value(exception), Exception("OrigException"), _handled(exception._handled)
+ Exception("OrigException"), _handled(exception._handled)
{
#ifdef ZTS
// copy tsrm_ls
@@ -71,7 +70,7 @@ public:
* @param exception
*/
OrigException(OrigException &&exception) :
- Value(std::move(exception)), Exception("OrigException"), _handled(exception._handled)
+ Exception("OrigException"), _handled(exception._handled)
{
// set other exception to handled so that it wont do anything on destruction
exception._handled = true;
diff --git a/zend/value.cpp b/zend/value.cpp
index 4aaec4c..d87e576 100644
--- a/zend/value.cpp
+++ b/zend/value.cpp
@@ -846,7 +846,7 @@ static Value do_exec(const zval *object, zval *method, int argc, zval *argv)
TSRMLS_FETCH();
// the current exception
- // zend_object *oldException = EG(exception);
+ zend_object *oldException = EG(exception);
// call the function
// we're casting the const away here, object is only const so we can call this method
@@ -863,8 +863,7 @@ static Value do_exec(const zval *object, zval *method, int argc, zval *argv)
{
// was an exception thrown inside the function? In that case we throw a C++ new exception
// to give the C++ code the chance to catch it
- // @todo: make OrigException except a zend_object instance
- // if (oldException != EG(exception) && EG(exception)) throw OrigException(EG(exception) TSRMLS_CC);
+ if (oldException != EG(exception) && EG(exception)) throw OrigException(EG(exception) TSRMLS_CC);
// leap out if nothing was returned
if (Z_ISUNDEF(retval)) return nullptr;