[C++-sig] help passing image data
J.D. Yamokoski
yamokosk at ufl.edu
Wed May 24 21:03:21 CEST 2006
>
> [Nat] Try moving the class_() call inside your BOOST_PYTHON_MODULE body?
>
>
>>BOOST_PYTHON_MODULE(Values)
>>{
>> class_< Values >("Values")
>> .def( "get_a", &Values::GetA )
>> .def( "get_b", &Values::GetB )
>> .def( "set_a", &Values::SetA )
>> .def( "set_b", &Values::SetB );
>>}
>
Ok I have done that and gotten rid of creating a global boost::python
object of type Values. I have also modified my code to copy what I found
here:
http://mail.python.org/pipermail/c++-sig/2002-December/002833.html
However, now I am running into a runtime problem. Instead of posting all
the code here, I have included the important files with the email.
Essentially, I have a class which wraps much of the code that was posted
in the above link email. And I have only made slight modifications to it
to fit my needs. The code seems to crash at PyImport_ImportModule():
handle<> CPythonDLL::importModule(std::string module_name)
{
PyObject *module_ptr =
PyImport_ImportModule(const_cast<char*>(module_name.c_str()));
if( module_ptr == NULL) {
python_exception exc = getExceptionDetail();
throw(exc);
}
return handle<>(module_ptr);
}
That is bothersome, but then I have a try block wrapped around the
calling of importModule():
// Import the module, storing the pointer in a handle<>
try {
module = importModule(scriptName);
} catch (...) {
python_exception exc = getExceptionDetail();
throw(exc);
}
The exception is caught and getExceptionDetail() is called. But then
within that function, the code throws another exception at PyErr_Occured():
python_exception CPythonDLL::getExceptionDetail()
{
std::string errmsg("");
int nIsInit = Py_IsInitialized();
if (!nIsInit) {
errmsg = "Python not initialized!";
return python_exception( errmsg );
}
// Extra paranoia...
if (!PyErr_Occurred()) {
errmsg = "Not a python error!";
return python_exception( errmsg );
}
PyObject* exc_type;
PyObject* exc_value;
PyObject* exc_traceback;
PyObject* pystring;
PyErr_Fetch(&exc_type, &exc_value, &exc_traceback);
// Rest let out for brevity
}
I don't know if it helps explain anything, but in the directory that my
"myscript.py" file is stored, a "myscript.pyc" file is created everytime
I run the program. I assume this has something to do with
PyImport_ImportModule().
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ValuesModule.h
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060524/147f57b3/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: PythonDLL.cpp
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060524/147f57b3/attachment-0001.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: PythonDLL.h
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060524/147f57b3/attachment-0002.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: myscript.py
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060524/147f57b3/attachment-0003.txt>
More information about the Cplusplus-sig
mailing list