Commit:    d8f8e98d8e0493adf1fae622595bd3435bdbf835
Author:    Xinchen Hui <larue...@gmail.com>         Sat, 24 Mar 2012 19:38:40 
+0800
Parents:   aa7cdcd13daca902a2b6995ff2e02acc57152cb3
Branches:  master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=d8f8e98d8e0493adf1fae622595bd3435bdbf835

Log:
Improve set_exception_handler while doing reset

Changed paths:
  M  NEWS
  M  Zend/zend_builtin_functions.c


Diff:
d8f8e98d8e0493adf1fae622595bd3435bdbf835
diff --git a/NEWS b/NEWS
index b945eff..9f1d520 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ PHP                                                             
           NEWS
 - General improvements:
   . Drop Windows XP and 2003 support. (Pierre)
   . World domination
+  . Improve set_exception_handler while doing reset.(Laruence)
 
 - cURL:
   . Added support for CURLOPT_FTP_RESPONSE_TIMEOUT, CURLOPT_APPEND, 
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index eab98ed..29f9ed3 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -1585,41 +1585,42 @@ ZEND_FUNCTION(set_exception_handler)
 {
        zval *exception_handler;
        char *exception_handler_name = NULL;
-       zend_bool had_orig_exception_handler=0;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", 
&exception_handler) == FAILURE) {
                return;
        }
 
        if (Z_TYPE_P(exception_handler) != IS_NULL) { /* NULL == unset */
+               zend_bool had_orig_exception_handler = 0;
+
                if (!zend_is_callable(exception_handler, 0, 
&exception_handler_name TSRMLS_CC)) {
                        zend_error(E_WARNING, "%s() expects the argument (%s) 
to be a valid callback",
-                                          get_active_function_name(TSRMLS_C), 
exception_handler_name?exception_handler_name:"unknown");
+                                       get_active_function_name(TSRMLS_C), 
exception_handler_name?exception_handler_name:"unknown");
                        efree(exception_handler_name);
                        return;
                }
                efree(exception_handler_name);
-       }
 
-       if (EG(user_exception_handler)) {
-               had_orig_exception_handler = 1;
-               *return_value = *EG(user_exception_handler);
-               zval_copy_ctor(return_value);
-               zend_ptr_stack_push(&EG(user_exception_handlers), 
EG(user_exception_handler));
-       }
-       ALLOC_ZVAL(EG(user_exception_handler));
+               if (EG(user_exception_handler)) {
+                       had_orig_exception_handler = 1;
+                       *return_value = *EG(user_exception_handler);
+                       zval_copy_ctor(return_value);
+                       zend_ptr_stack_push(&EG(user_exception_handlers), 
EG(user_exception_handler));
+               }
+
+               ALLOC_ZVAL(EG(user_exception_handler));
+               MAKE_COPY_ZVAL(&exception_handler, EG(user_exception_handler));
 
-       if (Z_TYPE_P(exception_handler) == IS_NULL) { /* unset user-defined 
handler */
-               FREE_ZVAL(EG(user_exception_handler));
+               if (!had_orig_exception_handler) {
+                       RETURN_NULL();
+               }
+       } else {
+               if (EG(user_exception_handler)) {
+                       zend_ptr_stack_push(&EG(user_exception_handlers), 
EG(user_exception_handler));
+               }
                EG(user_exception_handler) = NULL;
                RETURN_TRUE;
        }
-
-       MAKE_COPY_ZVAL(&exception_handler, EG(user_exception_handler))
-
-       if (!had_orig_exception_handler) {
-               RETURN_NULL();
-       }
 }
 /* }}} */


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to