diff options
author | Guido van Rossum <guido@python.org> | 2000-05-09 18:14:50 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-05-09 18:14:50 (GMT) |
commit | ea2b7157ababce79234978416a05a3bc7eddf960 (patch) | |
tree | 9066355920e5aee7caa7aed436f92179105b9960 /Modules/cPickle.c | |
parent | 625d70a7a6fed4193380cb410795e54a6069f3bf (diff) | |
download | cpython-ea2b7157ababce79234978416a05a3bc7eddf960.zip cpython-ea2b7157ababce79234978416a05a3bc7eddf960.tar.gz cpython-ea2b7157ababce79234978416a05a3bc7eddf960.tar.bz2 |
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.
Diffstat (limited to 'Modules/cPickle.c')
-rw-r--r-- | Modules/cPickle.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/Modules/cPickle.c b/Modules/cPickle.c index 73cb6ba..6eeb0a4 100644 --- a/Modules/cPickle.c +++ b/Modules/cPickle.c @@ -249,8 +249,8 @@ Pdata_popTuple(Pdata *self, int start) { 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++]); + for (i=start, j=0 ; j < l; i++, j++) + PyTuple_SET_ITEM(r, j, self->data[i]); self->length=start; return r; @@ -263,8 +263,8 @@ Pdata_popList(Pdata *self, int start) { 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++]); + for (i=start, j=0 ; j < l; i++, j++) + PyList_SET_ITEM(r, j, self->data[i]); self->length=start; return r; @@ -3104,11 +3104,20 @@ load_pop(Unpicklerobject *self) { 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 - Py_DECREF(self->stack->data[--(self->stack->length)]); + else { + len--; + Py_DECREF(self->stack->data[len]); + self->stack->length=len; + } return 0; } @@ -3434,6 +3443,11 @@ static int 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) { s=self->marks_size+20; if (s <= self->num_marks) s=self->num_marks + 1; |