]> granicus.if.org Git - python/commitdiff
Fixed cPickle, by restoring some of the deleted code.
authorGuido van Rossum <guido@python.org>
Thu, 17 Aug 2006 22:28:49 +0000 (22:28 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 17 Aug 2006 22:28:49 +0000 (22:28 +0000)
-This line, and those below, will be ignored--

M    setup.py
M    Modules/cPickle.c

Modules/cPickle.c
setup.py

index d6b4581b86fc0c529f898fc2d4e019bda7902d50..fabc3cde6db8eb96eeb46127aed3a0e8dea12020 100644 (file)
@@ -1786,7 +1786,6 @@ save_dict(Picklerobject *self, PyObject *args)
 }
 
 
-
 static int
 save_global(Picklerobject *self, PyObject *args, PyObject *name)
 {
@@ -2278,6 +2277,12 @@ save(Picklerobject *self, PyObject *args, int pers_save)
                }
                break;
 
+        case 'i':
+               break;
+
+        case 'c':
+               break;
+
         case 'f':
                if (type == &PyFunction_Type) {
                        res = save_global(self, args, NULL);
@@ -3438,6 +3443,30 @@ load_dict(Unpicklerobject *self)
        return 0;
 }
 
+static PyObject *
+Instance_New(PyObject *cls, PyObject *args)
+{
+       PyObject *r = 0;
+
+       if ((r=PyObject_CallObject(cls, args))) return r;
+
+       {
+               PyObject *tp, *v, *tb, *tmp_value;
+
+               PyErr_Fetch(&tp, &v, &tb);
+               tmp_value = v;
+               /* NULL occurs when there was a KeyboardInterrupt */
+               if (tmp_value == NULL)
+                       tmp_value = Py_None;
+               if ((r = PyTuple_Pack(3, tmp_value, cls, args))) {
+                       Py_XDECREF(v);
+                       v=r;
+               }
+               PyErr_Restore(tp,v,tb);
+       }
+       return NULL;
+}
+
 
 static int
 load_obj(Unpicklerobject *self)
@@ -3448,6 +3477,10 @@ load_obj(Unpicklerobject *self)
        if ((i = marker(self)) < 0) return -1;
        if (!( tup=Pdata_popTuple(self->stack, i+1)))  return -1;
        PDATA_POP(self->stack, class);
+       if (class) {
+               obj = Instance_New(class, tup);
+               Py_DECREF(class);
+       }
        Py_DECREF(tup);
 
        if (! obj) return -1;
@@ -3483,8 +3516,8 @@ load_inst(Unpicklerobject *self)
        if (! class) return -1;
 
        if ((tup=Pdata_popTuple(self->stack, i))) {
-               PyErr_SetString(UnpicklingError, "it's dead, Jim");
-               return -1;
+               obj = Instance_New(class, tup);
+               Py_DECREF(tup);
        }
        Py_DECREF(class);
 
@@ -4177,6 +4210,10 @@ load_reduce(Unpicklerobject *self)
        PDATA_POP(self->stack, arg_tup);
        if (! arg_tup) return -1;
        PDATA_POP(self->stack, callable);
+       if (callable) {
+               ob = Instance_New(callable, arg_tup);
+               Py_DECREF(callable);
+       }
        Py_DECREF(arg_tup);
 
        if (! ob) return -1;
index 1dac242b8f03aea688b8c823247993425c241b0e..5d711819e0f6af38ccbf10ca4aea9bbbd2c30e49 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -430,7 +430,7 @@ class PyBuildExt(build_ext):
 
         # cStringIO and cPickle
         exts.append( Extension('cStringIO', ['cStringIO.c']) )
-        ##exts.append( Extension('cPickle', ['cPickle.c']) )
+        exts.append( Extension('cPickle', ['cPickle.c']) )
 
         # Memory-mapped files (also works on Win32).
         if platform not in ['atheos', 'mac']: