diff options
author | Anthony Shaw <anthony.p.shaw@gmail.com> | 2023-10-31 23:17:20 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-31 08:17:20 -0600 |
commit | ad6380bc340900e0977ce54928b0d3e166c7cf99 (patch) | |
tree | 530b5c2f5bbd60627e5cad9a266304a95e0e2368 /Python/crossinterp.c | |
parent | 2904d99839cd4620818fd0556a1c0b0229944abc (diff) | |
download | cpython-ad6380bc340900e0977ce54928b0d3e166c7cf99.tar.gz cpython-ad6380bc340900e0977ce54928b0d3e166c7cf99.zip |
GH-111438: Add Support for Sharing Floats Between Interpreters (gh-111439)
This only affects users of the APIs in pycore_crossinterp.h (AKA _xxsubinterpretersmodule.c and _xxinterpchannels.c).
Diffstat (limited to 'Python/crossinterp.c')
-rw-r--r-- | Python/crossinterp.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Python/crossinterp.c b/Python/crossinterp.c index 74f1d6ecef1..17c476ba436 100644 --- a/Python/crossinterp.c +++ b/Python/crossinterp.c @@ -586,6 +586,29 @@ _long_shared(PyThreadState *tstate, PyObject *obj, } static PyObject * +_new_float_object(_PyCrossInterpreterData *data) +{ + double * value_ptr = data->data; + return PyFloat_FromDouble(*value_ptr); +} + +static int +_float_shared(PyThreadState *tstate, PyObject *obj, + _PyCrossInterpreterData *data) +{ + if (_PyCrossInterpreterData_InitWithSize( + data, tstate->interp, sizeof(double), NULL, + _new_float_object + ) < 0) + { + return -1; + } + double *shared = (double *)data->data; + *shared = PyFloat_AsDouble(obj); + return 0; +} + +static PyObject * _new_none_object(_PyCrossInterpreterData *data) { // XXX Singleton refcounts are problematic across interpreters... @@ -624,4 +647,9 @@ _register_builtins_for_crossinterpreter_data(struct _xidregistry *xidregistry) if (_xidregistry_add_type(xidregistry, &PyUnicode_Type, _str_shared) != 0) { Py_FatalError("could not register str for cross-interpreter sharing"); } + + // float + if (_xidregistry_add_type(xidregistry, &PyFloat_Type, _float_shared) != 0) { + Py_FatalError("could not register float for cross-interpreter sharing"); + } } |