Commit 5f87ee33 authored by Skip Montanaro's avatar Skip Montanaro

Remove PyArg_Parse usage from time module. (An extra set of eyeballs on

this would be nice.  I'm a little rusty.)
parent c7cfd715
...@@ -35,6 +35,10 @@ typedef struct { ...@@ -35,6 +35,10 @@ typedef struct {
#define PyStructSequence_SET_ITEM(op, i, v) \ #define PyStructSequence_SET_ITEM(op, i, v) \
(((PyStructSequence *)(op))->ob_item[i] = v) (((PyStructSequence *)(op))->ob_item[i] = v)
#define PyStructSequence_GET_ITEM(op, i) \
(((PyStructSequence *)(op))->ob_item[i])
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -254,6 +254,29 @@ tmtotuple(struct tm *p) ...@@ -254,6 +254,29 @@ tmtotuple(struct tm *p)
return v; return v;
} }
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 * static PyObject *
time_convert(double when, struct tm * (*function)(const time_t *)) time_convert(double when, struct tm * (*function)(const time_t *))
{ {
...@@ -332,18 +355,36 @@ gettmarg(PyObject *args, struct tm *p) ...@@ -332,18 +355,36 @@ gettmarg(PyObject *args, struct tm *p)
{ {
int y; int y;
memset((void *) p, '\0', sizeof(struct tm)); memset((void *) p, '\0', sizeof(struct tm));
PyObject *t = NULL;
if (!PyArg_Parse(args, "(iiiiiiiii)", if (PyTuple_Check(args)) {
&y, t = args;
&p->tm_mon, Py_INCREF(t);
&p->tm_mday, }
&p->tm_hour, else if (Py_Type(args) == &StructTimeType) {
&p->tm_min, t = structtime_totuple(args);
&p->tm_sec, }
&p->tm_wday, else {
&p->tm_yday, PyErr_SetString(PyExc_TypeError,
&p->tm_isdst)) "Tuple or struct_time argument required");
return 0; 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) { if (y < 1900) {
PyObject *accept = PyDict_GetItemString(moddict, PyObject *accept = PyDict_GetItemString(moddict,
"accept2dyear"); "accept2dyear");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment