[C++-sig] Trying to clone Python object from C++ (again)
Paul F. Kunz
Paul_Kunz at slac.stanford.edu
Thu Jul 21 22:01:30 CEST 2005
>>>>> On Thu, 21 Jul 2005 15:27:59 -0400, David Abrahams <dave at boost-consulting.com> said:
> "Paul F. Kunz" <Paul_Kunz at slac.stanford.edu> writes:
>> I'm trying once again to clone a Python object whose class is
>> derived from an exposed C++ base class from C++. After I call from
>> C++ clone() on the base class pointer, I wind up here...
>>
>> FunctionBase * FunctionWrap:: clone () const { #ifndef
>> HAVE_OLD_PYTHON PyGILState_STATE state = PyGILState_Ensure ();
>> object py_result;
>>
>> if (override clone = this->get_override("clone"))
>> {
>> try {
>> // The Python class author overrode clone; do
>> // whatever she says
>> py_result = clone();
>> } catch ( error_already_set & e ) {
>> return 0;
>> }
>> } else
>>
>> (thanks to Dave for essentially writing this for me).
> I wrote that?? I wouldn't want to take responsibility for that
> try/catch block. It just discards all the information about what
> happened.
Ok, *I* added the try/catch block around the code you helped me
with a long time ago. Apologies.
>> The problem is that the exception is thrown.
> Which exception?
The error_already_set exception is always thrown.
> if (override clone = this->get_override("clone")) { // The Python
> class author overrode clone; do // whatever she says try { py_result
> = clone(); } catch ( error_already_set & e ) { PyErr_Print(); return
> 0 } } else
I'll try the PyErr_Print to see what I get. Thanks.
More information about the Cplusplus-sig
mailing list