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

Stefan Seefeld seefeld at sympatico.ca
Wed Aug 27 21:45:08 CEST 2008


Olaf Peter wrote:
> Hi,
>
> following http://www.python.org/doc/api/exceptionHandling.html,
> PyErr_Fetch returns objects and I own these (if!= NULL).
>
> I wrote:
>
> bpl::object exception, value, tb;
> PyErr_Fetch(&exception.ptr(), &value.ptr(), &tb.ptr());
>   

I wouldn't expect this to work: You can't assign to the return value of 
bpl::object::ptr().

> is there a way for this using bpl:object? 

Not at this time.

> Maybe I have to wrap this
> after calling PyErr_Fetch?
>   
Yes. Something like this should work:

namespace boost
{
namespace python
{
void fetch_error(object &type, object &value, object &traceback)
{
  PyObject *t, *v, *b;
  PyErr_Fetch(&t, &v, &b);
  type = detail::new_reference(t);
  value = v ? detail::new_reference(v) : object();
  traceback = b ? detail::new_reference(b) : object();
}
}
}

(There are more functions like this that could be added. Some day I'll 
submit a new patch...

HTH,
       Stefan


-- 

      ...ich hab' noch einen Koffer in Berlin...




More information about the Cplusplus-sig mailing list