Skip to content

Commit aee1184

Browse files
committed
Keep test_frozenmain.h stable
1 parent d234658 commit aee1184

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Objects/codeobject.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,16 @@ PyCode_ClearWatcher(int watcher_id)
105105
static int
106106
should_intern_string(PyObject *o)
107107
{
108-
#ifndef Py_GIL_DISABLED
108+
#ifdef Py_GIL_DISABLED
109+
// The free-threaded build interns (and immortalizes) all string constants
110+
// unless we've disabled immortalizing objects that use deferred reference
111+
// counting.
112+
PyInterpreterState *interp = _PyInterpreterState_GET();
113+
if (!interp->gc.immortalize.enable_on_thread_created) {
114+
return 1;
115+
}
116+
#endif
117+
109118
// compute if s matches [a-zA-Z0-9_]
110119
const unsigned char *s, *e;
111120

@@ -118,7 +127,6 @@ should_intern_string(PyObject *o)
118127
if (!Py_ISALNUM(*s) && *s != '_')
119128
return 0;
120129
}
121-
#endif
122130
return 1;
123131
}
124132

Programs/freeze_test_frozenmain.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import tokenize
33
import os.path
44
import sys
5+
from test.support import suppress_immortalization
56

67
PROGRAM_DIR = os.path.dirname(__file__)
78
SRC_DIR = os.path.dirname(PROGRAM_DIR)
@@ -24,7 +25,11 @@ def dump(fp, filename, name):
2425

2526
with tokenize.open(filename) as source_fp:
2627
source = source_fp.read()
27-
code = compile(source, code_filename, 'exec')
28+
# The output of marshal can depend on the reference count so suppress
29+
# immortalization in the free-threaded build to keep the output
30+
# consistent with the default build.
31+
with suppress_immortalization():
32+
code = compile(source, code_filename, 'exec')
2833

2934
data = marshal.dumps(code)
3035
writecode(fp, name, data)

0 commit comments

Comments
 (0)