Commit 7b8317ff authored by Jim Fulton's avatar Jim Fulton

Fixed a bug that led to core dumps 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.
parent ca9e2534
/*
* $Id: cPickle.c,v 1.71 1999/07/11 13:30:34 jim Exp $
* $Id: cPickle.c,v 1.72 2000/05/09 18:05:09 jim Exp $
*
* Copyright (c) 1996-1998, Digital Creations, Fredericksburg, VA, USA.
* All rights reserved.
......@@ -49,7 +49,7 @@
static char cPickle_module_documentation[] =
"C implementation and optimization of the Python pickle module\n"
"\n"
"$Id: cPickle.c,v 1.71 1999/07/11 13:30:34 jim Exp $\n"
"$Id: cPickle.c,v 1.72 2000/05/09 18:05:09 jim Exp $\n"
;
#include "Python.h"
......@@ -247,8 +247,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;
......@@ -261,8 +261,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;
......@@ -2976,11 +2976,19 @@ 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;
}
......@@ -3306,6 +3314,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;
......@@ -4369,7 +4382,7 @@ init_stuff(PyObject *module, PyObject *module_dict) {
DL_EXPORT(void)
initcPickle() {
PyObject *m, *d, *v;
char *rev="$Revision: 1.71 $";
char *rev="$Revision: 1.72 $";
PyObject *format_version;
PyObject *compatible_formats;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment