Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98680 > unrolled thread
| Started by | Xiang Zhang <18518281186@126.com> |
|---|---|
| First post | 2015-11-12 16:05 +0800 |
| Last post | 2015-11-12 16:05 +0800 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
What is the meaning of Py_INCREF a static PyTypeObject? Xiang Zhang <18518281186@126.com> - 2015-11-12 16:05 +0800
| From | Xiang Zhang <18518281186@126.com> |
|---|---|
| Date | 2015-11-12 16:05 +0800 |
| Subject | What is the meaning of Py_INCREF a static PyTypeObject? |
| Message-ID | <mailman.257.1447317406.16136.python-list@python.org> |
Recently I am learning Python C API. When I read the tutorial <https://docs.python.org/3/extending/newtypes.html#the-basics>, defining new types, I feel confused. After PyType_Ready(&noddy_NoddyType) comes Py_INCREF(&noddy_NoddyType). Actually noddy_NoddyType is a static struct so I don't understand why I need to Py_INCREF it. Since it's Py_INCREFed, does it mean sometimes we also need to Py_DECREF it? But then it seems that type_dealloc will be invoked and it will fail assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE); I haven't read the typeobject.c source code totally so I think I must have missed something. But I am quite confused. Hope someone can give me some hints. Thanks in advance.
Back to top | Article view | comp.lang.python
csiph-web