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
Prev Previous commit
Next Next commit
Move _str_replace_inf to _PyRuntimeState.
  • Loading branch information
ericsnowcurrently committed Nov 14, 2022
commit 526d2daa3373dae6fa294371b459752cb3f8513e
7 changes: 7 additions & 0 deletions Include/internal/pycore_global_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ extern "C" {
// Only immutable objects should be considered runtime-global.
// All others must be per-interpreter.

#define _Py_CACHED_OBJECT(NAME) \
_PyRuntime.cached_objects.NAME

struct _Py_cached_objects {
PyObject *str_replace_inf;
};

#define _Py_GLOBAL_OBJECT(NAME) \
_PyRuntime.global_objects.NAME
#define _Py_SINGLETON(NAME) \
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ typedef struct pyruntimestate {
} types;

/* All the objects that are shared by the runtime's interpreters. */
struct _Py_cached_objects cached_objects;
struct _Py_global_objects global_objects;

/* The following fields are here to avoid allocation during init.
Expand Down
4 changes: 4 additions & 0 deletions Parser/asdl_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -1483,6 +1483,10 @@ def generate_ast_fini(module_state, f):
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));
}

#if !defined(NDEBUG)
state->initialized = -1;
#else
Expand Down
4 changes: 4 additions & 0 deletions Python/Python-ast.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Python/ast_unparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ _Py_DECLARE_STR(open_br, "{");
_Py_DECLARE_STR(dbl_open_br, "{{");
_Py_DECLARE_STR(close_br, "}");
_Py_DECLARE_STR(dbl_close_br, "}}");
static PyObject *_str_replace_inf;
#define _str_replace_inf _Py_CACHED_OBJECT(str_replace_inf)

/* Forward declarations for recursion via helper functions. */
static PyObject *
Expand Down
6 changes: 0 additions & 6 deletions Tools/c-analyzer/cpython/globals-to-fix.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,6 @@ Objects/setobject.c - _dummy_struct -
Objects/setobject.c - _PySet_Dummy -
Objects/sliceobject.c - _Py_EllipsisObject -

#-----------------------
# cached - initialized once

# manually cached PyUnicodeObject
Python/ast_unparse.c - _str_replace_inf -

#-----------------------
# other

Expand Down