Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ea2b715

Browse files
committed
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.
1 parent 625d70a commit ea2b715

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

Modules/cPickle.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ Pdata_popTuple(Pdata *self, int start) {
249249

250250
l=self->length-start;
251251
UNLESS (r=PyTuple_New(l)) return NULL;
252-
for (i=start, j=0 ; j < l; )
253-
PyTuple_SET_ITEM(r,j++,self->data[i++]);
252+
for (i=start, j=0 ; j < l; i++, j++)
253+
PyTuple_SET_ITEM(r, j, self->data[i]);
254254

255255
self->length=start;
256256
return r;
@@ -263,8 +263,8 @@ Pdata_popList(Pdata *self, int start) {
263263

264264
l=self->length-start;
265265
UNLESS (r=PyList_New(l)) return NULL;
266-
for (i=start, j=0 ; j < l; )
267-
PyList_SET_ITEM(r,j++,self->data[i++]);
266+
for (i=start, j=0 ; j < l; i++, j++)
267+
PyList_SET_ITEM(r, j, self->data[i]);
268268

269269
self->length=start;
270270
return r;
@@ -3104,11 +3104,20 @@ load_pop(Unpicklerobject *self) {
31043104

31053105
UNLESS ((len=self->stack->length) > 0) return stackUnderflow();
31063106

3107+
/* Note that we split the (pickle.py) stack into two stacks,
3108+
an object stack and a mark stack. We have to be clever and
3109+
pop the right one. We do this by looking at the top of the
3110+
mark stack.
3111+
*/
3112+
31073113
if ((self->num_marks > 0) &&
31083114
(self->marks[self->num_marks - 1] == len))
31093115
self->num_marks--;
3110-
else
3111-
Py_DECREF(self->stack->data[--(self->stack->length)]);
3116+
else {
3117+
len--;
3118+
Py_DECREF(self->stack->data[len]);
3119+
self->stack->length=len;
3120+
}
31123121

31133122
return 0;
31143123
}
@@ -3434,6 +3443,11 @@ static int
34343443
load_mark(Unpicklerobject *self) {
34353444
int s;
34363445

3446+
/* Note that we split the (pickle.py) stack into two stacks, an
3447+
object stack and a mark stack. Here we push a mark onto the
3448+
mark stack.
3449+
*/
3450+
34373451
if ((self->num_marks + 1) >= self->marks_size) {
34383452
s=self->marks_size+20;
34393453
if (s <= self->num_marks) s=self->num_marks + 1;

0 commit comments

Comments
 (0)