diff options
author | Skip Montanaro <skip@pobox.com> | 2007-08-24 21:11:00 (GMT) |
---|---|---|
committer | Skip Montanaro <skip@pobox.com> | 2007-08-24 21:11:00 (GMT) |
commit | 41cfce9c2bcfe6153ee2b42e05ff1d782d1d3b91 (patch) | |
tree | d29c82adfa534b7f7689a2004222858803febc65 /Modules | |
parent | b382b84abec70ca86683972ac1b0170d93ba7ea4 (diff) | |
download | cpython-41cfce9c2bcfe6153ee2b42e05ff1d782d1d3b91.zip cpython-41cfce9c2bcfe6153ee2b42e05ff1d782d1d3b91.tar.gz cpython-41cfce9c2bcfe6153ee2b42e05ff1d782d1d3b91.tar.bz2 |
Remove PyArg_Parse usage from time module. (An extra set of eyeballs on
this would be nice. I'm a little rusty.)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/timemodule.c | 61 |
1 files changed, 51 insertions, 10 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 8ce6667..c7acf3a 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -255,6 +255,29 @@ tmtotuple(struct tm *p) } static PyObject * +structtime_totuple(PyObject *t) +{ + PyObject *x = NULL; + unsigned int i; + PyObject *v = PyTuple_New(9); + if (v == NULL) + return NULL; + + for (i=0; i<9; i++) { + x = PyStructSequence_GET_ITEM(t, i); + Py_INCREF(x); + PyTuple_SET_ITEM(v, i, x); + } + + if (PyErr_Occurred()) { + Py_XDECREF(v); + return NULL; + } + + return v; +} + +static PyObject * time_convert(double when, struct tm * (*function)(const time_t *)) { struct tm *p; @@ -332,18 +355,36 @@ gettmarg(PyObject *args, struct tm *p) { int y; memset((void *) p, '\0', sizeof(struct tm)); + PyObject *t = NULL; - if (!PyArg_Parse(args, "(iiiiiiiii)", - &y, - &p->tm_mon, - &p->tm_mday, - &p->tm_hour, - &p->tm_min, - &p->tm_sec, - &p->tm_wday, - &p->tm_yday, - &p->tm_isdst)) + if (PyTuple_Check(args)) { + t = args; + Py_INCREF(t); + } + else if (Py_Type(args) == &StructTimeType) { + t = structtime_totuple(args); + } + else { + PyErr_SetString(PyExc_TypeError, + "Tuple or struct_time argument required"); return 0; + } + + if (t == NULL || !PyArg_ParseTuple(t, "iiiiiiiii", + &y, + &p->tm_mon, + &p->tm_mday, + &p->tm_hour, + &p->tm_min, + &p->tm_sec, + &p->tm_wday, + &p->tm_yday, + &p->tm_isdst)) { + Py_XDECREF(t); + return 0; + } + Py_DECREF(t); + if (y < 1900) { PyObject *accept = PyDict_GetItemString(moddict, "accept2dyear"); |