cvs: ZendEngine2 / zend_exceptions.c zend_exceptions.h

From: Date: Sun, 13 Jul 2008 21:35:23 +0000
Subject: cvs: ZendEngine2 / zend_exceptions.c zend_exceptions.h
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-6884@lists.php.net to get a copy of this message
helly Sun Jul 13 21:35:23 2008 UTC Modified files: /ZendEngine2 zend_exceptions.c zend_exceptions.h Log: - Fix setting previous exception and add new helper function http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_exceptions.c?r1=1.121&r2=1.122&diff_format=u Index: ZendEngine2/zend_exceptions.c diff -u ZendEngine2/zend_exceptions.c:1.121 ZendEngine2/zend_exceptions.c:1.122 --- ZendEngine2/zend_exceptions.c:1.121 Sat Jul 12 14:56:51 2008 +++ ZendEngine2/zend_exceptions.c Sun Jul 13 21:35:23 2008 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_exceptions.c,v 1.121 2008/07/12 14:56:51 helly Exp $ */ +/* $Id: zend_exceptions.c,v 1.122 2008/07/13 21:35:23 helly Exp $ */ #include "zend.h" #include "zend_API.h" @@ -33,13 +33,37 @@ static zend_object_handlers default_exception_handlers; ZEND_API void (*zend_throw_exception_hook)(zval *ex TSRMLS_DC); +void zend_exception_set_previous(zval *add_previous TSRMLS_DC) +{ + zval *exception = EG(exception), *previous; + + if (exception == add_previous || !add_previous) { + return; + } + if (Z_TYPE_P(add_previous) != IS_OBJECT && !instanceof_function(Z_OBJCE_P(add_previous), default_exception_ce TSRMLS_CC)) { + zend_error(E_ERROR, "Cannot set non exception as previous exception"); + return; + } + if (!exception) { + EG(exception) = add_previous; + return; + } + while (exception && exception != add_previous && Z_OBJ_HANDLE_P(exception) != Z_OBJ_HANDLE_P(add_previous)) { + previous = zend_read_property(default_exception_ce, exception, "previous", sizeof("previous")-1, 1 TSRMLS_CC); + if (Z_TYPE_P(previous) == IS_NULL) { + zend_update_property(default_exception_ce, exception, "previous", sizeof("previous")-1, add_previous TSRMLS_CC); + return; + } + exception = previous; + } +} + void zend_throw_exception_internal(zval *exception TSRMLS_DC) /* {{{ */ { if (exception != NULL) { - if (EG(exception)) { - zend_update_property(default_exception_ce, exception, "previous", sizeof("previous")-1, EG(exception) TSRMLS_CC); - } + zval *previous = EG(exception); EG(exception) = exception; + zend_exception_set_previous(previous TSRMLS_CC); } if (!EG(current_execute_data)) { zend_error(E_ERROR, "Exception thrown without a stack frame"); @@ -130,8 +154,8 @@ int argc = ZEND_NUM_ARGS(), message_len; zend_uchar message_type; - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, "|tlO", &message, &message_len, &message_type, &code, &previous, default_exception_ce) == FAILURE) { - zend_error(E_ERROR, "Wrong parameters for Exception([string $exception [, long $code ]])"); + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, "|tlO!", &message, &message_len, &message_type, &code, &previous, default_exception_ce) == FAILURE) { + zend_error(E_ERROR, "Wrong parameters for Exception([string $exception [, long $code [, Exception $previous = NULL]]])"); } object = getThis(); @@ -164,8 +188,8 @@ int argc = ZEND_NUM_ARGS(), message_len, filename_len; zend_uchar message_type, file_type; - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, "|tlltlO", &message, &message_len, &message_type, &code, &severity, &filename, &filename_len, &file_type, &lineno, &previous, default_exception_ce) == FAILURE) { - zend_error(E_ERROR, "Wrong parameters for ErrorException([string $exception [, long $code, [ long $severity, [ string $filename, [ long $lineno ]]]]])"); + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, "|tlltlO!", &message, &message_len, &message_type, &code, &severity, &filename, &filename_len, &file_type, &lineno, &previous, default_exception_ce) == FAILURE) { + zend_error(E_ERROR, "Wrong parameters for ErrorException([string $exception [, long $code, [ long $severity, [ string $filename, [ long $lineno [, Exception $previous = NULL]]]]]])"); } object = getThis(); @@ -317,7 +341,7 @@ #define TRACE_APPEND_STR(val) \ TRACE_APPEND_STRL(val, sizeof(val)-1) -#define TRACE_APPEND_KEY(key,dump) \ +#define TRACE_APPEND_KEY(key) \ if (zend_ascii_hash_find(ht, key, sizeof(key), (void**)&tmp) == SUCCESS) { \ TRACE_APPEND_ZVAL(*tmp); \ } @@ -493,9 +517,9 @@ } else { TRACE_APPEND_STR("[internal function]: "); } - TRACE_APPEND_KEY("class",0); - TRACE_APPEND_KEY("type",0); - TRACE_APPEND_KEY("function",1); + TRACE_APPEND_KEY("class"); + TRACE_APPEND_KEY("type"); + TRACE_APPEND_KEY("function"); TRACE_APPEND_CHR('('); if (zend_ascii_hash_find(ht, "args", sizeof("args"), (void**)&tmp) == SUCCESS) { int last_len = *len; http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_exceptions.h?r1=1.29&r2=1.30&diff_format=u Index: ZendEngine2/zend_exceptions.h diff -u ZendEngine2/zend_exceptions.h:1.29 ZendEngine2/zend_exceptions.h:1.30 --- ZendEngine2/zend_exceptions.h:1.29 Mon Dec 31 07:12:06 2007 +++ ZendEngine2/zend_exceptions.h Sun Jul 13 21:35:23 2008 @@ -19,13 +19,15 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_exceptions.h,v 1.29 2007/12/31 07:12:06 sebastian Exp $ */ +/* $Id: zend_exceptions.h,v 1.30 2008/07/13 21:35:23 helly Exp $ */ #ifndef ZEND_EXCEPTIONS_H #define ZEND_EXCEPTIONS_H BEGIN_EXTERN_C() +ZEND_API void zend_exception_set_previous(zval *add_previous TSRMLS_DC); + void zend_throw_exception_internal(zval *exception TSRMLS_DC); void zend_register_default_exception(TSRMLS_D);

« previous php.zend-engine.cvs (#6884) next »