Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:1821 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60793 invoked from network); 20 May 2003 19:47:14 -0000 Received: from unknown (HELO united.lan.codewhore.org) (24.95.48.170) by pb1.pair.com with SMTP; 20 May 2003 19:47:14 -0000 Received: from dave by united.lan.codewhore.org with local (Exim 3.16 #1) id 19ICsE-00083p-00 for internals@lists.php.net; Tue, 20 May 2003 15:34:10 -0400 Date: Tue, 20 May 2003 15:34:10 -0400 To: PHP Internals List Message-ID: <20030520193410.GA24309@codewhore.org> References: <20030520175903.GA24201@codewhore.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030520175903.GA24201@codewhore.org> User-Agent: Mutt/1.4i Sender: David Brown Subject: Re: [PHP-DEV] [PATCH] Add an optional size limit to debug_backtrace From: dave@codewhore.org (David Brown) On Tue, May 20, 2003 at 01:59:03PM -0400, David Brown wrote: | Hi: | Or, so as to not turn this into the Integer Overflow and Crappy C Competition (IOCCC ), perhaps this instead: --- 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); Thanks, - Dave dave@codewhore.org