]> granicus.if.org Git - python/commitdiff
time_strptime() uses PyObject_Call()
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 8 Dec 2016 23:38:53 +0000 (00:38 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Thu, 8 Dec 2016 23:38:53 +0000 (00:38 +0100)
Issue #28915: Use PyObject_Call() to pass a tuple of positional arguments,
instead of relying on _PyObject_CallMethodId() weird behaviour to unpack the
tuple.

Modules/timemodule.c

index db0ab5805c50d9e7514eba464877850afc41df49..e9edbf3d3f161f3d7161e6825e32493516f6ca98 100644 (file)
@@ -717,16 +717,22 @@ is not present, current time as returned by localtime() is used.\n\
 static PyObject *
 time_strptime(PyObject *self, PyObject *args)
 {
-    PyObject *strptime_module = PyImport_ImportModuleNoBlock("_strptime");
-    PyObject *strptime_result;
+    PyObject *module, *func, *result;
     _Py_IDENTIFIER(_strptime_time);
 
-    if (!strptime_module)
+    module = PyImport_ImportModuleNoBlock("_strptime");
+    if (!module)
         return NULL;
-    strptime_result = _PyObject_CallMethodId(strptime_module,
-                                             &PyId__strptime_time, "O", args);
-    Py_DECREF(strptime_module);
-    return strptime_result;
+
+    func = _PyObject_GetAttrId(module, &PyId__strptime_time);
+    Py_DECREF(module);
+    if (!func) {
+        return NULL;
+    }
+
+    result = PyObject_Call(func, args, NULL);
+    Py_DECREF(func);
+    return result;
 }