Skip to content

Commit d762ed5

Browse files
committed
Remove obsolete 'reloading' state.
1 parent 0ad304f commit d762ed5

1 file changed

Lines changed: 66 additions & 71 deletions

File tree

Modules/_datetimemodule.c

Lines changed: 66 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,9 @@ get_module_state(PyObject *module)
125125
#define INTERP_KEY ((PyObject *)&_Py_ID(cached_datetime_module))
126126

127127
static PyObject *
128-
get_current_module(PyInterpreterState *interp, int *p_reloading)
128+
get_current_module(PyInterpreterState *interp)
129129
{
130130
PyObject *mod = NULL;
131-
int reloading = 0;
132131

133132
PyObject *dict = PyInterpreterState_GetDict(interp);
134133
if (dict == NULL) {
@@ -139,7 +138,6 @@ get_current_module(PyInterpreterState *interp, int *p_reloading)
139138
goto error;
140139
}
141140
if (ref != NULL) {
142-
reloading = 1;
143141
if (ref != Py_None) {
144142
(void)PyWeakref_GetRef(ref, &mod);
145143
if (mod == Py_None) {
@@ -148,9 +146,6 @@ get_current_module(PyInterpreterState *interp, int *p_reloading)
148146
Py_DECREF(ref);
149147
}
150148
}
151-
if (p_reloading != NULL) {
152-
*p_reloading = reloading;
153-
}
154149
return mod;
155150

156151
error:
@@ -164,7 +159,7 @@ static datetime_state *
164159
_get_current_state(PyObject **p_mod)
165160
{
166161
PyInterpreterState *interp = PyInterpreterState_Get();
167-
PyObject *mod = get_current_module(interp, NULL);
162+
PyObject *mod = get_current_module(interp);
168163
if (mod == NULL) {
169164
assert(!PyErr_Occurred());
170165
if (PyErr_Occurred()) {
@@ -7348,7 +7343,70 @@ _PyDateTime_InitTypes(PyInterpreterState *interp)
73487343
}
73497344
}
73507345

7346+
#define DATETIME_ADD_MACRO(dict, c, value_expr) \
7347+
do { \
7348+
assert(!PyErr_Occurred()); \
7349+
PyObject *value = (value_expr); \
7350+
if (value == NULL) { \
7351+
goto error; \
7352+
} \
7353+
if (PyDict_SetItemString(dict, c, value) < 0) { \
7354+
Py_DECREF(value); \
7355+
goto error; \
7356+
} \
7357+
Py_DECREF(value); \
7358+
} while(0)
7359+
7360+
/* timedelta values */
7361+
PyObject *d = _PyType_GetDict(&PyDateTime_DeltaType);
7362+
DATETIME_ADD_MACRO(d, "resolution", new_delta(0, 0, 1, 0));
7363+
DATETIME_ADD_MACRO(d, "min", new_delta(-MAX_DELTA_DAYS, 0, 0, 0));
7364+
DATETIME_ADD_MACRO(d, "max",
7365+
new_delta(MAX_DELTA_DAYS, 24*3600-1, 1000000-1, 0));
7366+
7367+
/* date values */
7368+
d = _PyType_GetDict(&PyDateTime_DateType);
7369+
DATETIME_ADD_MACRO(d, "min", new_date(1, 1, 1));
7370+
DATETIME_ADD_MACRO(d, "max", new_date(MAXYEAR, 12, 31));
7371+
DATETIME_ADD_MACRO(d, "resolution", new_delta(1, 0, 0, 0));
7372+
7373+
/* time values */
7374+
d = _PyType_GetDict(&PyDateTime_TimeType);
7375+
DATETIME_ADD_MACRO(d, "min", new_time(0, 0, 0, 0, Py_None, 0));
7376+
DATETIME_ADD_MACRO(d, "max", new_time(23, 59, 59, 999999, Py_None, 0));
7377+
DATETIME_ADD_MACRO(d, "resolution", new_delta(0, 0, 1, 0));
7378+
7379+
/* datetime values */
7380+
d = _PyType_GetDict(&PyDateTime_DateTimeType);
7381+
DATETIME_ADD_MACRO(d, "min",
7382+
new_datetime(1, 1, 1, 0, 0, 0, 0, Py_None, 0));
7383+
DATETIME_ADD_MACRO(d, "max", new_datetime(MAXYEAR, 12, 31, 23, 59, 59,
7384+
999999, Py_None, 0));
7385+
DATETIME_ADD_MACRO(d, "resolution", new_delta(0, 0, 1, 0));
7386+
7387+
/* timezone values */
7388+
d = _PyType_GetDict(&PyDateTime_TimeZoneType);
7389+
if (PyDict_SetItemString(d, "utc", (PyObject *)&utc_timezone) < 0) {
7390+
goto error;
7391+
}
7392+
7393+
/* bpo-37642: These attributes are rounded to the nearest minute for backwards
7394+
* compatibility, even though the constructor will accept a wider range of
7395+
* values. This may change in the future.*/
7396+
7397+
/* -23:59 */
7398+
DATETIME_ADD_MACRO(d, "min", create_timezone_from_delta(-1, 60, 0, 1));
7399+
7400+
/* +23:59 */
7401+
DATETIME_ADD_MACRO(
7402+
d, "max", create_timezone_from_delta(0, (23 * 60 + 59) * 60, 0, 0));
7403+
7404+
#undef DATETIME_ADD_MACRO
7405+
73517406
return _PyStatus_OK();
7407+
7408+
error:
7409+
return _PyStatus_NO_MEMORY();
73527410
}
73537411

73547412

@@ -7366,10 +7424,9 @@ _datetime_exec(PyObject *module)
73667424
{
73677425
int rc = -1;
73687426
datetime_state *st = get_module_state(module);
7369-
int reloading = 0;
73707427

73717428
PyInterpreterState *interp = PyInterpreterState_Get();
7372-
PyObject *old_module = get_current_module(interp, &reloading);
7429+
PyObject *old_module = get_current_module(interp);
73737430
if (PyErr_Occurred()) {
73747431
assert(old_module == NULL);
73757432
goto error;
@@ -7389,68 +7446,6 @@ _datetime_exec(PyObject *module)
73897446
goto error;
73907447
}
73917448

7392-
#define DATETIME_ADD_MACRO(dict, c, value_expr) \
7393-
do { \
7394-
assert(!PyErr_Occurred()); \
7395-
PyObject *value = (value_expr); \
7396-
if (value == NULL) { \
7397-
goto error; \
7398-
} \
7399-
if (PyDict_SetItemString(dict, c, value) < 0) { \
7400-
Py_DECREF(value); \
7401-
goto error; \
7402-
} \
7403-
Py_DECREF(value); \
7404-
} while(0)
7405-
7406-
if (!reloading) {
7407-
/* timedelta values */
7408-
PyObject *d = _PyType_GetDict(&PyDateTime_DeltaType);
7409-
DATETIME_ADD_MACRO(d, "resolution", new_delta(0, 0, 1, 0));
7410-
DATETIME_ADD_MACRO(d, "min", new_delta(-MAX_DELTA_DAYS, 0, 0, 0));
7411-
DATETIME_ADD_MACRO(d, "max",
7412-
new_delta(MAX_DELTA_DAYS, 24*3600-1, 1000000-1, 0));
7413-
7414-
/* date values */
7415-
d = _PyType_GetDict(&PyDateTime_DateType);
7416-
DATETIME_ADD_MACRO(d, "min", new_date(1, 1, 1));
7417-
DATETIME_ADD_MACRO(d, "max", new_date(MAXYEAR, 12, 31));
7418-
DATETIME_ADD_MACRO(d, "resolution", new_delta(1, 0, 0, 0));
7419-
7420-
/* time values */
7421-
d = _PyType_GetDict(&PyDateTime_TimeType);
7422-
DATETIME_ADD_MACRO(d, "min", new_time(0, 0, 0, 0, Py_None, 0));
7423-
DATETIME_ADD_MACRO(d, "max", new_time(23, 59, 59, 999999, Py_None, 0));
7424-
DATETIME_ADD_MACRO(d, "resolution", new_delta(0, 0, 1, 0));
7425-
7426-
/* datetime values */
7427-
d = _PyType_GetDict(&PyDateTime_DateTimeType);
7428-
DATETIME_ADD_MACRO(d, "min",
7429-
new_datetime(1, 1, 1, 0, 0, 0, 0, Py_None, 0));
7430-
DATETIME_ADD_MACRO(d, "max", new_datetime(MAXYEAR, 12, 31, 23, 59, 59,
7431-
999999, Py_None, 0));
7432-
DATETIME_ADD_MACRO(d, "resolution", new_delta(0, 0, 1, 0));
7433-
7434-
/* timezone values */
7435-
d = _PyType_GetDict(&PyDateTime_TimeZoneType);
7436-
if (PyDict_SetItemString(d, "utc", (PyObject *)&utc_timezone) < 0) {
7437-
goto error;
7438-
}
7439-
7440-
/* bpo-37642: These attributes are rounded to the nearest minute for backwards
7441-
* compatibility, even though the constructor will accept a wider range of
7442-
* values. This may change in the future.*/
7443-
7444-
/* -23:59 */
7445-
DATETIME_ADD_MACRO(d, "min", create_timezone_from_delta(-1, 60, 0, 1));
7446-
7447-
/* +23:59 */
7448-
DATETIME_ADD_MACRO(
7449-
d, "max", create_timezone_from_delta(0, (23 * 60 + 59) * 60, 0, 0));
7450-
}
7451-
7452-
#undef DATETIME_ADD_MACRO
7453-
74547449
/* Add module level attributes */
74557450
if (PyModule_AddIntMacro(module, MINYEAR) < 0) {
74567451
goto error;

0 commit comments

Comments
 (0)