Skip to content
Closed
Prev Previous commit
Next Next commit
Revert "Use Py_mod_constants instead of PyModuleDef.m_constants"
This reverts commit 042e0999ed5ecf88de63de1140d968ab14745e3f.
  • Loading branch information
tiran committed Apr 17, 2021
commit 31f818933ae1fe3820dfa5bb551ad73848f596f5
7 changes: 2 additions & 5 deletions Include/moduleobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,8 @@ typedef struct PyModuleDef_Slot{
#define Py_mod_create 1
#define Py_mod_exec 2

#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03100000
#define Py_mod_constants 3
#endif

#ifndef Py_LIMITED_API
#define _Py_mod_LAST_SLOT 3
#define _Py_mod_LAST_SLOT 2
#endif

#endif /* New in 3.5 */
Expand Down Expand Up @@ -129,6 +125,7 @@ typedef struct PyModuleDef{
traverseproc m_traverse;
inquiry m_clear;
freefunc m_free;
struct PyModuleConst_Def* m_constants;
} PyModuleDef;


Expand Down
7 changes: 1 addition & 6 deletions Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3599,18 +3599,13 @@ PyDoc_STRVAR(module_doc,
"This module provides access to the mathematical functions\n"
"defined by the C standard.");

static PyModuleDef_Slot math_slots[] = {
{Py_mod_constants, math_constants},
{0, NULL}
};

static struct PyModuleDef mathmodule = {
PyModuleDef_HEAD_INIT,
.m_name = "math",
.m_doc = module_doc,
.m_size = 0,
.m_methods = math_methods,
.m_slots = math_slots,
.m_constants = math_constants,
};

PyMODINIT_FUNC
Expand Down
2 changes: 1 addition & 1 deletion Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -15772,7 +15772,6 @@ static PyModuleConst_Def _posix_constants[] = {

static PyModuleDef_Slot posixmodile_slots[] = {
{Py_mod_exec, posixmodule_exec},
{Py_mod_constants, _posix_constants},
{0, NULL}
};

Expand All @@ -15786,6 +15785,7 @@ static struct PyModuleDef posixmodule = {
.m_traverse = _posix_traverse,
.m_clear = _posix_clear,
.m_free = _posix_free,
.m_constants = _posix_constants,
};

PyMODINIT_FUNC
Expand Down
19 changes: 13 additions & 6 deletions Objects/moduleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ _PyModule_CreateInitialized(struct PyModuleDef* module, int module_api_version)
return NULL;
}
}
if (module->m_constants != NULL) {
if (PyModule_AddConstants((PyObject *) m, module->m_constants) != 0) {
Py_DECREF(m);
return NULL;
}
}
m->md_def = module;
return (PyObject*)m;
}
Expand Down Expand Up @@ -418,6 +424,13 @@ PyModule_FromDefAndSpec2(struct PyModuleDef* def, PyObject *spec, int module_api
}
}

if (def->m_constants != NULL) {
if (PyModule_AddConstants(m, def->m_constants) != 0) {
Py_DECREF(m);
return NULL;
}
}

Py_DECREF(nameobj);
return m;

Expand Down Expand Up @@ -481,12 +494,6 @@ PyModule_ExecDef(PyObject *module, PyModuleDef *def)
return -1;
}
break;
case Py_mod_constants:
ret = PyModule_AddConstants(module, (PyModuleConst_Def *)cur_slot->value);
if (ret == -1) {
return -1;
}
break;
default:
PyErr_Format(
PyExc_SystemError,
Expand Down