[C++-sig] BPL and Py_Clear()

Niall Douglas s_sourceforge at nedprod.com
Sun Jun 12 19:19:00 CEST 2005


On 12 Jun 2005 at 12:05, David Abrahams wrote:

> >> The former is easy: make sure the object is held by auto_ptr<T>,
> >> and pass the object to a function accepting an auto_ptr<T>.
> >
> > The latter could probably be made to work if given enough time, but
> > it would require a substantial amount of alterations to pyste to
> > achieve it - and even then, I still can see issues which may arise.
> >
> > Hence I must go the quick & dirty route. I was thinking of throwing
> > a dummy exception, reading the traceback & stack frame info and
> > recursing up through the globals() in each deleting any references
> > to my object. This would surely do it for the current interpreter at
> > least?
> 
> No, there may be references hiding in other pythong objects and, for
> that matter, in extension modules.
> 
> I don't see what advantage you gain from it either.  A variable or
> attribute in Python has to be bound to *something*, be it None or a
> zombie (which will act almost like None) or whatever.  You'll reclaim
> a small amount of memory, but that's about it.

As it turned out, pyste already supported auto_ptr. And it also seems 
that BPL treats auto_ptr quite sensibly, so it "just works". Wish I 
had known as it would have saved me a day's work :(

My current problem is when running through virtual function wrappers 
in that call_method<> tries converting an unsigned int * to an 
unsigned int which I don't want. I tried putting ptr() round it like 
this:

    void setData(FX::FXColor* p0, FX::FXuint p1) {
        call_method< void >(py_self, "setData", ptr(p0), p1);
    }

(here FXColor is a typedef for unsigned int)

... but BPL won't take pointers to integral types in ptr(), and thus 
I can't see how to pass the pointer as-is.

Why doesn't BPL's ptr() accept pointers to integral types?

Cheers,
Niall






More information about the Cplusplus-sig mailing list