mirror of
https://github.com/boostorg/build.git
synced 2026-02-16 01:12:13 +00:00
New Python rule -- 'backtrace'.
[SVN r40497]
This commit is contained in:
@@ -1775,6 +1775,32 @@ bjam_variable(PyObject* self, PyObject* args)
|
||||
return result;
|
||||
}
|
||||
|
||||
PyObject*
|
||||
bjam_backtrace(PyObject* self, PyObject *args)
|
||||
{
|
||||
PyObject *result = PyList_New(0);
|
||||
struct frame *f = frame_before_python_call;
|
||||
|
||||
for(; f = f->prev;)
|
||||
{
|
||||
PyObject *tuple = PyTuple_New(4);
|
||||
char* file;
|
||||
int line;
|
||||
char buf[32];
|
||||
get_source_line( f->procedure, &file, &line );
|
||||
sprintf( buf, "%d", line );
|
||||
|
||||
/* PyTuple_SetItem steals reference. */
|
||||
PyTuple_SetItem(tuple, 0, PyString_FromString(file));
|
||||
PyTuple_SetItem(tuple, 1, PyString_FromString(buf));
|
||||
PyTuple_SetItem(tuple, 2, PyString_FromString(f->module->name));
|
||||
PyTuple_SetItem(tuple, 3, PyString_FromString(f->rulename));
|
||||
|
||||
PyList_Append(result, tuple);
|
||||
Py_DECREF(tuple);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -94,6 +94,8 @@ void backtrace_line( FRAME *frame );
|
||||
void print_source_line( PARSE* p );
|
||||
|
||||
|
||||
struct frame *frame_before_python_call;
|
||||
|
||||
void frame_init( FRAME* frame )
|
||||
{
|
||||
frame->prev = 0;
|
||||
@@ -827,6 +829,7 @@ call_python_function(RULE* r, FRAME* frame)
|
||||
PyTuple_SetItem(arguments, i, arg);
|
||||
}
|
||||
|
||||
frame_before_python_call = frame;
|
||||
py_result = PyObject_CallObject(r->python_function, arguments);
|
||||
Py_DECREF(arguments);
|
||||
if (py_result != NULL) {
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
# include "frames.h"
|
||||
# include "lists.h"
|
||||
|
||||
|
||||
void frame_init( FRAME* frame )
|
||||
{
|
||||
frame->prev = 0;
|
||||
|
||||
@@ -24,6 +24,14 @@ struct frame
|
||||
char* rulename;
|
||||
};
|
||||
|
||||
/* When call into Python is in progress, this
|
||||
variable points to the bjam frame that
|
||||
was current at the moment of call. When the call
|
||||
completes, the variable 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;
|
||||
|
||||
void frame_init( FRAME* ); /* implemented in compile.c */
|
||||
void frame_free( FRAME* ); /* implemented in compile.c */
|
||||
|
||||
|
||||
@@ -212,6 +212,9 @@ static void run_unit_tests()
|
||||
|
||||
extern PyObject*
|
||||
bjam_variable(PyObject* self, PyObject* args);
|
||||
|
||||
extern PyObject*
|
||||
bjam_backtrace(PyObject* self, PyObject *args);
|
||||
#endif
|
||||
|
||||
int main( int argc, char **argv, char **arg_environ )
|
||||
@@ -349,6 +352,8 @@ int main( int argc, char **argv, char **arg_environ )
|
||||
"Defines a command line action."},
|
||||
{"variable", bjam_variable, METH_VARARGS,
|
||||
"Obtains a variable from bjam's global module."},
|
||||
{"backtrace", bjam_backtrace, METH_VARARGS,
|
||||
"Returns bjam backtrace from the last call into Python."},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user