Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:2075 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 31793 invoked from network); 28 May 2003 23:43:38 -0000 Received: from unknown (HELO united.lan.codewhore.org) (24.95.48.170) by pb1.pair.com with SMTP; 28 May 2003 23:43:38 -0000 Received: from dave by united.lan.codewhore.org with local (Exim 3.16 #1) id 19LAMO-0001DT-00 for internals@lists.php.net; Wed, 28 May 2003 19:29:32 -0400 Date: Wed, 28 May 2003 19:29:32 -0400 To: PHP Developers List Message-ID: <20030528232932.GA4500@codewhore.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i Sender: David Brown Subject: [PATCH (resend)] Add an optional size limit to debug_backtrace From: dave@codewhore.org (David Brown) Hi: Attached is a patch that adds an optional 'limit' parameter to debug_backtrace, which limits the size of the returned array. In cases where a script wants debug information only for the current function, or for the function levels above that, we can save a lot of unnecessary call-stack traversal and zval allocation by bailing out early. For a sufficiently large call depth and a small , I'd expect this to improve performance quite a bit. The patch adds a total of six lines to the function, and one test in the main loop for the zero-argument case. Should apply cleanly to both PHP_4_3 and HEAD. Is there any chance this could be applied? :) Thanks in advance, - Dave dave@codewhore.org --- Zend/zend_builtin_functions.c~ 2003-05-20 11:33:36.000000000 -0400 +++ Zend/zend_builtin_functions.c 2003-05-20 15:31:09.000000000 -0400 @@ -1173,7 +1173,7 @@ return arg_array; } -/* {{{ proto void debug_backtrace(void) +/* {{{ proto void debug_backtrace([int limit]) Prints out a backtrace */ ZEND_FUNCTION(debug_backtrace) { @@ -1189,11 +1189,21 @@ void **args = cur_arg_pos; int arg_stack_consistent = 0; int frames_on_stack = 0; + zval **limit_zval = NULL; + long limit; - if (ZEND_NUM_ARGS()) { + if (ZEND_NUM_ARGS() > 1) { ZEND_WRONG_PARAM_COUNT(); } + if (ZEND_NUM_ARGS() == 1 && zend_get_parameters_ex(1, &limit_zval) == SUCCESS) { + convert_to_long_ex(limit_zval); + if ((limit = (*limit_zval)->value.lval) <= 0) { + zend_error(E_WARNING, "Limit must be a non-zero positive integer"); + return; + } + } + while (--args >= EG(argument_stack).elements) { if (*args--) { break; @@ -1217,6 +1227,9 @@ array_init(return_value); while (ptr) { + if (limit_zval && --limit < 0) + break; + MAKE_STD_ZVAL(stack_frame); array_init(stack_frame);