Skip to content

Commit dbe28d2

Browse files
committed
time_strptime() uses PyObject_Call()
Issue python#28915: Use PyObject_Call() to pass a tuple of positional arguments, instead of relying on _PyObject_CallMethodId() weird behaviour to unpack the tuple.
1 parent 2b63597 commit dbe28d2

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

‎Modules/timemodule.c‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -717,16 +717,22 @@ is not present, current time as returned by localtime() is used.\n\
717717
static PyObject *
718718
time_strptime(PyObject *self, PyObject *args)
719719
{
720-
PyObject *strptime_module = PyImport_ImportModuleNoBlock("_strptime");
721-
PyObject *strptime_result;
720+
PyObject *module, *func, *result;
722721
_Py_IDENTIFIER(_strptime_time);
723722

724-
if (!strptime_module)
723+
module = PyImport_ImportModuleNoBlock("_strptime");
724+
if (!module)
725725
return NULL;
726-
strptime_result = _PyObject_CallMethodId(strptime_module,
727-
&PyId__strptime_time, "O", args);
728-
Py_DECREF(strptime_module);
729-
return strptime_result;
726+
727+
func = _PyObject_GetAttrId(module, &PyId__strptime_time);
728+
Py_DECREF(module);
729+
if (!func) {
730+
return NULL;
731+
}
732+
733+
result = PyObject_Call(func, args, NULL);
734+
Py_DECREF(func);
735+
return result;
730736
}
731737

732738

0 commit comments

Comments
 (0)