Dave wrote: Why struggle? This should be: object /* Returns a borrowed reference */ getPythonFunction(string moduleName,string functionName) { object _module(handle<>( PyImport_ImportModule(const_cast<char*>(moduleName.c_str())))); <<-- line 63 in Main.cpp return _module.attr(functionName.c_str()); } ------------------------------------------------------------------------ Always a good question. The code doesn't compile as presented. I added #include <boost/python/object.hpp> to my module, have completely opened the boost::python namespace. Get the error: Main.cpp:63: error: variable declaration is not allowed here If I just instanciate an empty object with its default constructor, the module compiles. An underlining concern I have is error handling. When PyImport_ImportModule fails, a NULL pointer is returned. Seems like the underlining machinery in "handle<>" is intolerant of this.
Jeff Holle <jeff.holle@verizon.net> writes:
Dave wrote:
Why struggle? This should be:
object /* Returns a borrowed reference */ getPythonFunction(string moduleName,string functionName) { object _module(handle<>( PyImport_ImportModule(const_cast<char*>(moduleName.c_str())))); <<-- line 63 in Main.cpp
return _module.attr(functionName.c_str()); }
------------------------------------------------------------------------
Always a good question. The code doesn't compile as presented.
Oh, it should; GCC bug it looks like. object getPythonFunction(string moduleName,string functionName) { object _module = object( handle<>( PyImport_ImportModule(const_cast<char*>(moduleName.c_str())) ) ); return _module.attr(functionName.c_str()); } or object getPythonFunction(string moduleName,string functionName) { object _module(( handle<>( PyImport_ImportModule(const_cast<char*>(moduleName.c_str())) ) )); return _module.attr(functionName.c_str()); } works.
An underlining concern I have is error handling. When PyImport_ImportModule fails, a NULL pointer is returned. Seems like the underlining machinery in "handle<>" is intolerant of this.
What makes you say that? -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
participants (2)
-
David Abrahams -
Jeff Holle