Skip to content

Commit 44d53c4

Browse files
committed
libs/python/build/Jamfile.v2: remove needless <define> 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]
1 parent e61401d commit 44d53c4

3 files changed

Lines changed: 29 additions & 29 deletions

File tree

build/Jamfile.v2

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ lib boost_python
6666
: # default build
6767
<link>shared
6868
: # usage requirements
69-
<link>static:<define>BOOST_PYTHON_STATIC_LIB
70-
<link>shared:<define>BOOST_PYTHON_DYNAMIC_LIB
69+
<link>static:<define>BOOST_PYTHON_STATIC_LIB
7170
;
7271
}
7372
else

test/Jamfile.v2

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ rule py-compile-fail ( sources * )
2727
}
2828

2929

30-
31-
#template py-unit-test
32-
# :
33-
# : $(PYTHON_PROPERTIES) <define>BOOST_PYTHON_SUPPRESS_REGISTRY_INITIALIZATION
34-
# [ difference $(PYTHON_PROPERTIES) : <define>BOOST_PYTHON_DYNAMIC_LIB ] <define>BOOST_PYTHON_STATIC_LIB
35-
# ;
36-
37-
3830
test-suite python
3931
:
4032

4133
[
4234
run exec.cpp ../build//boost_python/<link>static /python//python
35+
: # program args
36+
: exec.py # input files
37+
: # requirements
38+
: # target-name
39+
]
40+
41+
[
42+
run exec.cpp ../build//boost_python/<link>shared /python//python
4343
: # program args
4444
: exec.py
4545
: # requirements
46-
<define>BOOST_PYTHON_STATIC_MODULE
46+
: exec-dynamic # target-name
4747
]
4848

4949
[
@@ -77,8 +77,8 @@ bpl-test crossmod_exception
7777
[ bpl-test keywords : keywords.cpp keywords_test.py ]
7878

7979

80-
[ python-extension builtin_converters.ext : test_builtin_converters.cpp /boost/python//boost_python ]
81-
[ bpl-test builtin_converters : test_builtin_converters.py builtin_converters.ext ]
80+
[ python-extension builtin_converters_ext : test_builtin_converters.cpp /boost/python//boost_python ]
81+
[ bpl-test builtin_converters : test_builtin_converters.py builtin_converters_ext ]
8282

8383
[ bpl-test test_pointer_adoption ]
8484
[ bpl-test operators ]
@@ -144,7 +144,7 @@ bpl-test crossmod_opaque
144144
# Whenever the cause for the failure of the polymorphism test is found
145145
# and fixed, this should be retested.
146146
<toolset>hp_cxx:<build>no ]
147-
147+
148148
[ python-extension map_indexing_suite_ext
149149
: map_indexing_suite.cpp int_map_indexing_suite.cpp
150150
/boost/python//boost_python ]

test/import_.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,28 @@
44
// http://www.boost.org/LICENSE_1_0.txt)
55

66
#include <boost/python.hpp>
7-
7+
#include <boost/bind.hpp>
88
#include <boost/detail/lightweight_test.hpp>
99
#include <iostream>
1010
#include <sstream>
1111

1212
namespace bpl = boost::python;
1313

14-
void import_test()
14+
void import_test( char** argv )
1515
{
16+
// Retrieve the main module
17+
bpl::object main = bpl::import("__main__");
18+
19+
// Retrieve the main module's namespace
20+
bpl::object global(main.attr("__dict__"));
21+
22+
// Inject search path for import_ module
23+
std::ostringstream script;
24+
script << "import sys, os\n"
25+
<< "path = os.path.dirname('" << argv[1] << "')\n"
26+
<< "sys.path.insert(0, path)\n";
27+
bpl::exec(bpl::str(script.str()), global, global);
28+
1629
// Retrieve the main module
1730
bpl::object import_ = bpl::import("import_");
1831
int value = bpl::extract<int>(import_.attr("value")) BOOST_EXTRACT_WORKAROUND;
@@ -27,19 +40,7 @@ int main(int argc, char **argv)
2740
// Initialize the interpreter
2841
Py_Initialize();
2942

30-
// Retrieve the main module
31-
bpl::object main = bpl::import("__main__");
32-
33-
// Retrieve the main module's namespace
34-
bpl::object global(main.attr("__dict__"));
35-
36-
// Inject search path for import_ module
37-
std::ostringstream script;
38-
script << "import sys, os.path\n"
39-
<< "path = os.path.dirname('" << argv[1] << "')\n"
40-
<< "sys.path.insert(0, path)\n";
41-
bpl::object result = bpl::exec(bpl::str(script.str()), global, global);
42-
if (bpl::handle_exception(import_test))
43+
if (bpl::handle_exception(boost::bind(import_test, argv)))
4344
{
4445
if (PyErr_Occurred())
4546
{

0 commit comments

Comments
 (0)