Index: engine/builtins.c =================================================================== --- engine/builtins.c (revision 75605) +++ engine/builtins.c (working copy) @@ -2114,9 +2114,12 @@ PyObject * bjam_backtrace( PyObject * self, PyObject * args ) { PyObject * result = PyList_New( 0 ); - struct frame * f = frame_before_python_call; + struct frame * f = frame_before_python_call(); + + if ( f ) + f = f->prev - for ( ; f = f->prev; ) + for ( ; f; f = f->prev ) { PyObject * tuple = PyTuple_New( 4 ); char * file; @@ -2140,9 +2143,10 @@ PyObject * bjam_caller( PyObject * self, PyObject * args ) { - if ( !frame_before_python_call ) + struct frame * f = frame_before_python_call(); + if ( !f ) Py_RETURN_NONE; - return PyString_FromString(frame_before_python_call->prev->module->name); + return PyString_FromString(f->prev->module->name); } #endif /* #ifdef HAVE_PYTHON */ Index: engine/compile.c =================================================================== --- engine/compile.c (revision 75605) +++ engine/compile.c (working copy) @@ -93,8 +93,28 @@ void backtrace_line( FRAME *frame ); void print_source_line( PARSE* p ); -struct frame * frame_before_python_call; +#define MAX_FRAME_STACK_DEPTH 20 +static struct frame * frame_stack[ MAX_FRAME_STACK_DEPTH ]; +static unsigned int frame_depth; +static push_frame( struct frame * param ) +{ + assert( frame_depth < MAX_FRAME_STACK_DEPTH ); + frame_stack[ frame_depth ] = param; + frame_depth++; +} + +static pop_frame() +{ + assert( frame_depth > 0 ); + frame_depth--; +} + +struct frame * frame_before_python_call() +{ + return frame_depth > 0 ? frame_stack[ frame_depth - 1 ] : 0; +} + void frame_init( FRAME* frame ) { frame->prev = 0; @@ -863,9 +883,9 @@ } } - frame_before_python_call = frame; + push_frame( frame ); py_result = PyObject_Call( r->python_function, arguments, kw ); - frame_before_python_call = NULL; + pop_frame(); Py_DECREF(arguments); Py_XDECREF(kw); if ( py_result != NULL ) Index: engine/frames.h =================================================================== --- engine/frames.h (revision 75605) +++ engine/frames.h (working copy) @@ -29,7 +29,7 @@ * is not defined. Further, if Jam calls Python which calls Jam and so on, this * variable only keeps the most recent Jam frame. */ -extern struct frame * frame_before_python_call; +struct frame * frame_before_python_call(); void frame_init( FRAME * ); /* implemented in compile.c */ void frame_free( FRAME * ); /* implemented in compile.c */