From 44d53c448beb650610af6335b1352b2307e4c0d4 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Sat, 17 Mar 2007 20:17:56 +0000 Subject: [PATCH] libs/python/build/Jamfile.v2: remove needless property. libs/python/test/Jamfile.v2: * add dynamically-linked embedding test * fix builtin_converters test so it can work (BBv1 allowed the duplication of main target names; BBv2 does not) libs/python/test/import_.cpp: move some more of the Python code within a handle_exception callback so at least we can better diagnose failures. [SVN r37214] --- build/Jamfile.v2 | 3 +-- test/Jamfile.v2 | 24 ++++++++++++------------ test/import_.cpp | 31 ++++++++++++++++--------------- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index 1e2f677c..62184f83 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -66,8 +66,7 @@ lib boost_python : # default build shared : # usage requirements - static:BOOST_PYTHON_STATIC_LIB - shared:BOOST_PYTHON_DYNAMIC_LIB + static:BOOST_PYTHON_STATIC_LIB ; } else diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 51f59b63..5e9fba82 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -27,23 +27,23 @@ rule py-compile-fail ( sources * ) } - -#template py-unit-test -# : -# : $(PYTHON_PROPERTIES) BOOST_PYTHON_SUPPRESS_REGISTRY_INITIALIZATION -# [ difference $(PYTHON_PROPERTIES) : BOOST_PYTHON_DYNAMIC_LIB ] BOOST_PYTHON_STATIC_LIB -# ; - - test-suite python : [ run exec.cpp ../build//boost_python/static /python//python + : # program args + : exec.py # input files + : # requirements + : # target-name + ] + + [ + run exec.cpp ../build//boost_python/shared /python//python : # program args : exec.py : # requirements - BOOST_PYTHON_STATIC_MODULE + : exec-dynamic # target-name ] [ @@ -77,8 +77,8 @@ bpl-test crossmod_exception [ bpl-test keywords : keywords.cpp keywords_test.py ] -[ python-extension builtin_converters.ext : test_builtin_converters.cpp /boost/python//boost_python ] -[ bpl-test builtin_converters : test_builtin_converters.py builtin_converters.ext ] +[ python-extension builtin_converters_ext : test_builtin_converters.cpp /boost/python//boost_python ] +[ bpl-test builtin_converters : test_builtin_converters.py builtin_converters_ext ] [ bpl-test test_pointer_adoption ] [ bpl-test operators ] @@ -144,7 +144,7 @@ bpl-test crossmod_opaque # Whenever the cause for the failure of the polymorphism test is found # and fixed, this should be retested. hp_cxx:no ] - + [ python-extension map_indexing_suite_ext : map_indexing_suite.cpp int_map_indexing_suite.cpp /boost/python//boost_python ] diff --git a/test/import_.cpp b/test/import_.cpp index f50a0089..127dbb4f 100644 --- a/test/import_.cpp +++ b/test/import_.cpp @@ -4,15 +4,28 @@ // http://www.boost.org/LICENSE_1_0.txt) #include - +#include #include #include #include namespace bpl = boost::python; -void import_test() +void import_test( char** argv ) { + // Retrieve the main module + bpl::object main = bpl::import("__main__"); + + // Retrieve the main module's namespace + bpl::object global(main.attr("__dict__")); + + // Inject search path for import_ module + std::ostringstream script; + script << "import sys, os\n" + << "path = os.path.dirname('" << argv[1] << "')\n" + << "sys.path.insert(0, path)\n"; + bpl::exec(bpl::str(script.str()), global, global); + // Retrieve the main module bpl::object import_ = bpl::import("import_"); int value = bpl::extract(import_.attr("value")) BOOST_EXTRACT_WORKAROUND; @@ -27,19 +40,7 @@ int main(int argc, char **argv) // Initialize the interpreter Py_Initialize(); - // Retrieve the main module - bpl::object main = bpl::import("__main__"); - - // Retrieve the main module's namespace - bpl::object global(main.attr("__dict__")); - - // Inject search path for import_ module - std::ostringstream script; - script << "import sys, os.path\n" - << "path = os.path.dirname('" << argv[1] << "')\n" - << "sys.path.insert(0, path)\n"; - bpl::object result = bpl::exec(bpl::str(script.str()), global, global); - if (bpl::handle_exception(import_test)) + if (bpl::handle_exception(boost::bind(import_test, argv))) { if (PyErr_Occurred()) {