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