Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98680
| From | Xiang Zhang <18518281186@126.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | What is the meaning of Py_INCREF a static PyTypeObject? |
| Date | 2015-11-12 16:05 +0800 |
| Message-ID | <mailman.257.1447317406.16136.python-list@python.org> (permalink) |
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 comp.lang.python | Previous | Next | Find similar | Unroll thread
What is the meaning of Py_INCREF a static PyTypeObject? Xiang Zhang <18518281186@126.com> - 2015-11-12 16:05 +0800
csiph-web