Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7719eef

Browse filesBrowse files
authored
[3.12] gh-71587: Drop local reference cache to _strptime module in _datetime (gh-120431)
The _strptime module object was cached in a static local variable (in the datetime.strptime() implementation). That's a problem when it crosses isolation boundaries, such as reinitializing the runtme or between interpreters. This change fixes the problem by dropping the static variable, instead always relying on the normal sys.modules cache (via PyImport_Import()). (cherry picked from commit 127c1d2, AKA gh-120224)
1 parent eff0553 commit 7719eef
Copy full SHA for 7719eef

File tree

3 files changed

+9
-8
lines changed
Filter options

3 files changed

+9
-8
lines changed
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix crash in C version of :meth:`datetime.datetime.strptime` when called again
2+
on the restarted interpreter.

‎Modules/_datetimemodule.c

Copy file name to clipboardExpand all lines: Modules/_datetimemodule.c
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5209,19 +5209,19 @@ datetime_utcfromtimestamp(PyObject *cls, PyObject *args)
52095209
static PyObject *
52105210
datetime_strptime(PyObject *cls, PyObject *args)
52115211
{
5212-
static PyObject *module = NULL;
5213-
PyObject *string, *format;
5212+
PyObject *string, *format, *result;
52145213

52155214
if (!PyArg_ParseTuple(args, "UU:strptime", &string, &format))
52165215
return NULL;
52175216

5217+
PyObject *module = PyImport_ImportModule("_strptime");
52185218
if (module == NULL) {
5219-
module = PyImport_ImportModule("_strptime");
5220-
if (module == NULL)
5221-
return NULL;
5219+
return NULL;
52225220
}
5223-
return PyObject_CallMethodObjArgs(module, &_Py_ID(_strptime_datetime),
5224-
cls, string, format, NULL);
5221+
result = PyObject_CallMethodObjArgs(module, &_Py_ID(_strptime_datetime),
5222+
cls, string, format, NULL);
5223+
Py_DECREF(module);
5224+
return result;
52255225
}
52265226

52275227
/* Return new datetime from date/datetime and time arguments. */

‎Tools/c-analyzer/cpython/globals-to-fix.tsv

Copy file name to clipboardExpand all lines: Tools/c-analyzer/cpython/globals-to-fix.tsv
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,6 @@ Modules/_ctypes/_ctypes.c CreateSwappedType suffix -
422422
Modules/_ctypes/_ctypes.c - _unpickle -
423423
Modules/_ctypes/_ctypes.c PyCArrayType_from_ctype cache -
424424
Modules/_cursesmodule.c - ModDict -
425-
Modules/_datetimemodule.c datetime_strptime module -
426425
Modules/_datetimemodule.c - PyDateTime_TimeZone_UTC -
427426
Modules/_datetimemodule.c - PyDateTime_Epoch -
428427
Modules/_datetimemodule.c - us_per_ms -

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.