Re: [ZEND-ENGINE-CVS] cvs: ZendEngine2 / zend_default_classes.c zend_default_classes.h

From: Date: Sat, 30 Aug 2003 19:01:26 +0000
Subject: Re: [ZEND-ENGINE-CVS] cvs: ZendEngine2 / zend_default_classes.c zend_default_classes.h
References: 1  Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-1748@lists.php.net to get a copy of this message
Marcus, You shouldn't use malloc()/free() if possible during execution. I suggest you either use emalloc()/efree() or if you want to allocate on the stack then use do_alloca()/free_alloca(). Andi At 10:56 PM 8/28/2003 +0000, Marcus Boerger wrote:
helly           Thu Aug 28 18:56:41 2003 EDT
Modified files:
    /ZendEngine2        zend_default_classes.c zend_default_classes.h
Log: Add zend_throw_exception_ex() which allows to format exception messages. # # Since we don't have any portable way of printing into a dynamic buffer i # used a stack buffer of 1K (just like the error printing) and used a dynamic # buffer in case the necessary function is available. # Index: ZendEngine2/zend_default_classes.c diff -u ZendEngine2/zend_default_classes.c:1.17 ZendEngine2/zend_default_classes.c:1.18
--- ZendEngine2/zend_default_classes.c:1.17     Thu Aug 28 16:35:54 2003
+++ ZendEngine2/zend_default_classes.c Thu Aug 28 18:56:41 2003 @@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
*/ -/* $Id: zend_default_classes.c,v 1.17 2003/08/28 20:35:54 helly Exp $ */ +/* $Id: zend_default_classes.c,v 1.18 2003/08/28 22:56:41 helly Exp $ */ #include "zend.h" #include "zend_API.h" @@ -144,6 +144,53 @@
        return default_exception_ptr;
} +ZEND_API void zend_throw_exception_ex(zend_class_entry *exception_ce, long code TSRMLS_DC, char *format, ...) +{
+       zval *ex;
+       va_list arg;
+ +#ifdef _GNU_SOURCE
+       char *message;
+       va_start(arg, format);
+       vasprintf(message, format, arg);
+       va_end(arg);
+#else
+       char message[1024];
+       va_start(arg, format);
+       vsnprintf(message, sizeof(message), format, arg);
+       va_end(arg);
+#endif +
+       MAKE_STD_ZVAL(ex);
+       if (exception_ce) {
+               if (!instanceof_function(exception_ce, default_exception_ptr TSRMLS_CC)) {
+                       zend_error(E_NOTICE, "Exceptions must be derived from exception");
+                       exception_ce = default_exception_ptr;
+               }
+       } else {
+               exception_ce = default_exception_ptr;
+       }
+       object_init_ex(ex, exception_ce);
+ +
+       if (message) {
+               zend_update_property_string(exception_ce, ex, "message", sizeof("message")-1, message TSRMLS_CC);
+       }
+       if (code) {
+               zend_update_property_long(exception_ce, ex, "code", sizeof("code")-1, code TSRMLS_CC);
+       }
+ +#ifdef _GNU_SOURCE
+       free(message);
+#endif +
+       EG(exception) = ex;
+} + +/* 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;
Index: ZendEngine2/zend_default_classes.h diff -u ZendEngine2/zend_default_classes.h:1.9 ZendEngine2/zend_default_classes.h:1.10
--- ZendEngine2/zend_default_classes.h:1.9      Sun Aug 24 11:07:00 2003
+++ ZendEngine2/zend_default_classes.h Thu Aug 28 18:56:41 2003 @@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
*/ -/* $Id: zend_default_classes.h,v 1.9 2003/08/24 15:07:00 helly Exp $ */ +/* $Id: zend_default_classes.h,v 1.10 2003/08/28 22:56:41 helly Exp $ */ #ifndef ZEND_DEFAULT_CLASSES_H #define ZEND_DEFAULT_CLASSES_H @@ -30,6 +30,7 @@ /* exception_ce NULL or zend_exception_get_default() or a derived class
  * 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, ...);
/* show an exception using zend_error(E_ERROR,...) */ ZEND_API void zend_exception_error(zval *exception TSRMLS_DC); -- Zend Engine CVS Mailing List (http://cvs.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


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