Skip to content

Commit 46d77fd

Browse files
committed
Compute initial value of code version during deepfreeze.
1 parent 004b132 commit 46d77fd

File tree

6 files changed

+9
-4
lines changed

6 files changed

+9
-4
lines changed

Include/internal/pycore_code.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ _PyCode_LineNumberFromArray(PyCodeObject *co, int index)
455455
}
456456
}
457457

458+
extern uint32_t _Py_next_func_version;
459+
458460

459461
#ifdef __cplusplus
460462
}

Objects/codeobject.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#include "pycore_tuple.h" // _PyTuple_ITEMS()
1212
#include "clinic/codeobject.c.h"
1313

14-
extern uint32_t _Py_next_func_version;
15-
1614
/******************
1715
* generic helpers
1816
******************/

Objects/funcobject.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33

44
#include "Python.h"
55
#include "pycore_ceval.h" // _PyEval_BuiltinsFromGlobals()
6+
#include "pycore_code.h" // _Py_next_func_version
67
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
78
#include "pycore_pyerrors.h" // _PyErr_Occurred()
89
#include "structmember.h" // PyMemberDef
910

10-
uint32_t _Py_next_func_version = 10000; /* Leave plenty of space for deep frozen code objects */
11-
1211
PyFunctionObject *
1312
_PyFunction_FromConstructor(PyFrameConstructor *constr)
1413
{

Programs/_bootstrap_python.c

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

17+
uint32_t _Py_next_func_version = 1;
18+
1719
/* Empty initializer for deepfrozen modules */
1820
int _Py_Deepfreeze_Init(void)
1921
{

Programs/_freeze_module.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Keep this file in sync with Programs/_freeze_module.py.
1010
*/
1111

12+
1213
#include <Python.h>
1314
#include <marshal.h>
1415
#include "pycore_fileutils.h" // _Py_stat_struct
@@ -22,6 +23,8 @@
2223
#include <unistd.h>
2324
#endif
2425

26+
uint32_t _Py_next_func_version = 1;
27+
2528
/* Empty initializer for deepfrozen modules */
2629
int _Py_Deepfreeze_Init(void)
2730
{

Tools/build/deepfreeze.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ def generate(args: list[str], output: TextIO) -> None:
472472
with printer.block(f"if ({p} < 0)"):
473473
printer.write("return -1;")
474474
printer.write("return 0;")
475+
printer.write(f"\nuint32_t _Py_next_func_version = {next_code_version};\n")
475476
if verbose:
476477
print(f"Cache hits: {printer.hits}, misses: {printer.misses}")
477478

0 commit comments

Comments
 (0)