summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorAnthony Shaw <anthony.p.shaw@gmail.com>2023-11-02 00:09:01 (GMT)
committerGitHub <noreply@github.com>2023-11-02 00:09:01 (GMT)
commit230e8e924dbafe093fd1cc7b6c510dc0b9ec0caf (patch)
treec29c9b40b9f3bf85884bdc51aa654d579222179b /Python
parent9322ce90ac8f4d4647a59bbfab48fad6f4e4e856 (diff)
downloadcpython-230e8e924dbafe093fd1cc7b6c510dc0b9ec0caf.zip
cpython-230e8e924dbafe093fd1cc7b6c510dc0b9ec0caf.tar.gz
cpython-230e8e924dbafe093fd1cc7b6c510dc0b9ec0caf.tar.bz2
GH-111435: Add Support for Sharing True and False Between Interpreters (gh-111436)
This only affects users of the APIs in pycore_crossinterp.h (AKA _xxsubinterpretersmodule.c and _xxinterpchannels.c).
Diffstat (limited to 'Python')
-rw-r--r--Python/crossinterp.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/Python/crossinterp.c b/Python/crossinterp.c
index 00eccbd..5e3bf4c 100644
--- a/Python/crossinterp.c
+++ b/Python/crossinterp.c
@@ -693,6 +693,26 @@ _none_shared(PyThreadState *tstate, PyObject *obj,
return 0;
}
+static PyObject *
+_new_bool_object(_PyCrossInterpreterData *data)
+{
+ if (data->data){
+ Py_RETURN_TRUE;
+ }
+ Py_RETURN_FALSE;
+}
+
+static int
+_bool_shared(PyThreadState *tstate, PyObject *obj,
+ _PyCrossInterpreterData *data)
+{
+ _PyCrossInterpreterData_Init(data, tstate->interp,
+ (void *) (Py_IsTrue(obj) ? (uintptr_t) 1 : (uintptr_t) 0), NULL,
+ _new_bool_object);
+ // data->obj and data->free remain NULL
+ return 0;
+}
+
static void
_register_builtins_for_crossinterpreter_data(struct _xidregistry *xidregistry)
{
@@ -716,6 +736,11 @@ _register_builtins_for_crossinterpreter_data(struct _xidregistry *xidregistry)
Py_FatalError("could not register str for cross-interpreter sharing");
}
+ // bool
+ if (_xidregistry_add_type(xidregistry, &PyBool_Type, _bool_shared) != 0) {
+ Py_FatalError("could not register bool 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");