Skip to content

Commit 97a6d0d

Browse files
authored
Set a spec later in set_current_module()
1 parent b9eaee1 commit 97a6d0d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Modules/_datetimemodule.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,14 @@ set_current_module(PyInterpreterState *interp, PyObject *mod)
219219
if (ref == NULL) {
220220
return -1;
221221
}
222-
/* Module spec remains in the interpreter's dict. */
222+
if (PyDict_SetItem(dict, INTERP_KEY, ref) < 0) {
223+
Py_DECREF(ref);
224+
return -1;
225+
}
226+
Py_DECREF(ref);
227+
228+
/* Make the module spec remain in the interpreter's dict. Not required,
229+
* but reserve the new one for memory efficiency. */
223230
PyObject *mod_dict = PyModule_GetDict(mod);
224231
if (mod_dict == NULL) {
225232
return -1;
@@ -233,10 +240,7 @@ set_current_module(PyInterpreterState *interp, PyObject *mod)
233240
return -1;
234241
}
235242
Py_DECREF(spec);
236-
237-
int rc = PyDict_SetItem(dict, INTERP_KEY, ref);
238-
Py_DECREF(ref);
239-
return rc;
243+
return 0;
240244
}
241245

242246
static void

0 commit comments

Comments
 (0)