Mercurial > cpython-lru_cache-weakref
comparison Python/Python-ast.c @ 78006:85cccc38d01c
add gc support to the AST base type (closes #15293)
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sun, 08 Jul 2012 11:03:46 -0700 |
| parents | 048d8d9aecf1 |
| children | ffb2fa900cb7 |
comparison
equal
deleted
inserted
replaced
| 78005:9c345b4bd97e | 78006:85cccc38d01c |
|---|---|
| 466 Py_CLEAR(self->dict); | 466 Py_CLEAR(self->dict); |
| 467 Py_TYPE(self)->tp_free(self); | 467 Py_TYPE(self)->tp_free(self); |
| 468 } | 468 } |
| 469 | 469 |
| 470 static int | 470 static int |
| 471 ast_traverse(AST_object *self, visitproc visit, void *arg) | |
| 472 { | |
| 473 Py_VISIT(self->dict); | |
| 474 return 0; | |
| 475 } | |
| 476 | |
| 477 static void | |
| 478 ast_clear(AST_object *self) | |
| 479 { | |
| 480 Py_CLEAR(self->dict); | |
| 481 } | |
| 482 | |
| 483 static int | |
| 471 ast_type_init(PyObject *self, PyObject *args, PyObject *kw) | 484 ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 472 { | 485 { |
| 473 _Py_IDENTIFIER(_fields); | 486 _Py_IDENTIFIER(_fields); |
| 474 Py_ssize_t i, numfields = 0; | 487 Py_ssize_t i, numfields = 0; |
| 475 int res = -1; | 488 int res = -1; |
| 568 0, /* tp_call */ | 581 0, /* tp_call */ |
| 569 0, /* tp_str */ | 582 0, /* tp_str */ |
| 570 PyObject_GenericGetAttr, /* tp_getattro */ | 583 PyObject_GenericGetAttr, /* tp_getattro */ |
| 571 PyObject_GenericSetAttr, /* tp_setattro */ | 584 PyObject_GenericSetAttr, /* tp_setattro */ |
| 572 0, /* tp_as_buffer */ | 585 0, /* tp_as_buffer */ |
| 573 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ | 586 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
| 574 0, /* tp_doc */ | 587 0, /* tp_doc */ |
| 575 0, /* tp_traverse */ | 588 (traverseproc)ast_traverse, /* tp_traverse */ |
| 576 0, /* tp_clear */ | 589 (inquiry)ast_clear, /* tp_clear */ |
| 577 0, /* tp_richcompare */ | 590 0, /* tp_richcompare */ |
| 578 0, /* tp_weaklistoffset */ | 591 0, /* tp_weaklistoffset */ |
| 579 0, /* tp_iter */ | 592 0, /* tp_iter */ |
| 580 0, /* tp_iternext */ | 593 0, /* tp_iternext */ |
| 581 ast_type_methods, /* tp_methods */ | 594 ast_type_methods, /* tp_methods */ |
| 587 0, /* tp_descr_set */ | 600 0, /* tp_descr_set */ |
| 588 offsetof(AST_object, dict),/* tp_dictoffset */ | 601 offsetof(AST_object, dict),/* tp_dictoffset */ |
| 589 (initproc)ast_type_init, /* tp_init */ | 602 (initproc)ast_type_init, /* tp_init */ |
| 590 PyType_GenericAlloc, /* tp_alloc */ | 603 PyType_GenericAlloc, /* tp_alloc */ |
| 591 PyType_GenericNew, /* tp_new */ | 604 PyType_GenericNew, /* tp_new */ |
| 592 PyObject_Del, /* tp_free */ | 605 PyObject_GC_Del, /* tp_free */ |
| 593 }; | 606 }; |
| 594 | 607 |
| 595 | 608 |
| 596 static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) | 609 static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
| 597 { | 610 { |
