Commit 90cf25e6 authored by chris's avatar chris

object stored in Pickler memo along with id

parent 20a05502
/*
$Id: cPickle.c,v 1.21 1997/02/19 15:29:36 jim Exp $
$Id: cPickle.c,v 1.22 1997/02/26 19:34:38 chris Exp $
Copyright
......@@ -486,6 +486,9 @@ get(Picklerobject *self, PyObject *id) {
UNLESS(value = PyDict_GetItem(self->memo, id))
return -1;
UNLESS(value = PyTuple_GetItem(value, 0))
return -1;
c_value = PyInt_AsLong(value);
if (!self->bin) {
......@@ -520,7 +523,7 @@ static int
put(Picklerobject *self, PyObject *ob) {
char c_str[30];
int p, len, res = -1;
PyObject *py_ob_id = 0, *memo_len = 0;
PyObject *py_ob_id = 0, *memo_len = 0, *t = 0;
if (ob->ob_refcnt < 2)
return 0;
......@@ -558,7 +561,15 @@ put(Picklerobject *self, PyObject *ob) {
UNLESS(memo_len = PyInt_FromLong(p))
goto finally;
if (PyDict_SetItem(self->memo, py_ob_id, memo_len) < 0)
UNLESS(t = PyTuple_New(2))
goto finally;
PyTuple_SET_ITEM(t, 0, memo_len);
Py_INCREF(memo_len);
PyTuple_SET_ITEM(t, 1, ob);
Py_INCREF(ob);
if (PyDict_SetItem(self->memo, py_ob_id, t) < 0)
goto finally;
res = 0;
......@@ -566,6 +577,7 @@ put(Picklerobject *self, PyObject *ob) {
finally:
Py_XDECREF(py_ob_id);
Py_XDECREF(memo_len);
Py_XDECREF(t);
return res;
}
......@@ -3507,7 +3519,7 @@ init_stuff(PyObject *module, PyObject *module_dict) {
void
initcPickle() {
PyObject *m, *d;
char *rev="$Revision: 1.21 $";
char *rev="$Revision: 1.22 $";
/* Create the module and add the functions */
m = Py_InitModule4("cPickle", cPickle_methods,
......
# $Id: pickle.py,v 1.7 1997/02/21 22:24:23 chris Exp $
# $Id: pickle.py,v 1.8 1997/02/26 19:34:53 chris Exp $
#
# Copyright
#
......@@ -295,7 +295,7 @@ class Pickler:
return
if memo.has_key(d):
self.write(self.get(memo[d]))
self.write(self.get(memo[d][0]))
return
try:
......@@ -417,7 +417,7 @@ class Pickler:
memo_len = len(memo)
self.write(self.put(memo_len))
memo[d] = memo_len
memo[d] = (memo_len, object)
dispatch[StringType] = save_string
def save_tuple(self, object):
......@@ -434,12 +434,12 @@ class Pickler:
save(element)
if (memo.has_key(d)):
write(POP * len(object) + self.get(memo[d]))
write(POP * len(object) + self.get(memo[d][0]))
return
memo_len = len(memo)
self.write(TUPLE + self.put(memo_len))
memo[d] = memo_len
memo[d] = (memo_len, object)
dispatch[TupleType] = save_tuple
def save_empty_tuple(self, object):
......@@ -473,7 +473,7 @@ class Pickler:
memo_len = len(memo)
write(self.put(memo_len))
memo[d] = memo_len
memo[d] = (memo_len, object)
dispatch[ListType] = save_list
def save_dict(self, object):
......@@ -506,7 +506,7 @@ class Pickler:
memo_len = len(memo)
self.write(self.put(memo_len))
memo[d] = memo_len
memo[d] = (memo_len, object)
dispatch[DictionaryType] = save_dict
def save_inst(self, object):
......@@ -540,7 +540,7 @@ class Pickler:
write(INST + module + '\n' + name + '\n' +
self.put(memo_len))
memo[d] = memo_len
memo[d] = (memo_len, object)
try:
getstate = object.__getstate__
......@@ -564,7 +564,7 @@ class Pickler:
memo_len = len(memo)
write(GLOBAL + module + '\n' + name + '\n' +
self.put(memo_len))
memo[id(object)] = memo_len
memo[id(object)] = (memo_len, object)
dispatch[ClassType] = save_global
dispatch[FunctionType] = save_global
dispatch[BuiltinFunctionType] = save_global
......
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