@@ -126,8 +126,8 @@ get_module_state(PyObject *module)
126126
127127#define INTERP_KEY ((PyObject *)&_Py_ID(cached_datetime_module))
128128
129- static PyObject *
130- get_current_module (PyInterpreterState * interp )
129+ static int
130+ get_current_module (PyInterpreterState * interp , PyObject * * p_mod )
131131{
132132 PyObject * mod = NULL ;
133133
@@ -151,11 +151,14 @@ get_current_module(PyInterpreterState *interp)
151151 Py_DECREF (ref );
152152 }
153153 }
154- return mod ;
154+ assert (!PyErr_Occurred ());
155+ * p_mod = mod ;
156+ return mod != NULL ;
155157
156158error :
157159 assert (PyErr_Occurred ());
158- return NULL ;
160+ * p_mod = NULL ;
161+ return -1 ;
159162}
160163
161164static PyModuleDef datetimemodule ;
@@ -164,11 +167,11 @@ static datetime_state *
164167_get_current_state (PyObject * * p_mod )
165168{
166169 PyInterpreterState * interp = PyInterpreterState_Get ();
167- PyObject * mod = get_current_module (interp );
170+ PyObject * mod ;
171+ if (get_current_module (interp , & mod ) < 0 ) {
172+ goto error ;
173+ }
168174 if (mod == NULL ) {
169- if (PyErr_Occurred ()) {
170- goto error ;
171- }
172175 /* The static types can outlive the module,
173176 * so we must re-import the module. */
174177 mod = PyImport_ImportModule ("_datetime" );
@@ -7610,9 +7613,8 @@ _datetime_exec(PyObject *module)
76107613 datetime_state * st = get_module_state (module );
76117614
76127615 PyInterpreterState * interp = PyInterpreterState_Get ();
7613- PyObject * old_module = get_current_module (interp );
7614- if (PyErr_Occurred ()) {
7615- assert (old_module == NULL );
7616+ PyObject * old_module ;
7617+ if (get_current_module (interp , & old_module ) < 0 ) {
76167618 goto error ;
76177619 }
76187620 /* We actually set the "current" module right before a successful return. */
0 commit comments