mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
bpo-46430: Intern strings in deep-frozen modules (GH-30683)
This commit is contained in:
parent
128ab092ca
commit
c0a5ebeb12
4 changed files with 16 additions and 0 deletions
|
@ -279,6 +279,8 @@ void _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
|
||||||
|
|
||||||
/* Deallocator function for static codeobjects used in deepfreeze.py */
|
/* Deallocator function for static codeobjects used in deepfreeze.py */
|
||||||
void _PyStaticCode_Dealloc(PyCodeObject *co);
|
void _PyStaticCode_Dealloc(PyCodeObject *co);
|
||||||
|
/* Function to intern strings of codeobjects */
|
||||||
|
void _PyStaticCode_InternStrings(PyCodeObject *co);
|
||||||
|
|
||||||
#ifdef Py_STATS
|
#ifdef Py_STATS
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Intern strings in deep-frozen modules. Patch by Kumar Aditya.
|
|
@ -1924,3 +1924,15 @@ _PyStaticCode_Dealloc(PyCodeObject *co)
|
||||||
co->co_weakreflist = NULL;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -279,6 +279,7 @@ class Printer:
|
||||||
self.write(f".co_cellvars = {co_cellvars},")
|
self.write(f".co_cellvars = {co_cellvars},")
|
||||||
self.write(f".co_freevars = {co_freevars},")
|
self.write(f".co_freevars = {co_freevars},")
|
||||||
self.deallocs.append(f"_PyStaticCode_Dealloc(&{name});")
|
self.deallocs.append(f"_PyStaticCode_Dealloc(&{name});")
|
||||||
|
self.patchups.append(f"_PyStaticCode_InternStrings(&{name});")
|
||||||
return f"& {name}.ob_base"
|
return f"& {name}.ob_base"
|
||||||
|
|
||||||
def generate_tuple(self, name: str, t: Tuple[object, ...]) -> str:
|
def generate_tuple(self, name: str, t: Tuple[object, ...]) -> str:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue