aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/sysmodule.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2022-07-25 12:47:31 -0600
committerGitHub <noreply@github.com>2022-07-25 12:47:31 -0600
commit4a1dd734311891662a6fc3394f93db98c93e7219 (patch)
tree2f85a419478553aeedd1622cb53dd5b302f77785 /Python/sysmodule.c
parentc5140945c723ae6c4b7ee81ff720ac8ea4b52cfd (diff)
downloadcpython-4a1dd734311891662a6fc3394f93db98c93e7219.tar.gz
cpython-4a1dd734311891662a6fc3394f93db98c93e7219.zip
gh-94673: Add _PyStaticType_InitBuiltin() (#95152)
This is the first of several precursors to storing tp_subclasses (and tp_weaklist) on the interpreter state for static builtin types. We do the following: * add `_PyStaticType_InitBuiltin()` * add `_Py_TPFLAGS_STATIC_BUILTIN` * set it on all static builtin types in `_PyStaticType_InitBuiltin()` * shuffle some code around to be able to use _PyStaticType_InitBuiltin() * rename `_PyStructSequence_InitType()` to `_PyStructSequence_InitBuiltinWithFlags()` * add `_PyStructSequence_InitBuiltin()`.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r--Python/sysmodule.c41
1 files changed, 18 insertions, 23 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index a5fa551b957..e861d9cbce4 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -28,7 +28,7 @@ Data members:
#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
#include "pycore_pymem.h" // _PyMem_SetDefaultAllocator()
#include "pycore_pystate.h" // _PyThreadState_GET()
-#include "pycore_structseq.h" // _PyStructSequence_InitType()
+#include "pycore_structseq.h" // _PyStructSequence_InitBuiltinWithFlags()
#include "pycore_tuple.h" // _PyTuple_FromArray()
#include "frameobject.h" // PyFrame_FastToLocalsWithError()
@@ -2921,7 +2921,7 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
SET_SYS("int_info", PyLong_GetInfo());
/* initialize hash_info */
if (Hash_InfoType.tp_name == NULL) {
- if (PyStructSequence_InitType2(&Hash_InfoType, &hash_info_desc) < 0) {
+ if (_PyStructSequence_InitBuiltin(&Hash_InfoType, &hash_info_desc) < 0) {
goto type_init_failed;
}
}
@@ -2943,14 +2943,18 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
SET_SYS_FROM_STRING("abiflags", ABIFLAGS);
#endif
+#define ENSURE_INFO_TYPE(TYPE, DESC) \
+ do { \
+ if (TYPE.tp_name == NULL) { \
+ if (_PyStructSequence_InitBuiltinWithFlags( \
+ &TYPE, &DESC, Py_TPFLAGS_DISALLOW_INSTANTIATION) < 0) { \
+ goto type_init_failed; \
+ } \
+ } \
+ } while (0)
+
/* version_info */
- if (VersionInfoType.tp_name == NULL) {
- if (_PyStructSequence_InitType(&VersionInfoType,
- &version_info_desc,
- Py_TPFLAGS_DISALLOW_INSTANTIATION) < 0) {
- goto type_init_failed;
- }
- }
+ ENSURE_INFO_TYPE(VersionInfoType, version_info_desc);
version_info = make_version_info(tstate);
SET_SYS("version_info", version_info);
@@ -2958,27 +2962,18 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
SET_SYS("implementation", make_impl_info(version_info));
// sys.flags: updated in-place later by _PySys_UpdateConfig()
- if (FlagsType.tp_name == 0) {
- if (_PyStructSequence_InitType(&FlagsType, &flags_desc,
- Py_TPFLAGS_DISALLOW_INSTANTIATION) < 0) {
- goto type_init_failed;
- }
- }
+ ENSURE_INFO_TYPE(FlagsType, flags_desc);
SET_SYS("flags", make_flags(tstate->interp));
#if defined(MS_WINDOWS)
/* getwindowsversion */
- if (WindowsVersionType.tp_name == 0) {
- if (_PyStructSequence_InitType(&WindowsVersionType,
- &windows_version_desc,
- Py_TPFLAGS_DISALLOW_INSTANTIATION) < 0) {
- goto type_init_failed;
- }
- }
+ ENSURE_INFO_TYPE(WindowsVersionType, windows_version_desc);
SET_SYS_FROM_STRING("_vpath", VPATH);
#endif
+#undef ENSURE_INFO_TYPE
+
/* float repr style: 0.03 (short) vs 0.029999999999999999 (legacy) */
#if _PY_SHORT_FLOAT_REPR == 1
SET_SYS_FROM_STRING("float_repr_style", "short");
@@ -2990,7 +2985,7 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
/* initialize asyncgen_hooks */
if (AsyncGenHooksType.tp_name == NULL) {
- if (PyStructSequence_InitType2(
+ if (_PyStructSequence_InitBuiltin(
&AsyncGenHooksType, &asyncgen_hooks_desc) < 0) {
goto type_init_failed;
}