[C++-sig] Re: Pyste: Virtual class wrapper doesn't refcount object

David Abrahams dave at boost-consulting.com
Fri Apr 2 00:20:52 CEST 2004

Dan Halbert <halbert at bbn.com> writes:

> In Pyste from the 1.31.0 release:
> If Pyste finds any virtual methods in a class it is wrapping (if I
> understand correctly), it generates a class wrapper for that class
> that looks something like this:
>     struct VMClass_Wrapper : VMClass_Wrapper
>     {
>         (PyObject* self_):
>             VMClass(), self(self_) {}
>         void f(long int p0) {
>             call_method< void >(self, "f", p0);
> 	}
>         PyObject* self;
>     };
> Note that the self object is not properly reference-counted. It seems
> to me it should be

No, Pyste generates correct code for this case.  See

The Python class already owns the C++ class. That would create an
ownership cycle.

> since it's held by the struct, and can disappear from scope in the
> Python code, and so would go out of existence.
> I had just such an error when using this class in a callback situation:
>    registerMyCallback(VMClass(), ...)  # uses an anonymous VMClass() object

I'm not sure what that's doing, but your problem lies elsewhere.

Dave Abrahams
Boost Consulting

More information about the Cplusplus-sig mailing list