diff options
author | Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> | 2022-02-09 16:52:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-09 16:52:42 (GMT) |
commit | c0a5ebeb1239020f2ecc199053bb1a70d78841a1 (patch) | |
tree | d22793b254aaab45ddb161502d15796f4918f9aa | |
parent | 128ab092cad984b73a117f58fa0e9b4105051a04 (diff) | |
download | cpython-c0a5ebeb1239020f2ecc199053bb1a70d78841a1.zip cpython-c0a5ebeb1239020f2ecc199053bb1a70d78841a1.tar.gz cpython-c0a5ebeb1239020f2ecc199053bb1a70d78841a1.tar.bz2 |
bpo-46430: Intern strings in deep-frozen modules (GH-30683)
-rw-r--r-- | Include/internal/pycore_code.h | 2 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Build/2022-01-19-11-08-32.bpo-46430.k403m_.rst | 1 | ||||
-rw-r--r-- | Objects/codeobject.c | 12 | ||||
-rw-r--r-- | Tools/scripts/deepfreeze.py | 1 |
4 files changed, 16 insertions, 0 deletions
diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h index 3897ea0..2d8fe20 100644 --- a/Include/internal/pycore_code.h +++ b/Include/internal/pycore_code.h @@ -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 index 0000000..2929c51 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2022-01-19-11-08-32.bpo-46430.k403m_.rst @@ -0,0 +1 @@ +Intern strings in deep-frozen modules. Patch by Kumar Aditya.
\ No newline at end of file diff --git a/Objects/codeobject.c b/Objects/codeobject.c index bb8ffa7..efb5146 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -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; +} diff --git a/Tools/scripts/deepfreeze.py b/Tools/scripts/deepfreeze.py index 080980f..0edf3af 100644 --- a/Tools/scripts/deepfreeze.py +++ b/Tools/scripts/deepfreeze.py @@ -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: |