Dag Sverre Seljebotn wrote: >> Dag Sverre Seljebotn wrote: >>> Allocation would happen through an actual (as light-weight as >>> possible, and probably mostly opaque, perhaps doing as much as printing >>> the C++ name of the class in its repr) Python object >> >> That wouldn't work, though. Imagine you'd return the C++ object pointer >> from a function. What would happen to the Python object that holds it? >> How would you keep the ref-counting context for it? > > There would be no coercion between pointers and refcounted variables. I.e. > if you have > > cdef extern CppObject* foo() > > you can NOT do > > cdef CppObject obj = foo() > > It would only work when C++ returned an object *by value*: > > cdef extern CppObject foo() > cdef CppObject obj = foo() > > This would then heap-allocate a CppObject, passing in the object that is > returned to the copy constructor.
Ah, ok, got it. So they'd basically be distinct types and you cannot (implicitly) coerce a C++ object to a pointer. That should work then. Can C++ objects override their own allocation, or could you use a PyVarObject to allocate both the object and the Cython wrapper at once? (targeting heap allocation here, I assume that stack allocated objects do not need ref-counting anyway?) Stefan _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
