summaryrefslogtreecommitdiffstats
path: root/Modules/_testinternalcapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_testinternalcapi.c')
-rw-r--r--Modules/_testinternalcapi.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c
index 1869f48..a71e7e1 100644
--- a/Modules/_testinternalcapi.c
+++ b/Modules/_testinternalcapi.c
@@ -1466,6 +1466,58 @@ run_in_subinterp_with_config(PyObject *self, PyObject *args, PyObject *kwargs)
}
+static void
+_xid_capsule_destructor(PyObject *capsule)
+{
+ _PyCrossInterpreterData *data = \
+ (_PyCrossInterpreterData *)PyCapsule_GetPointer(capsule, NULL);
+ if (data != NULL) {
+ assert(_PyCrossInterpreterData_Release(data) == 0);
+ _PyCrossInterpreterData_Free(data);
+ }
+}
+
+static PyObject *
+get_crossinterp_data(PyObject *self, PyObject *args)
+{
+ PyObject *obj = NULL;
+ if (!PyArg_ParseTuple(args, "O:get_crossinterp_data", &obj)) {
+ return NULL;
+ }
+
+ _PyCrossInterpreterData *data = _PyCrossInterpreterData_New();
+ if (data == NULL) {
+ return NULL;
+ }
+ if (_PyObject_GetCrossInterpreterData(obj, data) != 0) {
+ _PyCrossInterpreterData_Free(data);
+ return NULL;
+ }
+ PyObject *capsule = PyCapsule_New(data, NULL, _xid_capsule_destructor);
+ if (capsule == NULL) {
+ assert(_PyCrossInterpreterData_Release(data) == 0);
+ _PyCrossInterpreterData_Free(data);
+ }
+ return capsule;
+}
+
+static PyObject *
+restore_crossinterp_data(PyObject *self, PyObject *args)
+{
+ PyObject *capsule = NULL;
+ if (!PyArg_ParseTuple(args, "O:restore_crossinterp_data", &capsule)) {
+ return NULL;
+ }
+
+ _PyCrossInterpreterData *data = \
+ (_PyCrossInterpreterData *)PyCapsule_GetPointer(capsule, NULL);
+ if (data == NULL) {
+ return NULL;
+ }
+ return _PyCrossInterpreterData_NewObject(data);
+}
+
+
/*[clinic input]
_testinternalcapi.write_unraisable_exc
exception as exc: object
@@ -1645,6 +1697,8 @@ static PyMethodDef module_functions[] = {
METH_VARARGS | METH_KEYWORDS},
{"compile_perf_trampoline_entry", compile_perf_trampoline_entry, METH_VARARGS},
{"perf_trampoline_set_persist_after_fork", perf_trampoline_set_persist_after_fork, METH_VARARGS},
+ {"get_crossinterp_data", get_crossinterp_data, METH_VARARGS},
+ {"restore_crossinterp_data", restore_crossinterp_data, METH_VARARGS},
_TESTINTERNALCAPI_WRITE_UNRAISABLE_EXC_METHODDEF
_TESTINTERNALCAPI_TEST_LONG_NUMBITS_METHODDEF
{NULL, NULL} /* sentinel */