[C++-sig] rfe: change of behaviour with return_internal_reference policy

David Abrahams dave at boost-consulting.com
Mon Aug 19 17:34:42 CEST 2002


From: "gideon may" <gideon at computer.org>
> --On Monday, August 19, 2002 9:25 AM -0400 David Abrahams
> <dave at boost-consulting.com> wrote:
> > From: "gideon may" <gideon at computer.org>


> >
> >> In my case the result can be
> >> a NULL pointer,
> >
> > Which gets translated to None.
>
> Right.
>
> >
> >> failing
> >> the PyWeakref_NewRef function.
> >
> > Ah yes; None doesn't support weak references.
> >
>
>
> > However, we /could/ check explicitly for None, since that's going to
stay
> > alive no matter what we do.
> > I think in the case that's failing for you, both the nurse and patient
> > parameters in make_nurse_and_patient are PyNone, right?
>
> Actually, you're right, that's what I had before. But only the nurse
needs
> to be checked for PyNone, the patient is the 'self' parameter in toGroup
> afaik,
> which is guaranteed to be not PyNone. Thus I guess that it suffices to
> change the
> beginning of the function to :
>
> if (nurse == Py_None) {
>     Py_INCREF(Py_None);
>     return Py_None;
> }

Okay, fixed.

> >> This brings me to a second point, it seems that life_support_dealloc
is
> >> never called.
> >> If it would,
> >> the tp_free would be called for self, which is not initialized ie a
NULL
> >> function pointer.
> >
> > Really? Hmm, I'm not sure about that. Which fields in an extension type
> > are filled in automatically by Python and when they're called remains a
> > little mysterious to me, I have to admit.
> >
>
> I stumbled upon this because of my previous point. Without the mentioned
> change,
> PyWeakref_Newref returns a NULL. This causes 'system' to be
Py_XDEFREF'd ->
> crash in
> life_support_dealloc (line 24). But somehow the the life_support_dealloc
> function is never
> being called.

Those two sentences contradict one another!
However, I think it's fixed.

> BTW, am enjoying BPL more and more!

Great!

> Any news on enum_ <wink> ?

Contract obligations force me to concentrate on other things until probably
9/30.

However, you could do:

    .setattr("enum_value_1", (int)enum_value_1)

on your module object.

-Dave





More information about the Cplusplus-sig mailing list