summaryrefslogtreecommitdiffstats
path: root/Objects/floatobject.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2021-12-09 19:59:26 (GMT)
committerGitHub <noreply@github.com>2021-12-09 19:59:26 (GMT)
commitc8749b578324ad4089c8d014d9136bc42b065343 (patch)
tree8b74af3da8568651c2c2068d9fe544617d70554f /Objects/floatobject.c
parentd8a464ef0380692975d73a3a1513d901b6af8e65 (diff)
downloadcpython-c8749b578324ad4089c8d014d9136bc42b065343.zip
cpython-c8749b578324ad4089c8d014d9136bc42b065343.tar.gz
cpython-c8749b578324ad4089c8d014d9136bc42b065343.tar.bz2
bpo-46008: Make runtime-global object/type lifecycle functions and state consistent. (gh-29998)
This change is strictly renames and moving code around. It helps in the following ways: * ensures type-related init functions focus strictly on one of the three aspects (state, objects, types) * passes in PyInterpreterState * to all those functions, simplifying work on moving types/objects/state to the interpreter * consistent naming conventions help make what's going on more clear * keeping API related to a type in the corresponding header file makes it more obvious where to look for it https://bugs.python.org/issue46008
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r--Objects/floatobject.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 7fc192e..f8620d6 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -6,6 +6,7 @@
#include "Python.h"
#include "pycore_dtoa.h" // _Py_dg_dtoa()
#include "pycore_floatobject.h" // _PyFloat_FormatAdvancedWriter()
+#include "pycore_initconfig.h" // _PyStatus_OK()
#include "pycore_interp.h" // _PyInterpreterState.float_state
#include "pycore_long.h" // _PyLong_GetOne()
#include "pycore_object.h" // _PyObject_Init()
@@ -1981,8 +1982,12 @@ PyTypeObject PyFloat_Type = {
};
void
-_PyFloat_Init(void)
+_PyFloat_InitState(PyInterpreterState *interp)
{
+ if (!_Py_IsMainInterpreter(interp)) {
+ return;
+ }
+
/* We attempt to determine if this machine is using IEEE
floating point formats by peering at the bits of some
carefully chosen values. If it looks like we are on an
@@ -2030,16 +2035,25 @@ _PyFloat_Init(void)
float_format = detected_float_format;
}
-int
-_PyFloat_InitTypes(void)
+PyStatus
+_PyFloat_InitTypes(PyInterpreterState *interp)
{
+ if (!_Py_IsMainInterpreter(interp)) {
+ return _PyStatus_OK();
+ }
+
+ if (PyType_Ready(&PyFloat_Type) < 0) {
+ return _PyStatus_ERR("Can't initialize float type");
+ }
+
/* Init float info */
if (FloatInfoType.tp_name == NULL) {
if (PyStructSequence_InitType2(&FloatInfoType, &floatinfo_desc) < 0) {
- return -1;
+ return _PyStatus_ERR("can't init float info type");
}
}
- return 0;
+
+ return _PyStatus_OK();
}
void