[C++-sig] test/embedding.cpp in bpl 1.31
seefeld at sympatico.ca
Thu Aug 12 03:20:12 CEST 2004
debugging my applications, I'v had a closer
look into the test/embedding.cpp file, and I'd
like to suggest two changes, one cosmetic, and one fix.
The fix concerns line line 108/109, which read:
python::object py_base = PythonDerived();
Base& py = python::extract<Base&>(py_base)();
PythonDerived is a type object extracted from
a python script, so the first line calls the
constructor. The second takes the instance and
extracts a 'Base' reference for later use.
But what's the '()' operator supposed to do in
that line ? If I remove it, the test still
performs correctly, so it seems it doesn't
have any effect (at least in this context).
Can anybody explain this behavior ?
The other change concerns the way the 'PythonDerived'
type object is obtained. Instead of running 'PyRun_String'
I'd just extract it from the 'main_namespace' dictionary
after the first script has been evaluated:
python::object PythonDerived = main_namespace["PythonDerived"];
Both changes are contained in the attached patch...
My original goal looking into this file was to
understand a crash I get when running 'PyRun_File',
so I tried to do what the comment in embedding.cpp suggests,
i.e. I put the script defining the 'PythonDerived' class into a
separate file and then use 'PyRun_File' to evaluate that script
instead of 'PyRun_String'. While this works fine on linux, the
application crashes on windows (msvc) somewhere inside the PyRun_File
I did the appropriate (I think) changes to 'test/embedding.cpp' for
comparison, and I observed the same crash (i.e. just recompiling
the modified 'embedding' test inside the boost build system).
I'd very much appreciate if anybody could either confirm this
behavior on windows (msvc) or show what changes need to be done
to the code to make it work. (I believe this use case is sufficiently
important to warrant a demo /test in its own right.)
Thanks a lot !
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
More information about the Cplusplus-sig