Several questions about embedding Python

Emmanuel eastier at free.fr
Thu May 6 16:30:41 EDT 2004



Miki Tebeka a écrit :

> Hello All,
>
> I'm trying to extend a hardware simulator (written in C/C++) by
> embedding Python.
> After reading the documentation and playing around several questions
> popped up:
>
> 1. Is there a way (using SWIG/Boost.Python ...) to export existing C/C++
> functions other than hand writing the wrapper functions.
> Something like: py_export(a_c_function)
> Since the Python module need to get information from the simulator I
> can't just write pure SWIG wrapper (or can I?)

? I don't understand...
Just have a header file with the function you want to call from Python, and
let SWIG parse it. That's what I'm doing...


>
>
> 2. How do I debug the Python code? Since the interpreter is called from
> the simulator application I can't run `pdb' on it.

I used HAP editor/debugger, that can be quite simply included in a embedded
app.
But I must admit there are still some bugs in it, and I'm not sure it's
still actively developped...


>
>
> 3. Why on does pyconfig.h decides that `python23_d.lib' should be used
> when _DEBUG is on (IMO is should use Py_DEBUG)? I'm debugging *my*
> application not Python.

You should use :
#ifdef _DEBUG
#undef _DEBUG
#include "python.h"
#define _DEBUG
#else
#include "python.h"
#endif

instead of the main
#include "python.h"

to get rid of this issue.
Actually, I have a special MyPython.h for this. ( I add a special define in
order to allow this trick or not, I remember times where step into python
for debugging )

Hope it helps,

Emmanuel





More information about the Python-list mailing list