@@ -2331,32 +2331,45 @@ _count_elements(PyObject *self, PyObject *args)
23312331/* Helper functions for namedtuples */
23322332
23332333typedef struct {
2334- propertyobject po ;
2334+ PyObject_HEAD
23352335 Py_ssize_t index ;
23362336 PyObject * doc ;
23372337} _tuplegetterobject ;
23382338
23392339static PyObject *
23402340tuplegetter_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
2341+ {
2342+ _tuplegetterobject * self ;
2343+ self = (_tuplegetterobject * )type -> tp_alloc (type , 0 );
2344+ if (self == NULL ) {
2345+ return NULL ;
2346+ }
2347+ self -> index = 0 ;
2348+ Py_INCREF (Py_None );
2349+ self -> doc = Py_None ;
2350+ return (PyObject * )self ;
2351+ }
2352+
2353+
2354+ static int
2355+ tuplegetter_init (_tuplegetterobject * self , PyObject * args , PyObject * kwds )
23412356{
23422357 Py_ssize_t index ;
2343- PyObject * doc ;
2344- _tuplegetterobject * self ;
2358+ PyObject * doc , * tmp ;
23452359
23462360 static char * kwlist [] = {"index" , "doc" , NULL };
23472361 if (!PyArg_ParseTupleAndKeywords (args , kwds , "n$O" , kwlist ,
23482362 & index , & doc )){
2349- return NULL ;
2350- }
2351-
2352- self = (_tuplegetterobject * )PyProperty_Type .tp_new (type , args , kwds );
2353- if (self == NULL ) {
2354- return NULL ;
2363+ return -1 ;
23552364 }
23562365 self -> index = index ;
2357- Py_INCREF (doc );
2358- self -> doc = doc ;
2359- return (PyObject * )self ;
2366+ if (doc ) {
2367+ tmp = self -> doc ;
2368+ Py_INCREF (doc );
2369+ self -> doc = doc ;
2370+ Py_DECREF (tmp );
2371+ }
2372+ return 0 ;
23602373}
23612374
23622375static PyObject *
@@ -2376,11 +2389,29 @@ tuplegetterdescr_get(PyObject *self, PyObject *obj, PyObject *type)
23762389 return result ;
23772390}
23782391
2392+
2393+ static int
2394+ tuplegetter_traverse (PyObject * self , visitproc visit , void * arg )
2395+ {
2396+ _tuplegetterobject * tuplegetter = (_tuplegetterobject * )self ;
2397+ Py_VISIT (tuplegetter -> doc );
2398+ return 0 ;
2399+ }
2400+
2401+ static int
2402+ tuplegetter_clear (PyObject * self )
2403+ {
2404+ _tuplegetterobject * tuplegetter = (_tuplegetterobject * )self ;
2405+ Py_CLEAR (tuplegetter -> doc );
2406+ return 0 ;
2407+ }
2408+
23792409static void
23802410tuplegetter_dealloc (_tuplegetterobject * self )
23812411{
2382- Py_XDECREF (self -> doc );
2383- PyProperty_Type .tp_dealloc ((PyObject * )self );
2412+ PyObject_GC_UnTrack (self );
2413+ tuplegetter_clear ((PyObject * )self );
2414+ Py_TYPE (self )-> tp_free ((PyObject * )self );
23842415}
23852416
23862417
@@ -2410,23 +2441,23 @@ static PyTypeObject tuplegetter_type = {
24102441 0 , /* tp_getattro */
24112442 0 , /* tp_setattro */
24122443 0 , /* tp_as_buffer */
2413- Py_TPFLAGS_DEFAULT , /* tp_flags */
2444+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC , /* tp_flags */
24142445 0 , /* tp_doc */
2415- 0 , /* tp_traverse */
2416- 0 , /* tp_clear */
2446+ ( traverseproc ) tuplegetter_traverse , /* tp_traverse */
2447+ ( inquiry ) tuplegetter_clear , /* tp_clear */
24172448 0 , /* tp_richcompare */
24182449 0 , /* tp_weaklistoffset */
24192450 0 , /* tp_iter */
24202451 0 , /* tp_iternext */
24212452 0 , /* tp_methods */
24222453 tuplegetter_members , /* tp_members */
24232454 0 , /* tp_getset */
2424- & PyProperty_Type , /* tp_base */
2455+ 0 , /* tp_base */
24252456 0 , /* tp_dict */
24262457 tuplegetterdescr_get , /* tp_descr_get */
24272458 0 , /* tp_descr_set */
24282459 0 , /* tp_dictoffset */
2429- 0 , /* tp_init */
2460+ ( initproc ) tuplegetter_init , /* tp_init */
24302461 0 , /* tp_alloc */
24312462 tuplegetter_new , /* tp_new */
24322463 0 ,
0 commit comments