summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2022-11-16 17:37:29 (GMT)
committerGitHub <noreply@github.com>2022-11-16 17:37:29 (GMT)
commit9db1e17c80217d7b18a2f44297d72acd10ee73d6 (patch)
tree4d0256b80f512133b1fb6db73a68da5bdbe22c5c /Include
parent8211cf5d287acfd815b6a7f6471cdf83dcd2bb9b (diff)
downloadcpython-9db1e17c80217d7b18a2f44297d72acd10ee73d6.zip
cpython-9db1e17c80217d7b18a2f44297d72acd10ee73d6.tar.gz
cpython-9db1e17c80217d7b18a2f44297d72acd10ee73d6.tar.bz2
gh-81057: Move the global Dict-Related Versions to _PyRuntimeState (gh-99497)
We also move the global func version. https://github.com/python/cpython/issues/81057
Diffstat (limited to 'Include')
-rw-r--r--Include/internal/pycore_dict.h28
-rw-r--r--Include/internal/pycore_dict_state.h47
-rw-r--r--Include/internal/pycore_function.h4
-rw-r--r--Include/internal/pycore_interp.h4
-rw-r--r--Include/internal/pycore_runtime.h4
-rw-r--r--Include/internal/pycore_runtime_init.h6
6 files changed, 67 insertions, 26 deletions
diff --git a/Include/internal/pycore_dict.h b/Include/internal/pycore_dict.h
index ae4094a..25bd3bf 100644
--- a/Include/internal/pycore_dict.h
+++ b/Include/internal/pycore_dict.h
@@ -9,6 +9,9 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif
+#include "pycore_dict_state.h"
+#include "pycore_runtime.h" // _PyRuntime
+
/* runtime lifecycle */
@@ -17,25 +20,6 @@ extern void _PyDict_Fini(PyInterpreterState *interp);
/* other API */
-#ifndef WITH_FREELISTS
-// without freelists
-# define PyDict_MAXFREELIST 0
-#endif
-
-#ifndef PyDict_MAXFREELIST
-# define PyDict_MAXFREELIST 80
-#endif
-
-struct _Py_dict_state {
-#if PyDict_MAXFREELIST > 0
- /* Dictionary reuse scheme to save calls to malloc and free */
- PyDictObject *free_list[PyDict_MAXFREELIST];
- int numfree;
- PyDictKeysObject *keys_free_list[PyDict_MAXFREELIST];
- int keys_numfree;
-#endif
-};
-
typedef struct {
/* Cached hash code of me_key. */
Py_hash_t me_hash;
@@ -152,13 +136,11 @@ struct _dictvalues {
(PyDictUnicodeEntry*)(&((int8_t*)((dk)->dk_indices))[(size_t)1 << (dk)->dk_log2_index_bytes]))
#define DK_IS_UNICODE(dk) ((dk)->dk_kind != DICT_KEYS_GENERAL)
-extern uint64_t _pydict_global_version;
-
-#define DICT_MAX_WATCHERS 8
#define DICT_VERSION_INCREMENT (1 << DICT_MAX_WATCHERS)
#define DICT_VERSION_MASK (DICT_VERSION_INCREMENT - 1)
-#define DICT_NEXT_VERSION() (_pydict_global_version += DICT_VERSION_INCREMENT)
+#define DICT_NEXT_VERSION() \
+ (_PyRuntime.dict_state.global_version += DICT_VERSION_INCREMENT)
void
_PyDict_SendEvent(int watcher_bits,
diff --git a/Include/internal/pycore_dict_state.h b/Include/internal/pycore_dict_state.h
new file mode 100644
index 0000000..77375ea
--- /dev/null
+++ b/Include/internal/pycore_dict_state.h
@@ -0,0 +1,47 @@
+#ifndef Py_INTERNAL_DICT_STATE_H
+#define Py_INTERNAL_DICT_STATE_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef Py_BUILD_CORE
+# error "this header requires Py_BUILD_CORE define"
+#endif
+
+
+struct _Py_dict_runtime_state {
+ /*Global counter used to set ma_version_tag field of dictionary.
+ * It is incremented each time that a dictionary is created and each
+ * time that a dictionary is modified. */
+ uint64_t global_version;
+ uint32_t next_keys_version;
+};
+
+
+#ifndef WITH_FREELISTS
+// without freelists
+# define PyDict_MAXFREELIST 0
+#endif
+
+#ifndef PyDict_MAXFREELIST
+# define PyDict_MAXFREELIST 80
+#endif
+
+#define DICT_MAX_WATCHERS 8
+
+struct _Py_dict_state {
+#if PyDict_MAXFREELIST > 0
+ /* Dictionary reuse scheme to save calls to malloc and free */
+ PyDictObject *free_list[PyDict_MAXFREELIST];
+ PyDictKeysObject *keys_free_list[PyDict_MAXFREELIST];
+ int numfree;
+ int keys_numfree;
+#endif
+ PyDict_WatchCallback watchers[DICT_MAX_WATCHERS];
+};
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_INTERNAL_DICT_STATE_H */
diff --git a/Include/internal/pycore_function.h b/Include/internal/pycore_function.h
index 1c87aa3..c95190f 100644
--- a/Include/internal/pycore_function.h
+++ b/Include/internal/pycore_function.h
@@ -8,6 +8,10 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif
+struct _py_func_runtime_state {
+ uint32_t next_version;
+};
+
extern PyFunctionObject* _PyFunction_FromConstructor(PyFrameConstructor *constr);
extern uint32_t _PyFunction_GetVersionForCurrentState(PyFunctionObject *func);
diff --git a/Include/internal/pycore_interp.h b/Include/internal/pycore_interp.h
index b7fc4b4..437bf74 100644
--- a/Include/internal/pycore_interp.h
+++ b/Include/internal/pycore_interp.h
@@ -14,7 +14,7 @@ extern "C" {
#include "pycore_ast_state.h" // struct ast_state
#include "pycore_code.h" // struct callable_cache
#include "pycore_context.h" // struct _Py_context_state
-#include "pycore_dict.h" // struct _Py_dict_state
+#include "pycore_dict_state.h" // struct _Py_dict_state
#include "pycore_exceptions.h" // struct _Py_exc_state
#include "pycore_floatobject.h" // struct _Py_float_state
#include "pycore_genobject.h" // struct _Py_async_gen_state
@@ -171,8 +171,6 @@ struct _is {
// Initialized to _PyEval_EvalFrameDefault().
_PyFrameEvalFunction eval_frame;
- PyDict_WatchCallback dict_watchers[DICT_MAX_WATCHERS];
-
Py_ssize_t co_extra_user_count;
freefunc co_extra_freefuncs[MAX_CO_EXTRA_USERS];
diff --git a/Include/internal/pycore_runtime.h b/Include/internal/pycore_runtime.h
index f8b9880..c1829cb 100644
--- a/Include/internal/pycore_runtime.h
+++ b/Include/internal/pycore_runtime.h
@@ -9,8 +9,10 @@ extern "C" {
#endif
#include "pycore_atomic.h" /* _Py_atomic_address */
+#include "pycore_dict_state.h" // struct _Py_dict_runtime_state
#include "pycore_dtoa.h" // struct _dtoa_runtime_state
#include "pycore_floatobject.h" // struct _Py_float_runtime_state
+#include "pycore_function.h" // struct _func_runtime_state
#include "pycore_gil.h" // struct _gil_runtime_state
#include "pycore_global_objects.h" // struct _Py_global_objects
#include "pycore_import.h" // struct _import_runtime_state
@@ -151,6 +153,8 @@ typedef struct pyruntimestate {
struct _Py_float_runtime_state float_state;
struct _Py_unicode_runtime_state unicode_state;
+ struct _Py_dict_runtime_state dict_state;
+ struct _py_func_runtime_state func_state;
struct {
/* Used to set PyTypeObject.tp_version_tag */
diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h
index 334928e..ab53876 100644
--- a/Include/internal/pycore_runtime_init.h
+++ b/Include/internal/pycore_runtime_init.h
@@ -58,6 +58,12 @@ extern "C" {
.float_format = _py_float_format_unknown, \
.double_format = _py_float_format_unknown, \
}, \
+ .dict_state = { \
+ .next_keys_version = 2, \
+ }, \
+ .func_state = { \
+ .next_version = 1, \
+ }, \
.types = { \
.next_version_tag = 1, \
}, \