Skip to content

Commit 225e6aa

Browse files
committed
Address review
1 parent a60ec4c commit 225e6aa

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

Modules/_datetimemodule.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,23 @@ _get_current_state(PyObject **p_mod)
167167
PyObject *mod = get_current_module(interp);
168168
if (mod == NULL) {
169169
if (PyErr_Occurred()) {
170-
return NULL;
170+
goto error;
171171
}
172172
/* The static types can outlive the module,
173173
* so we must re-import the module. */
174174
mod = PyImport_ImportModule("_datetime");
175175
if (mod == NULL) {
176-
return NULL;
176+
goto error;
177177
}
178178
}
179179
datetime_state *st = get_module_state(mod);
180180
*p_mod = mod;
181181
return st;
182+
183+
error:
184+
assert(PyErr_Occurred());
185+
*p_mod = NULL;
186+
return NULL;
182187
}
183188

184189
#define GET_CURRENT_STATE(MOD_VAR) \
@@ -2130,10 +2135,9 @@ delta_to_microseconds(PyDateTime_Delta *self)
21302135
PyObject *x3 = NULL;
21312136
PyObject *result = NULL;
21322137

2133-
PyObject *current_mod = NULL;
2138+
PyObject *current_mod;
21342139
datetime_state *st = GET_CURRENT_STATE(current_mod);
21352140
if (st == NULL) {
2136-
assert(current_mod == NULL);
21372141
return NULL;
21382142
}
21392143

@@ -2213,10 +2217,9 @@ microseconds_to_delta_ex(PyObject *pyus, PyTypeObject *type)
22132217
PyObject *num = NULL;
22142218
PyObject *result = NULL;
22152219

2216-
PyObject *current_mod = NULL;
2220+
PyObject *current_mod;
22172221
datetime_state *st = GET_CURRENT_STATE(current_mod);
22182222
if (st == NULL) {
2219-
assert(current_mod == NULL);
22202223
return NULL;
22212224
}
22222225

@@ -2825,10 +2828,9 @@ delta_new_impl(PyTypeObject *type, PyObject *days, PyObject *seconds,
28252828
{
28262829
PyObject *self = NULL;
28272830

2828-
PyObject *current_mod = NULL;
2831+
PyObject *current_mod;
28292832
datetime_state *st = GET_CURRENT_STATE(current_mod);
28302833
if (st == NULL) {
2831-
assert(current_mod == NULL);
28322834
return NULL;
28332835
}
28342836

@@ -3028,10 +3030,9 @@ delta_total_seconds(PyObject *op, PyObject *Py_UNUSED(dummy))
30283030
if (total_microseconds == NULL)
30293031
return NULL;
30303032

3031-
PyObject *current_mod = NULL;
3033+
PyObject *current_mod;
30323034
datetime_state *st = GET_CURRENT_STATE(current_mod);
30333035
if (st == NULL) {
3034-
assert(current_mod == NULL);
30353036
Py_DECREF(total_microseconds);
30363037
return NULL;
30373038
}
@@ -3886,10 +3887,9 @@ date_isocalendar(PyObject *self, PyObject *Py_UNUSED(dummy))
38863887
week = 0;
38873888
}
38883889

3889-
PyObject *current_mod = NULL;
3890+
PyObject *current_mod;
38903891
datetime_state *st = GET_CURRENT_STATE(current_mod);
38913892
if (st == NULL) {
3892-
assert(current_mod == NULL);
38933893
return NULL;
38943894
}
38953895

@@ -6823,10 +6823,9 @@ local_timezone(PyDateTime_DateTime *utc_time)
68236823
PyObject *one_second;
68246824
PyObject *seconds;
68256825

6826-
PyObject *current_mod = NULL;
6826+
PyObject *current_mod;
68276827
datetime_state *st = GET_CURRENT_STATE(current_mod);
68286828
if (st == NULL) {
6829-
assert(current_mod == NULL);
68306829
return NULL;
68316830
}
68326831

@@ -7074,10 +7073,9 @@ datetime_timestamp(PyObject *op, PyObject *Py_UNUSED(dummy))
70747073
PyObject *result;
70757074

70767075
if (HASTZINFO(self) && self->tzinfo != Py_None) {
7077-
PyObject *current_mod = NULL;
7076+
PyObject *current_mod;
70787077
datetime_state *st = GET_CURRENT_STATE(current_mod);
70797078
if (st == NULL) {
7080-
assert(current_mod == NULL);
70817079
return NULL;
70827080
}
70837081

0 commit comments

Comments
 (0)