[PATCH] Add an optional size limit to debug_backtrace

From: Date: Tue, 20 May 2003 17:59:03 +0000
Subject: [PATCH] Add an optional size limit to debug_backtrace
Groups: php.internals 
Request: Send a blank email to internals+get-1812@lists.php.net to get a copy of this message
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 <n> 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 <n>, 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 13:34:40.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,18 @@ 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); + limit = (*limit_zval)->value.lval; + } + while (--args >= EG(argument_stack).elements) { if (*args--) { break; @@ -1217,6 +1224,9 @@ array_init(return_value); while (ptr) { + if (limit_zval && --limit < 0) + break; + MAKE_STD_ZVAL(stack_frame); array_init(stack_frame);

« previous php.internals (#1812) next »