Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Include/internal/pycore_tstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ typedef struct _PyThreadStateImpl {
} refcounts;

// When >1, code objects do not immortalize their non-string constants.
int suppress_immortalization;
int suppress_co_const_immortalization;
#endif

#if defined(Py_REF_DEBUG) && defined(Py_GIL_DISABLED)
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_ast/test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -2277,6 +2277,7 @@ def test_values(self):
for value in values:
with self.subTest(value=value):
result = self.compile_constant(value)
self.assertIs(result, value)
self.assertEqual(result, value)

def test_assign_to_constant(self):
Expand Down
2 changes: 1 addition & 1 deletion Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ intern_constants(PyObject *tuple, int *modified)
// Intern non-string constants in the free-threaded build
_PyThreadStateImpl *tstate = (_PyThreadStateImpl *)_PyThreadState_GET();
if (!_Py_IsImmortal(v) && !PyCode_Check(v) &&
!PyUnicode_CheckExact(v) && !tstate->suppress_immortalization)
!PyUnicode_CheckExact(v) && !tstate->suppress_co_const_immortalization)
{
PyObject *interned = intern_one_constant(v);
if (interned == NULL) {
Expand Down
8 changes: 4 additions & 4 deletions Python/bltinmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -871,13 +871,13 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
// compile() calls to get consistent frozen outputs between the default
// and free-threaded builds.
_PyThreadStateImpl *tstate = (_PyThreadStateImpl *)_PyThreadState_GET();
tstate->suppress_immortalization++;
tstate->suppress_co_const_immortalization++;
#endif

result = Py_CompileStringObject(str, filename, start[compile_mode], &cf, optimize);

#ifdef Py_GIL_DISABLED
tstate->suppress_immortalization--;
tstate->suppress_co_const_immortalization--;
#endif

Py_XDECREF(source_copy);
Expand Down Expand Up @@ -1027,11 +1027,11 @@ builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals,
// Don't immortalize code constants for explicit eval() calls
// to avoid memory leaks.
_PyThreadStateImpl *tstate = (_PyThreadStateImpl *)_PyThreadState_GET();
tstate->suppress_immortalization++;
tstate->suppress_co_const_immortalization++;
#endif
result = PyRun_StringFlags(str, Py_eval_input, globals, locals, &cf);
#ifdef Py_GIL_DISABLED
tstate->suppress_immortalization--;
tstate->suppress_co_const_immortalization--;
#endif
Py_XDECREF(source_copy);
}
Expand Down
Loading