diff --git a/Zend/zend.c b/Zend/zend.c index 942b0a0c59b41..03781d846906a 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -1245,6 +1245,57 @@ ZEND_API void zend_output_debug_string(zend_bool trigger_break, const char *form } /* }}} */ + +ZEND_API int zend_execute_string(int type, zval *retval, const char *string, size_t len, const char *filename) /* {{{ */ +{ + zend_op_array *op_array; + zval zstring; + + ZVAL_STRINGL(&zstring, string, len); + + op_array = zend_compile_string(&zstring, filename); + if (op_array) { + zend_execute(op_array, retval); + zend_exception_restore(); + if (EG(exception)) { + if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) { + zval orig_user_exception_handler; + zval params[1], retval2; + zend_object *old_exception; + old_exception = EG(exception); + EG(exception) = NULL; + ZVAL_OBJ(¶ms[0], old_exception); + ZVAL_COPY_VALUE(&orig_user_exception_handler, &EG(user_exception_handler)); + ZVAL_UNDEF(&retval2); + if (call_user_function_ex(CG(function_table), NULL, &orig_user_exception_handler, &retval2, 1, params, 1, NULL) == SUCCESS) { + zval_ptr_dtor(&retval2); + if (EG(exception)) { + OBJ_RELEASE(EG(exception)); + EG(exception) = NULL; + } + OBJ_RELEASE(old_exception); + } else { + EG(exception) = old_exception; + zend_exception_error(EG(exception), E_ERROR); + } + } else { + zend_exception_error(EG(exception), E_ERROR); + } + } + destroy_op_array(op_array); + efree_size(op_array, sizeof(zend_op_array)); + } else if (type==ZEND_REQUIRE) { + zval_dtor(&zstring); + return FAILURE; + } + zval_dtor(&zstring); + return SUCCESS; +} +/* }}} */ + + + + ZEND_API int zend_execute_scripts(int type, zval *retval, int file_count, ...) /* {{{ */ { va_list files; diff --git a/acinclude.m4 b/acinclude.m4 index a4d4d509e06f0..921c3e5d05250 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -2604,6 +2604,20 @@ AC_DEFUN([PHP_INSTALL_HEADERS],[ ]) ]) +dnl +dnl PHP_BUILTIN_SCRIPT(name, file) +dnl +dnl data to be built with the extension +dnl +AC_DEFUN([PHP_BUILTIN_SCRIPT],[ + destdir=PHP_EXT_DIR($1) + + echo "const char *$1_script =" > $destdir/builtinscript.c && hexdump -e '16/1 "_x%02X" "\n"' $2 | sed 's/_/\\/g; s/\\x //g; s/.*/ "&"/' >> $destdir/builtinscript.c && echo ";" >> $destdir/builtinscript.c + echo "extern const char *$1_script;" > $destdir/builtinscript.h + PHP_ADD_SOURCES(PHP_EXT_DIR($1), builtinscript.c) + ]) +]) + dnl dnl PHP_AP_EXTRACT_VERSION(/path/httpd) dnl diff --git a/ext/date/date.php b/ext/date/date.php new file mode 100644 index 0000000000000..4c5eb85f8f3b2 --- /dev/null +++ b/ext/date/date.php @@ -0,0 +1,4 @@ +function date_builtin() +{ + echo "this is a builtin date script\n"; +} diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 5f415fd7f3920..b51afc036782b 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -30,6 +30,7 @@ #include "zend_interfaces.h" #include "lib/timelib.h" #include +#include "builtinscript.h" #ifdef PHP_WIN32 static __inline __int64 php_date_llabs( __int64 i ) { return i >= 0? i: -i; } @@ -693,6 +694,8 @@ static void _php_date_tzinfo_dtor(zval *zv) /* {{{ */ /* {{{ PHP_RINIT_FUNCTION */ PHP_RINIT_FUNCTION(date) { + zval script; + if (DATEG(timezone)) { efree(DATEG(timezone)); } @@ -700,6 +703,7 @@ PHP_RINIT_FUNCTION(date) DATEG(tzcache) = NULL; DATEG(last_errors) = NULL; + zend_execute_string(ZEND_REQUIRE, &script, date_script, strlen(date_script), "date_builtin_php"); return SUCCESS; } /* }}} */