| 833 | |
| 834 | |
| 835 | class PyTypesVisitor(PickleVisitor): |
| 836 | |
| 837 | def visitModule(self, mod): |
| 838 | self.emit(""" |
| 839 | |
| 840 | typedef struct { |
| 841 | PyObject_HEAD |
| 842 | PyObject *dict; |
| 843 | } AST_object; |
| 844 | |
| 845 | static void |
| 846 | ast_dealloc(PyObject *op) |
| 847 | { |
| 848 | AST_object *self = (AST_object*)op; |
| 849 | /* bpo-31095: UnTrack is needed before calling any callbacks */ |
| 850 | PyTypeObject *tp = Py_TYPE(self); |
| 851 | PyObject_GC_UnTrack(self); |
| 852 | Py_CLEAR(self->dict); |
| 853 | freefunc free_func = PyType_GetSlot(tp, Py_tp_free); |
| 854 | assert(free_func != NULL); |
| 855 | free_func(self); |
| 856 | Py_DECREF(tp); |
| 857 | } |
| 858 | |
| 859 | static int |
| 860 | ast_traverse(PyObject *op, visitproc visit, void *arg) |
| 861 | { |
| 862 | AST_object *self = (AST_object*)op; |
| 863 | Py_VISIT(Py_TYPE(self)); |
| 864 | Py_VISIT(self->dict); |
| 865 | return 0; |
| 866 | } |
| 867 | |
| 868 | static int |
| 869 | ast_clear(PyObject *op) |
| 870 | { |
| 871 | AST_object *self = (AST_object*)op; |
| 872 | Py_CLEAR(self->dict); |
| 873 | return 0; |
| 874 | } |
| 875 | |
| 876 | static int |
| 877 | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
| 878 | { |
| 879 | struct ast_state *state = get_ast_state(); |
| 880 | if (state == NULL) { |
| 881 | return -1; |
| 882 | } |
| 883 | |
| 884 | Py_ssize_t i, numfields = 0; |
| 885 | int res = -1; |
| 886 | PyObject *key, *value, *fields, *attributes = NULL, *remaining_fields = NULL; |
| 887 | |
| 888 | fields = PyObject_GetAttr((PyObject*)Py_TYPE(self), state->_fields); |
| 889 | if (fields == NULL) { |
| 890 | goto cleanup; |
| 891 | } |
| 892 |
no outgoing calls
no test coverage detected
searching dependent graphs…