]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46430: Intern strings in deep-frozen modules (GH-30683)
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Wed, 9 Feb 2022 16:52:42 +0000 (22:22 +0530)
committerGitHub <noreply@github.com>
Wed, 9 Feb 2022 16:52:42 +0000 (08:52 -0800)
Include/internal/pycore_code.h
Misc/NEWS.d/next/Build/2022-01-19-11-08-32.bpo-46430.k403m_.rst [new file with mode: 0644]
Objects/codeobject.c
Tools/scripts/deepfreeze.py

index 3897ea0ab6a1a68c484bfea1729dfcd42b8d770b..2d8fe20e1a6f0bbc0226154577df3bd38b8e2a53 100644 (file)
@@ -279,6 +279,8 @@ void _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
 
 /* Deallocator function for static codeobjects used in deepfreeze.py */
 void _PyStaticCode_Dealloc(PyCodeObject *co);
+/* Function to intern strings of codeobjects */
+void _PyStaticCode_InternStrings(PyCodeObject *co);
 
 #ifdef Py_STATS
 
diff --git a/Misc/NEWS.d/next/Build/2022-01-19-11-08-32.bpo-46430.k403m_.rst b/Misc/NEWS.d/next/Build/2022-01-19-11-08-32.bpo-46430.k403m_.rst
new file mode 100644 (file)
index 0000000..2929c51
--- /dev/null
@@ -0,0 +1 @@
+Intern strings in deep-frozen modules. Patch by Kumar Aditya.
\ No newline at end of file
index bb8ffa794a96d3243ae6f0549c61fbcedd0720fc..efb51464bd87a168f3ad3009ec68ca3601dd41ff 100644 (file)
@@ -1924,3 +1924,15 @@ _PyStaticCode_Dealloc(PyCodeObject *co)
         co->co_weakreflist = NULL;
     }
 }
+
+void
+_PyStaticCode_InternStrings(PyCodeObject *co) 
+{
+    int res = intern_strings(co->co_names);
+    assert(res == 0);
+    res = intern_string_constants(co->co_consts, NULL);
+    assert(res == 0);
+    res = intern_strings(co->co_localsplusnames);
+    assert(res == 0);
+    (void)res;
+}
index 080980f6d0ae5d94c9d73f708949facab9260ef5..0edf3af71d9934d1057243d329a3d1e8ddcedc98 100644 (file)
@@ -279,6 +279,7 @@ class Printer:
             self.write(f".co_cellvars = {co_cellvars},")
             self.write(f".co_freevars = {co_freevars},")
         self.deallocs.append(f"_PyStaticCode_Dealloc(&{name});")
+        self.patchups.append(f"_PyStaticCode_InternStrings(&{name});")
         return f"& {name}.ob_base"
 
     def generate_tuple(self, name: str, t: Tuple[object, ...]) -> str: