diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2022-10-27 03:20:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-27 03:20:54 (GMT) |
commit | 731909ebef3add602374e8a10002c4574bb24d4b (patch) | |
tree | 92c1b2dab288c04429d67a25c4d4c594bd2d5815 /Objects/moduleobject.c | |
parent | 96ae80f1d004f2df4a707919853f0745c9c352d1 (diff) | |
download | cpython-731909ebef3add602374e8a10002c4574bb24d4b.zip cpython-731909ebef3add602374e8a10002c4574bb24d4b.tar.gz cpython-731909ebef3add602374e8a10002c4574bb24d4b.tar.bz2 |
gh-98627: Use a Switch in PyModule_FromDefAndSpec2() (gh-98734)
This helps simplify some changes in follow-up PRs. It also matches what we're doing in PyModule_ExecDef().
Diffstat (limited to 'Objects/moduleobject.c')
-rw-r--r-- | Objects/moduleobject.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index dba20a0..ee8ef7f 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -291,23 +291,27 @@ PyModule_FromDefAndSpec2(PyModuleDef* def, PyObject *spec, int module_api_versio } for (cur_slot = def->m_slots; cur_slot && cur_slot->slot; cur_slot++) { - if (cur_slot->slot == Py_mod_create) { - if (create) { + switch (cur_slot->slot) { + case Py_mod_create: + if (create) { + PyErr_Format( + PyExc_SystemError, + "module %s has multiple create slots", + name); + goto error; + } + create = cur_slot->value; + break; + case Py_mod_exec: + has_execution_slots = 1; + break; + default: + assert(cur_slot->slot < 0 || cur_slot->slot > _Py_mod_LAST_SLOT); PyErr_Format( PyExc_SystemError, - "module %s has multiple create slots", - name); + "module %s uses unknown slot ID %i", + name, cur_slot->slot); goto error; - } - create = cur_slot->value; - } else if (cur_slot->slot < 0 || cur_slot->slot > _Py_mod_LAST_SLOT) { - PyErr_Format( - PyExc_SystemError, - "module %s uses unknown slot ID %i", - name, cur_slot->slot); - goto error; - } else { - has_execution_slots = 1; } } |