[Python-checkins] cpython: time_strptime() uses PyObject_Call()

victor.stinner python-checkins at python.org
Thu Dec 8 20:16:59 EST 2016


https://hg.python.org/cpython/rev/49a7fdc0d40a
changeset: 105541:49a7fdc0d40a
user: Victor Stinner <victor.stinner at gmail.com>
date: Fri Dec 09 00:38:53 2016 +0100
summary:
 time_strptime() uses PyObject_Call()
Issue #28915: Use PyObject_Call() to pass a tuple of positional arguments,
instead of relying on _PyObject_CallMethodId() weird behaviour to unpack the
tuple.
files:
 Modules/timemodule.c | 20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -717,16 +717,22 @@
 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;
 }
 
 
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /