mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
gh-71587: Drop local reference cache to _strptime
module in _datetime
(gh-120224)
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()).
This commit is contained in:
parent
fabcf6bc8f
commit
127c1d2771
8 changed files with 24 additions and 8 deletions
|
@ -5514,19 +5514,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_Import(&_Py_ID(_strptime));
|
||||
if (module == NULL) {
|
||||
module = PyImport_ImportModule("_strptime");
|
||||
if (module == NULL)
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
return PyObject_CallMethodObjArgs(module, &_Py_ID(_strptime_datetime),
|
||||
cls, string, format, NULL);
|
||||
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. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue