[C++-sig] [boost.python] PyErr_Fetch and object

Olaf Peter ope-devel at gmx.de
Fri Aug 29 07:38:34 CEST 2008


Alex Mohr schrieb:
>> Thanks ! Actually, the lack of a check for 'type' was intentional: 
>> Even if an error is set, 'value' and 'traceback' may be set to NULL.
>> 'type' can only be NULL if no error is set, and thus has to be handled 
>> special. (For example, we could throw an exception in that case, as 
>> calling fetch_error if no error is set is an error (or may be, if we 
>> make it so).
> 
> Hmm -- well, my personal preference is for it to mimic the python c api, 
> so if there is no error set, then all three are set to None, if there is 
> an error set, then type is not None, and value and traceback may or may 
> not be None.  That's how I tried to write it.

which is intuitive to C/API. To check the case mentioned by Stefan one 
has to test on PyErr_Occured() and than decide the individual error 
handling.

>> Of course, with that then come other function wrappers for 'restore', 
>> 'clear', etc.
> 
> Indeed.  It would be nice to do a project that tried to wrap up all (or 
> as much as possible) of the python C api.  That would benefit and appeal 
> to a wide audience, I think.  Even including folks who don't use 
> boost.python to generate bindings.
> 
>> I'll think about a patch, if no-one else beats me to it <wink/>

I will do it too ;-) At this time I wrote my own extension to 
boost.python like the above.

Anyway, what are the appropriate user functions for
detail { new_reference, borrowed_reference and new_non_null_reference }?
Why does detail::borrow owns a reference and do not decide the user what 
to do?

Thanks,
Olaf




More information about the Cplusplus-sig mailing list