On Tue, May 20, 2003 at 01:59:03PM -0400, David Brown wrote:
| Hi:
| <patch>
Or, so as to not turn this into the Integer Overflow and Crappy C
Competition (IOCCC <grin>), 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