[Python-checkins] python/nondist/sandbox/datetime obj_date.c,1.35,1.36 obj_datetime.c,1.28,1.29
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Fri, 06 Dec 2002 19:12:59 -0800
- Previous message: [Python-checkins] python/dist/src/Modules cPickle.c,2.96,2.97
- Next message: [Python-checkins] python/nondist/sandbox/datetime doc.txt,1.22,1.23 obj_datetime.c,1.29,1.30 test_both.py,1.47,1.48 test_datetime.py,1.54,1.55
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv4101
Modified Files:
obj_date.c obj_datetime.c
Log Message:
Fixed leaks in the date and datetime picklers. Along with the leaks in
Python that got fixed, there are no leaks visible now in the Python or
C implementations.
Also reworked all the pickle support functions to raise errors when
their arguments suck, instead of just asserting they're correct. While
these are intended to be module-private functions, there's really nothing
to stop a user from calling them.
Index: obj_date.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_date.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -C2 -d -r1.35 -r1.36
*** obj_date.c 6 Dec 2002 17:20:58 -0000 1.35
--- obj_date.c 7 Dec 2002 03:12:57 -0000 1.36
***************
*** 435,440 ****
unsigned char *pdata = (unsigned char*)PyString_AsString(state);
! assert(len == _PyDateTime_DATE_DATA_SIZE);
!
memcpy(self->data, pdata, _PyDateTime_DATE_DATA_SIZE);
self->hashcode = -1;
--- 435,444 ----
unsigned char *pdata = (unsigned char*)PyString_AsString(state);
! if (! PyString_Check(state) ||
! len != _PyDateTime_DATE_DATA_SIZE) {
! PyErr_SetString(PyExc_TypeError,
! "bad argument to date.__setstate__");
! return NULL;
! }
memcpy(self->data, pdata, _PyDateTime_DATE_DATA_SIZE);
self->hashcode = -1;
***************
*** 451,458 ****
PyObject *result = NULL;
! assert(date->ob_type == &PyDateTime_DateType);
state = date_getstate(date);
! if (state)
result = Py_BuildValue("O(O)", date_unpickler_object, state);
return result;
}
--- 455,469 ----
PyObject *result = NULL;
! if (date->ob_type != &PyDateTime_DateType) {
! PyErr_Format(PyExc_TypeError,
! "bad type passed to date pickler: %s",
! date->ob_type->tp_name);
! return NULL;
! }
state = date_getstate(date);
! if (state) {
result = Py_BuildValue("O(O)", date_unpickler_object, state);
+ Py_DECREF(state);
+ }
return result;
}
***************
*** 464,468 ****
if (! PyString_CheckExact(arg)) {
! PyErr_BadInternalCall();
return NULL;
}
--- 475,481 ----
if (! PyString_CheckExact(arg)) {
! PyErr_Format(PyExc_TypeError,
! "bad type passed to date unpickler: %s",
! arg->ob_type->tp_name);
return NULL;
}
Index: obj_datetime.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_datetime.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** obj_datetime.c 6 Dec 2002 21:03:09 -0000 1.28
--- obj_datetime.c 7 Dec 2002 03:12:57 -0000 1.29
***************
*** 497,502 ****
unsigned char *pdata = (unsigned char*)PyString_AsString(state);
! assert(len == _PyDateTime_DATETIME_DATA_SIZE);
!
memcpy(self->data, pdata, _PyDateTime_DATETIME_DATA_SIZE);
self->hashcode = -1;
--- 497,506 ----
unsigned char *pdata = (unsigned char*)PyString_AsString(state);
! if (! PyString_Check(state) ||
! len != _PyDateTime_DATETIME_DATA_SIZE) {
! PyErr_SetString(PyExc_TypeError,
! "bad argument to datetime.__setstate__");
! return NULL;
! }
memcpy(self->data, pdata, _PyDateTime_DATETIME_DATA_SIZE);
self->hashcode = -1;
***************
*** 513,522 ****
PyObject *result = NULL;
! assert(datetime->ob_type == &PyDateTime_DateTimeType);
state = datetime_getstate(datetime);
! if (state)
result = Py_BuildValue("O(O)",
datetime_unpickler_object,
state);
return result;
}
--- 517,533 ----
PyObject *result = NULL;
! if (datetime->ob_type != &PyDateTime_DateTimeType) {
! PyErr_Format(PyExc_TypeError,
! "bad type passed to datetime pickler: %s",
! datetime->ob_type->tp_name);
! return NULL;
! }
state = datetime_getstate(datetime);
! if (state) {
result = Py_BuildValue("O(O)",
datetime_unpickler_object,
state);
+ Py_DECREF(state);
+ }
return result;
}
***************
*** 528,532 ****
if (! PyString_CheckExact(arg)) {
! PyErr_BadInternalCall();
return NULL;
}
--- 539,545 ----
if (! PyString_CheckExact(arg)) {
! PyErr_Format(PyExc_TypeError,
! "bad type passed to datetime unpickler: %s",
! arg->ob_type->tp_name);
return NULL;
}
- Previous message: [Python-checkins] python/dist/src/Modules cPickle.c,2.96,2.97
- Next message: [Python-checkins] python/nondist/sandbox/datetime doc.txt,1.22,1.23 obj_datetime.c,1.29,1.30 test_both.py,1.47,1.48 test_datetime.py,1.54,1.55
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]