extern PyStatus _PyImportZip_Init(PyThreadState *tstate);
extern PyStatus _PyGC_Init(PyInterpreterState *interp);
extern PyStatus _PyAtExit_Init(PyInterpreterState *interp);
-
+extern void _Py_Deepfreeze_Init(void);
/* Various internal finalizers */
#include "Python/frozen_modules/importlib._bootstrap_external.h"
/* End includes */
-/* Empty finalizer for deepfrozen modules*/
+/* Empty initializer for deepfrozen modules */
+void _Py_Deepfreeze_Init(void)
+{
+}
+/* Empty finalizer for deepfrozen modules */
void
-_Py_Deepfreeze_Fini(void)
+_Py_Deepfreeze_Fini(void)
{
}
#include <unistd.h>
#endif
+/* Empty initializer for deepfrozen modules */
+void _Py_Deepfreeze_Init(void)
+{
+}
/* Empty finalizer for deepfrozen modules */
void
_Py_Deepfreeze_Fini(void)
if (_PyStatus_EXCEPTION(status)) {
return status;
}
-
return _PyStatus_OK();
}
if (_PyStatus_EXCEPTION(status)) {
return status;
}
-
+ // Intern strings in deep-frozen modules first so that others
+ // can use it instead of creating a heap allocated string.
+ _Py_Deepfreeze_Init();
+
status = pycore_init_types(interp);
if (_PyStatus_EXCEPTION(status)) {
goto done;
self.hits, self.misses = 0, 0
self.patchups: list[str] = []
self.deallocs: list[str] = []
+ self.interns: list[str] = []
self.write('#include "Python.h"')
self.write('#include "internal/pycore_gc.h"')
self.write('#include "internal/pycore_code.h"')
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});")
+ self.interns.append(f"_PyStaticCode_InternStrings(&{name});")
return f"& {name}.ob_base"
def generate_tuple(self, name: str, t: Tuple[object, ...]) -> str:
with printer.block(f"void\n_Py_Deepfreeze_Fini(void)"):
for p in printer.deallocs:
printer.write(p)
+ with printer.block(f"void\n_Py_Deepfreeze_Init(void)"):
+ for p in printer.interns:
+ printer.write(p)
if verbose:
print(f"Cache hits: {printer.hits}, misses: {printer.misses}")