[Python-bugs-list] [ python-Bugs-494007 ] Py_INCREF(Py_None) in documentation

noreply@sourceforge.net noreply@sourceforge.net
Sun, 16 Dec 2001 17:03:17 -0800


Bugs item #494007, was opened at 2001-12-16 15:19
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=494007&group_id=5470

Category: Documentation
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Achim Gaedke (achimgaedke)
Assigned to: Fred L. Drake, Jr. (fdrake)
Summary: Py_INCREF(Py_None) in documentation

Initial Comment:
Since 5 hours I am debugging the pygsl (
http://pygsl.sourceforge.net ) module... The reason: I
forgot to increment the reference counter of Py_None
before returning it. Maybe it is a good idea to
underline this case. The Py_None object is a constant
pointer, maybe some other people do not think about it.

Here is a code example:

static PyObject* my_func(PyObject *self,
                           PyObject *args
                           )
{
  Py_INCREF(Py_None);
  return Py_None;
}

Is it possible, that this case was handled without
reference counter in version 2.0 and older?


----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2001-12-16 17:03

Message:
Logged In: YES 
user_id=31435

No, Py_None has always pointed to an object, exactly like 
every other object wrt reference counting.  But, also as 
for any other object, if you screw up its refcount, there's 
no predicting when (or even if) an error will result -- it 
depends on all other uses of the object everywhere.

Note that a debug build of Python 2.2 will print a message 
when Py_DECREF creates a negative refcount.  That should 
help a lot in cases like this.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=494007&group_id=5470