Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Intern strings in deep-frozen modules. Patch by Kumar Aditya.
12 changes: 12 additions & 0 deletions Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions Tools/scripts/deepfreeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ def generate_code(self, name: str, code: types.CodeType) -> str:
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:
Expand Down