Skip to content

Commit 44b0e76

Browse files
authoredDec 9, 2021
bpo-45654: Freeze the runpy module and stuff it imports (pythonGH-29903)
1 parent dc4a212 commit 44b0e76

File tree

7 files changed

+101
-0
lines changed

7 files changed

+101
-0
lines changed
 

‎Makefile.pre.in

+36
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,10 @@ DEEPFREEZE_OBJS = \
490490
Python/deepfreeze/os.o \
491491
Python/deepfreeze/site.o \
492492
Python/deepfreeze/stat.o \
493+
Python/deepfreeze/types.o \
494+
Python/deepfreeze/importlib.util.o \
495+
Python/deepfreeze/importlib.machinery.o \
496+
Python/deepfreeze/runpy.o \
493497
Python/deepfreeze/__hello__.o \
494498
Python/deepfreeze/__phello__.o \
495499
Python/deepfreeze/__phello__.ham.o \
@@ -1010,6 +1014,18 @@ Python/deepfreeze/site.c: Python/frozen_modules/site.h $(DEEPFREEZE_DEPS)
10101014
Python/deepfreeze/stat.c: Python/frozen_modules/stat.h $(DEEPFREEZE_DEPS)
10111015
$(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/stat.h -m stat -o Python/deepfreeze/stat.c
10121016

1017+
Python/deepfreeze/types.c: Python/frozen_modules/types.h $(DEEPFREEZE_DEPS)
1018+
$(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/types.h -m types -o Python/deepfreeze/types.c
1019+
1020+
Python/deepfreeze/importlib.util.c: Python/frozen_modules/importlib.util.h $(DEEPFREEZE_DEPS)
1021+
$(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/importlib.util.h -m importlib.util -o Python/deepfreeze/importlib.util.c
1022+
1023+
Python/deepfreeze/importlib.machinery.c: Python/frozen_modules/importlib.machinery.h $(DEEPFREEZE_DEPS)
1024+
$(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/importlib.machinery.h -m importlib.machinery -o Python/deepfreeze/importlib.machinery.c
1025+
1026+
Python/deepfreeze/runpy.c: Python/frozen_modules/runpy.h $(DEEPFREEZE_DEPS)
1027+
$(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/runpy.h -m runpy -o Python/deepfreeze/runpy.c
1028+
10131029
Python/deepfreeze/__hello__.c: Python/frozen_modules/__hello__.h $(DEEPFREEZE_DEPS)
10141030
$(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/__hello__.h -m __hello__ -o Python/deepfreeze/__hello__.c
10151031

@@ -1049,6 +1065,10 @@ FROZEN_FILES_IN = \
10491065
Lib/os.py \
10501066
Lib/site.py \
10511067
Lib/stat.py \
1068+
Lib/types.py \
1069+
Lib/importlib/util.py \
1070+
Lib/importlib/machinery.py \
1071+
Lib/runpy.py \
10521072
Lib/__hello__.py \
10531073
Lib/__phello__/__init__.py \
10541074
Lib/__phello__/ham/__init__.py \
@@ -1071,6 +1091,10 @@ FROZEN_FILES_OUT = \
10711091
Python/frozen_modules/os.h \
10721092
Python/frozen_modules/site.h \
10731093
Python/frozen_modules/stat.h \
1094+
Python/frozen_modules/types.h \
1095+
Python/frozen_modules/importlib.util.h \
1096+
Python/frozen_modules/importlib.machinery.h \
1097+
Python/frozen_modules/runpy.h \
10741098
Python/frozen_modules/__hello__.h \
10751099
Python/frozen_modules/__phello__.h \
10761100
Python/frozen_modules/__phello__.ham.h \
@@ -1130,6 +1154,18 @@ Python/frozen_modules/site.h: $(FREEZE_MODULE) Lib/site.py
11301154
Python/frozen_modules/stat.h: $(FREEZE_MODULE) Lib/stat.py
11311155
$(FREEZE_MODULE) stat $(srcdir)/Lib/stat.py Python/frozen_modules/stat.h
11321156

1157+
Python/frozen_modules/types.h: $(FREEZE_MODULE) Lib/types.py
1158+
$(FREEZE_MODULE) types $(srcdir)/Lib/types.py Python/frozen_modules/types.h
1159+
1160+
Python/frozen_modules/importlib.util.h: $(FREEZE_MODULE) Lib/importlib/util.py
1161+
$(FREEZE_MODULE) importlib.util $(srcdir)/Lib/importlib/util.py Python/frozen_modules/importlib.util.h
1162+
1163+
Python/frozen_modules/importlib.machinery.h: $(FREEZE_MODULE) Lib/importlib/machinery.py
1164+
$(FREEZE_MODULE) importlib.machinery $(srcdir)/Lib/importlib/machinery.py Python/frozen_modules/importlib.machinery.h
1165+
1166+
Python/frozen_modules/runpy.h: $(FREEZE_MODULE) Lib/runpy.py
1167+
$(FREEZE_MODULE) runpy $(srcdir)/Lib/runpy.py Python/frozen_modules/runpy.h
1168+
11331169
Python/frozen_modules/__hello__.h: $(FREEZE_MODULE) Lib/__hello__.py
11341170
$(FREEZE_MODULE) __hello__ $(srcdir)/Lib/__hello__.py Python/frozen_modules/__hello__.h
11351171

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deepfreeze :mod:`runpy`, patch by Kumar Aditya.

‎PCbuild/_freeze_module.vcxproj

+28
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,34 @@
330330
<DeepIntFile>$(IntDir)stat.g.c</DeepIntFile>
331331
<DeepOutFile>$(PySourcePath)Python\deepfreeze\df.stat.c</DeepOutFile>
332332
</None>
333+
<None Include="..\Lib\types.py">
334+
<ModName>types</ModName>
335+
<IntFile>$(IntDir)types.g.h</IntFile>
336+
<OutFile>$(PySourcePath)Python\frozen_modules\types.h</OutFile>
337+
<DeepIntFile>$(IntDir)types.g.c</DeepIntFile>
338+
<DeepOutFile>$(PySourcePath)Python\deepfreeze\df.types.c</DeepOutFile>
339+
</None>
340+
<None Include="..\Lib\importlib\util.py">
341+
<ModName>importlib.util</ModName>
342+
<IntFile>$(IntDir)importlib.util.g.h</IntFile>
343+
<OutFile>$(PySourcePath)Python\frozen_modules\importlib.util.h</OutFile>
344+
<DeepIntFile>$(IntDir)importlib.util.g.c</DeepIntFile>
345+
<DeepOutFile>$(PySourcePath)Python\deepfreeze\df.importlib.util.c</DeepOutFile>
346+
</None>
347+
<None Include="..\Lib\importlib\machinery.py">
348+
<ModName>importlib.machinery</ModName>
349+
<IntFile>$(IntDir)importlib.machinery.g.h</IntFile>
350+
<OutFile>$(PySourcePath)Python\frozen_modules\importlib.machinery.h</OutFile>
351+
<DeepIntFile>$(IntDir)importlib.machinery.g.c</DeepIntFile>
352+
<DeepOutFile>$(PySourcePath)Python\deepfreeze\df.importlib.machinery.c</DeepOutFile>
353+
</None>
354+
<None Include="..\Lib\runpy.py">
355+
<ModName>runpy</ModName>
356+
<IntFile>$(IntDir)runpy.g.h</IntFile>
357+
<OutFile>$(PySourcePath)Python\frozen_modules\runpy.h</OutFile>
358+
<DeepIntFile>$(IntDir)runpy.g.c</DeepIntFile>
359+
<DeepOutFile>$(PySourcePath)Python\deepfreeze\df.runpy.c</DeepOutFile>
360+
</None>
333361
<None Include="..\Lib\__hello__.py">
334362
<ModName>__hello__</ModName>
335363
<IntFile>$(IntDir)__hello__.g.h</IntFile>

‎PCbuild/_freeze_module.vcxproj.filters

+12
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,18 @@
447447
<None Include="..\Lib\stat.py">
448448
<Filter>Python Files</Filter>
449449
</None>
450+
<None Include="..\Lib\types.py">
451+
<Filter>Python Files</Filter>
452+
</None>
453+
<None Include="..\Lib\importlib\util.py">
454+
<Filter>Python Files</Filter>
455+
</None>
456+
<None Include="..\Lib\importlib\machinery.py">
457+
<Filter>Python Files</Filter>
458+
</None>
459+
<None Include="..\Lib\runpy.py">
460+
<Filter>Python Files</Filter>
461+
</None>
450462
<None Include="..\Lib\__hello__.py">
451463
<Filter>Python Files</Filter>
452464
</None>

‎PCbuild/pythoncore.vcxproj

+4
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,10 @@
532532
<ClCompile Include="..\Python\deepfreeze\df.os.c" />
533533
<ClCompile Include="..\Python\deepfreeze\df.site.c" />
534534
<ClCompile Include="..\Python\deepfreeze\df.stat.c" />
535+
<ClCompile Include="..\Python\deepfreeze\df.types.c" />
536+
<ClCompile Include="..\Python\deepfreeze\df.importlib.util.c" />
537+
<ClCompile Include="..\Python\deepfreeze\df.importlib.machinery.c" />
538+
<ClCompile Include="..\Python\deepfreeze\df.runpy.c" />
535539
<ClCompile Include="..\Python\deepfreeze\df.__hello__.c" />
536540
<ClCompile Include="..\Python\deepfreeze\df.__phello__.c" />
537541
<ClCompile Include="..\Python\deepfreeze\df.__phello__.ham.c" />

‎Python/frozen.c

+14
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
#include "frozen_modules/os.h"
5454
#include "frozen_modules/site.h"
5555
#include "frozen_modules/stat.h"
56+
#include "frozen_modules/types.h"
57+
#include "frozen_modules/importlib.util.h"
58+
#include "frozen_modules/importlib.machinery.h"
59+
#include "frozen_modules/runpy.h"
5660
#include "frozen_modules/__hello__.h"
5761
#include "frozen_modules/__phello__.h"
5862
#include "frozen_modules/__phello__.ham.h"
@@ -79,6 +83,10 @@ extern PyObject *_Py_get_posixpath_toplevel(void);
7983
extern PyObject *_Py_get_os_toplevel(void);
8084
extern PyObject *_Py_get_site_toplevel(void);
8185
extern PyObject *_Py_get_stat_toplevel(void);
86+
extern PyObject *_Py_get_types_toplevel(void);
87+
extern PyObject *_Py_get_importlib_util_toplevel(void);
88+
extern PyObject *_Py_get_importlib_machinery_toplevel(void);
89+
extern PyObject *_Py_get_runpy_toplevel(void);
8290
extern PyObject *_Py_get___hello___toplevel(void);
8391
extern PyObject *_Py_get___hello___toplevel(void);
8492
extern PyObject *_Py_get___hello___toplevel(void);
@@ -116,6 +124,12 @@ static const struct _frozen stdlib_modules[] = {
116124
{"os", _Py_M__os, (int)sizeof(_Py_M__os), GET_CODE(os)},
117125
{"site", _Py_M__site, (int)sizeof(_Py_M__site), GET_CODE(site)},
118126
{"stat", _Py_M__stat, (int)sizeof(_Py_M__stat), GET_CODE(stat)},
127+
128+
/* runpy - run module with -m */
129+
{"types", _Py_M__types, (int)sizeof(_Py_M__types), GET_CODE(types)},
130+
{"importlib.util", _Py_M__importlib_util, (int)sizeof(_Py_M__importlib_util), GET_CODE(importlib_util)},
131+
{"importlib.machinery", _Py_M__importlib_machinery, (int)sizeof(_Py_M__importlib_machinery), GET_CODE(importlib_machinery)},
132+
{"runpy", _Py_M__runpy, (int)sizeof(_Py_M__runpy), GET_CODE(runpy)},
119133
{0, 0, 0} /* stdlib sentinel */
120134
};
121135
static const struct _frozen test_modules[] = {

‎Tools/scripts/freeze_modules.py

+6
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@
6868
'site',
6969
'stat',
7070
]),
71+
('runpy - run module with -m', [
72+
"types",
73+
"importlib.util",
74+
"importlib.machinery",
75+
"runpy"
76+
]),
7177
(TESTS_SECTION, [
7278
'__hello__',
7379
'__hello__ : __hello_alias__',

0 commit comments

Comments
 (0)
Failed to load comments.