[Python-checkins] python/dist/src/Modules datetimemodule.c,1.50,1.51
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Fri, 31 Jan 2003 14:27:20 -0800
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv23124/Modules
Modified Files:
datetimemodule.c
Log Message:
The various datetime object __setstate__() methods are no longer public
(pickling no longer needs them, and immutable objects shouldn't have
visible __setstate__() methods regardless). Rearranged the code to
put the internal setstate functions in the constructor sections.
Repaired the timedelta reduce() method, which was still producing
stuff that required a public timedelta.__setstate__() when unpickling.
Index: datetimemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/datetimemodule.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -C2 -d -r1.50 -r1.51
*** datetimemodule.c 31 Jan 2003 01:37:35 -0000 1.50
--- datetimemodule.c 31 Jan 2003 22:27:17 -0000 1.51
***************
*** 1960,1963 ****
--- 1960,1964 ----
}
+ /* __setstate__ isn't exposed. */
static PyObject *
delta_setstate(PyDateTime_Delta *self, PyObject *state)
***************
*** 1989,1993 ****
* tuple as the 2nd component of the result 3-tuple.
*/
! result = Py_BuildValue("O()O", self->ob_type, state);
Py_DECREF(state);
}
--- 1990,1998 ----
* tuple as the 2nd component of the result 3-tuple.
*/
! result = Py_BuildValue("O(iii)",
! self->ob_type,
! self->days,
! self->seconds,
! self->microseconds);
Py_DECREF(state);
}
***************
*** 2011,2018 ****
static PyMethodDef delta_methods[] = {
-
- {"__setstate__", (PyCFunction)delta_setstate, METH_O,
- PyDoc_STR("__setstate__(state)")},
-
{"__getstate__", (PyCFunction)delta_getstate, METH_NOARGS,
PyDoc_STR("__getstate__() -> state")},
--- 2016,2019 ----
***************
*** 2146,2150 ****
static char *date_kws[] = {"year", "month", "day", NULL};
! static PyObject *date_setstate(PyDateTime_Date *self, PyObject *arg);
static PyObject *
--- 2147,2179 ----
static char *date_kws[] = {"year", "month", "day", NULL};
! /* __setstate__ isn't exposed. */
! static PyObject *
! date_setstate(PyDateTime_Date *self, PyObject *arg)
! {
! PyObject *state;
! int len;
! unsigned char *pdata;
!
! if (!PyTuple_Check(arg) || PyTuple_GET_SIZE(arg) != 1)
! goto error;
! state = PyTuple_GET_ITEM(arg, 0);
! if (!PyString_Check(state))
! goto error;
!
! len = PyString_Size(state);
! if (len != _PyDateTime_DATE_DATASIZE)
! goto error;
!
! pdata = (unsigned char*)PyString_AsString(state);
! memcpy(self->data, pdata, _PyDateTime_DATE_DATASIZE);
! self->hashcode = -1;
!
! Py_INCREF(Py_None);
! return Py_None;
! error:
! PyErr_SetString(PyExc_TypeError,
! "bad argument to date.__setstate__");
! return NULL;
! }
static PyObject *
***************
*** 2543,2575 ****
static PyObject *
- date_setstate(PyDateTime_Date *self, PyObject *arg)
- {
- PyObject *state;
- int len;
- unsigned char *pdata;
-
- if (!PyTuple_Check(arg) || PyTuple_GET_SIZE(arg) != 1)
- goto error;
- state = PyTuple_GET_ITEM(arg, 0);
- if (!PyString_Check(state))
- goto error;
-
- len = PyString_Size(state);
- if (len != _PyDateTime_DATE_DATASIZE)
- goto error;
-
- pdata = (unsigned char*)PyString_AsString(state);
- memcpy(self->data, pdata, _PyDateTime_DATE_DATASIZE);
- self->hashcode = -1;
-
- Py_INCREF(Py_None);
- return Py_None;
- error:
- PyErr_SetString(PyExc_TypeError,
- "bad argument to date.__setstate__");
- return NULL;
- }
-
- static PyObject *
date_reduce(PyDateTime_Date *self, PyObject *arg)
{
--- 2572,2575 ----
***************
*** 2628,2634 ****
PyDoc_STR("Return date with new specified fields.")},
- {"__setstate__", (PyCFunction)date_setstate, METH_O,
- PyDoc_STR("__setstate__(state)")},
-
{"__getstate__", (PyCFunction)date_getstate, METH_NOARGS,
PyDoc_STR("__getstate__() -> state")},
--- 2628,2631 ----
***************
*** 3013,3017 ****
"tzinfo", NULL};
! static PyObject *time_setstate(PyDateTime_Time *self, PyObject *state);
static PyObject *
--- 3010,3048 ----
"tzinfo", NULL};
! /* __setstate__ isn't exposed. */
! static PyObject *
! time_setstate(PyDateTime_Time *self, PyObject *state)
! {
! PyObject *basestate;
! PyObject *tzinfo = Py_None;
!
! if (! PyArg_ParseTuple(state, "O!|O:__setstate__",
! &PyString_Type, &basestate,
! &tzinfo))
! return NULL;
! if (PyString_Size(basestate) != _PyDateTime_TIME_DATASIZE ||
! check_tzinfo_subclass(tzinfo) < 0) {
! PyErr_SetString(PyExc_TypeError,
! "bad argument to time.__setstate__");
! return NULL;
! }
! if (tzinfo != Py_None && ! HASTZINFO(self)) {
! PyErr_SetString(PyExc_ValueError, "time.__setstate__ can't "
! "add a non-None tzinfo to a time object that "
! "doesn't have one already");
! return NULL;
! }
! memcpy((char *)self->data,
! PyString_AsString(basestate),
! _PyDateTime_TIME_DATASIZE);
! self->hashcode = -1;
! if (HASTZINFO(self)) {
! Py_INCREF(tzinfo);
! Py_XDECREF(self->tzinfo);
! self->tzinfo = tzinfo;
! }
! Py_INCREF(Py_None);
! return Py_None;
! }
static PyObject *
***************
*** 3368,3406 ****
static PyObject *
- time_setstate(PyDateTime_Time *self, PyObject *state)
- {
- PyObject *basestate;
- PyObject *tzinfo = Py_None;
-
- if (! PyArg_ParseTuple(state, "O!|O:__setstate__",
- &PyString_Type, &basestate,
- &tzinfo))
- return NULL;
- if (PyString_Size(basestate) != _PyDateTime_TIME_DATASIZE ||
- check_tzinfo_subclass(tzinfo) < 0) {
- PyErr_SetString(PyExc_TypeError,
- "bad argument to time.__setstate__");
- return NULL;
- }
- if (tzinfo != Py_None && ! HASTZINFO(self)) {
- PyErr_SetString(PyExc_ValueError, "time.__setstate__ can't "
- "add a non-None tzinfo to a time object that "
- "doesn't have one already");
- return NULL;
- }
- memcpy((char *)self->data,
- PyString_AsString(basestate),
- _PyDateTime_TIME_DATASIZE);
- self->hashcode = -1;
- if (HASTZINFO(self)) {
- Py_INCREF(tzinfo);
- Py_XDECREF(self->tzinfo);
- self->tzinfo = tzinfo;
- }
- Py_INCREF(Py_None);
- return Py_None;
- }
-
- static PyObject *
time_reduce(PyDateTime_Time *self, PyObject *arg)
{
--- 3399,3402 ----
***************
*** 3429,3435 ****
PyDoc_STR("Return time with new specified fields.")},
- {"__setstate__", (PyCFunction)time_setstate, METH_O,
- PyDoc_STR("__setstate__(state)")},
-
{"__getstate__", (PyCFunction)time_getstate, METH_NOARGS,
PyDoc_STR("__getstate__() -> state")},
--- 3425,3428 ----
***************
*** 3560,3564 ****
};
! static PyObject *datetime_setstate(PyDateTime_DateTime *self, PyObject *state);
static PyObject *
--- 3553,3591 ----
};
! /* __setstate__ isn't exposed. */
! static PyObject *
! datetime_setstate(PyDateTime_DateTime *self, PyObject *state)
! {
! PyObject *basestate;
! PyObject *tzinfo = Py_None;
!
! if (! PyArg_ParseTuple(state, "O!|O:__setstate__",
! &PyString_Type, &basestate,
! &tzinfo))
! return NULL;
! if (PyString_Size(basestate) != _PyDateTime_DATETIME_DATASIZE ||
! check_tzinfo_subclass(tzinfo) < 0) {
! PyErr_SetString(PyExc_TypeError,
! "bad argument to datetime.__setstate__");
! return NULL;
! }
! if (tzinfo != Py_None && ! HASTZINFO(self)) {
! PyErr_SetString(PyExc_ValueError, "datetime.__setstate__ "
! "can't add a non-None tzinfo to a datetime "
! "object that doesn't have one already");
! return NULL;
! }
! memcpy((char *)self->data,
! PyString_AsString(basestate),
! _PyDateTime_DATETIME_DATASIZE);
! self->hashcode = -1;
! if (HASTZINFO(self)) {
! Py_INCREF(tzinfo);
! Py_XDECREF(self->tzinfo);
! self->tzinfo = tzinfo;
! }
! Py_INCREF(Py_None);
! return Py_None;
! }
static PyObject *
***************
*** 4372,4410 ****
static PyObject *
- datetime_setstate(PyDateTime_DateTime *self, PyObject *state)
- {
- PyObject *basestate;
- PyObject *tzinfo = Py_None;
-
- if (! PyArg_ParseTuple(state, "O!|O:__setstate__",
- &PyString_Type, &basestate,
- &tzinfo))
- return NULL;
- if (PyString_Size(basestate) != _PyDateTime_DATETIME_DATASIZE ||
- check_tzinfo_subclass(tzinfo) < 0) {
- PyErr_SetString(PyExc_TypeError,
- "bad argument to datetime.__setstate__");
- return NULL;
- }
- if (tzinfo != Py_None && ! HASTZINFO(self)) {
- PyErr_SetString(PyExc_ValueError, "datetime.__setstate__ "
- "can't add a non-None tzinfo to a datetime "
- "object that doesn't have one already");
- return NULL;
- }
- memcpy((char *)self->data,
- PyString_AsString(basestate),
- _PyDateTime_DATETIME_DATASIZE);
- self->hashcode = -1;
- if (HASTZINFO(self)) {
- Py_INCREF(tzinfo);
- Py_XDECREF(self->tzinfo);
- self->tzinfo = tzinfo;
- }
- Py_INCREF(Py_None);
- return Py_None;
- }
-
- static PyObject *
datetime_reduce(PyDateTime_DateTime *self, PyObject *arg)
{
--- 4399,4402 ----
***************
*** 4477,4483 ****
{"astimezone", (PyCFunction)datetime_astimezone, METH_KEYWORDS,
PyDoc_STR("tz -> convert to local time in new timezone tz\n")},
-
- {"__setstate__", (PyCFunction)datetime_setstate, METH_O,
- PyDoc_STR("__setstate__(state)")},
{"__getstate__", (PyCFunction)datetime_getstate, METH_NOARGS,
--- 4469,4472 ----