From: Brendon Costa <brendon@ch...> - 2007-02-25 03:44:25
I have been using SWIG recently and it has been working great. Thanks
for the nifty tool.
I am having difficulty trying to use the resulting plugin module in the
manner i wish to use it.
Basically i have a C++ library:
which i use SWIG on to generate a set of wrappers for python. This
produces a edoc_wrap.cpp, which i then link using libtool into a module:
This all works fine so i can then write python applications that make
use of an "edoc" module. I then have an application:
appedoc that uses libedoc to perform most of its processing. This
application also embeds a python interpreter that allows the user to
provide a python script to configure the application (By modifying
objects from libedoc using the SWIG wrapper to libedoc).
So what i have is an extended, embedded python interpreter. In appedoc i
will execute some users python code like:
PyObject* result = PyRun_String(....);
This is where the problem is. In the SWIG wrappers i have code that
automatically converts C++ exceptions into python exceptions. And now i
want to go the other way. The function: PythonExceptionToCXXException()
works fine at doing this but it seems necessary for it to be a part of
the _edoc.la python dynamically loadable library module as it uses types
defined in that module as part of the SWIG interface. The appropriate
section of edoc.i where i added this looks a bit like:
PyErr_Fetch(&exc_type, &exc_value, &exc_tb);
if (PyErr_GivenExceptionMatches(exc_value, EDoc_MergeException))
Now the problem is that i cant seem to move the
PythonExceptionToCXXException() from out of the module and if i link
against the module directly: _edoc.la then libtool warns that this is a
bad idea as it is not portable to link an application to a dynamically
Besides re-writing the entire application (With the exception of
libedoc) in python so i just have a python application that makes use of
the edoc module, does anyone know a portable way to resolve this issue?