summaryrefslogtreecommitdiff
path: root/Modules/_datetimemodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_datetimemodule.c')
-rw-r--r--Modules/_datetimemodule.c60
1 files changed, 36 insertions, 24 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index 291920dc0f..205b15bb18 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -987,7 +987,8 @@ call_tzname(PyObject *tzinfo, PyObject *tzinfoarg)
if (tzinfo == Py_None)
Py_RETURN_NONE;
- result = _PyObject_CallMethodId(tzinfo, &PyId_tzname, "O", tzinfoarg);
+ result = _PyObject_CallMethodIdObjArgs(tzinfo, &PyId_tzname,
+ tzinfoarg, NULL);
if (result == NULL || result == Py_None)
return result;
@@ -1343,8 +1344,8 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
goto Done;
format = PyUnicode_FromString(PyBytes_AS_STRING(newfmt));
if (format != NULL) {
- result = _PyObject_CallMethodId(time, &PyId_strftime, "OO",
- format, timetuple, NULL);
+ result = _PyObject_CallMethodIdObjArgs(time, &PyId_strftime,
+ format, timetuple, NULL);
Py_DECREF(format);
}
Py_DECREF(time);
@@ -1385,21 +1386,31 @@ 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);
+ Py_DECREF(args);
return result;
}
@@ -2548,7 +2559,8 @@ date_today(PyObject *cls, PyObject *dummy)
* time.time() delivers; if someone were gonzo about optimization,
* date.today() could get away with plain C time().
*/
- result = _PyObject_CallMethodId(cls, &PyId_fromtimestamp, "O", time);
+ result = _PyObject_CallMethodIdObjArgs(cls, &PyId_fromtimestamp,
+ time, NULL);
Py_DECREF(time);
return result;
}
@@ -2736,7 +2748,8 @@ date_format(PyDateTime_Date *self, PyObject *args)
if (PyUnicode_GetLength(format) == 0)
return PyObject_Str((PyObject *)self);
- return _PyObject_CallMethodId((PyObject *)self, &PyId_strftime, "O", format);
+ return _PyObject_CallMethodIdObjArgs((PyObject *)self, &PyId_strftime,
+ format, NULL);
}
/* ISO methods. */
@@ -3156,7 +3169,7 @@ tzinfo_reduce(PyObject *self)
PyErr_Clear();
state = Py_None;
dictptr = _PyObject_GetDictPtr(self);
- if (dictptr && *dictptr && PyDict_Size(*dictptr)) {
+ if (dictptr && *dictptr && PyDict_GET_SIZE(*dictptr)) {
state = *dictptr;
}
Py_INCREF(state);
@@ -3243,9 +3256,8 @@ timezone_new(PyTypeObject *type, PyObject *args, PyObject *kw)
{
PyObject *offset;
PyObject *name = NULL;
- if (PyArg_ParseTupleAndKeywords(args, kw, "O!|O!:timezone", timezone_kws,
- &PyDateTime_DeltaType, &offset,
- &PyUnicode_Type, &name))
+ if (PyArg_ParseTupleAndKeywords(args, kw, "O!|U:timezone", timezone_kws,
+ &PyDateTime_DeltaType, &offset, &name))
return new_timezone(offset, name);
return NULL;
@@ -4420,8 +4432,8 @@ datetime_strptime(PyObject *cls, PyObject *args)
if (module == NULL)
return NULL;
}
- return _PyObject_CallMethodId(module, &PyId__strptime_datetime, "OOO",
- cls, string, format);
+ return _PyObject_CallMethodIdObjArgs(module, &PyId__strptime_datetime,
+ cls, string, format, NULL);
}
/* Return new datetime from date/datetime and time arguments. */
@@ -4674,7 +4686,7 @@ datetime_repr(PyDateTime_DateTime *self)
static PyObject *
datetime_str(PyDateTime_DateTime *self)
{
- return _PyObject_CallMethodId((PyObject *)self, &PyId_isoformat, "(s)", " ");
+ return _PyObject_CallMethodId((PyObject *)self, &PyId_isoformat, "s", " ");
}
static PyObject *
@@ -5218,7 +5230,7 @@ datetime_astimezone(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
temp = (PyObject *)result;
result = (PyDateTime_DateTime *)
- _PyObject_CallMethodId(tzinfo, &PyId_fromutc, "O", temp);
+ _PyObject_CallMethodIdObjArgs(tzinfo, &PyId_fromutc, temp, NULL);
Py_DECREF(temp);
return result;