LoLBench / cpython_18 /tests /private /eval_helpers.patch
lolbench26's picture
Publish LoLBench Harbor tasks from artifact branch (part 2)
a4edccc verified
Raw History Blame Contribute Delete
44.9 kB
diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in
--- a/Modules/Setup.stdlib.in
+++ b/Modules/Setup.stdlib.in
@@ -176,7 +176,7 @@
@MODULE__TESTBUFFER_TRUE@_testbuffer _testbuffer.c
@MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c _testinternalcapi/test_lock.c _testinternalcapi/pytime.c _testinternalcapi/set.c _testinternalcapi/test_critical_sections.c _testinternalcapi/complex.c _testinternalcapi/interpreter.c _testinternalcapi/tuple.c
@MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/heaptype.c _testcapi/abstract.c _testcapi/unicode.c _testcapi/dict.c _testcapi/set.c _testcapi/list.c _testcapi/tuple.c _testcapi/getargs.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/complex.c _testcapi/numbers.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/buffer.c _testcapi/pyatomic.c _testcapi/run.c _testcapi/file.c _testcapi/codec.c _testcapi/immortal.c _testcapi/gc.c _testcapi/hash.c _testcapi/time.c _testcapi/bytes.c _testcapi/object.c _testcapi/modsupport.c _testcapi/monitoring.c _testcapi/config.c _testcapi/import.c _testcapi/frame.c _testcapi/type.c _testcapi/function.c _testcapi/module.c
-@MODULE__TESTLIMITEDCAPI_TRUE@_testlimitedcapi _testlimitedcapi.c _testlimitedcapi/abstract.c _testlimitedcapi/bytearray.c _testlimitedcapi/bytes.c _testlimitedcapi/codec.c _testlimitedcapi/complex.c _testlimitedcapi/dict.c _testlimitedcapi/eval.c _testlimitedcapi/float.c _testlimitedcapi/heaptype_relative.c _testlimitedcapi/import.c _testlimitedcapi/list.c _testlimitedcapi/long.c _testlimitedcapi/object.c _testlimitedcapi/pyos.c _testlimitedcapi/set.c _testlimitedcapi/sys.c _testlimitedcapi/threadstate.c _testlimitedcapi/tuple.c _testlimitedcapi/unicode.c _testlimitedcapi/vectorcall_limited.c _testlimitedcapi/version.c _testlimitedcapi/file.c
+@MODULE__TESTLIMITEDCAPI_TRUE@_testlimitedcapi _testlimitedcapi.c _testlimitedcapi/abstract.c _testlimitedcapi/bytearray.c _testlimitedcapi/bytes.c _testlimitedcapi/codec.c _testlimitedcapi/complex.c _testlimitedcapi/dict.c _testlimitedcapi/eval.c _testlimitedcapi/float.c _testlimitedcapi/heaptype_relative.c _testlimitedcapi/import.c _testlimitedcapi/list.c _testlimitedcapi/long.c _testlimitedcapi/object.c _testlimitedcapi/pyos.c _testlimitedcapi/set.c _testlimitedcapi/slots.c _testlimitedcapi/sys.c _testlimitedcapi/threadstate.c _testlimitedcapi/tuple.c _testlimitedcapi/unicode.c _testlimitedcapi/vectorcall_limited.c _testlimitedcapi/version.c _testlimitedcapi/file.c
@MODULE__TESTCLINIC_TRUE@_testclinic _testclinic.c
@MODULE__TESTCLINIC_LIMITED_TRUE@_testclinic_limited _testclinic_limited.c
diff --git a/Modules/_testcapi/module.c b/Modules/_testcapi/module.c
--- a/Modules/_testcapi/module.c
+++ b/Modules/_testcapi/module.c
@@ -13,18 +13,18 @@ PyABIInfo_VAR(abi_info);
static PyObject *
module_from_slots_empty(PyObject *self, PyObject *spec)
{
- PyModuleDef_Slot slots[] = {
- {0},
+ PySlot slots[] = {
+ PySlot_END,
};
return PyModule_FromSlotsAndSpec(slots, spec);
}
static PyObject *
module_from_slots_minimal(PyObject *self, PyObject *spec)
{
- PyModuleDef_Slot slots[] = {
- {Py_mod_abi, &abi_info},
- {0},
+ PySlot slots[] = {
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_END,
};
return PyModule_FromSlotsAndSpec(slots, spec);
}
@@ -38,38 +38,38 @@ module_from_slots_null(PyObject *self, PyObject *spec)
static PyObject *
module_from_slots_name(PyObject *self, PyObject *spec)
{
- PyModuleDef_Slot slots[] = {
- {Py_mod_abi, &abi_info},
- {Py_mod_name, "currently ignored..."},
- {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
- {Py_mod_gil, Py_MOD_GIL_NOT_USED},
- {0},
+ PySlot slots[] = {
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_DATA(Py_mod_name, "currently ignored..."),
+ PySlot_DATA(Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED),
+ PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED),
+ PySlot_END,
};
return PyModule_FromSlotsAndSpec(slots, spec);
}
static PyObject *
module_from_slots_doc(PyObject *self, PyObject *spec)
{
- PyModuleDef_Slot slots[] = {
- {Py_mod_abi, &abi_info},
- {Py_mod_doc, "the docstring"},
- {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
- {Py_mod_gil, Py_MOD_GIL_NOT_USED},
- {0},
+ PySlot slots[] = {
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_DATA(Py_mod_doc, "the docstring"),
+ PySlot_DATA(Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED),
+ PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED),
+ PySlot_END,
};
return PyModule_FromSlotsAndSpec(slots, spec);
}
static PyObject *
module_from_slots_size(PyObject *self, PyObject *spec)
{
- PyModuleDef_Slot slots[] = {
- {Py_mod_abi, &abi_info},
- {Py_mod_state_size, (void*)123},
- {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
- {Py_mod_gil, Py_MOD_GIL_NOT_USED},
- {0},
+ PySlot slots[] = {
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_SIZE(Py_mod_state_size, (void*)123),
+ PySlot_DATA(Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED),
+ PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED),
+ PySlot_END,
};
PyObject *mod = PyModule_FromSlotsAndSpec(slots, spec);
if (!mod) {
@@ -92,12 +92,12 @@ static PyMethodDef a_methoddef_array[] = {
static PyObject *
module_from_slots_methods(PyObject *self, PyObject *spec)
{
- PyModuleDef_Slot slots[] = {
- {Py_mod_abi, &abi_info},
- {Py_mod_methods, a_methoddef_array},
- {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
- {Py_mod_gil, Py_MOD_GIL_NOT_USED},
- {0},
+ PySlot slots[] = {
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_STATIC_DATA(Py_mod_methods, a_methoddef_array),
+ PySlot_DATA(Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED),
+ PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED),
+ PySlot_END,
};
return PyModule_FromSlotsAndSpec(slots, spec);
}
@@ -111,14 +111,14 @@ static void noop_free(void *self) { }
static PyObject *
module_from_slots_gc(PyObject *self, PyObject *spec)
{
- PyModuleDef_Slot slots[] = {
- {Py_mod_abi, &abi_info},
- {Py_mod_state_traverse, noop_traverse},
- {Py_mod_state_clear, noop_clear},
- {Py_mod_state_free, noop_free},
- {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
- {Py_mod_gil, Py_MOD_GIL_NOT_USED},
- {0},
+ PySlot slots[] = {
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_FUNC(Py_mod_state_traverse, noop_traverse),
+ PySlot_FUNC(Py_mod_state_clear, noop_clear),
+ PySlot_FUNC(Py_mod_state_free, noop_free),
+ PySlot_DATA(Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED),
+ PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED),
+ PySlot_END,
};
PyObject *mod = PyModule_FromSlotsAndSpec(slots, spec);
if (!mod) {
@@ -144,12 +144,12 @@ static const char test_token;
static PyObject *
module_from_slots_token(PyObject *self, PyObject *spec)
{
- PyModuleDef_Slot slots[] = {
- {Py_mod_abi, &abi_info},
- {Py_mod_token, (void*)&test_token},
- {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
- {Py_mod_gil, Py_MOD_GIL_NOT_USED},
- {0},
+ PySlot slots[] = {
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_DATA(Py_mod_token, (void*)&test_token),
+ PySlot_DATA(Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED),
+ PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED),
+ PySlot_END,
};
PyObject *mod = PyModule_FromSlotsAndSpec(slots, spec);
if (!mod) {
@@ -175,12 +175,12 @@ simple_exec(PyObject *module)
static PyObject *
module_from_slots_exec(PyObject *self, PyObject *spec)
{
- PyModuleDef_Slot slots[] = {
- {Py_mod_abi, &abi_info},
- {Py_mod_exec, simple_exec},
- {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
- {Py_mod_gil, Py_MOD_GIL_NOT_USED},
- {0},
+ PySlot slots[] = {
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_FUNC(Py_mod_exec, simple_exec),
+ PySlot_DATA(Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED),
+ PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED),
+ PySlot_END,
};
PyObject *mod = PyModule_FromSlotsAndSpec(slots, spec);
if (!mod) {
@@ -209,12 +209,12 @@ create_attr_from_spec(PyObject *spec, PyModuleDef *def)
static PyObject *
module_from_slots_create(PyObject *self, PyObject *spec)
{
- PyModuleDef_Slot slots[] = {
- {Py_mod_abi, &abi_info},
- {Py_mod_create, create_attr_from_spec},
- {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
- {Py_mod_gil, Py_MOD_GIL_NOT_USED},
- {0},
+ const PySlot slots[] = {
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_FUNC(Py_mod_create, create_attr_from_spec),
+ PySlot_DATA(Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED),
+ PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED),
+ PySlot_END,
};
return PyModule_FromSlotsAndSpec(slots, spec);
}
@@ -241,13 +241,13 @@ module_from_slots_repeat_slot(PyObject *self, PyObject *spec)
if (slot_id < 0) {
return NULL;
}
- PyModuleDef_Slot slots[] = {
- {Py_mod_abi, &abi_info},
- {slot_id, "anything"},
- {slot_id, "anything else"},
- {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
- {Py_mod_gil, Py_MOD_GIL_NOT_USED},
- {0},
+ const PySlot slots[] = {
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_PTR_STATIC(slot_id, "anything"),
+ PySlot_PTR_STATIC(slot_id, "anything_else"),
+ PySlot_DATA(Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED),
+ PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED),
+ PySlot_END,
};
return PyModule_FromSlotsAndSpec(slots, spec);
}
@@ -259,12 +259,12 @@ module_from_slots_null_slot(PyObject *self, PyObject *spec)
if (slot_id < 0) {
return NULL;
}
- PyModuleDef_Slot slots[] = {
- {slot_id, NULL},
- {Py_mod_abi, &abi_info},
- {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
- {Py_mod_gil, Py_MOD_GIL_NOT_USED},
- {0},
+ const PySlot slots[] = {
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_PTR_STATIC(slot_id, NULL),
+ PySlot_DATA(Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED),
+ PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED),
+ PySlot_END,
};
return PyModule_FromSlotsAndSpec(slots, spec);
}
@@ -347,12 +347,12 @@ module_from_bad_abiinfo(PyObject *self, PyObject *spec)
1, 0,
.abi_version=0x02080000,
};
- PyModuleDef_Slot slots[] = {
- {Py_mod_abi, &abi_info},
- {Py_mod_abi, &bad_abi_info},
- {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
- {Py_mod_gil, Py_MOD_GIL_NOT_USED},
- {0},
+ PySlot slots[] = {
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_DATA(Py_mod_abi, &bad_abi_info),
+ PySlot_DATA(Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED),
+ PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED),
+ PySlot_END,
};
return PyModule_FromSlotsAndSpec(slots, spec);
}
@@ -365,14 +365,14 @@ module_from_multiple_abiinfo(PyObject *self, PyObject *spec)
.flags=PyABIInfo_STABLE | PyABIInfo_FREETHREADING_AGNOSTIC,
.abi_version=0x03040000,
};
- PyModuleDef_Slot slots[] = {
- {Py_mod_abi, &abi_info},
- {Py_mod_abi, &abi_info},
- {Py_mod_abi, &extra_abi_info},
- {Py_mod_abi, &extra_abi_info},
- {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
- {Py_mod_gil, Py_MOD_GIL_NOT_USED},
- {0},
+ PySlot slots[] = {
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_DATA(Py_mod_abi, &extra_abi_info),
+ PySlot_DATA(Py_mod_abi, &extra_abi_info),
+ PySlot_DATA(Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED),
+ PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED),
+ PySlot_END,
};
return PyModule_FromSlotsAndSpec(slots, spec);
}
@@ -466,6 +466,53 @@ pymodule_get_state_size(PyObject *self, PyObject *module)
return PyLong_FromSsize_t(size);
}
+static PyObject *
+module_from_null_def_slot(PyObject* Py_UNUSED(module), PyObject *args)
+{
+ long slot_number;
+ PyObject *spec;
+ if (!PyArg_ParseTuple(args, "lO", &slot_number, &spec)) {
+ return NULL;
+ }
+ static PyModuleDef_Slot slots[] = {
+ {0, NULL},
+ {0},
+ };
+ static PyModuleDef def = {
+ PyModuleDef_HEAD_INIT,
+ .m_name = "mymod",
+ .m_slots = slots,
+ };
+ // hack: def is supposed to be constant.
+ // Don't do this at home; use PyModule_FromSlotsAndSpec throwaway
+ // definitions!
+ slots[0].slot = slot_number;
+ return PyModule_FromDefAndSpec(&def, spec);
+}
+
+static PyObject *
+module_from_def_nonstatic_nested(PyObject* Py_UNUSED(module), PyObject *spec)
+{
+ static PyModuleDef_Slot subsubslots[] = {
+ {Py_mod_gil, Py_MOD_GIL_NOT_USED},
+ {0},
+ };
+ static PySlot subslots[] = {
+ PySlot_DATA(Py_mod_slots, subsubslots),
+ PySlot_END,
+ };
+ static PyModuleDef_Slot slots[] = {
+ {Py_slot_subslots, subslots},
+ {0},
+ };
+ static PyModuleDef def = {
+ PyModuleDef_HEAD_INIT,
+ .m_name = "mymod",
+ .m_slots = slots,
+ };
+ return PyModule_FromDefAndSpec(&def, spec);
+}
+
static PyMethodDef test_methods[] = {
{"module_from_slots_empty", module_from_slots_empty, METH_O},
{"module_from_slots_minimal", module_from_slots_minimal, METH_O},
@@ -489,6 +536,8 @@ static PyMethodDef test_methods[] = {
{"pymodule_get_def", pymodule_get_def, METH_O},
{"pymodule_get_state_size", pymodule_get_state_size, METH_O},
{"pymodule_exec", pymodule_exec, METH_O},
+ {"module_from_null_def_slot", module_from_null_def_slot, METH_VARARGS},
+ {"module_from_def_nonstatic_nested", module_from_def_nonstatic_nested, METH_O},
{NULL},
};
diff --git a/Modules/_testcapi/type.c b/Modules/_testcapi/type.c
--- a/Modules/_testcapi/type.c
+++ b/Modules/_testcapi/type.c
@@ -110,9 +110,9 @@ test_get_statictype_slots(PyObject *self, PyObject *Py_UNUSED(ignored))
return NULL;
}
- void *over_value = PyType_GetSlot(&PyLong_Type, Py_bf_releasebuffer + 1);
+ void *over_value = PyType_GetSlot(&PyLong_Type, Py_mod_name + 1);
if (over_value != NULL) {
- PyErr_SetString(PyExc_AssertionError, "mismatch: max+1 of long");
+ PyErr_SetString(PyExc_AssertionError, "mismatch: mod_name of long");
return NULL;
}
diff --git a/Modules/_testlimitedcapi.c b/Modules/_testlimitedcapi.c
--- a/Modules/_testlimitedcapi.c
+++ b/Modules/_testlimitedcapi.c
@@ -74,6 +74,9 @@ PyInit__testlimitedcapi(void)
if (_PyTestLimitedCAPI_Init_Set(mod) < 0) {
return NULL;
}
+ if (_PyTestLimitedCAPI_Init_Slots(mod) < 0) {
+ return NULL;
+ }
if (_PyTestLimitedCAPI_Init_Sys(mod) < 0) {
return NULL;
}
diff --git a/Modules/_testlimitedcapi/parts.h b/Modules/_testlimitedcapi/parts.h
--- a/Modules/_testlimitedcapi/parts.h
+++ b/Modules/_testlimitedcapi/parts.h
@@ -37,6 +37,7 @@ int _PyTestLimitedCAPI_Init_List(PyObject *module);
int _PyTestLimitedCAPI_Init_Long(PyObject *module);
int _PyTestLimitedCAPI_Init_PyOS(PyObject *module);
int _PyTestLimitedCAPI_Init_Set(PyObject *module);
+int _PyTestLimitedCAPI_Init_Slots(PyObject *module);
int _PyTestLimitedCAPI_Init_Sys(PyObject *module);
int _PyTestLimitedCAPI_Init_ThreadState(PyObject *module);
int _PyTestLimitedCAPI_Init_Tuple(PyObject *module);
diff --git a/Modules/_testlimitedcapi/slots.c b/Modules/_testlimitedcapi/slots.c
new file mode 100644
--- /dev/null
+++ b/Modules/_testlimitedcapi/slots.c
@@ -0,0 +1,629 @@
+#define Py_LIMITED_API 0x030f0000
+
+#include "parts.h"
+
+PyABIInfo_VAR(abi_info);
+
+/* Define a bunch of (mostly nonsensical) functions to put in slots, so
+ * Lib/test/test_capi/test_slots.py can verify they've been assigned to
+ * the right slots.
+
+ * This module is full of "magic constants" which simply need to match
+ * between the C and Python part of the tests.
+ */
+
+// getbufferproc: export buffer; increment a counter
+static int
+demo_getbuffer(PyObject *exporter, Py_buffer *view, int flags)
+{
+ Py_INCREF(exporter);
+ // PyObject_GetTypeData & Py_TYPE: safe on non-subclassable type
+ int *data = PyObject_GetTypeData(exporter, Py_TYPE(exporter));
+ if (!data) {
+ return -1;
+ }
+ (*data)++;
+ return PyBuffer_FillInfo(view, exporter, "buf", 4, 1, flags);
+}
+
+// releasebufferproc: release buffer; decrement a counter
+static void
+demo_releasebuffer(PyObject *exporter, Py_buffer *view)
+{
+ Py_DECREF(exporter);
+ // PyObject_GetTypeData & Py_TYPE: safe on non-subclassable type
+ int *data = PyObject_GetTypeData(exporter, Py_TYPE(exporter));
+ if (!data) {
+ PyErr_WriteUnraisable(exporter);
+ return;
+ }
+ (*data)--;
+ return;
+}
+
+// objobjargproc: raise KeyError
+static int
+demo_ass_subscript(PyObject *o, PyObject *key, PyObject *v)
+{
+ PyErr_Format(PyExc_KeyError, "I don't like that key");
+ return -1;
+}
+
+// lenfunc: report 456
+static Py_ssize_t
+demo_length(PyObject *o)
+{
+ return (Py_ssize_t)456;
+}
+
+// binaryfunc; return constant value
+static PyObject *binop_123(PyObject* a, PyObject *b) { return PyLong_FromLong(123); }
+static PyObject *binop_234(PyObject* a, PyObject *b) { return PyLong_FromLong(234); }
+static PyObject *binop_345(PyObject* a, PyObject *b) { return PyLong_FromLong(345); }
+static PyObject *binop_456(PyObject* a, PyObject *b) { return PyLong_FromLong(456); }
+static PyObject *binop_567(PyObject* a, PyObject *b) { return PyLong_FromLong(567); }
+static PyObject *binop_678(PyObject* a, PyObject *b) { return PyLong_FromLong(678); }
+
+static PyObject *
+type_from_slots(PyObject* module, PyObject *args)
+{
+ char *case_name;
+ if (!PyArg_ParseTuple(args, "s", &case_name)) {
+ return NULL;
+ }
+#define CASE(NAME) \
+ if (strcmp(case_name, NAME) == 0) { \
+ return PyType_FromSlots((PySlot[]) { \
+ PySlot_DATA(Py_tp_name, "_testlimitedcapi.MyType"), \
+ PySlot_DATA(Py_tp_module, module), \
+ /////////////////////////////////////////////////////////////////////////
+#define ENDCASE() \
+ PySlot_END \
+ }); \
+ } \
+ /////////////////////////////////////////////////////////////////////////
+
+ CASE("basic")
+ ENDCASE()
+ CASE("foreign_slot")
+ PySlot_DATA(Py_mod_name, "this is not a module"),
+ ENDCASE()
+ CASE("basicsize")
+ PySlot_SIZE(Py_tp_basicsize, 256),
+ ENDCASE()
+ CASE("extra_basicsize")
+ PySlot_SIZE(Py_tp_extra_basicsize, 256),
+ ENDCASE()
+ CASE("itemsize")
+ PySlot_SIZE(Py_tp_itemsize, 16),
+ ENDCASE()
+ CASE("flags")
+ PySlot_UINT64(Py_tp_flags,
+ Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_BASETYPE),
+ ENDCASE()
+ CASE("matmul_123")
+ PySlot_FUNC(Py_nb_matrix_multiply, binop_123),
+ ENDCASE()
+ CASE("optional_end")
+ {.sl_flags=PySlot_OPTIONAL},
+ ENDCASE()
+ CASE("invalid")
+ {.sl_id=Py_slot_invalid},
+ ENDCASE()
+ CASE("invalid_fbad")
+ {.sl_id=0xfbad},
+ ENDCASE()
+ CASE("optional_invalid")
+ {.sl_id=Py_slot_invalid, .sl_flags=PySlot_OPTIONAL},
+ PySlot_SIZE(Py_tp_extra_basicsize, 256),
+ ENDCASE()
+ CASE("optional_invalid_fbad")
+ {.sl_id=0xfbad, .sl_flags=PySlot_OPTIONAL},
+ PySlot_SIZE(Py_tp_extra_basicsize, 256),
+ ENDCASE()
+ CASE("old_slot_numbers")
+ PySlot_FUNC(1, demo_getbuffer),
+ PySlot_FUNC(2, demo_releasebuffer),
+ PySlot_FUNC(3, demo_ass_subscript),
+ PySlot_FUNC(4, demo_length),
+ PySlot_SIZE(Py_tp_extra_basicsize, sizeof(int)),
+ PySlot_STATIC_DATA(Py_tp_members, ((PyMemberDef[]) {
+ {"buf_counter", Py_T_INT, 0, Py_READONLY | Py_RELATIVE_OFFSET},
+ {NULL},
+ })),
+ ENDCASE()
+ CASE("new_slot_numbers")
+ PySlot_FUNC(88, demo_getbuffer),
+ PySlot_FUNC(89, demo_releasebuffer),
+ PySlot_FUNC(90, demo_ass_subscript),
+ PySlot_FUNC(91, demo_length),
+ PySlot_SIZE(Py_tp_extra_basicsize, sizeof(int)),
+ PySlot_STATIC_DATA(Py_tp_members, ((PyMemberDef[]) {
+ {"buf_counter", Py_T_INT, 0, Py_READONLY | Py_RELATIVE_OFFSET},
+ {NULL},
+ })),
+ ENDCASE()
+ CASE("nonstatic_tp_members")
+ PySlot_SIZE(Py_tp_extra_basicsize, sizeof(int)),
+ PySlot_DATA(Py_tp_members, ((PyMemberDef[]) {
+ {"buf_counter", Py_T_INT, 0, Py_READONLY | Py_RELATIVE_OFFSET},
+ {NULL},
+ })),
+ ENDCASE()
+ CASE("intptr_flags_macro")
+ PySlot_PTR(Py_tp_flags, (void*)(intptr_t)Py_TPFLAGS_IMMUTABLETYPE),
+ ENDCASE()
+ CASE("intptr_flags_struct")
+ {.sl_id=Py_tp_flags,
+ .sl_flags=PySlot_INTPTR,
+ .sl_ptr=(void*)(intptr_t)Py_TPFLAGS_IMMUTABLETYPE,
+ },
+ ENDCASE()
+ CASE("intptr_static")
+ PySlot_SIZE(Py_tp_extra_basicsize, sizeof(int)),
+ PySlot_PTR_STATIC(Py_tp_members, ((PyMemberDef[]) {
+ {"attribute", Py_T_INT, 0, Py_READONLY | Py_RELATIVE_OFFSET},
+ {NULL},
+ })),
+ ENDCASE()
+ CASE("nested")
+ PySlot_FUNC(Py_nb_add, binop_123),
+ PySlot_DATA(Py_slot_subslots, ((PySlot[]) {
+ PySlot_FUNC(Py_nb_subtract, binop_234),
+ PySlot_END,
+ })),
+ ENDCASE()
+ CASE("nested_max")
+ PySlot_FUNC(Py_nb_add, binop_123),
+ PySlot_DATA(Py_slot_subslots, ((PySlot[]) {
+ PySlot_FUNC(Py_nb_subtract, binop_234),
+ PySlot_DATA(Py_slot_subslots, ((PySlot[]) {
+ PySlot_FUNC(Py_nb_multiply, binop_345),
+ PySlot_DATA(Py_slot_subslots, ((PySlot[]) {
+ PySlot_FUNC(Py_nb_true_divide, binop_456),
+ PySlot_DATA(Py_slot_subslots, ((PySlot[]) {
+ PySlot_FUNC(Py_nb_remainder, binop_567),
+ PySlot_END
+ })),
+ PySlot_END,
+ })),
+ PySlot_END,
+ })),
+ PySlot_END,
+ })),
+ ENDCASE()
+ CASE("nested_over_limit")
+ PySlot_FUNC(Py_nb_add, binop_123),
+ PySlot_DATA(Py_slot_subslots, ((PySlot[]) {
+ PySlot_FUNC(Py_nb_subtract, binop_234),
+ PySlot_DATA(Py_slot_subslots, ((PySlot[]) {
+ PySlot_FUNC(Py_nb_multiply, binop_345),
+ PySlot_DATA(Py_slot_subslots, ((PySlot[]) {
+ PySlot_FUNC(Py_nb_true_divide, binop_456),
+ PySlot_DATA(Py_slot_subslots, ((PySlot[]) {
+ PySlot_FUNC(Py_nb_remainder, binop_567),
+ PySlot_DATA(Py_slot_subslots, ((PySlot[]) {
+ PySlot_FUNC(Py_nb_xor, binop_678),
+ PySlot_END
+ })),
+ PySlot_END
+ })),
+ PySlot_END,
+ })),
+ PySlot_END,
+ })),
+ PySlot_END,
+ })),
+ ENDCASE()
+ CASE("nested_old")
+ PySlot_FUNC(Py_nb_add, binop_123),
+ PySlot_DATA(Py_tp_slots, ((PyType_Slot[]) {
+ {Py_nb_subtract, binop_234},
+ {0},
+ })),
+ ENDCASE()
+ CASE("nested_old_max")
+ PySlot_FUNC(Py_nb_add, binop_123),
+ PySlot_DATA(Py_tp_slots, ((PyType_Slot[]) {
+ {Py_nb_subtract, binop_234},
+ {Py_tp_slots, ((PyType_Slot[]) {
+ {Py_nb_multiply, binop_345},
+ {Py_tp_slots, ((PyType_Slot[]) {
+ {Py_nb_true_divide, binop_456},
+ {Py_tp_slots, ((PyType_Slot[]) {
+ {Py_nb_remainder, binop_567},
+ {0},
+ })},
+ {0},
+ })},
+ {0},
+ })},
+ {0},
+ })),
+ ENDCASE()
+ CASE("nested_old_over_limit")
+ PySlot_FUNC(Py_nb_add, binop_123),
+ PySlot_DATA(Py_tp_slots, ((PyType_Slot[]) {
+ {Py_nb_subtract, binop_234},
+ {Py_tp_slots, ((PyType_Slot[]) {
+ {Py_nb_multiply, binop_345},
+ {Py_tp_slots, ((PyType_Slot[]) {
+ {Py_nb_true_divide, binop_456},
+ {Py_tp_slots, ((PyType_Slot[]) {
+ {Py_nb_remainder, binop_567},
+ {Py_tp_slots, ((PyType_Slot[]) {
+ {Py_nb_xor, binop_678},
+ {0},
+ })},
+ {0},
+ })},
+ {0},
+ })},
+ {0},
+ })},
+ {0},
+ })),
+ ENDCASE()
+ CASE("nested_pingpong")
+ PySlot_FUNC(Py_nb_add, binop_123),
+ PySlot_DATA(Py_tp_slots, ((PyType_Slot[]) {
+ {Py_nb_subtract, binop_234},
+ {Py_slot_subslots, ((PySlot[]) {
+ PySlot_FUNC(Py_nb_multiply, binop_345),
+ PySlot_DATA(Py_tp_slots, ((PyType_Slot[]) {
+ {Py_nb_true_divide, binop_456},
+ {Py_slot_subslots, ((PySlot[]) {
+ PySlot_FUNC(Py_nb_remainder, binop_567),
+ PySlot_END
+ })},
+ {0},
+ })),
+ PySlot_END,
+ })},
+ {0},
+ })),
+ ENDCASE()
+ CASE("repeat_add")
+ PySlot_FUNC(Py_nb_add, binop_123),
+ PySlot_FUNC(Py_nb_add, binop_456),
+ ENDCASE()
+ CASE("repeat_module")
+ PySlot_DATA(Py_tp_module, Py_True),
+ PySlot_DATA(Py_tp_module, Py_False),
+ ENDCASE()
+
+#undef CASE
+#undef ENDCASE
+ PyErr_Format(PyExc_SystemError, "bad case: %s", case_name);
+ return NULL;
+}
+
+static PyObject *
+type_from_null_slot(PyObject* module, PyObject *args)
+{
+ long slot_number;
+ if (!PyArg_ParseTuple(args, "l", &slot_number)) {
+ return NULL;
+ }
+ return PyType_FromSlots((PySlot[]) {
+ PySlot_DATA(Py_tp_name, "_testlimitedcapi.MyType"),
+ PySlot_DATA(Py_tp_module, module),
+ PySlot_PTR_STATIC((uint16_t)slot_number, NULL),
+ PySlot_END
+ });
+}
+
+static PyObject *
+type_from_null_spec_slot(PyObject* Py_UNUSED(module), PyObject *args)
+{
+ long slot_number;
+ if (!PyArg_ParseTuple(args, "l", &slot_number)) {
+ return NULL;
+ }
+ return PyType_FromSpec(&(PyType_Spec) {
+ .name = "_testlimitedcapi.MyType",
+ .slots = (PyType_Slot[]) {
+ {slot_number, NULL},
+ {0},
+ },
+ });
+}
+
+static PyObject *
+demo_create(PyObject *spec, PyModuleDef *def)
+{
+ assert(def == NULL);
+ return Py_NewRef(spec);
+}
+
+static int
+demo_exec(PyObject *mod)
+{
+ return PyModule_AddStringConstant(mod, "exec_done", "yes");
+}
+
+static PyMethodDef *TestMethods;
+
+static PyObject *
+module_from_slots(PyObject* Py_UNUSED(module), PyObject *args)
+{
+ PyObject *spec;
+ char *case_name;
+ if (!PyArg_ParseTuple(args, "sO", &case_name, &spec)) {
+ return NULL;
+ }
+ PyObject *mod = NULL;
+#define CASE(NAME) \
+ if (strcmp(case_name, NAME) == 0) { \
+ mod = PyModule_FromSlotsAndSpec((PySlot[]) { \
+ PySlot_DATA(Py_mod_abi, &abi_info), \
+ PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED), \
+ /////////////////////////////////////////////////////////////////////////
+#define ENDCASE() \
+ PySlot_END \
+ }, spec); \
+ } \
+ /////////////////////////////////////////////////////////////////////////
+
+ CASE("basic")
+ ENDCASE()
+ CASE("foreign_slot")
+ PySlot_DATA(Py_tp_name, "this is not a type"),
+ ENDCASE()
+ CASE("state_size")
+ PySlot_SIZE(Py_mod_state_size, 42),
+ ENDCASE()
+ CASE("multi_interp")
+ PySlot_DATA(Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED),
+ ENDCASE()
+ CASE("exec")
+ PySlot_FUNC(Py_mod_exec, demo_exec),
+ ENDCASE()
+ CASE("optional_end")
+ {.sl_flags=PySlot_OPTIONAL},
+ ENDCASE()
+ CASE("invalid")
+ {.sl_id=Py_slot_invalid},
+ ENDCASE()
+ CASE("invalid_fbad")
+ {.sl_id=0xfbad},
+ ENDCASE()
+ CASE("optional_invalid")
+ {.sl_id=Py_slot_invalid, .sl_flags=PySlot_OPTIONAL},
+ PySlot_SIZE(Py_mod_exec, demo_exec),
+ ENDCASE()
+ CASE("optional_invalid_fbad")
+ {.sl_id=0xfbad, .sl_flags=PySlot_OPTIONAL},
+ PySlot_SIZE(Py_mod_exec, demo_exec),
+ ENDCASE()
+ CASE("old_slot_numbers")
+ // 1: see old_slot_number_create case
+ PySlot_FUNC(2, demo_exec),
+ PySlot_DATA(3, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED),
+ // 4: see module_from_gil_slot function
+ ENDCASE()
+ CASE("new_slot_numbers")
+ // 84: see new_slot_number_create case
+ PySlot_FUNC(85, demo_exec),
+ PySlot_FUNC(86, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED),
+ // 87: see module_from_gil_slot function
+ ENDCASE()
+ CASE("old_slot_number_create")
+ PySlot_FUNC(1, demo_create),
+ ENDCASE()
+ CASE("new_slot_number_create")
+ PySlot_FUNC(84, demo_create),
+ ENDCASE()
+ CASE("nonstatic_mod_methods")
+ PySlot_DATA(Py_mod_methods, TestMethods),
+ ENDCASE()
+ CASE("intptr_methods")
+ PySlot_PTR_STATIC(Py_mod_methods, TestMethods),
+ ENDCASE()
+ CASE("nested")
+ PySlot_FUNC(Py_mod_exec, demo_exec),
+ PySlot_DATA(Py_slot_subslots, ((PySlot[]) {
+ PySlot_DATA(Py_mod_doc, "doc"),
+ PySlot_END,
+ })),
+ ENDCASE()
+ CASE("nested_max")
+ PySlot_FUNC(Py_mod_exec, demo_exec),
+ PySlot_DATA(Py_slot_subslots, ((PySlot[]) {
+ PySlot_DATA(Py_slot_subslots, ((PySlot[]) {
+ PySlot_DATA(Py_slot_subslots, ((PySlot[]) {
+ PySlot_SIZE(Py_mod_state_size, 53),
+ PySlot_DATA(Py_slot_subslots, ((PySlot[]) {
+ PySlot_DATA(Py_mod_doc, "doc"),
+ PySlot_END
+ })),
+ PySlot_END,
+ })),
+ PySlot_END,
+ })),
+ PySlot_END,
+ })),
+ ENDCASE()
+ CASE("nested_over_limit")
+ PySlot_FUNC(Py_mod_exec, demo_exec),
+ PySlot_DATA(Py_slot_subslots, ((PySlot[]) {
+ PySlot_DATA(Py_slot_subslots, ((PySlot[]) {
+ PySlot_DATA(Py_slot_subslots, ((PySlot[]) {
+ PySlot_SIZE(Py_mod_state_size, 53),
+ PySlot_DATA(Py_slot_subslots, ((PySlot[]) {
+ PySlot_DATA(Py_mod_doc, "doc"),
+ PySlot_DATA(Py_slot_subslots, ((PySlot[]) {
+ PySlot_END
+ })),
+ PySlot_END
+ })),
+ PySlot_END,
+ })),
+ PySlot_END,
+ })),
+ PySlot_END,
+ })),
+ ENDCASE()
+ CASE("nested_old")
+ PySlot_FUNC(Py_mod_exec, demo_exec),
+ PySlot_DATA(Py_mod_slots, ((PyModuleDef_Slot[]) {
+ {Py_mod_doc, "doc"},
+ {0},
+ })),
+ ENDCASE()
+ CASE("nested_old_max")
+ PySlot_FUNC(Py_mod_exec, demo_exec),
+ PySlot_DATA(Py_mod_slots, ((PyModuleDef_Slot[]) {
+ {Py_mod_slots, ((PyModuleDef_Slot[]) {
+ {Py_mod_state_size, (void*)(intptr_t)53},
+ {Py_mod_slots, ((PyModuleDef_Slot[]) {
+ {Py_mod_slots, ((PyModuleDef_Slot[]) {
+ {Py_mod_doc, "doc"},
+ {0},
+ })},
+ {0},
+ })},
+ {0},
+ })},
+ {0},
+ })),
+ ENDCASE()
+ CASE("nested_old_over_limit")
+ PySlot_FUNC(Py_mod_exec, demo_exec),
+ PySlot_DATA(Py_mod_slots, ((PyModuleDef_Slot[]) {
+ {Py_mod_slots, ((PyModuleDef_Slot[]) {
+ {Py_mod_state_size, (void*)(intptr_t)53},
+ {Py_mod_slots, ((PyModuleDef_Slot[]) {
+ {Py_mod_slots, ((PyModuleDef_Slot[]) {
+ {Py_mod_slots, ((PyModuleDef_Slot[]) {
+ {Py_mod_doc, "doc"},
+ {0},
+ })},
+ {0},
+ })},
+ {0},
+ })},
+ {0},
+ })},
+ {0},
+ })),
+ ENDCASE()
+ CASE("nested_pingpong")
+ PySlot_FUNC(Py_mod_exec, demo_exec),
+ PySlot_DATA(Py_mod_slots, ((PyModuleDef_Slot[]) {
+ {Py_slot_subslots, ((PySlot[]) {
+ PySlot_DATA(Py_mod_slots, ((PyModuleDef_Slot[]) {
+ {Py_mod_state_size, (void*)(intptr_t)53},
+ {Py_slot_subslots, ((PySlot[]) {
+ PySlot_DATA(Py_mod_doc, "doc"),
+ PySlot_END
+ })},
+ {0},
+ })),
+ PySlot_END,
+ })},
+ {0},
+ })),
+ ENDCASE()
+ CASE("repeat_create")
+ PySlot_DATA(Py_mod_create, demo_create),
+ PySlot_DATA(Py_mod_create, demo_create),
+ PySlot_DATA(Py_mod_create, demo_create),
+ ENDCASE()
+ CASE("repeat_gil")
+ PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED),
+ PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED),
+ PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED),
+ ENDCASE()
+ CASE("repeat_exec")
+ PySlot_FUNC(Py_mod_exec, demo_exec),
+ PySlot_FUNC(Py_mod_exec, demo_exec),
+ ENDCASE()
+
+#undef CASE
+#undef ENDCASE
+ if (!mod) {
+ if (!PyErr_Occurred()) {
+ PyErr_Format(PyExc_SystemError, "bad case: %s", case_name);
+ return NULL;
+ }
+ return NULL;
+ }
+ if (PyModule_Check(mod)) {
+ Py_ssize_t size;
+ if (PyModule_GetStateSize(mod, &size) < 0) {
+ Py_DECREF(mod);
+ return NULL;
+ }
+ if (PyModule_AddIntConstant(mod, "state_size", (long)size) < 0) {
+ Py_DECREF(mod);
+ return NULL;
+ }
+ if (PyModule_Exec(mod) < 0) {
+ return NULL;
+ }
+ }
+ return mod;
+}
+
+static PyObject *
+module_from_gil_slot(PyObject* Py_UNUSED(module), PyObject *args)
+{
+ long slot_number;
+ PyObject *spec;
+ if (!PyArg_ParseTuple(args, "lO", &slot_number, &spec)) {
+ return NULL;
+ }
+ return PyModule_FromSlotsAndSpec((PySlot[]) {
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_PTR_STATIC((uint16_t)slot_number, Py_MOD_GIL_NOT_USED),
+ PySlot_END
+ }, spec);
+}
+
+static PyObject *
+module_from_null_slot(PyObject* Py_UNUSED(module), PyObject *args)
+{
+ long slot_number;
+ PyObject *spec;
+ if (!PyArg_ParseTuple(args, "lO", &slot_number, &spec)) {
+ return NULL;
+ }
+ uint16_t maybe_gil_slot = Py_mod_gil;
+ if ((slot_number == 4) || (slot_number == 87)) {
+ // Do not repeat the GIL slot
+ maybe_gil_slot = Py_slot_invalid;
+ }
+ return PyModule_FromSlotsAndSpec((PySlot[]) {
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_DATA(Py_mod_name, "mymod"),
+ PySlot_PTR_STATIC((uint16_t)slot_number, NULL),
+ {
+ .sl_id=maybe_gil_slot,
+ .sl_flags=PySlot_OPTIONAL,
+ .sl_ptr=Py_MOD_GIL_NOT_USED,
+ },
+ PySlot_END
+ }, spec);
+}
+
+static PyMethodDef _TestMethods[] = {
+ {"type_from_slots", type_from_slots, METH_VARARGS},
+ {"module_from_gil_slot", module_from_gil_slot, METH_VARARGS},
+ {"type_from_null_slot", type_from_null_slot, METH_VARARGS},
+ {"type_from_null_spec_slot", type_from_null_spec_slot, METH_VARARGS},
+ {"module_from_slots", module_from_slots, METH_VARARGS},
+ {"module_from_null_slot", module_from_null_slot, METH_VARARGS},
+ {NULL},
+};
+static PyMethodDef *TestMethods = _TestMethods;
+
+int
+_PyTestLimitedCAPI_Init_Slots(PyObject *m)
+{
+ if (PyModule_AddFunctions(m, TestMethods) < 0) {
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/Modules/_testmultiphase.c b/Modules/_testmultiphase.c
--- a/Modules/_testmultiphase.c
+++ b/Modules/_testmultiphase.c
@@ -603,7 +603,7 @@ PyInit__testmultiphase_null_slots(void)
/**** Problematic modules ****/
static PyModuleDef_Slot slots_bad_large[] = {
- {_Py_mod_LAST_SLOT + 1, NULL},
+ {Py_slot_invalid, NULL},
{0, NULL},
};
@@ -1051,25 +1051,25 @@ PyABIInfo_VAR(abi_info);
PyMODEXPORT_FUNC
PyModExport__test_from_modexport(void)
{
- static PyModuleDef_Slot slots[] = {
- {Py_mod_abi, &abi_info},
- {Py_mod_name, "_test_from_modexport"},
- {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
- {Py_mod_gil, Py_MOD_GIL_NOT_USED},
- {0},
+ static PySlot slots[] = {
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_DATA(Py_mod_name, "_test_from_modexport"),
+ PySlot_DATA(Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED),
+ PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED),
+ PySlot_END,
};
return slots;
}
PyMODEXPORT_FUNC
PyModExport__test_from_modexport_gil_used(void)
{
- static PyModuleDef_Slot slots[] = {
- {Py_mod_abi, &abi_info},
- {Py_mod_name, "_test_from_modexport_gil_used"},
- {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
- {Py_mod_gil, Py_MOD_GIL_USED},
- {0},
+ static PySlot slots[] = {
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_DATA(Py_mod_name, "_test_from_modexport_gil_used"),
+ PySlot_DATA(Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED),
+ PySlot_DATA(Py_mod_gil, Py_MOD_GIL_USED),
+ PySlot_END,
};
return slots;
}
@@ -1115,33 +1115,33 @@ modexport_create_string(PyObject *spec, PyModuleDef *def)
PyMODEXPORT_FUNC
PyModExport__test_from_modexport_create_nonmodule(void)
{
- static PyModuleDef_Slot slots[] = {
- {Py_mod_abi, &abi_info},
- {Py_mod_name, "_test_from_modexport_create_nonmodule"},
- {Py_mod_create, modexport_create_string},
- {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
- {Py_mod_gil, Py_MOD_GIL_NOT_USED},
- {0},
+ static PySlot slots[] = {
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_DATA(Py_mod_name, "_test_from_modexport_create_nonmodule"),
+ PySlot_FUNC(Py_mod_create, modexport_create_string),
+ PySlot_DATA(Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED),
+ PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED),
+ PySlot_END,
};
return slots;
}
PyMODEXPORT_FUNC
PyModExport__test_from_modexport_create_nonmodule_gil_used(void)
{
- static PyModuleDef_Slot slots[] = {
- {Py_mod_abi, &abi_info},
- {Py_mod_name, "_test_from_modexport_create_nonmodule"},
- {Py_mod_create, modexport_create_string},
- {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
- {Py_mod_gil, Py_MOD_GIL_USED},
- {0},
+ static PySlot slots[] = {
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_DATA(Py_mod_name, "_test_from_modexport_create_nonmodule"),
+ PySlot_FUNC(Py_mod_create, modexport_create_string),
+ PySlot_DATA(Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED),
+ PySlot_DATA(Py_mod_gil, Py_MOD_GIL_USED),
+ PySlot_END,
};
return slots;
}
-static PyModuleDef_Slot modexport_empty_slots[] = {
- {0},
+static PySlot modexport_empty_slots[] = {
+ PySlot_END,
};
PyMODEXPORT_FUNC
@@ -1151,9 +1151,9 @@ PyModExport__test_from_modexport_empty_slots(void)
}
-static PyModuleDef_Slot modexport_minimal_slots[] = {
- {Py_mod_abi, &abi_info},
- {0},
+static PySlot modexport_minimal_slots[] = {
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_END,
};
PyMODEXPORT_FUNC
@@ -1234,18 +1234,18 @@ PyModExport__test_from_modexport_smoke(void)
{"get_modexport_minimal_slots", modexport_get_minimal_slots, METH_NOARGS},
{0},
};
- static PyModuleDef_Slot slots[] = {
- {Py_mod_abi, &abi_info},
- {Py_mod_name, "_test_from_modexport_smoke"},
- {Py_mod_doc, "the expected docstring"},
- {Py_mod_exec, modexport_smoke_exec},
- {Py_mod_state_size, (void*)sizeof(int)},
- {Py_mod_methods, methods},
- {Py_mod_state_free, modexport_smoke_free},
- {Py_mod_token, (void*)&modexport_smoke_test_token},
- {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
- {Py_mod_gil, Py_MOD_GIL_NOT_USED},
- {0},
+ static PySlot slots[] = {
+ PySlot_DATA(Py_mod_abi, &abi_info),
+ PySlot_DATA(Py_mod_name, "_test_from_modexport_smoke"),
+ PySlot_DATA(Py_mod_doc, "the expected docstring"),
+ PySlot_FUNC(Py_mod_exec, modexport_smoke_exec),
+ PySlot_SIZE(Py_mod_state_size, (void*)sizeof(int)),
+ PySlot_STATIC_DATA(Py_mod_methods, methods),
+ PySlot_FUNC(Py_mod_state_free, modexport_smoke_free),
+ PySlot_DATA(Py_mod_token, (void*)&modexport_smoke_test_token),
+ PySlot_DATA(Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED),
+ PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED),
+ PySlot_END,
};
return slots;
}
diff --git a/PCbuild/_testlimitedcapi.vcxproj b/PCbuild/_testlimitedcapi.vcxproj
--- a/PCbuild/_testlimitedcapi.vcxproj
+++ b/PCbuild/_testlimitedcapi.vcxproj
@@ -109,6 +109,7 @@
<ClCompile Include="..\Modules\_testlimitedcapi\object.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\pyos.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\set.c" />
+ <ClCompile Include="..\Modules\_testlimitedcapi\slots.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\sys.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\threadstate.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\tuple.c" />
diff --git a/PCbuild/_testlimitedcapi.vcxproj.filters b/PCbuild/_testlimitedcapi.vcxproj.filters
--- a/PCbuild/_testlimitedcapi.vcxproj.filters
+++ b/PCbuild/_testlimitedcapi.vcxproj.filters
@@ -24,6 +24,7 @@
<ClCompile Include="..\Modules\_testlimitedcapi\object.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\pyos.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\set.c" />
+ <ClCompile Include="..\Modules\_testlimitedcapi\slots.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\sys.c" />
<ClCompile Include="..\Modules\_testlimitedcapi\testcapi_long.h" />
<ClCompile Include="..\Modules\_testlimitedcapi\threadstate.c" />