Skip to content

Commit 4b9c943

Browse files
committed
Make Py_mod_abi mandatory for PyModExport
1 parent b4fac15 commit 4b9c943

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

Lib/test/test_cext/extension.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ _Py_COMP_DIAG_PUSH
119119
#endif
120120

121121
PyDoc_STRVAR(_testcext_doc, "C test extension.");
122+
PyABIInfo_VAR(abi_info);
122123

123124
static PyModuleDef_Slot _testcext_slots[] = {
125+
{Py_mod_abi, &abi_info},
124126
{Py_mod_name, STR(MODULE_NAME)},
125127
{Py_mod_doc, (void*)(char*)_testcext_doc},
126128
{Py_mod_exec, (void*)_testcext_exec},

Objects/moduleobject.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ module_from_def_and_spec(
446446
bool seen_m_traverse_slot = false;
447447
bool seen_m_clear_slot = false;
448448
bool seen_m_free_slot = false;
449+
bool seen_m_abi_slot = false;
449450
for (cur_slot = def_like->m_slots; cur_slot && cur_slot->slot; cur_slot++) {
450451

451452
// Macro to copy a non-NULL, non-repeatable slot.
@@ -555,6 +556,7 @@ module_from_def_and_spec(
555556
if (PyABIInfo_Check((PyABIInfo *)cur_slot->value, name) < 0) {
556557
goto error;
557558
}
559+
seen_m_abi_slot = true;
558560
break;
559561
DEF_SLOT_CASE(Py_mod_name, char*, m_name)
560562
DEF_SLOT_CASE(Py_mod_doc, char*, m_doc)
@@ -587,6 +589,14 @@ module_from_def_and_spec(
587589
#undef COPY_NONDEF_SLOT
588590
#undef COPY_NONNULL_SLOT
589591
}
592+
if (!original_def && !seen_m_abi_slot) {
593+
PyErr_Format(
594+
PyExc_SystemError,
595+
"module %s does not define Py_mod_abi,"
596+
" which is mandatory for modules defined from slots only.",
597+
name);
598+
goto error;
599+
}
590600

591601
#ifdef Py_GIL_DISABLED
592602
// For modules created directly from slots (not from a def), we enable

0 commit comments

Comments
 (0)