cvs: ZendEngine2 / zend_default_classes.c zend_default_classes.h zend_execute.h zend_execute_API.c

From: Date: Thu, 12 Feb 2004 10:24:40 +0000
Subject: cvs: ZendEngine2 / zend_default_classes.c zend_default_classes.h zend_execute.h zend_execute_API.c
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-2364@lists.php.net to get a copy of this message
zeev Thu Feb 12 05:24:40 2004 EDT Modified files: /ZendEngine2 zend_default_classes.c zend_default_classes.h zend_execute.h zend_execute_API.c Log: Exceptions updates: - Enforce exceptions to be derived from class Exception. This allows users to perform catch-all. It's not yet complete, so don't get comfortable with it just yet :) Updates are coming soon. - Implement zend_throw_exception() using zend_throw_exception_ex() http://cvs.php.net/diff.php/ZendEngine2/zend_default_classes.c?r1=1.56&r2=1.57&ty=u Index: ZendEngine2/zend_default_classes.c diff -u ZendEngine2/zend_default_classes.c:1.56 ZendEngine2/zend_default_classes.c:1.57 --- ZendEngine2/zend_default_classes.c:1.56 Tue Feb 10 11:08:01 2004 +++ ZendEngine2/zend_default_classes.c Thu Feb 12 05:24:40 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_default_classes.c,v 1.56 2004/02/10 16:08:01 zeev Exp $ */ +/* $Id: zend_default_classes.c,v 1.57 2004/02/12 10:24:40 zeev Exp $ */ #include "zend.h" #include "zend_API.h" @@ -25,7 +25,7 @@ #include "zend_builtin_functions.h" #include "zend_interfaces.h" -static zend_class_entry *default_exception_ce; +zend_class_entry *default_exception_ce; static zend_object_handlers default_exception_handlers; ZEND_API void zend_throw_exception(zend_class_entry *exception_ce, char *message, long code TSRMLS_DC); @@ -452,36 +452,13 @@ zend_throw_exception_internal(ex TSRMLS_CC); } -/* at the moment we can't use zend_throw_exception_ex because we don't have a protable - * vsnprintf that tells us the number of characters needed nor do we have spprintf from - * php or asprintf from glibc always. - */ + ZEND_API void zend_throw_exception(zend_class_entry *exception_ce, char *message, long code TSRMLS_DC) { - zval *ex; - - MAKE_STD_ZVAL(ex); - if (exception_ce) { - if (!instanceof_function(exception_ce, default_exception_ce TSRMLS_CC)) { - zend_error(E_NOTICE, "Exceptions must be derived from exception"); - exception_ce = default_exception_ce; - } - } else { - exception_ce = default_exception_ce; - } - object_init_ex(ex, exception_ce); - - - if (message) { - zend_update_property_string(default_exception_ce, ex, "message", sizeof("message")-1, message TSRMLS_CC); - } - if (code) { - zend_update_property_long(default_exception_ce, ex, "code", sizeof("code")-1, code TSRMLS_CC); - } - - zend_throw_exception_internal(ex TSRMLS_CC); + zend_throw_exception_ex(exception_ce, code TSRMLS_CC, "%s", message); } + static void zend_error_va(int type, const char *file, uint lineno, const char *format, ...) { va_list args; @@ -534,6 +511,24 @@ } } + +ZEND_API void zend_throw_exception_object(zval *exception TSRMLS_DC) +{ + zend_class_entry *exception_ce; + + if (exception == NULL || exception->type != IS_OBJECT) { + zend_error(E_ERROR, "Need to supply an object when throwing an exception"); + } + + exception_ce = Z_OBJCE_P(exception); + + if (!exception_ce || !instanceof_function(exception_ce, default_exception_ce TSRMLS_CC)) { + zend_error(E_ERROR, "Exceptions must valid objects that are derived from class Exception"); + } + zend_throw_exception_internal(exception TSRMLS_CC); +} + + ZEND_API void zend_register_default_classes(TSRMLS_D) { zend_register_interfaces(TSRMLS_C); http://cvs.php.net/diff.php/ZendEngine2/zend_default_classes.h?r1=1.13&r2=1.14&ty=u Index: ZendEngine2/zend_default_classes.h diff -u ZendEngine2/zend_default_classes.h:1.13 ZendEngine2/zend_default_classes.h:1.14 --- ZendEngine2/zend_default_classes.h:1.13 Thu Jan 8 12:31:47 2004 +++ ZendEngine2/zend_default_classes.h Thu Feb 12 05:24:40 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_default_classes.h,v 1.13 2004/01/08 17:31:47 sniper Exp $ */ +/* $Id: zend_default_classes.h,v 1.14 2004/02/12 10:24:40 zeev Exp $ */ #ifndef ZEND_DEFAULT_CLASSES_H #define ZEND_DEFAULT_CLASSES_H @@ -31,6 +31,7 @@ * message NULL or the message of the exception */ ZEND_API void zend_throw_exception(zend_class_entry *exception_ce, char *message, long code TSRMLS_DC); ZEND_API void zend_throw_exception_ex(zend_class_entry *exception_ce, long code TSRMLS_DC, char *format, ...); +ZEND_API void zend_throw_exception_object(zval *exception TSRMLS_DC); /* show an exception using zend_error(E_ERROR,...) */ ZEND_API void zend_exception_error(zval *exception TSRMLS_DC); http://cvs.php.net/diff.php/ZendEngine2/zend_execute.h?r1=1.66&r2=1.67&ty=u Index: ZendEngine2/zend_execute.h diff -u ZendEngine2/zend_execute.h:1.66 ZendEngine2/zend_execute.h:1.67 --- ZendEngine2/zend_execute.h:1.66 Thu Feb 12 04:50:08 2004 +++ ZendEngine2/zend_execute.h Thu Feb 12 05:24:40 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute.h,v 1.66 2004/02/12 09:50:08 andi Exp $ */ +/* $Id: zend_execute.h,v 1.67 2004/02/12 10:24:40 zeev Exp $ */ #ifndef ZEND_EXECUTE_H #define ZEND_EXECUTE_H @@ -65,8 +65,6 @@ 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); -ZEND_API void zend_throw_exception_object(zval *exception TSRMLS_DC); - static inline int i_zend_is_true(zval *op) { int result; http://cvs.php.net/diff.php/ZendEngine2/zend_execute_API.c?r1=1.268&r2=1.269&ty=u Index: ZendEngine2/zend_execute_API.c diff -u ZendEngine2/zend_execute_API.c:1.268 ZendEngine2/zend_execute_API.c:1.269 --- ZendEngine2/zend_execute_API.c:1.268 Thu Feb 12 04:50:08 2004 +++ ZendEngine2/zend_execute_API.c Thu Feb 12 05:24:40 2004 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute_API.c,v 1.268 2004/02/12 09:50:08 andi Exp $ */ +/* $Id: zend_execute_API.c,v 1.269 2004/02/12 10:24:40 zeev Exp $ */ #include <stdio.h> #include <signal.h> @@ -1221,13 +1221,6 @@ EG(current_execute_data)->opline = &EG(active_op_array)->opcodes[EG(active_op_array)->last-1-1]; } -ZEND_API void zend_throw_exception_object(zval *exception TSRMLS_DC) -{ - if (exception == NULL) { - zend_error(E_ERROR, "Need to supply object when throwing exception"); - } - zend_throw_exception_internal(exception TSRMLS_CC); -}

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