cvs: ZendEngine2 / zend.c zend_default_classes.c zend_default_classes.h zend_execute.h zend_execute_API.c php-src/sapi/cli php_cli.c
| From: | Marcus Boerger | Date: | Sun, 24 Aug 2003 13:10:03 +0000 |
| Subject: | cvs: ZendEngine2 / zend.c zend_default_classes.c zend_default_classes.h zend_execute.h zend_execute_API.c php-src/sapi/cli php_cli.c | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-1682@lists.php.net to get a copy of this message | ||
helly Sun Aug 24 09:10:03 2003 EDT
Modified files:
/php-src/sapi/cli php_cli.c
/ZendEngine2 zend.c zend_default_classes.c zend_default_classes.h
zend_execute.h zend_execute_API.c
Log:
- Provide a unified way to display uncaught exceptions, which shows
file/line/message info if possible.
- Add zend_eval_string_ex() to be able to handle exceptions in eval'd code.
- Use above function to fix memleaks in CLI.
Index: php-src/sapi/cli/php_cli.c
diff -u php-src/sapi/cli/php_cli.c:1.100 php-src/sapi/cli/php_cli.c:1.101
--- php-src/sapi/cli/php_cli.c:1.100 Thu Aug 21 21:50:02 2003
+++ php-src/sapi/cli/php_cli.c Sun Aug 24 09:10:02 2003
@@ -19,7 +19,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_cli.c,v 1.100 2003/08/22 01:50:02 iliaa Exp $ */
+/* $Id: php_cli.c,v 1.101 2003/08/24 13:10:02 helly Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -945,7 +945,7 @@
#endif
case PHP_MODE_CLI_DIRECT:
cli_register_file_handles(TSRMLS_C);
- if (zend_eval_string(exec_direct, NULL, "Command line code" TSRMLS_CC) == FAILURE) {
+ if (zend_eval_string_ex(exec_direct, NULL, "Command line code", 1 TSRMLS_CC) ==
FAILURE) {
exit_status=254;
}
break;
@@ -958,7 +958,7 @@
cli_register_file_handles(TSRMLS_C);
- if (exec_begin && zend_eval_string(exec_begin, NULL, "Command line begin
code" TSRMLS_CC) == FAILURE) {
+ if (exec_begin && zend_eval_string_ex(exec_begin, NULL, "Command line begin
code", 1 TSRMLS_CC) == FAILURE) {
exit_status=254;
}
ALLOC_ZVAL(argi);
@@ -979,7 +979,7 @@
zend_hash_update(&EG(symbol_table), "argn", sizeof("argn"), &argn,
sizeof(pval *), NULL);
Z_LVAL_P(argi) = ++index;
if (exec_run) {
- if (zend_eval_string(exec_run, NULL, "Command line run code" TSRMLS_CC) == FAILURE)
{
+ if (zend_eval_string_ex(exec_run, NULL, "Command line run code", 1 TSRMLS_CC) ==
FAILURE) {
exit_status=254;
}
} else {
@@ -995,7 +995,7 @@
}
efree(input);
}
- if (exec_end && zend_eval_string(exec_end, NULL, "Command line end code"
TSRMLS_CC) == FAILURE) {
+ if (exec_end && zend_eval_string_ex(exec_end, NULL, "Command line end code",
1 TSRMLS_CC) == FAILURE) {
exit_status=254;
}
Index: ZendEngine2/zend.c
diff -u ZendEngine2/zend.c:1.243 ZendEngine2/zend.c:1.244
--- ZendEngine2/zend.c:1.243 Wed Jul 30 12:13:52 2003
+++ ZendEngine2/zend.c Sun Aug 24 09:10:02 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend.c,v 1.243 2003/07/30 16:13:52 zeev Exp $ */
+/* $Id: zend.c,v 1.244 2003/08/24 13:10:02 helly Exp $ */
#include "zend.h"
#include "zend_extensions.h"
@@ -1052,9 +1052,9 @@
zval_ptr_dtor(&retval2);
}
} else {
+ zend_exception_error(EG(exception) TSRMLS_CC);
zval_ptr_dtor(&EG(exception));
EG(exception) = NULL;
- zend_error(E_ERROR, "Uncaught exception '%s'!", ex_class_name);
}
efree(params);
zval_ptr_dtor(&old_exception);
@@ -1063,17 +1063,17 @@
EG(exception) = NULL;
}
} else {
+ zend_exception_error(EG(exception) TSRMLS_CC);
zval_ptr_dtor(&EG(exception));
EG(exception) = NULL;
- zend_error(E_ERROR, "Uncaught exception '%s'!", ex_class_name);
}
if (retval == NULL && *EG(return_value_ptr_ptr) != NULL) {
zval_ptr_dtor(EG(return_value_ptr_ptr));
local_retval = NULL;
}
#else
+ zend_exception_error(EG(exception) TSRMLS_CC);
zval_ptr_dtor(&EG(exception));
- zend_error(E_ERROR, "Uncaught exception '%s'!", ex_class_name);
#endif
} else if (!retval) {
zval_ptr_dtor(EG(return_value_ptr_ptr));
Index: ZendEngine2/zend_default_classes.c
diff -u ZendEngine2/zend_default_classes.c:1.12 ZendEngine2/zend_default_classes.c:1.13
--- ZendEngine2/zend_default_classes.c:1.12 Sun Aug 24 07:25:08 2003
+++ ZendEngine2/zend_default_classes.c Sun Aug 24 09:10:02 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_default_classes.c,v 1.12 2003/08/24 11:25:08 helly Exp $ */
+/* $Id: zend_default_classes.c,v 1.13 2003/08/24 13:10:02 helly Exp $ */
#include "zend.h"
#include "zend_API.h"
@@ -151,6 +151,27 @@
}
EG(exception) = ex;
+}
+
+static void zend_error_va(int type, const char *file, uint lineno, const char *format, ...)
+{
+ va_list args;
+
+ va_start(args, format);
+ zend_error_cb(E_ERROR, file, lineno, format, args);
+ va_end(args);
+}
+
+ZEND_API void zend_exception_error(zval *exception TSRMLS_DC)
+{
+ if (instanceof_function(Z_OBJCE_P(exception), default_exception_ptr TSRMLS_CC)) {
+ zval *message = zend_read_property(default_exception_ptr, exception, "message",
sizeof("message")-1, 1 TSRMLS_CC);
+ zval *file = zend_read_property(default_exception_ptr, exception, "file",
sizeof("file")-1, 1 TSRMLS_CC);
+ zval *lineno = zend_read_property(default_exception_ptr, exception, "line",
sizeof("line")-1, 1 TSRMLS_CC);
+ zend_error_va(E_ERROR, Z_STRVAL_P(file), Z_LVAL_P(lineno), "Uncaught exception
'%s' with message '%s'", Z_OBJCE_P(exception)->name,
Z_STRVAL_P(message));
+ } else {
+ zend_error(E_ERROR, "Uncaught exception '%s'!",
Z_OBJCE_P(exception)->name);
+ }
}
ZEND_API void zend_register_default_classes(TSRMLS_D)
Index: ZendEngine2/zend_default_classes.h
diff -u ZendEngine2/zend_default_classes.h:1.7 ZendEngine2/zend_default_classes.h:1.8
--- ZendEngine2/zend_default_classes.h:1.7 Sat Aug 23 15:48:52 2003
+++ ZendEngine2/zend_default_classes.h Sun Aug 24 09:10:02 2003
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_default_classes.h,v 1.7 2003/08/23 19:48:52 helly Exp $ */
+/* $Id: zend_default_classes.h,v 1.8 2003/08/24 13:10:02 helly Exp $ */
#ifndef ZEND_DEFAULT_CLASSES_H
#define ZEND_DEFAULT_CLASSES_H
@@ -26,6 +26,7 @@
ZEND_API zend_class_entry *zend_exception_get_default(void);
ZEND_API void zend_throw_exception(char *message, long code TSRMLS_DC);
ZEND_API void zend_register_default_classes(TSRMLS_D);
+ZEND_API void zend_exception_error(zval *exception TSRMLS_DC);
END_EXTERN_C()
Index: ZendEngine2/zend_execute.h
diff -u ZendEngine2/zend_execute.h:1.57 ZendEngine2/zend_execute.h:1.58
--- ZendEngine2/zend_execute.h:1.57 Sun Aug 3 04:21:08 2003
+++ ZendEngine2/zend_execute.h Sun Aug 24 09:10:02 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_execute.h,v 1.57 2003/08/03 08:21:08 zeev Exp $ */
+/* $Id: zend_execute.h,v 1.58 2003/08/24 13:10:02 helly Exp $ */
#ifndef ZEND_EXECUTE_H
#define ZEND_EXECUTE_H
@@ -69,6 +69,7 @@
}
ZEND_API int zend_lookup_class(char *name, int name_length, zend_class_entry ***ce TSRMLS_DC);
ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name TSRMLS_DC);
+ZEND_API int zend_eval_string_ex(char *str, zval *retval_ptr, char *string_name, int
handle_exceptions TSRMLS_DC);
static inline int i_zend_is_true(zval *op)
{
Index: ZendEngine2/zend_execute_API.c
diff -u ZendEngine2/zend_execute_API.c:1.231 ZendEngine2/zend_execute_API.c:1.232
--- ZendEngine2/zend_execute_API.c:1.231 Thu Aug 7 03:37:19 2003
+++ ZendEngine2/zend_execute_API.c Sun Aug 24 09:10:03 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_execute_API.c,v 1.231 2003/08/07 07:37:19 zeev Exp $ */
+/* $Id: zend_execute_API.c,v 1.232 2003/08/24 13:10:03 helly Exp $ */
#include <stdio.h>
#include <signal.h>
@@ -29,6 +29,7 @@
#include "zend_ptr_stack.h"
#include "zend_constants.h"
#include "zend_extensions.h"
+#include "zend_default_classes.h"
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
@@ -857,6 +858,26 @@
}
zval_dtor(&pv);
return retval;
+}
+
+
+ZEND_API int zend_eval_string_ex(char *str, zval *retval_ptr, char *string_name, int
handle_exceptions TSRMLS_DC)
+{
+ int result;
+ zval *exception = EG(exception);
+
+
+ if (handle_exceptions) {
+ EG(exception) = NULL;
+ }
+ result = zend_eval_string(str, retval_ptr, string_name TSRMLS_CC);
+ if (handle_exceptions && EG(exception)) {
+ zend_exception_error(EG(exception) TSRMLS_CC);
+ zval_ptr_dtor(&EG(exception));
+ EG(exception) = exception;
+ result = FAILURE;
+ }
+ return result;
}