diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-07-26 11:50:02 +0200 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-07-26 11:50:02 +0200 |
commit | ff83769a9d5fc2f0f88cd42bdb3355f509294ad9 (patch) | |
tree | 66275722fa134c72d9dd061d6bde749296901d91 /zend | |
parent | 7de92192f6791ea326f8acbee90c4fa7f5880eae (diff) | |
parent | d24ce36eaa07e9e924e7084fafa4f504cde39c2f (diff) |
Merge branch 'issue#98' of https://github.com/andot/PHP-CPP into andot-issue#98
Diffstat (limited to 'zend')
-rw-r--r-- | zend/fastcall.cpp | 40 | ||||
-rw-r--r-- | zend/includes.h | 1 |
2 files changed, 41 insertions, 0 deletions
diff --git a/zend/fastcall.cpp b/zend/fastcall.cpp new file mode 100644 index 0000000..3ecd598 --- /dev/null +++ b/zend/fastcall.cpp @@ -0,0 +1,40 @@ +/** + * fastcall.cpp + * + * This file holds some PHP functions implementation in C directly. + * + */ + +#include "includes.h" + +namespace Php { + + Value eval(const std::string &phpCode) { + // we need the tsrm_ls variable + TSRMLS_FETCH(); + + // the current exception + zval* oldException = EG(exception); + + // the return zval + zval* retval = nullptr; + if (zend_eval_stringl_ex((char *)phpCode.c_str(), (int32_t)phpCode.length(), retval, (char *)"", 1 TSRMLS_CC) != SUCCESS) + { + // throw an exception, php couldn't evaluate code + throw Exception("PHP couldn't evaluate: " + phpCode); + + // unreachable, but let's return at least something to prevent compiler warnings + return nullptr; + } + else + { + // 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 + if (oldException != EG(exception) && EG(exception)) throw OrigException(EG(exception) TSRMLS_CC); + + // no (additional) exception was thrown + return retval ? Value(retval) : nullptr; + } + } + +}
\ No newline at end of file diff --git a/zend/includes.h b/zend/includes.h index 63b435e..8af557c 100644 --- a/zend/includes.h +++ b/zend/includes.h @@ -79,6 +79,7 @@ #include "../include/namespace.h" #include "../include/extension.h" #include "../include/call.h" +#include "../include/fastcall.h" /** * Common header files for internal use only |