Skip to content

Commit e5bb7c8

Browse files
authored
Update _datetimemodule.c
1 parent 76cc153 commit e5bb7c8

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Modules/_datetimemodule.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ typedef struct {
5050
/* The interned Unix epoch datetime instance */
5151
PyObject *epoch;
5252

53-
/* Interpreter's dict holds the module */
53+
/* Reference to the interpreter's dict where the current module will be
54+
* reserved even after the referent dict becomes NULL at shutdown. */
5455
PyObject *interp_dict;
5556
} datetime_state;
5657

@@ -185,7 +186,8 @@ _get_current_state(PyObject **p_mod)
185186
Py_DECREF(MOD_VAR)
186187

187188
static int
188-
set_current_module(datetime_state *st, PyObject *mod)
189+
set_current_module(datetime_state *st,
190+
PyInterpreterState *interp, PyObject *mod)
189191
{
190192
assert(mod != NULL);
191193
PyObject *dict = st->interp_dict;
@@ -199,13 +201,13 @@ set_current_module(datetime_state *st, PyObject *mod)
199201
static void
200202
clear_current_module(datetime_state *st, PyObject *expected)
201203
{
202-
PyObject *exc = PyErr_GetRaisedException();
203-
204204
PyObject *dict = st->interp_dict;
205205
if (dict == NULL) {
206206
return; /* Already cleared */
207207
}
208208

209+
PyObject *exc = PyErr_GetRaisedException();
210+
209211
if (expected != NULL) {
210212
PyObject *current;
211213
if (PyDict_GetItemRef(dict, INTERP_KEY, &current) < 0) {
@@ -7284,10 +7286,8 @@ init_state(datetime_state *st,
72847286
static int
72857287
traverse_state(datetime_state *st, visitproc visit, void *arg)
72867288
{
7287-
/* heap types */
72887289
Py_VISIT(st->isocalendar_date_type);
72897290
Py_VISIT(st->interp_dict);
7290-
72917291
return 0;
72927292
}
72937293

@@ -7477,7 +7477,7 @@ _datetime_exec(PyObject *module)
74777477
static_assert(DI100Y == 25 * DI4Y - 1, "DI100Y");
74787478
assert(DI100Y == days_before_year(100+1));
74797479

7480-
if (set_current_module(st, module) < 0) {
7480+
if (set_current_module(st, interp, module) < 0) {
74817481
goto error;
74827482
}
74837483

0 commit comments

Comments
 (0)