[Python-checkins] CVS: python/dist/src/Modules cPickle.c,2.41,2.42

Guido van Rossum python-dev@python.org
Tue, 9 May 2000 14:14:53 -0400 (EDT)


Update of /projects/cvsroot/python/dist/src/Modules
In directory eric:/projects/python/develop/guido/src/Modules

Modified Files:
	cPickle.c 
Log Message:
New version from Jim Fulton to fix a problem that Eric Raymond ran
into.  Jim writes:

The core dump was due to a C decrement operation
in a macro invocation in load_pop.  (BAD)

I fixed this by moving the decrement outside
the macro call.  

I added a comment to load_pop and load_mark
to document the fact that cPickle separates the
unpickling stack into two separate stacks, one for
objects and one for marks.

I also moved some increments out of some macro 
calls (PyTuple_SET_ITEM and PyList_SET_ITEM). 
This wasn't necessary, but made me feel better. :)

I tested these changes in *my* cPickle, which
doesn't have the new Unicode stuff.


Index: cPickle.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Modules/cPickle.c,v
retrieving revision 2.41
retrieving revision 2.42
diff -C2 -r2.41 -r2.42
*** cPickle.c	2000/05/03 23:44:31	2.41
--- cPickle.c	2000/05/09 18:14:50	2.42
***************
*** 250,255 ****
      l=self->length-start;
      UNLESS (r=PyTuple_New(l)) return NULL;
!     for (i=start, j=0 ; j < l; )
!         PyTuple_SET_ITEM(r,j++,self->data[i++]);
  
      self->length=start;
--- 250,255 ----
      l=self->length-start;
      UNLESS (r=PyTuple_New(l)) return NULL;
!     for (i=start, j=0 ; j < l; i++, j++)
!         PyTuple_SET_ITEM(r, j, self->data[i]);
  
      self->length=start;
***************
*** 264,269 ****
      l=self->length-start;
      UNLESS (r=PyList_New(l)) return NULL;
!     for (i=start, j=0 ; j < l; )
!         PyList_SET_ITEM(r,j++,self->data[i++]);
  
      self->length=start;
--- 264,269 ----
      l=self->length-start;
      UNLESS (r=PyList_New(l)) return NULL;
!     for (i=start, j=0 ; j < l; i++, j++)
!         PyList_SET_ITEM(r, j, self->data[i]);
  
      self->length=start;
***************
*** 3105,3113 ****
      UNLESS ((len=self->stack->length) > 0) return stackUnderflow();
  
      if ((self->num_marks > 0) && 
          (self->marks[self->num_marks - 1] == len))
          self->num_marks--;
!     else 
!         Py_DECREF(self->stack->data[--(self->stack->length)]);
  
      return 0;
--- 3105,3122 ----
      UNLESS ((len=self->stack->length) > 0) return stackUnderflow();
  
+     /* Note that we split the (pickle.py) stack into two stacks, 
+        an object stack and a mark stack. We have to be clever and
+        pop the right one. We do this by looking at the top of the
+        mark stack.
+     */
+ 
      if ((self->num_marks > 0) && 
          (self->marks[self->num_marks - 1] == len))
          self->num_marks--;
!     else { 
!         len--;
!         Py_DECREF(self->stack->data[len]);
! 	self->stack->length=len;
!     }
  
      return 0;
***************
*** 3434,3437 ****
--- 3443,3451 ----
  load_mark(Unpicklerobject *self) {
      int s;
+ 
+     /* Note that we split the (pickle.py) stack into two stacks, an
+        object stack and a mark stack. Here we push a mark onto the
+        mark stack.  
+     */
  
      if ((self->num_marks + 1) >= self->marks_size) {