Skip to content

Commit 15d4c9f

Browse files
authored
GH-108716: Turn off deep-freezing of code objects. (GH-108722)
1 parent 00cf626 commit 15d4c9f

File tree

15 files changed

+50
-86
lines changed

15 files changed

+50
-86
lines changed

Include/cpython/import.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ struct _frozen {
1717
const unsigned char *code;
1818
int size;
1919
int is_package;
20-
PyObject *(*get_code)(void);
2120
};
2221

2322
/* Embedding apps may change this pointer to point to their favorite

Include/internal/pycore_code.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,6 @@ adaptive_counter_backoff(uint16_t counter) {
465465
return adaptive_counter_bits(value, backoff);
466466
}
467467

468-
extern uint32_t _Py_next_func_version;
469-
470468

471469
/* Comparison bit masks. */
472470

Include/internal/pycore_interp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ struct _is {
186186
_PyOptimizerObject *optimizer;
187187
uint16_t optimizer_resume_threshold;
188188
uint16_t optimizer_backedge_threshold;
189+
uint32_t next_func_version;
189190

190191
_Py_GlobalMonitors monitors;
191192
bool f_opcode_trace_set;

Lib/test/test_ctypes/test_values.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ class struct_frozen(Structure):
5858
("code", POINTER(c_ubyte)),
5959
("size", c_int),
6060
("is_package", c_int),
61-
("get_code", POINTER(c_ubyte)), # Function ptr
6261
]
6362
FrozenTable = POINTER(struct_frozen)
6463

Makefile.pre.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,6 @@ LIBRARY_OBJS_OMIT_FROZEN= \
505505

506506
LIBRARY_OBJS= \
507507
$(LIBRARY_OBJS_OMIT_FROZEN) \
508-
$(DEEPFREEZE_OBJS) \
509508
Modules/getpath.o \
510509
Python/frozen.o
511510

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Turn off deep-freezing of code objects. Modules are still frozen, so that a
2+
file system search is not needed for common modules.

Objects/codeobject.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,10 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
427427
co->co_framesize = nlocalsplus + con->stacksize + FRAME_SPECIALS_SIZE;
428428
co->co_ncellvars = ncellvars;
429429
co->co_nfreevars = nfreevars;
430-
co->co_version = _Py_next_func_version;
431-
if (_Py_next_func_version != 0) {
432-
_Py_next_func_version++;
430+
PyInterpreterState *interp = _PyInterpreterState_GET();
431+
co->co_version = interp->next_func_version;
432+
if (interp->next_func_version != 0) {
433+
interp->next_func_version++;
433434
}
434435
co->_co_monitoring = NULL;
435436
co->_co_instrumentation_version = 0;

Objects/funcobject.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include "Python.h"
55
#include "pycore_ceval.h" // _PyEval_BuiltinsFromGlobals()
6-
#include "pycore_code.h" // _Py_next_func_version
76
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
87
#include "pycore_pyerrors.h" // _PyErr_Occurred()
98

@@ -252,11 +251,9 @@ When the function version is 0, the `CALL` bytecode is not specialized.
252251
Code object versions
253252
--------------------
254253
255-
So where to code objects get their `co_version`? There is a single
256-
static global counter, `_Py_next_func_version`. This is initialized in
257-
the generated (!) file `Python/deepfreeze/deepfreeze.c`, to 1 plus the
258-
number of deep-frozen function objects in that file.
259-
(In `_bootstrap_python.c` and `freeze_module.c` it is initialized to 1.)
254+
So where to code objects get their `co_version`?
255+
There is a per-interpreter counter, `next_func_version`.
256+
This is initialized to 1 when the interpreter is created.
260257
261258
Code objects get a new `co_version` allocated from this counter upon
262259
creation. Since code objects are nominally immutable, `co_version` can

Programs/_bootstrap_python.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include "Python/frozen_modules/zipimport.h"
1616
/* End includes */
1717

18-
uint32_t _Py_next_func_version = 1;
19-
2018
/* Empty initializer for deepfrozen modules */
2119
int _Py_Deepfreeze_Init(void)
2220
{

Programs/_freeze_module.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
# include <unistd.h>
2323
#endif
2424

25-
uint32_t _Py_next_func_version = 1;
26-
2725
/* Empty initializer for deepfrozen modules */
2826
int _Py_Deepfreeze_Init(void)
2927
{

0 commit comments

Comments
 (0)