9 #include <boost/version.hpp>
10 #include <boost/algorithm/string/predicate.hpp>
13 #if BOOST_VERSION / 100 % 1000 == 58
27 bp::object main_module = bp::import(
"__main__");
29 bp::dict globals = bp::extract<bp::dict>(main_module.attr(
"__dict__"));
33 bp::object cpp_module(
34 (bp::handle<>(bp::borrowed(PyImport_AddModule(
"libpinocchio_pywrap")))));
41 #if BOOST_VERSION / 100 % 1000 == 58
45 std::stringstream buffer;
47 bp::exec(buffer.str().c_str(), globals);
48 #else // default implementation
49 bp::exec_file((bp::str)
filename, globals);
52 catch (bp::error_already_set & e)
60 bp::object obj_model = globals[model_name];
61 model = bp::extract<Model>(obj_model);
63 catch (bp::error_already_set & e)
70 #if PY_MAJOR_VERSION < 3
74 PyObject * poMainModule = PyImport_AddModule(
"__main__");
75 PyObject * poAttrList = PyObject_Dir(poMainModule);
76 PyObject * poAttrIter = PyObject_GetIter(poAttrList);
77 PyObject * poAttrName;
79 while ((poAttrName = PyIter_Next(poAttrIter)) != NULL)
81 std::string oAttrName((bp::extract<char const *>(poAttrName)));
84 if (!boost::starts_with(oAttrName,
"__") || !boost::ends_with(oAttrName,
"__"))
86 PyObject * poAttr = PyObject_GetAttr(poMainModule, poAttrName);
89 if (poAttr && poAttr->ob_type != poMainModule->ob_type)
90 PyObject_SetAttr(poMainModule, poAttrName, NULL);
93 Py_DecRef(poAttrName);
95 Py_DecRef(poAttrIter);
96 Py_DecRef(poAttrList);