Skip to content

Commit bb6f52d

Browse files
vmurashevstefanseefeld
authored andcommitted
test/exec.cpp - register builtin module before call 'Py_Initialize'
1 parent d422058 commit bb6f52d

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

test/exec.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,6 @@ void eval_test()
5858

5959
void exec_test()
6060
{
61-
// Register the module with the interpreter
62-
if (PyImport_AppendInittab(const_cast<char*>("embedded_hello"),
63-
#if PY_VERSION_HEX >= 0x03000000
64-
PyInit_embedded_hello
65-
#else
66-
initembedded_hello
67-
#endif
68-
) == -1)
69-
throw std::runtime_error("Failed to add embedded_hello to the interpreter's "
70-
"builtin modules");
7161
// Retrieve the main module
7262
python::object main = python::import("__main__");
7363

@@ -152,6 +142,20 @@ int main(int argc, char **argv)
152142
{
153143
BOOST_TEST(argc == 2 || argc == 3);
154144
std::string script = argv[1];
145+
146+
// Register the module with the interpreter
147+
if (PyImport_AppendInittab(const_cast<char*>("embedded_hello"),
148+
#if PY_VERSION_HEX >= 0x03000000
149+
PyInit_embedded_hello
150+
#else
151+
initembedded_hello
152+
#endif
153+
) == -1)
154+
{
155+
BOOST_ERROR("Failed to add embedded_hello to the interpreter's "
156+
"builtin modules");
157+
}
158+
155159
// Initialize the interpreter
156160
Py_Initialize();
157161

0 commit comments

Comments
 (0)