Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a leak of NaN constants in code objects created by :func:`marshal.loads`
on the free-threaded build.
12 changes: 10 additions & 2 deletions Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,16 @@ should_immortalize_constant(PyObject *v)
_Py_IsImmortal(slice->stop) &&
_Py_IsImmortal(slice->step));
}
return (PyLong_CheckExact(v) || PyFloat_CheckExact(v) ||
PyComplex_CheckExact(v) || PyBytes_CheckExact(v));
// The hash of a NaN depends on its address, so the table would keep every
// NaN object it gets (and merging them would shrink frozensets).
if (PyFloat_CheckExact(v)) {
return !isnan(PyFloat_AS_DOUBLE(v));
}
if (PyComplex_CheckExact(v)) {
Py_complex c = ((PyComplexObject *)v)->cval;
return !isnan(c.real) && !isnan(c.imag);
}
return PyLong_CheckExact(v) || PyBytes_CheckExact(v);
}
#endif

Expand Down
Loading