From 52eb370501c3d899166462dd67437ff3b655d9a0 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Tue, 22 Nov 2011 11:20:42 +0000 Subject: [PATCH] Fix a crash when using bjam.caller. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch from Juraj Ivančić [SVN r75605] --- src/build/toolset.py | 4 ++-- src/engine/builtins.c | 6 +++--- src/engine/compile.c | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/build/toolset.py b/src/build/toolset.py index d7b121a2a..84fa767f0 100644 --- a/src/build/toolset.py +++ b/src/build/toolset.py @@ -117,8 +117,8 @@ def flags(rule_or_module, variable_name, condition, values = []): is specified, then the value of 'feature' will be added. """ - caller = bjam.caller()[:-1] - if not '.' in rule_or_module and caller.startswith("Jamfile"): + caller = bjam.caller() + if not '.' in rule_or_module and caller and caller[:-1].startswith("Jamfile"): # Unqualified rule name, used inside Jamfile. Most likely used with # 'make' or 'notfile' rules. This prevents setting flags on the entire # Jamfile module (this will be considered as rule), but who cares? diff --git a/src/engine/builtins.c b/src/engine/builtins.c index dc723e19b..449823973 100644 --- a/src/engine/builtins.c +++ b/src/engine/builtins.c @@ -2140,9 +2140,9 @@ PyObject * bjam_backtrace( PyObject * self, PyObject * args ) PyObject * bjam_caller( PyObject * self, PyObject * args ) { - PyObject *result = PyString_FromString( - frame_before_python_call->prev->module->name); - return result; + if ( !frame_before_python_call ) + Py_RETURN_NONE; + return PyString_FromString(frame_before_python_call->prev->module->name); } #endif /* #ifdef HAVE_PYTHON */ diff --git a/src/engine/compile.c b/src/engine/compile.c index 04783f1c8..dd8c7f22d 100644 --- a/src/engine/compile.c +++ b/src/engine/compile.c @@ -865,6 +865,7 @@ call_python_function(RULE* r, FRAME* frame) frame_before_python_call = frame; py_result = PyObject_Call( r->python_function, arguments, kw ); + frame_before_python_call = NULL; Py_DECREF(arguments); Py_XDECREF(kw); if ( py_result != NULL )