[Python-checkins] python/nondist/sandbox/datetime obj_date.c,1.18,1.19 obj_datetime.c,1.13,1.14

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Tue, 03 Dec 2002 11:32:29 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv28261

Modified Files:
	obj_date.c obj_datetime.c 
Log Message:
Some cosmetic improvements, and more error-checking, in the pickle/
unpickle functions.


Index: obj_date.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_date.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** obj_date.c	3 Dec 2002 19:18:15 -0000	1.18
--- obj_date.c	3 Dec 2002 19:32:27 -0000	1.19
***************
*** 380,387 ****
  }
  
! /* Pickle support.  Quite a maze!  While __getstate__/__setstate__ sufficed
!  * in the Python implementation, the C implementation also requires
!  * __reduce__, and a __safe_for_unpickling__ attr in the type object.
!  */
  static PyObject *
  date_getstate(PyDateTime_Date *self)
--- 380,384 ----
  }
  
! /* Pickle support.  Quite a maze! */
  static PyObject *
  date_getstate(PyDateTime_Date *self)
***************
*** 413,416 ****
--- 410,414 ----
  	PyObject *result = NULL;
  
+ 	assert(date->ob_type == &PyDateTime_DateType);
  	state = date_getstate(date);
  	if (state)
***************
*** 423,431 ****
  {
  	PyDateTime_Date *self;
- 	PyObject *res;
  
  	self = PyObject_New(PyDateTime_Date, &PyDateTime_DateType);
  	if (self != NULL) {
! 		res = date_setstate(self, arg);
  		Py_XDECREF(res);
  	}
--- 421,432 ----
  {
  	PyDateTime_Date *self;
  
+ 	if (! PyString_CheckExact(arg)) {
+ 		PyErr_BadInternalCall();
+ 		return NULL;
+ 	}
  	self = PyObject_New(PyDateTime_Date, &PyDateTime_DateType);
  	if (self != NULL) {
! 		PyObject *res = date_setstate(self, arg);
  		Py_XDECREF(res);
  	}

Index: obj_datetime.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_datetime.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** obj_datetime.c	3 Dec 2002 19:18:15 -0000	1.13
--- obj_datetime.c	3 Dec 2002 19:32:27 -0000	1.14
***************
*** 1,7 ****
! /* imp_datetime.c
   *
   * PyDateTime_DateTime implementation.
   */
  
  static int
  normalize_datetime(long *year, long *month, long *day,
--- 1,10 ----
! /* obj_datetime.c
   *
   * PyDateTime_DateTime implementation.
   */
  
+ /* Force all the datetime fields into range.  The parameters are both
+  * inputs and outputs.  Returns < 0 on error.
+  */
  static int
  normalize_datetime(long *year, long *month, long *day,
***************
*** 394,401 ****
  }
  
! /* Pickle support.  Quite a maze!  While __getstate__/__setstate__ sufficed
!  * in the Python implementation, the C implementation also requires
!  * __reduce__, and a __safe_for_unpickling__ attr in the type object.
!  */
  static PyObject *
  datetime_getstate(PyDateTime_DateTime *self)
--- 397,401 ----
  }
  
! /* Pickle support.  Quite a maze! */
  static PyObject *
  datetime_getstate(PyDateTime_DateTime *self)
***************
*** 427,430 ****
--- 427,431 ----
  	PyObject *result = NULL;
  
+ 	assert(datetime->ob_type == &PyDateTime_DateTimeType);
  	state = datetime_getstate(datetime);
  	if (state)
***************
*** 439,447 ****
  {
  	PyDateTime_DateTime *self;
- 	PyObject *res;
  
  	self = PyObject_New(PyDateTime_DateTime, &PyDateTime_DateTimeType);
  	if (self != NULL) {
! 		res = datetime_setstate(self, arg);
  		Py_XDECREF(res);
  	}
--- 440,451 ----
  {
  	PyDateTime_DateTime *self;
  
+ 	if (! PyString_CheckExact(arg)) {
+ 		PyErr_BadInternalCall();
+ 		return NULL;
+ 	}
  	self = PyObject_New(PyDateTime_DateTime, &PyDateTime_DateTimeType);
  	if (self != NULL) {
! 		PyObject *res = datetime_setstate(self, arg);
  		Py_XDECREF(res);
  	}