[Python-checkins] python/nondist/sandbox/datetime datetime.c,1.36,1.37 obj_date.c,1.17,1.18 obj_datetime.c,1.12,1.13

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
2002年12月03日 11:18:18 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv14760
Modified Files:
	datetime.c obj_date.c obj_datetime.c 
Log Message:
Removed all traces of the __reduce__-based pickling support. It's not
size-competitive with Fred's copy_reg-based approach.
Added some sanity checks to the pickling functions.
Index: datetime.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** datetime.c	3 Dec 2002 02:27:01 -0000	1.36
--- datetime.c	3 Dec 2002 19:18:15 -0000	1.37
***************
*** 536,543 ****
 }
 
- #if 0
- static PyObject *three_ones = NULL;	/* an argument tuple for __reduce__ */
- #endif
- 
 static PyObject *date_unpickler_object = NULL;
 static PyObject *datetime_unpickler_object = NULL;
--- 536,539 ----
***************
*** 731,753 ****
 		Py_DECREF(copyreg_pickle);
 	}
- #if 0
- 	{
- 		/* Build (1, 1, 1) so __reduce__ for date-like objects
- 		 * has something to pass to the type.
- 		 */
- 		int i;
- 		PyObject *one = PyInt_FromLong(1);
- 
- 		if (one == NULL)
- 			return;
- 		three_ones = PyTuple_New(3);
- 		if (three_ones == NULL)
- 			return;
- 		for (i = 0; i < 3; ++i) {
- 			Py_INCREF(one);
- 			PyTuple_SetItem(three_ones, i, one);
- 		}
- 		Py_DECREF(one);
- 	}
- #endif
 }
--- 727,729 ----
Index: obj_date.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_date.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** obj_date.c	3 Dec 2002 02:27:01 -0000	1.17
--- obj_date.c	3 Dec 2002 19:18:15 -0000	1.18
***************
*** 406,436 ****
 }
 
- #if 0
- static PyObject *
- date_reduce(PyDateTime_Date* self)
- {
- 	PyObject* result = NULL;
- 	PyObject* state;
- 
- 	state = date_getstate(self);
- 	if (state != NULL) {
- 		result = Py_BuildValue("OOO",
- 				 self->ob_type,
- 				 three_ones,
- 				 state);
- 		Py_DECREF(state);
- 	}
- 	return result;
- }
- #endif
- 
 /* XXX This seems a ridiculously inefficient way to pickle a short string. */
 static PyObject *
 date_pickler(PyObject *module, PyDateTime_Date *date)
 {
! 	PyObject *state = date_getstate(date);
! 	PyObject *tuple = Py_BuildValue("O(O)",
! 		date_unpickler_object, state);
! 	return tuple;
 }
 
--- 406,420 ----
 }
 
 /* XXX This seems a ridiculously inefficient way to pickle a short string. */
 static PyObject *
 date_pickler(PyObject *module, PyDateTime_Date *date)
 {
! 	PyObject *state;
! 	PyObject *result = NULL;
! 
! 	state = date_getstate(date);
! 	if (state)
! 		result = Py_BuildValue("O(O)", date_unpickler_object, state);
! 	return result;
 }
 
***************
*** 477,484 ****
 	{"__setstate__", (PyCFunction)date_setstate,	METH_O,
 	 	PyDoc_STR("__setstate__(state)")},
- #if 0
- 	{"__reduce__", (PyCFunction)date_reduce, 	METH_NOARGS,
- 		NULL},
- #endif
 	{"__getstate__", (PyCFunction)date_getstate,	METH_NOARGS,
 	 	PyDoc_STR("__getstate__() -> state")},
--- 461,464 ----
Index: obj_datetime.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_datetime.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** obj_datetime.c	3 Dec 2002 02:27:01 -0000	1.12
--- obj_datetime.c	3 Dec 2002 19:18:15 -0000	1.13
***************
*** 420,451 ****
 }
 
! #if 0
 static PyObject *
! datetime_reduce(PyDateTime_DateTime* self)
 {
! 	PyObject* result = NULL;
! 	PyObject* state;
 
! 	state = datetime_getstate(self);
! 	if (state != NULL) {
! 		result = Py_BuildValue("OOO",
! 				 self->ob_type,
! 				 three_ones,
 				 state);
- 		Py_DECREF(state);
- 	}
 	return result;
 }
- #endif
- 
- /* XXX This seems a ridiculously inefficient way to pickle a short string. */
- static PyObject *
- datetime_pickler(PyObject *module, PyDateTime_DateTime *datetime)
- {
- 	PyObject *state = datetime_getstate(datetime);
- 	PyObject *tuple = Py_BuildValue("O(O)",
- 		datetime_unpickler_object, state);
- 	return tuple;
- }
 
 static PyObject *
--- 420,437 ----
 }
 
! /* XXX This seems a ridiculously inefficient way to pickle a short string. */
 static PyObject *
! datetime_pickler(PyObject *module, PyDateTime_DateTime *datetime)
 {
! 	PyObject *state;
! 	PyObject *result = NULL;
 
! 	state = datetime_getstate(datetime);
! 	if (state)
! 		result = Py_BuildValue("O(O)",
! 				 datetime_unpickler_object,
 				 state);
 	return result;
 }
 
 static PyObject *
***************
*** 478,485 ****
 	{"__setstate__", (PyCFunction)datetime_setstate, METH_O,
 	 	PyDoc_STR("__setstate__(state)")},
- #if 0
- 	{"__reduce__", (PyCFunction)datetime_reduce,	METH_NOARGS,
- 		NULL},
- #endif
 	{"__getstate__", (PyCFunction)datetime_getstate, METH_NOARGS,
 	 	PyDoc_STR("__getstate__() -> state")},
--- 464,467 ----

AltStyle によって変換されたページ (->オリジナル) /