Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:21461 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 6850 invoked by uid 1010); 10 Jan 2006 13:43:04 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 6834 invoked from network); 10 Jan 2006 13:43:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Jan 2006 13:43:04 -0000 X-Host-Fingerprint: 80.74.107.235 mail.zend.com Linux 2.5 (sometimes 2.4) (4) Received: from ([80.74.107.235:22006] helo=mail.zend.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id CB/91-32252-5E9B3C34 for ; Tue, 10 Jan 2006 08:43:02 -0500 Received: (qmail 3453 invoked from network); 10 Jan 2006 13:42:57 -0000 Received: from internal.zend.office (HELO ?127.0.0.1?) (10.1.1.1) by internal.zend.office with SMTP; 10 Jan 2006 13:42:57 -0000 Message-ID: <43C3B9E0.9010502@zend.com> Date: Tue, 10 Jan 2006 16:42:56 +0300 User-Agent: Thunderbird 1.5 (X11/20051025) MIME-Version: 1.0 To: php-dev Content-Type: multipart/mixed; boundary="------------060906060003060000040803" Subject: Exception::fillException() proposal From: antony@zend.com (Antony Dovgal) --------------060906060003060000040803 Content-Type: text/plain; charset=KOI8-R; format=flowed Content-Transfer-Encoding: 7bit Hello all. I'd like to propose addition of a new method of standard Exception class. This method is somewhat identical to Java's fillInStackTrace() [0], but fills not only the "trace", but also "line" and "file" properties. See #33407 [1], this report explains how this method can be used. Short example: Exception::fillException() (the name is still under question) returns new exception object that can be used this way: fillException(); } ?> In the code above "line", "file" and "trace" properties will point at the file/line where fillException() is called, not the file/line where $e was constructed. All the other properties of $e are copied, so they remain untouched. See diff against HEAD in attachment. [0] http://java.sun.com/j2se/1.3/docs/api/java/lang/Throwable.html#fillInStackTrace() [1] http://bugs.php.net/bug.php?id=33407 -- Wbr, Antony Dovgal --------------060906060003060000040803 Content-Type: text/plain; name="fillException.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="fillException.diff" Index: Zend/zend_exceptions.c =================================================================== RCS file: /repository/ZendEngine2/zend_exceptions.c,v retrieving revision 1.94 diff -u -p -d -r1.94 zend_exceptions.c --- Zend/zend_exceptions.c 4 Jan 2006 23:52:06 -0000 1.94 +++ Zend/zend_exceptions.c 10 Jan 2006 13:24:57 -0000 @@ -294,6 +294,37 @@ ZEND_METHOD(error_exception, getSeverity } /* }}} */ +/* {{{ proto int ErrorException::fillException() + Fill in exception properties */ +ZEND_METHOD(exception, fillException) +{ + zval *exception = getThis(); + zval *trace, tmp; + zend_object *object; + + DEFAULT_0_PARAMS; + + INIT_PZVAL(return_value); + Z_TYPE_P(return_value) = IS_OBJECT; + Z_OBJVAL_P(return_value) = zend_objects_new(&object, Z_OBJCE_P(exception) TSRMLS_CC); + Z_OBJ_HT_P(return_value) = Z_OBJ_HT_P(exception); + + ALLOC_HASHTABLE(object->properties); + zend_u_hash_init(object->properties, 0, NULL, ZVAL_PTR_DTOR, 0, UG(unicode)); + zend_hash_copy(object->properties, Z_OBJPROP_P(exception), (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); + + ALLOC_ZVAL(trace); + trace->is_ref = 0; + trace->refcount = 0; + + zend_fetch_debug_backtrace(trace, 0, 0 TSRMLS_CC); + + zend_update_property(Z_OBJCE_P(exception), return_value, "trace", sizeof("trace")-1, trace TSRMLS_CC); + zend_update_property_rt_string(Z_OBJCE_P(exception), return_value, "file", sizeof("file")-1, zend_get_executed_filename(TSRMLS_C) TSRMLS_CC); + zend_update_property_long(Z_OBJCE_P(exception), return_value, "line", sizeof("line")-1, zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC); +} +/* }}} */ + /* {{{ ZEND_METHOD(exception, gettraceasstring) */ #define TRACE_APPEND_CHR(chr) \ *str = (char*)erealloc(*str, *len + 1 + 1); \ @@ -604,6 +635,7 @@ static zend_function_entry default_excep ZEND_ME(exception, getTrace, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(exception, getTraceAsString, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(exception, __toString, NULL, 0) + ZEND_ME(exception, fillException, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) {NULL, NULL, NULL} }; --------------060906060003060000040803--