Several questions about embedding Python

Miki Tebeka miki.tebeka at zoran.com
Sun May 9 07:01:02 EDT 2004


Emmanuel wrote:

>>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...
Yes. But the Python code is on the DLL generated by SWIG and the 
functions it needs to call are part of the main executable.

>>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...
Thanks! I'll check it out.

>>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"
Yeah. I just make sure the last #include lines are #undef _DEBUG and 
#include <Python.h>

Thanks.
Miki



More information about the Python-list mailing list