[Python-checkins] python/dist/src/Modules cPickle.c,2.116,2.117

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
2003年2月03日 07:45:59 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv29027/Modules
Modified Files:
	cPickle.c 
Log Message:
PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
readability.
load_bool(): Now that I know the intended difference between _PUSH and
_APPEND, used the right one.
Pdata_grow(): Squashed out a redundant overflow test.
Index: cPickle.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/cPickle.c,v
retrieving revision 2.116
retrieving revision 2.117
diff -C2 -d -r2.116 -r2.117
*** cPickle.c	2 Feb 2003 20:29:39 -0000	2.116
--- cPickle.c	3 Feb 2003 15:45:56 -0000	2.117
***************
*** 189,196 ****
 	size_t nbytes;
 
- 	if (! self->size)
- 		goto nomemory;
 	bigger = self->size << 1;
! 	if (bigger <= 0)
 		goto nomemory;
 	if ((int)(size_t)bigger != bigger)
--- 189,194 ----
 	size_t nbytes;
 
 	bigger = self->size << 1;
! 	if (bigger <= 0)	/* was 0, or new value overflows */
 		goto nomemory;
 	if ((int)(size_t)bigger != bigger)
***************
*** 211,227 ****
 }
 
! /* D is a Pdata *. Pop the topmost element and store it into V, which
! * must be an lvalue holding PyObject *. On stack underflow, UnpicklingError
 * is raised and V is set to NULL. D and V may be evaluated several times.
 */
 #define PDATA_POP(D, V) {					\
! if ((D)->length)						\
! 	(V) = (D)->data[--((D)->length)];			\
! else {							\
! PyErr_SetString(UnpicklingError, "bad pickle data");	\
! (V) = NULL;						\
! }								\
 }
 
 static PyObject *
 Pdata_popTuple(Pdata *self, int start)
--- 209,253 ----
 }
 
! /* D is a Pdata*. Pop the topmost element and store it into V, which
! * must be an lvalue holding PyObject*. On stack underflow, UnpicklingError
 * is raised and V is set to NULL. D and V may be evaluated several times.
 */
 #define PDATA_POP(D, V) {					\
! 	if ((D)->length)					\
! 		(V) = (D)->data[--((D)->length)];		\
! 	else {							\
! 		PyErr_SetString(UnpicklingError, "bad pickle data");	\
! 		(V) = NULL;					\
! 	}							\
! }
! 
! /* PDATA_PUSH and PDATA_APPEND both push rvalue PyObject* O on to Pdata*
! * D. If the Pdata stack can't be grown to hold the new value, both
! * raise MemoryError and execute "return ER". The difference is in ownership
! * of O after: _PUSH transfers ownership of O from the caller to the stack
! * (no incref of O is done, and in case of error O is decrefed), while
! * _APPEND pushes a new reference.
! */
! 
! /* Push O on stack D, giving ownership of O to the stack. */
! #define PDATA_PUSH(D, O, ER) {					\
! 	if (((Pdata*)(D))->length == ((Pdata*)(D))->size &&	\
! 	 Pdata_grow((Pdata*)(D)) < 0) {			\
! 		Py_DECREF(O);					\
! 		return ER;					\
! 	}							\
! 	((Pdata*)(D))->data[((Pdata*)(D))->length++] = (O);	\
 }
 
+ /* Push O on stack D, pushing a new reference. */
+ #define PDATA_APPEND(D, O, ER) {				\
+ 	if (((Pdata*)(D))->length == ((Pdata*)(D))->size &&	\
+ 	 Pdata_grow((Pdata*)(D)) < 0)			\
+ 		return ER;					\
+ 	Py_INCREF(O);						\
+ 	((Pdata*)(D))->data[((Pdata*)(D))->length++] = (O);	\
+ }
+ 
+ 
 static PyObject *
 Pdata_popTuple(Pdata *self, int start)
***************
*** 256,276 ****
 }
 
- #define PDATA_APPEND(D,O,ER) { \
- if (((Pdata*)(D))->length == ((Pdata*)(D))->size && \
- Pdata_grow((Pdata*)(D)) < 0) \
- return ER; \
- Py_INCREF(O); \
- ((Pdata*)(D))->data[((Pdata*)(D))->length++]=O; \
- }
- 
- #define PDATA_PUSH(D,O,ER) { \
- if (((Pdata*)(D))->length == ((Pdata*)(D))->size && \
- Pdata_grow((Pdata*)(D)) < 0) { \
- Py_DECREF(O); \
- return ER; \
- } \
- ((Pdata*)(D))->data[((Pdata*)(D))->length++]=O; \
- }
- 
 /*************************************************************************/
 
--- 282,285 ----
***************
*** 2887,2892 ****
 {
 	assert(boolean == Py_True || boolean == Py_False);
! 	Py_INCREF(boolean);
! 	PDATA_PUSH(self->stack, boolean, -1);
 	return 0;
 }
--- 2896,2900 ----
 {
 	assert(boolean == Py_True || boolean == Py_False);
! 	PDATA_APPEND(self->stack, boolean, -1);
 	return 0;
 }

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