@@ -622,6 +622,9 @@ class PyTypesVisitor(PickleVisitor):
622622
623623 def visitModule (self , mod ):
624624 self .emit ("""
625+ _Py_IDENTIFIER(_fields);
626+ _Py_IDENTIFIER(_attributes);
627+
625628typedef struct {
626629 PyObject_HEAD
627630 PyObject *dict;
@@ -650,7 +653,6 @@ def visitModule(self, mod):
650653static int
651654ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
652655{
653- _Py_IDENTIFIER(_fields);
654656 Py_ssize_t i, numfields = 0;
655657 int res = -1;
656658 PyObject *key, *value, *fields;
@@ -775,6 +777,8 @@ def visitModule(self, mod):
775777
776778static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
777779{
780+ _Py_IDENTIFIER(__module__);
781+ _Py_IDENTIFIER(_ast);
778782 PyObject *fnames, *result;
779783 int i;
780784 fnames = PyTuple_New(num_fields);
@@ -787,16 +791,18 @@ def visitModule(self, mod):
787791 }
788792 PyTuple_SET_ITEM(fnames, i, field);
789793 }
790- result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
791- type, base, "_fields", fnames, "__module__", "_ast");
794+ result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}",
795+ type, base,
796+ _PyUnicode_FromId(&PyId__fields), fnames,
797+ _PyUnicode_FromId(&PyId___module__),
798+ _PyUnicode_FromId(&PyId__ast));
792799 Py_DECREF(fnames);
793800 return (PyTypeObject*)result;
794801}
795802
796803static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
797804{
798805 int i, result;
799- _Py_IDENTIFIER(_attributes);
800806 PyObject *s, *l = PyTuple_New(num_fields);
801807 if (!l)
802808 return 0;
@@ -942,8 +948,8 @@ def visitModule(self, mod):
942948 d = AST_type.tp_dict;
943949 empty_tuple = PyTuple_New(0);
944950 if (!empty_tuple ||
945- PyDict_SetItemString (d, "_fields" , empty_tuple) < 0 ||
946- PyDict_SetItemString (d, "_attributes" , empty_tuple) < 0) {
951+ _PyDict_SetItemId (d, &PyId__fields , empty_tuple) < 0 ||
952+ _PyDict_SetItemId (d, &PyId__attributes , empty_tuple) < 0) {
947953 Py_XDECREF(empty_tuple);
948954 return -1;
949955 }
@@ -1091,8 +1097,7 @@ def func_begin(self, name):
10911097 self .emit ("%s o = (%s)_o;" % (ctype , ctype ), 1 )
10921098 self .emit ("PyObject *result = NULL, *value = NULL;" , 1 )
10931099 self .emit ('if (!o) {' , 1 )
1094- self .emit ("Py_INCREF(Py_None);" , 2 )
1095- self .emit ('return Py_None;' , 2 )
1100+ self .emit ("Py_RETURN_NONE;" , 2 )
10961101 self .emit ("}" , 1 )
10971102 self .emit ('' , 0 )
10981103
0 commit comments