[C++-sig] need help with numpy converter

Neal Becker ndbecker2 at gmail.com
Fri Feb 8 17:26:46 CET 2008


numpy is a bit tricky.  The python type object is not a compile time
constant.  The value has to be filled in at runtime.

I've gotten pretty far using these:

namespace boost { namespace python { 
template<>
struct base_type_traits<PyArrayObject> {
  typedef PyObject type;
};
}}

namespace boost { namespace python { namespace converter {
template<>
struct pyobject_traits<PyArrayObject> : public pyobject_traits<PyObject> {};
}}}


But when I do
(o is an object wrapping a PyArrayObject)

return bp::handle<PyArrayObject> (bp::borrowed (o.ptr())

I get an infinite recursion in upcast.  It's trying to upcase a PyObject to
a PyArrayObject (I think).

This is really hard to debug.  Any ideas?
(I'm pretty sure that just adding a C-style cast would fix the above, but
I'd rather understand the problem better and the recommended solution)




More information about the Cplusplus-sig mailing list