Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98744 > unrolled thread
| Started by | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
|---|---|
| First post | 2015-11-13 14:59 +0000 |
| Last post | 2015-11-13 14:59 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: What is the meaning of Py_INCREF a static PyTypeObject? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-11-13 14:59 +0000
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
|---|---|
| Date | 2015-11-13 14:59 +0000 |
| Subject | Re: What is the meaning of Py_INCREF a static PyTypeObject? |
| Message-ID | <mailman.290.1447426808.16136.python-list@python.org> |
On 13 November 2015 at 03:08, Xiang Zhang <18518281186@126.com> wrote:
> I think the meaning of Py_INCREF a static type object is to prevent it from
> being deallocated when it is Py_DECREFed somehow later. Just as you said, it
> may be somehow deallocated when using.
>
> NoddyType is a static struct so I don't think it lives on Python's heap and
> deallocating it is a wrong action. Just as I mentioned, type_dealloc seems
> to only deallocated HEAPTYPE. And by the way, when NoddyType is created, it
> has a reference count 1 with PyVarObject_HEAD_INIT. So if I don't Py_INCREF
> it, when it is somehow Py_DECREDed later, it will reach reference count 0
> and fail the assert in type_dealloc. If it is Py_INCREFed, just like the
> module holds a reference to it, it will at least have a reference count 1
> and never reach 0.
Other code shouldn't Py_DECREF it unless it owns a reference meaning
that it has first called Py_INCREF. The only exception I can think is
possibly that someone would do:
>>> import noddy
>>> del noddy.Noddy
For that to work properly I guess that Noddy needs a reference count
of 2: one for being a module attribute and an extra one to prevent it
from ever being deallocated.
--
Oscar
Back to top | Article view | comp.lang.python
csiph-web