@@ -603,6 +603,11 @@ class PyTypesVisitor(PickleVisitor):
603603
604604 def visitModule (self , mod ):
605605 self .emit ("""
606+ typedef struct {
607+ PyObject_HEAD;
608+ PyObject *dict;
609+ } AST_object;
610+
606611static int
607612ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
608613{
@@ -681,10 +686,15 @@ def visitModule(self, mod):
681686 {NULL}
682687};
683688
689+ static PyGetSetDef ast_type_getsets[] = {
690+ {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
691+ {NULL}
692+ };
693+
684694static PyTypeObject AST_type = {
685695 PyVarObject_HEAD_INIT(&PyType_Type, 0)
686696 "_ast.AST",
687- sizeof(PyObject ),
697+ sizeof(AST_object ),
688698 0,
689699 0, /* tp_dealloc */
690700 0, /* tp_print */
@@ -711,12 +721,12 @@ def visitModule(self, mod):
711721 0, /* tp_iternext */
712722 ast_type_methods, /* tp_methods */
713723 0, /* tp_members */
714- 0, /* tp_getset */
724+ ast_type_getsets, /* tp_getset */
715725 0, /* tp_base */
716726 0, /* tp_dict */
717727 0, /* tp_descr_get */
718728 0, /* tp_descr_set */
719- 0, /* tp_dictoffset */
729+ offsetof(AST_object, dict), /* tp_dictoffset */
720730 (initproc)ast_type_init, /* tp_init */
721731 PyType_GenericAlloc, /* tp_alloc */
722732 PyType_GenericNew, /* tp_new */
@@ -1185,6 +1195,8 @@ def main(srcfile):
11851195 p = os .path .join (SRC_DIR , str (mod .name ) + "-ast.c" )
11861196 f = open (p , "w" )
11871197 f .write (auto_gen_msg )
1198+ f .write ('#include <stddef.h>\n ' )
1199+ f .write ('\n ' )
11881200 f .write ('#include "Python.h"\n ' )
11891201 f .write ('#include "%s-ast.h"\n ' % mod .name )
11901202 f .write ('\n ' )
0 commit comments