[Python-checkins] bpo-43372: Use _freeze_importlib for regen-frozen. (GH-24759)

nascheme webhook-mailer at python.org
Sat Mar 6 16:34:08 EST 2021


https://github.com/python/cpython/commit/87ec26b812e9c4095c017dc60f246eda37b83ab2
commit: 87ec26b812e9c4095c017dc60f246eda37b83ab2
branch: master
author: Neil Schemenauer <nas-github at arctrix.com>
committer: nascheme <nas-github at arctrix.com>
date: 2021-03-06T13:34:03-08:00
summary:

bpo-43372: Use _freeze_importlib for regen-frozen. (GH-24759)

This approach ensures the code matches the interpreter version.
Previously, PYTHON_FOR_REGEN was used to generate the code, which might
be wrong. The marshal format for code objects has changed with
bpo-42246, commit 877df851. Update the code and the expected code sizes
in ctypes test_frozentable.

files:
A Misc/NEWS.d/next/Build/2021-03-04-17-13-57.bpo-43372.FfqDVL.rst
M Lib/ctypes/test/test_values.py
M Makefile.pre.in
M Python/frozen.c
M Python/frozen_hello.h

diff --git a/Lib/ctypes/test/test_values.py b/Lib/ctypes/test/test_values.py
index 44128298390d9..b38b63f870a65 100644
--- a/Lib/ctypes/test/test_values.py
+++ b/Lib/ctypes/test/test_values.py
@@ -80,9 +80,9 @@ class struct_frozen(Structure):
                 continue
             items.append((entry.name.decode("ascii"), entry.size))
 
-        expected = [("__hello__", 125),
-                    ("__phello__", -125),
-                    ("__phello__.spam", 125),
+        expected = [("__hello__", 139),
+                    ("__phello__", -139),
+                    ("__phello__.spam", 139),
                     ]
         self.assertEqual(items, expected, "PyImport_FrozenModules example "
             "in Doc/library/ctypes.rst may be out of date")
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 0f59700952989..5d230ecb3d1f0 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -871,9 +871,13 @@ regen-opcode:
 	$(UPDATE_FILE) $(srcdir)/Include/opcode.h $(srcdir)/Include/opcode.h.new
 
 .PHONY: regen-frozen
-regen-frozen:
+regen-frozen: Programs/_freeze_importlib
 	# Regenerate code for frozen module "__hello__".
-	$(PYTHON_FOR_REGEN) $(srcdir)/Tools/freeze/regen_frozen.py $(srcdir)/Python/frozen_hello.h
+	./Programs/_freeze_importlib hello \
+		$(srcdir)/Tools/freeze/flag.py \
+		$(srcdir)/Python/frozen_hello.h.new
+	$(UPDATE_FILE) $(srcdir)/Python/frozen_hello.h \
+		$(srcdir)/Python/frozen_hello.h.new
 
 .PHONY: regen-token
 regen-token:
diff --git a/Misc/NEWS.d/next/Build/2021-03-04-17-13-57.bpo-43372.FfqDVL.rst b/Misc/NEWS.d/next/Build/2021-03-04-17-13-57.bpo-43372.FfqDVL.rst
new file mode 100644
index 0000000000000..e9c6f2a916492
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2021-03-04-17-13-57.bpo-43372.FfqDVL.rst
@@ -0,0 +1,5 @@
+Use ``_freeze_importlib`` to generate code for the ``__hello__`` module.
+This approach ensures the code matches the interpreter version.  Previously,
+PYTHON_FOR_REGEN was used to generate the code, which might be wrong.  The
+marshal format for code objects has changed with bpo-42246, commit 877df851.
+Update the code and the expected code sizes in ctypes test_frozentable.
diff --git a/Python/frozen.c b/Python/frozen.c
index d4104e166401a..7f433ff80ca12 100644
--- a/Python/frozen.c
+++ b/Python/frozen.c
@@ -11,12 +11,11 @@
    some famous words... */
 
 /* Run "make regen-frozen" to regen the file below (e.g. after a bytecode
- * format change).  The file is created by Tools/frozen/regen_frozen.py.  The
- * include file defines M___hello__ as an array of bytes.
+ * format change).  The include file defines _Py_M__hello as an array of bytes.
  */
 #include "frozen_hello.h"
 
-#define SIZE (int)sizeof(M___hello__)
+#define SIZE (int)sizeof(_Py_M__hello)
 
 static const struct _frozen _PyImport_FrozenModules[] = {
     /* importlib */
@@ -27,10 +26,10 @@ static const struct _frozen _PyImport_FrozenModules[] = {
     {"zipimport", _Py_M__zipimport,
         (int)sizeof(_Py_M__zipimport)},
     /* Test module */
-    {"__hello__", M___hello__, SIZE},
+    {"__hello__", _Py_M__hello, SIZE},
     /* Test package (negative size indicates package-ness) */
-    {"__phello__", M___hello__, -SIZE},
-    {"__phello__.spam", M___hello__, SIZE},
+    {"__phello__", _Py_M__hello, -SIZE},
+    {"__phello__.spam", _Py_M__hello, SIZE},
     {0, 0, 0} /* sentinel */
 };
 
diff --git a/Python/frozen_hello.h b/Python/frozen_hello.h
index 9c566cc81ebf0..c2101f425b41e 100644
--- a/Python/frozen_hello.h
+++ b/Python/frozen_hello.h
@@ -1,13 +1,12 @@
-/* Generated with Tools/freeze/regen_frozen.py */
-static unsigned char M___hello__[] = {
-    227,0,0,0,0,0,0,0,0,0,0,0,0,
-    0,0,0,0,2,0,0,0,64,0,0,0,115,
-    16,0,0,0,100,0,90,0,101,1,100,1,131,
-    1,1,0,100,2,83,0,41,3,84,122,12,72,
-    101,108,108,111,32,119,111,114,108,100,33,78,41,
-    2,90,11,105,110,105,116,105,97,108,105,122,101,
-    100,218,5,112,114,105,110,116,169,0,114,2,0,
-    0,0,114,2,0,0,0,218,4,110,111,110,101,
-    218,8,60,109,111,100,117,108,101,62,1,0,0,
-    0,115,2,0,0,0,4,1,
+/* Auto-generated by Programs/_freeze_importlib.c */
+const unsigned char _Py_M__hello[] = {
+    99,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,2,0,0,0,64,0,0,0,115,16,0,0,0,100,0,
+    90,0,101,1,100,1,131,1,1,0,100,2,83,0,41,3,
+    84,122,12,72,101,108,108,111,32,119,111,114,108,100,33,78,
+    41,2,90,11,105,110,105,116,105,97,108,105,122,101,100,218,
+    5,112,114,105,110,116,169,0,114,1,0,0,0,114,1,0,
+    0,0,122,14,60,102,114,111,122,101,110,32,104,101,108,108,
+    111,62,218,8,60,109,111,100,117,108,101,62,1,0,0,0,
+    115,6,0,0,0,4,0,12,1,255,128,
 };



More information about the Python-checkins mailing list