summaryrefslogtreecommitdiff
path: root/zend
diff options
context:
space:
mode:
authorandot <mabingyao@gmail.com>2014-07-10 12:45:04 +0800
committerandot <mabingyao@gmail.com>2014-07-10 12:45:04 +0800
commitd24ce36eaa07e9e924e7084fafa4f504cde39c2f (patch)
treedd5e7766be851e88db6192d3d0da18508d01cf15 /zend
parent28578382589dab25ea5fbd35b7754687706abc07 (diff)
Implementation issue #98
Diffstat (limited to 'zend')
-rw-r--r--zend/fastcall.cpp40
-rw-r--r--zend/includes.h1
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