_PyRuntime.cached_objects.NAME
struct _Py_cached_objects {
- PyObject *str_replace_inf;
-
PyObject *interned_strings;
};
(interp)->cached_objects.NAME
struct _Py_interp_cached_objects {
- int _not_set;
+ /* AST */
+ PyObject *str_replace_inf;
+
/* object.__reduce__ */
PyObject *objreduce;
PyObject *type_slots_pname;
pytype_slotdef *type_slots_ptrs[MAX_EQUIV];
+
};
#define _Py_INTERP_STATIC_OBJECT(interp, NAME) \
for s in module_state:
f.write(" Py_CLEAR(state->" + s + ');\n')
f.write(textwrap.dedent("""
- if (_PyInterpreterState_Get() == _PyInterpreterState_Main()) {
- Py_CLEAR(_Py_CACHED_OBJECT(str_replace_inf));
- }
+ Py_CLEAR(_Py_INTERP_CACHED_OBJECT(interp, str_replace_inf));
#if !defined(NDEBUG)
state->initialized = -1;
Py_CLEAR(state->vararg);
Py_CLEAR(state->withitem_type);
- if (_PyInterpreterState_Get() == _PyInterpreterState_Main()) {
- Py_CLEAR(_Py_CACHED_OBJECT(str_replace_inf));
- }
+ Py_CLEAR(_Py_INTERP_CACHED_OBJECT(interp, str_replace_inf));
#if !defined(NDEBUG)
state->initialized = -1;
#include "Python.h"
#include "pycore_ast.h" // expr_ty
+#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_runtime.h" // _Py_ID()
#include <float.h> // DBL_MAX_10_EXP
#include <stdbool.h>
_Py_DECLARE_STR(dbl_open_br, "{{");
_Py_DECLARE_STR(close_br, "}");
_Py_DECLARE_STR(dbl_close_br, "}}");
-#define _str_replace_inf _Py_CACHED_OBJECT(str_replace_inf)
+
+/* We would statically initialize this if doing so were simple enough. */
+#define _str_replace_inf(interp) \
+ _Py_INTERP_CACHED_OBJECT(interp, str_replace_inf)
/* Forward declarations for recursion via helper functions. */
static PyObject *
if ((PyFloat_CheckExact(obj) && Py_IS_INFINITY(PyFloat_AS_DOUBLE(obj))) ||
PyComplex_CheckExact(obj))
{
+ PyInterpreterState *interp = _PyInterpreterState_GET();
PyObject *new_repr = PyUnicode_Replace(
repr,
&_Py_ID(inf),
- _str_replace_inf,
+ _str_replace_inf(interp),
-1
);
Py_DECREF(repr);
static int
maybe_init_static_strings(void)
{
- if (!_str_replace_inf &&
- !(_str_replace_inf = PyUnicode_FromFormat("1e%d", 1 + DBL_MAX_10_EXP))) {
- return -1;
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ if (_str_replace_inf(interp) == NULL) {
+ PyObject *tmp = PyUnicode_FromFormat("1e%d", 1 + DBL_MAX_10_EXP);
+ if (tmp == NULL) {
+ return -1;
+ }
+ _str_replace_inf(interp) = tmp;
}
return 0;
}