[C++-sig] Re: boost:python:embedding

Dirk Gerrits dirk at gerrits.homeip.net
Tue May 6 19:04:28 CEST 2003

David Abrahams wrote:
> Dirk Gerrits <dirk at gerrits.homeip.net> writes:
>>David Abrahams wrote:
>>>Dirk Gerrits <dirk at gerrits.homeip.net> writes:
>>No that's not what I meant. You need this only to call the C++ code
>>from the embedding program. Say that the C++ program contains the
>>functions foo and bar that work on some shared data. (Perhaps they are
>>members of the same class.) Now if foo calls some Python code, and
>>that Python code needs bar, then obviously bar can't be in a .pyd when
>>foo is in a .exe, right?
> Ahhm.  Not on Windows, no.  You'd have to link your application and
> the .pyd to the Python DLL, instead of linking Python into your
> program statically.  On most Unices, extension modules actually get
> their Python symbols resolved back into the python executable.

Interesting! I think I'll need to update the tutorial on this. At the 
moment it only mentions linking Python statically to the embedding program.

>>Yes I looked into it a bit, but I haven't actually changed any
>>code. For one, I'm not totally sure how the releasing should be
>>done. Py_AtExit() won't suffice
> Why, pray tell?

 From the docs:

int Py_AtExit(void (*func) ())
     Register a cleanup function to be called by Py_Finalize()
Since Python's internal finallization will have completed before the 
cleanup function, no Python APIs should be called by func.

I assumed that the releasing would need to make Python API calls. But 
perhaps I'm mistaken?

>>so I suppose the cleanup function must be exposed to Python to be
>>registered with atexit.register() through PyRun_String?
> I guess that would be fine.
>>BTW, you didn't say anything about whether embedding makes sense
>>without defining BOOST_PYTHON_STATIC_MODULE. 
> Probably because I don't know ;-)

I see. I guess I'll have to look into it then. ;)

Dirk Gerrits

More information about the Cplusplus-sig mailing list