summaryrefslogtreecommitdiff
path: root/Include
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2022-11-16 09:37:14 -0700
committerGitHub <noreply@github.com>2022-11-16 09:37:14 -0700
commit5f55067e238c21de25f09ece9bb24ae8c42d02b4 (patch)
treef3fbce5e16aaa3a8871518c4ccb18bc8a1d86e9e /Include
parent5cfb7d19f5242c9b8ffd2fe30a24569e85a99e1d (diff)
downloadcpython-git-5f55067e238c21de25f09ece9bb24ae8c42d02b4.tar.gz
gh-81057: Move More Globals in Core Code to _PyRuntimeState (gh-99516)
https://github.com/python/cpython/issues/81057
Diffstat (limited to 'Include')
-rw-r--r--Include/cpython/modsupport.h2
-rw-r--r--Include/internal/pycore_fileutils.h5
-rw-r--r--Include/internal/pycore_floatobject.h12
-rw-r--r--Include/internal/pycore_import.h2
-rw-r--r--Include/internal/pycore_interp.h1
-rw-r--r--Include/internal/pycore_pyhash.h32
-rw-r--r--Include/internal/pycore_pylifecycle.h4
-rw-r--r--Include/internal/pycore_runtime.h12
-rw-r--r--Include/internal/pycore_runtime_init.h34
-rw-r--r--Include/internal/pycore_unicodeobject.h4
10 files changed, 87 insertions, 21 deletions
diff --git a/Include/cpython/modsupport.h b/Include/cpython/modsupport.h
index d8458923b3..88f34fe751 100644
--- a/Include/cpython/modsupport.h
+++ b/Include/cpython/modsupport.h
@@ -106,5 +106,3 @@ PyAPI_FUNC(PyObject * const *) _PyArg_UnpackKeywordsWithVararg(
(minpos), (maxpos), (minkw), (buf)))
PyAPI_FUNC(PyObject *) _PyModule_CreateInitialized(PyModuleDef*, int apiver);
-
-PyAPI_DATA(const char *) _Py_PackageContext;
diff --git a/Include/internal/pycore_fileutils.h b/Include/internal/pycore_fileutils.h
index 3ce8108e4e..ac89c43d56 100644
--- a/Include/internal/pycore_fileutils.h
+++ b/Include/internal/pycore_fileutils.h
@@ -10,6 +10,11 @@ extern "C" {
#include <locale.h> /* struct lconv */
+
+struct _fileutils_state {
+ int force_ascii;
+};
+
typedef enum {
_Py_ERROR_UNKNOWN=0,
_Py_ERROR_STRICT,
diff --git a/Include/internal/pycore_floatobject.h b/Include/internal/pycore_floatobject.h
index 8a65554332..27c63bc87f 100644
--- a/Include/internal/pycore_floatobject.h
+++ b/Include/internal/pycore_floatobject.h
@@ -19,6 +19,18 @@ extern void _PyFloat_FiniType(PyInterpreterState *);
/* other API */
+enum _py_float_format_type {
+ _py_float_format_unknown,
+ _py_float_format_ieee_big_endian,
+ _py_float_format_ieee_little_endian,
+};
+
+struct _Py_float_runtime_state {
+ enum _py_float_format_type float_format;
+ enum _py_float_format_type double_format;
+};
+
+
#ifndef WITH_FREELISTS
// without freelists
# define PyFloat_MAXFREELIST 0
diff --git a/Include/internal/pycore_import.h b/Include/internal/pycore_import.h
index 8ba9666cdc..9036dff672 100644
--- a/Include/internal/pycore_import.h
+++ b/Include/internal/pycore_import.h
@@ -32,6 +32,8 @@ struct _import_runtime_state {
_PyTime_t accumulated;
int header;
} find_and_load;
+ /* Package context -- the full module name for package imports */
+ const char * pkgcontext;
};
diff --git a/Include/internal/pycore_interp.h b/Include/internal/pycore_interp.h
index a13bc32e11..b7fc4b480d 100644
--- a/Include/internal/pycore_interp.h
+++ b/Include/internal/pycore_interp.h
@@ -28,6 +28,7 @@ extern "C" {
struct _pending_calls {
+ int busy;
PyThread_type_lock lock;
/* Request for running pending calls. */
_Py_atomic_int calls_to_do;
diff --git a/Include/internal/pycore_pyhash.h b/Include/internal/pycore_pyhash.h
index a229f8d8b7..34dfa53771 100644
--- a/Include/internal/pycore_pyhash.h
+++ b/Include/internal/pycore_pyhash.h
@@ -5,6 +5,36 @@
# error "this header requires Py_BUILD_CORE define"
#endif
-uint64_t _Py_KeyedHash(uint64_t, const char *, Py_ssize_t);
+struct pyhash_runtime_state {
+ struct {
+#ifndef MS_WINDOWS
+ int fd;
+ dev_t st_dev;
+ ino_t st_ino;
+#else
+ // This is a placeholder so the struct isn't empty on Windows.
+ int _not_used;
+#endif
+ } urandom_cache;
+};
+
+#ifndef MS_WINDOWS
+# define _py_urandom_cache_INIT \
+ { \
+ .fd = -1, \
+ }
+#else
+# define _py_urandom_cache_INIT {0}
#endif
+
+#define pyhash_state_INIT \
+ { \
+ .urandom_cache = _py_urandom_cache_INIT, \
+ }
+
+
+uint64_t _Py_KeyedHash(uint64_t, const char *, Py_ssize_t);
+
+
+#endif // Py_INTERNAL_HASH_H
diff --git a/Include/internal/pycore_pylifecycle.h b/Include/internal/pycore_pylifecycle.h
index 359b809d58..4c0ffa7a9b 100644
--- a/Include/internal/pycore_pylifecycle.h
+++ b/Include/internal/pycore_pylifecycle.h
@@ -14,10 +14,6 @@ extern "C" {
struct _PyArgv;
struct pyruntimestate;
-/* True if the main interpreter thread exited due to an unhandled
- * KeyboardInterrupt exception, suggesting the user pressed ^C. */
-PyAPI_DATA(int) _Py_UnhandledKeyboardInterrupt;
-
extern int _Py_SetFileSystemEncoding(
const char *encoding,
const char *errors);
diff --git a/Include/internal/pycore_runtime.h b/Include/internal/pycore_runtime.h
index 8b2b9d7a85..f8b988021b 100644
--- a/Include/internal/pycore_runtime.h
+++ b/Include/internal/pycore_runtime.h
@@ -10,11 +10,13 @@ extern "C" {
#include "pycore_atomic.h" /* _Py_atomic_address */
#include "pycore_dtoa.h" // struct _dtoa_runtime_state
+#include "pycore_floatobject.h" // struct _Py_float_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
#include "pycore_interp.h" // PyInterpreterState
#include "pycore_pymem.h" // struct _pymem_allocators
+#include "pycore_pyhash.h" // struct pyhash_runtime_state
#include "pycore_obmalloc.h" // struct obmalloc_state
#include "pycore_unicodeobject.h" // struct _Py_unicode_runtime_ids
@@ -92,6 +94,12 @@ typedef struct pyruntimestate {
struct _pymem_allocators allocators;
struct _obmalloc_state obmalloc;
+ struct pyhash_runtime_state pyhash_state;
+ struct {
+ /* True if the main interpreter thread exited due to an unhandled
+ * KeyboardInterrupt exception, suggesting the user pressed ^C. */
+ int unhandled_keyboard_interrupt;
+ } signals;
struct pyinterpreters {
PyThread_type_lock mutex;
@@ -131,6 +139,7 @@ typedef struct pyruntimestate {
struct _PyTraceMalloc_Config config;
} tracemalloc;
struct _dtoa_runtime_state dtoa;
+ struct _fileutils_state fileutils;
PyPreConfig preconfig;
@@ -140,7 +149,8 @@ typedef struct pyruntimestate {
void *open_code_userdata;
_Py_AuditHookEntry *audit_hook_head;
- struct _Py_unicode_runtime_ids unicode_ids;
+ struct _Py_float_runtime_state float_state;
+ struct _Py_unicode_runtime_state unicode_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 6bdee36a85..37bc54ff96 100644
--- a/Include/internal/pycore_runtime_init.h
+++ b/Include/internal/pycore_runtime_init.h
@@ -19,30 +19,18 @@ extern "C" {
#define _PyRuntimeState_INIT(runtime) \
{ \
- .gilstate = { \
- .check_enabled = 1, \
- /* A TSS key must be initialized with Py_tss_NEEDS_INIT \
- in accordance with the specification. */ \
- .autoTSSkey = Py_tss_NEEDS_INIT, \
- }, \
.allocators = { \
_pymem_allocators_standard_INIT(runtime), \
_pymem_allocators_debug_INIT, \
_pymem_allocators_obj_arena_INIT, \
}, \
.obmalloc = _obmalloc_state_INIT(runtime.obmalloc), \
+ .pyhash_state = pyhash_state_INIT, \
.interpreters = { \
/* This prevents interpreters from getting created \
until _PyInterpreterState_Enable() is called. */ \
.next_id = -1, \
}, \
- .tracemalloc = { \
- .config = _PyTraceMalloc_Config_INIT, \
- }, \
- .dtoa = _dtoa_runtime_state_INIT(runtime), \
- .types = { \
- .next_version_tag = 1, \
- }, \
.imports = { \
.lock = { \
.mutex = NULL, \
@@ -53,6 +41,26 @@ extern "C" {
.header = 1, \
}, \
}, \
+ .gilstate = { \
+ .check_enabled = 1, \
+ /* A TSS key must be initialized with Py_tss_NEEDS_INIT \
+ in accordance with the specification. */ \
+ .autoTSSkey = Py_tss_NEEDS_INIT, \
+ }, \
+ .tracemalloc = { \
+ .config = _PyTraceMalloc_Config_INIT, \
+ }, \
+ .dtoa = _dtoa_runtime_state_INIT(runtime), \
+ .fileutils = { \
+ .force_ascii = -1, \
+ }, \
+ .float_state = { \
+ .float_format = _py_float_format_unknown, \
+ .double_format = _py_float_format_unknown, \
+ }, \
+ .types = { \
+ .next_version_tag = 1, \
+ }, \
.global_objects = { \
.singletons = { \
.small_ints = _Py_small_ints_INIT, \
diff --git a/Include/internal/pycore_unicodeobject.h b/Include/internal/pycore_unicodeobject.h
index 63bf04b3e1..b315ca1ae5 100644
--- a/Include/internal/pycore_unicodeobject.h
+++ b/Include/internal/pycore_unicodeobject.h
@@ -31,6 +31,10 @@ struct _Py_unicode_runtime_ids {
Py_ssize_t next_index;
};
+struct _Py_unicode_runtime_state {
+ struct _Py_unicode_runtime_ids ids;
+};
+
/* fs_codec.encoding is initialized to NULL.
Later, it is set to a non-NULL string by _PyUnicode_InitEncodings(). */
struct _Py_unicode_fs_codec {