]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-36876: Moved Parser/listnode.c statics to interpreter state. (GH-16328)
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Thu, 7 Nov 2019 10:08:58 +0000 (10:08 +0000)
committerGitHub <noreply@github.com>
Thu, 7 Nov 2019 10:08:58 +0000 (10:08 +0000)
Include/internal/pycore_pystate.h
Parser/listnode.c

index 91003dbead0545da04258f567ad00e443b690c08..eb44ae93fc4c4409fba3e98b2bfed6f1a2dfd16d 100644 (file)
@@ -125,6 +125,15 @@ struct _is {
     struct _warnings_runtime_state warnings;
 
     PyObject *audit_hooks;
+/*
+ * See bpo-36876: miscellaneous ad hoc statics have been moved here.
+ */
+    struct {
+        struct {
+            int level;
+            int atbol;
+        } listnode;
+    } parser;
 };
 
 PyAPI_FUNC(struct _is*) _PyInterpreterState_LookUpID(PY_INT64_T);
index 8f1a1163b63d5c137b0d0e3b01ac655339a8c73b..d431ae537e3b412ba4edacc0d881c7f72513d0ce 100644 (file)
@@ -2,6 +2,7 @@
 /* List a node on a file */
 
 #include "Python.h"
+#include "pycore_pystate.h"
 #include "token.h"
 #include "node.h"
 
@@ -15,19 +16,21 @@ PyNode_ListTree(node *n)
     listnode(stdout, n);
 }
 
-static int level, atbol;
-
 static void
 listnode(FILE *fp, node *n)
 {
-    level = 0;
-    atbol = 1;
+    PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
+
+    interp->parser.listnode.level = 0;
+    interp->parser.listnode.atbol = 1;
     list1node(fp, n);
 }
 
 static void
 list1node(FILE *fp, node *n)
 {
+    PyInterpreterState *interp;
+
     if (n == NULL)
         return;
     if (ISNONTERMINAL(TYPE(n))) {
@@ -36,25 +39,26 @@ list1node(FILE *fp, node *n)
             list1node(fp, CHILD(n, i));
     }
     else if (ISTERMINAL(TYPE(n))) {
+        interp = _PyInterpreterState_GET_UNSAFE();
         switch (TYPE(n)) {
         case INDENT:
-            ++level;
+            interp->parser.listnode.level++;
             break;
         case DEDENT:
-            --level;
+            interp->parser.listnode.level--;
             break;
         default:
-            if (atbol) {
+            if (interp->parser.listnode.atbol) {
                 int i;
-                for (i = 0; i < level; ++i)
+                for (i = 0; i < interp->parser.listnode.level; ++i)
                     fprintf(fp, "\t");
-                atbol = 0;
+                interp->parser.listnode.atbol = 0;
             }
             if (TYPE(n) == NEWLINE) {
                 if (STR(n) != NULL)
                     fprintf(fp, "%s", STR(n));
                 fprintf(fp, "\n");
-                atbol = 1;
+                interp->parser.listnode.atbol = 1;
             }
             else
                 fprintf(fp, "%s ", STR(n));