@@ -537,8 +537,11 @@ def visitField(self, field, name, sum=None, prod=None, depth=0):
537
537
self .emit ("if (%s == NULL) goto failed;" % field .name , depth + 1 )
538
538
self .emit ("for (i = 0; i < len; i++) {" , depth + 1 )
539
539
self .emit ("%s val;" % ctype , depth + 2 )
540
- self .emit ("res = obj2ast_%s(PyList_GET_ITEM(tmp, i), &val, arena);" %
540
+ self .emit ("PyObject *tmp2 = PyList_GET_ITEM(tmp, i);" , depth + 2 )
541
+ self .emit ("Py_INCREF(tmp2);" , depth + 2 )
542
+ self .emit ("res = obj2ast_%s(tmp2, &val, arena);" %
541
543
field .type , depth + 2 , reflow = False )
544
+ self .emit ("Py_DECREF(tmp2);" , depth + 2 )
542
545
self .emit ("if (res != 0) goto failed;" , depth + 2 )
543
546
self .emit ("if (len != PyList_GET_SIZE(tmp)) {" , depth + 2 )
544
547
self .emit ("PyErr_SetString(PyExc_RuntimeError, \" %s field \\ \" %s\\ \" "
@@ -576,14 +579,14 @@ def visitProduct(self, prod, name):
576
579
if prod .attributes :
577
580
for a in prod .attributes :
578
581
self .emit_identifier (a .name )
579
- self .emit ("static char *%s_attributes[] = {" % name , 0 )
582
+ self .emit ("static const char * const %s_attributes[] = {" % name , 0 )
580
583
for a in prod .attributes :
581
584
self .emit ('"%s",' % a .name , 1 )
582
585
self .emit ("};" , 0 )
583
586
if prod .fields :
584
587
for f in prod .fields :
585
588
self .emit_identifier (f .name )
586
- self .emit ("static char *%s_fields[]={" % name ,0 )
589
+ self .emit ("static const char * const %s_fields[]={" % name ,0 )
587
590
for f in prod .fields :
588
591
self .emit ('"%s",' % f .name , 1 )
589
592
self .emit ("};" , 0 )
@@ -593,7 +596,7 @@ def visitSum(self, sum, name):
593
596
if sum .attributes :
594
597
for a in sum .attributes :
595
598
self .emit_identifier (a .name )
596
- self .emit ("static char *%s_attributes[] = {" % name , 0 )
599
+ self .emit ("static const char * const %s_attributes[] = {" % name , 0 )
597
600
for a in sum .attributes :
598
601
self .emit ('"%s",' % a .name , 1 )
599
602
self .emit ("};" , 0 )
@@ -614,7 +617,7 @@ def visitConstructor(self, cons, name):
614
617
if cons .fields :
615
618
for t in cons .fields :
616
619
self .emit_identifier (t .name )
617
- self .emit ("static char *%s_fields[]={" % cons .name , 0 )
620
+ self .emit ("static const char * const %s_fields[]={" % cons .name , 0 )
618
621
for t in cons .fields :
619
622
self .emit ('"%s",' % t .name , 1 )
620
623
self .emit ("};" ,0 )
@@ -771,7 +774,8 @@ def visitModule(self, mod):
771
774
};
772
775
773
776
774
- static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
777
+ static PyTypeObject *
778
+ make_type(const char *type, PyTypeObject *base, const char * const *fields, int num_fields)
775
779
{
776
780
_Py_IDENTIFIER(__module__);
777
781
_Py_IDENTIFIER(_ast);
@@ -780,7 +784,7 @@ def visitModule(self, mod):
780
784
fnames = PyTuple_New(num_fields);
781
785
if (!fnames) return NULL;
782
786
for (i = 0; i < num_fields; i++) {
783
- PyObject *field = PyUnicode_FromString (fields[i]);
787
+ PyObject *field = PyUnicode_InternFromString (fields[i]);
784
788
if (!field) {
785
789
Py_DECREF(fnames);
786
790
return NULL;
@@ -796,14 +800,15 @@ def visitModule(self, mod):
796
800
return (PyTypeObject*)result;
797
801
}
798
802
799
- static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
803
+ static int
804
+ add_attributes(PyTypeObject *type, const char * const *attrs, int num_fields)
800
805
{
801
806
int i, result;
802
807
PyObject *s, *l = PyTuple_New(num_fields);
803
808
if (!l)
804
809
return 0;
805
810
for (i = 0; i < num_fields; i++) {
806
- s = PyUnicode_FromString (attrs[i]);
811
+ s = PyUnicode_InternFromString (attrs[i]);
807
812
if (!s) {
808
813
Py_DECREF(l);
809
814
return 0;
@@ -1193,7 +1198,7 @@ class PartingShots(StaticVisitor):
1193
1198
{
1194
1199
mod_ty res;
1195
1200
PyObject *req_type[3];
1196
- char *req_name[] = {"Module", "Expression", "Interactive"};
1201
+ const char * const req_name[] = {"Module", "Expression", "Interactive"};
1197
1202
int isinstance;
1198
1203
1199
1204
if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
0 commit comments