mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[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 127c1d2771
, AKA gh-120224)
This commit is contained in:
parent
eff055340f
commit
7719eefcce
3 changed files with 9 additions and 8 deletions
|
@ -0,0 +1,2 @@
|
|||
Fix crash in C version of :meth:`datetime.datetime.strptime` when called again
|
||||
on the restarted interpreter.
|
|
@ -5209,19 +5209,19 @@ datetime_utcfromtimestamp(PyObject *cls, PyObject *args)
|
|||
static PyObject *
|
||||
datetime_strptime(PyObject *cls, PyObject *args)
|
||||
{
|
||||
static PyObject *module = NULL;
|
||||
PyObject *string, *format;
|
||||
PyObject *string, *format, *result;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "UU:strptime", &string, &format))
|
||||
return NULL;
|
||||
|
||||
PyObject *module = PyImport_ImportModule("_strptime");
|
||||
if (module == NULL) {
|
||||
module = PyImport_ImportModule("_strptime");
|
||||
if (module == NULL)
|
||||
return NULL;
|
||||
}
|
||||
return PyObject_CallMethodObjArgs(module, &_Py_ID(_strptime_datetime),
|
||||
result = PyObject_CallMethodObjArgs(module, &_Py_ID(_strptime_datetime),
|
||||
cls, string, format, NULL);
|
||||
Py_DECREF(module);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Return new datetime from date/datetime and time arguments. */
|
||||
|
|
|
@ -422,7 +422,6 @@ Modules/_ctypes/_ctypes.c CreateSwappedType suffix -
|
|||
Modules/_ctypes/_ctypes.c - _unpickle -
|
||||
Modules/_ctypes/_ctypes.c PyCArrayType_from_ctype cache -
|
||||
Modules/_cursesmodule.c - ModDict -
|
||||
Modules/_datetimemodule.c datetime_strptime module -
|
||||
Modules/_datetimemodule.c - PyDateTime_TimeZone_UTC -
|
||||
Modules/_datetimemodule.c - PyDateTime_Epoch -
|
||||
Modules/_datetimemodule.c - us_per_ms -
|
||||
|
|
Can't render this file because it has a wrong number of fields in line 4.
|
Loading…
Add table
Add a link
Reference in a new issue