Skip to content

Commit 22c4764

Browse files
authored
Correct PyModule_GetDict() usage
1 parent e5900ef commit 22c4764

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Modules/_datetimemodule.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ _get_current_state(PyObject **p_mod)
191191
Py_DECREF(spec);
192192

193193
/* The module will be held by heaptypes. Prefer
194-
* it not to be stored in the interp-dict. */
194+
* it not to be stored in the interpreter's dict. */
195195
if (PyModule_ExecDef(mod, &datetimemodule) < 0) {
196196
return NULL;
197197
}
@@ -219,9 +219,13 @@ set_current_module(PyInterpreterState *interp, PyObject *mod)
219219
if (ref == NULL) {
220220
return -1;
221221
}
222-
/* A module spec remains in the dict */
222+
/* A module spec remains in the interpreter's dict. */
223+
PyObject *mod_dict = PyModule_GetDict(mod);
224+
if (mod_dict == NULL) {
225+
return -1;
226+
}
223227
PyObject *spec;
224-
if (PyDict_GetItemRef(PyModule_GetDict(mod), &_Py_ID(__spec__), &spec) != 1) {
228+
if (PyDict_GetItemRef(mod_dict, &_Py_ID(__spec__), &spec) != 1) {
225229
return -1;
226230
}
227231
if (PyDict_SetItemString(dict, "datetime_module_spec", spec) < 0) {

0 commit comments

Comments
 (0)