diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-12-08 23:38:16 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-12-08 23:38:16 (GMT) |
commit | 2b635971e7fedc06b8a12d467a8b717c9752f4a4 (patch) | |
tree | 7ea961b4b7269c77680970122737760d92ed9446 /Modules/_datetimemodule.c | |
parent | 7e42541d08b6cc103b892c1cb70ea68c66751078 (diff) | |
download | cpython-2b635971e7fedc06b8a12d467a8b717c9752f4a4.zip cpython-2b635971e7fedc06b8a12d467a8b717c9752f4a4.tar.gz cpython-2b635971e7fedc06b8a12d467a8b717c9752f4a4.tar.bz2 |
build_struct_time() uses Py_BuildValue()
Issue #28915: Avoid calling _PyObject_CallMethodId() with "(...)" format to
avoid the creation of a temporary tuple: use Py_BuildValue() with
_PyObject_CallMethodIdObjArgs().
Diffstat (limited to 'Modules/_datetimemodule.c')
-rw-r--r-- | Modules/_datetimemodule.c | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 0999218..77caba1 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -1385,21 +1385,30 @@ static PyObject * build_struct_time(int y, int m, int d, int hh, int mm, int ss, int dstflag) { PyObject *time; - PyObject *result = NULL; + PyObject *result; + _Py_IDENTIFIER(struct_time); + PyObject *args; + time = PyImport_ImportModuleNoBlock("time"); - if (time != NULL) { - _Py_IDENTIFIER(struct_time); - - result = _PyObject_CallMethodId(time, &PyId_struct_time, - "((iiiiiiiii))", - y, m, d, - hh, mm, ss, - weekday(y, m, d), - days_before_month(y, m) + d, - dstflag); + if (time == NULL) { + return NULL; + } + + args = Py_BuildValue("iiiiiiiii", + y, m, d, + hh, mm, ss, + weekday(y, m, d), + days_before_month(y, m) + d, + dstflag); + if (args == NULL) { Py_DECREF(time); + return NULL; } + + result = _PyObject_CallMethodIdObjArgs(time, &PyId_struct_time, + args, NULL); + Py_DECREF(time); return result; } |