[C++-sig] Re: boost:python:embedding
dirk at gerrits.homeip.net
Tue May 6 09:03:06 CEST 2003
David Abrahams wrote:
> Dirk Gerrits <dirk at gerrits.homeip.net> writes:
>>To do this, you can't simply create a module_name.so or
>>module_name.pyd as you'd do when extending; the BPL wrapper code
>>must be in the C++ program itself.
> Loading of plugin extension libraries is disabled? Are you sure?
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,
> I can understand why you'd want to link statically, but it seems to
> me that dynamic linking should still be possible... no?
Yes, you can still have *other* C++ code stuffed into extension
libaries. Sorry for the confusion. This wasn't a bug report. ;)
>># define BOOST_PYTHON_FORWARD_DECLARE_MODULE_INIT(name) \
>>I have some issues with this though. For starters, the macro name is
>>much too long for my taste. ;)
> You could leave out the word "DECLARE".
[snipped bug description]
>>Has it been fixed then?
> No, it hasn't. This should still be addressed, and in fact it isn't
> that difficult. As I've said before, I'm sure you could do it with a
> little hand-holding. The problem is that some references to Python
> objects are being kept alive by global data
> (e.g. boost::python::object instances) which must be released before
> Py_Finalize is called.
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, so I suppose the cleanup function must be exposed to
Python to be registered with atexit.register() through PyRun_String?
BTW, you didn't say anything about whether embedding makes sense without
defining BOOST_PYTHON_STATIC_MODULE. My guess is that it doesn't. I'd
have to put something about this in the tutorial and/or reference so I'd
like your thoughts.
More information about the Cplusplus-sig