Commit 3840b0d2 authored by chris's avatar chris

*** empty log message ***

parent dd4479e8
/* /*
$Id: cPickle.c,v 1.15 1997/02/03 17:27:06 jim Exp $ $Id: cPickle.c,v 1.16 1997/02/05 15:32:05 chris Exp $
Copyright Copyright
...@@ -95,18 +95,21 @@ static PyObject *ErrorObject; ...@@ -95,18 +95,21 @@ static PyObject *ErrorObject;
#define BUILD 'b' #define BUILD 'b'
#define GLOBAL 'c' #define GLOBAL 'c'
#define DICT 'd' #define DICT 'd'
#define EMPTY_DICT '}'
#define APPENDS 'e' #define APPENDS 'e'
#define GET 'g' #define GET 'g'
#define BINGET 'h' #define BINGET 'h'
#define INST 'i' #define INST 'i'
#define LONG_BINGET 'j' #define LONG_BINGET 'j'
#define LIST 'l' #define LIST 'l'
#define EMPTY_LIST ']'
#define OBJ 'o' #define OBJ 'o'
#define PUT 'p' #define PUT 'p'
#define BINPUT 'q' #define BINPUT 'q'
#define LONG_BINPUT 'r' #define LONG_BINPUT 'r'
#define SETITEM 's' #define SETITEM 's'
#define TUPLE 't' #define TUPLE 't'
#define EMPTY_TUPLE ')'
#define SETITEMS 'u' #define SETITEMS 'u'
static char MARKv = MARK; static char MARKv = MARK;
...@@ -122,6 +125,11 @@ static PyObject *safe_constructors; ...@@ -122,6 +125,11 @@ static PyObject *safe_constructors;
static PyObject *class_map; static PyObject *class_map;
static PyObject *empty_tuple; static PyObject *empty_tuple;
static PyObject *__class___str, *__getinitargs___str, *__dict___str,
*__getstate___str, *__setstate___str, *__name___str, *__reduce___str,
*write_str, *__safe_for_unpickling___str, *append_str,
*read_str, *readline_str;
/* __builtins__ module */ /* __builtins__ module */
static PyObject *builtins; static PyObject *builtins;
...@@ -535,6 +543,7 @@ whichmodule(PyObject *global, PyObject *global_name) { ...@@ -535,6 +543,7 @@ whichmodule(PyObject *global, PyObject *global_name) {
if (module = PyDict_GetItem(class_map, global)) if (module = PyDict_GetItem(class_map, global))
{ {
Py_INCREF(module);
return module; return module;
} }
else else
...@@ -727,7 +736,7 @@ save_string(Picklerobject *self, PyObject *args) { ...@@ -727,7 +736,7 @@ save_string(Picklerobject *self, PyObject *args) {
else { else {
c_str[0] = BINSTRING; c_str[0] = BINSTRING;
for (i = 1; i < 5; i++) for (i = 1; i < 5; i++)
c_str[i] = (int)(size << ((i - 1) * 8)); c_str[i] = (int)(size >> ((i - 1) * 8));
len = 5; len = 5;
} }
...@@ -770,7 +779,7 @@ save_tuple(Picklerobject *self, PyObject *args) { ...@@ -770,7 +779,7 @@ save_tuple(Picklerobject *self, PyObject *args) {
UNLESS(py_tuple_id = PyInt_FromLong((long)args)) UNLESS(py_tuple_id = PyInt_FromLong((long)args))
goto finally; goto finally;
if ((has_key = PyMapping_HasKey(self->memo, py_tuple_id)) < 0) if ((has_key = len && PyMapping_HasKey(self->memo, py_tuple_id)) < 0)
goto finally; goto finally;
if (has_key) { if (has_key) {
...@@ -803,6 +812,13 @@ finally: ...@@ -803,6 +812,13 @@ finally:
return res; return res;
} }
static int
save_empty_tuple(Picklerobject *self, PyObject *args) {
static char tuple = EMPTY_TUPLE;
return (*self->write_func)(self, &tuple, 1);
}
static int static int
save_list(Picklerobject *self, PyObject *args) { save_list(Picklerobject *self, PyObject *args) {
...@@ -812,19 +828,21 @@ save_list(Picklerobject *self, PyObject *args) { ...@@ -812,19 +828,21 @@ save_list(Picklerobject *self, PyObject *args) {
static char append = APPEND, appends = APPENDS; static char append = APPEND, appends = APPENDS;
s[0] = MARK; if(self->bin) {
s[1] = LIST; s[0] = EMPTY_LIST;
s_len = 2; s_len = 1;
} else {
s[0] = MARK;
s[1] = LIST;
s_len = 2;
}
if ((len = PyList_Size(args)) < 0) if ((len = PyList_Size(args)) < 0)
goto finally; goto finally;
using_appends = (self->bin && (len > 1)); using_appends = (self->bin && (len > 1));
if (using_appends) { if (using_appends) s[s_len++] = MARK;
s[2] = MARK;
s_len++;
}
if ((*self->write_func)(self, s, s_len) < 0) if ((*self->write_func)(self, s, s_len) < 0)
goto finally; goto finally;
...@@ -866,16 +884,19 @@ save_dict(Picklerobject *self, PyObject *args) { ...@@ -866,16 +884,19 @@ save_dict(Picklerobject *self, PyObject *args) {
static char setitem = SETITEM, setitems = SETITEMS; static char setitem = SETITEM, setitems = SETITEMS;
s[0] = MARK; if(self->bin) {
s[1] = DICT; s[0]=EMPTY_DICT;
len = 2; len=1;
}
else {
s[0] = MARK;
s[1] = DICT;
len = 2;
}
using_setitems = (self->bin && (PyDict_Size(args) > 1)); using_setitems = (self->bin && (PyDict_Size(args) > 1));
if (using_setitems) { if (using_setitems) s[len++] = MARK;
s[2] = MARK;
len++;
}
if ((*self->write_func)(self, s, len) < 0) if ((*self->write_func)(self, s, len) < 0)
goto finally; goto finally;
...@@ -918,17 +939,11 @@ save_inst(Picklerobject *self, PyObject *args) { ...@@ -918,17 +939,11 @@ save_inst(Picklerobject *self, PyObject *args) {
int module_size, name_size, res = -1; int module_size, name_size, res = -1;
static char inst = INST, obj = OBJ, build = BUILD; static char inst = INST, obj = OBJ, build = BUILD;
static PyObject *__class__str = 0, *__getinitargs__str = 0,
*__dict__str = 0, *__getstate__str = 0;
if ((*self->write_func)(self, &MARKv, 1) < 0) if ((*self->write_func)(self, &MARKv, 1) < 0)
goto finally; goto finally;
UNLESS(__class__str) UNLESS(class = PyObject_GetAttr(args, __class___str))
UNLESS(__class__str = PyString_FromString("__class__"))
goto finally;
UNLESS(class = PyObject_GetAttr(args, __class__str))
goto finally; goto finally;
if (self->bin) { if (self->bin) {
...@@ -936,11 +951,7 @@ save_inst(Picklerobject *self, PyObject *args) { ...@@ -936,11 +951,7 @@ save_inst(Picklerobject *self, PyObject *args) {
goto finally; goto finally;
} }
UNLESS(__getinitargs__str) if (getinitargs_func = PyObject_GetAttr(args, __getinitargs___str)) {
UNLESS(__getinitargs__str = PyString_FromString("__getinitargs__"))
goto finally;
if (getinitargs_func = PyObject_GetAttr(args, __getinitargs__str)) {
PyObject *element = 0; PyObject *element = 0;
int i, len; int i, len;
...@@ -1005,22 +1016,14 @@ save_inst(Picklerobject *self, PyObject *args) { ...@@ -1005,22 +1016,14 @@ save_inst(Picklerobject *self, PyObject *args) {
goto finally; goto finally;
} }
UNLESS(__getstate__str) if (getstate_func = PyObject_GetAttr(args, __getstate___str)) {
UNLESS(__getstate__str = PyString_FromString("__getstate__"))
goto finally;
if (getstate_func = PyObject_GetAttr(args, __getstate__str)) {
UNLESS(state = PyObject_CallObject(getstate_func, empty_tuple)) UNLESS(state = PyObject_CallObject(getstate_func, empty_tuple))
goto finally; goto finally;
} }
else { else {
PyErr_Clear(); PyErr_Clear();
UNLESS(__dict__str) UNLESS(state = PyObject_GetAttr(args, __dict___str)) {
UNLESS(__dict__str = PyString_FromString("__dict__"))
goto finally;
UNLESS(state = PyObject_GetAttr(args, __dict__str)) {
PyErr_Clear(); PyErr_Clear();
res = 0; res = 0;
goto finally; goto finally;
...@@ -1053,11 +1056,6 @@ save_global(Picklerobject *self, PyObject *args, PyObject *name) { ...@@ -1053,11 +1056,6 @@ save_global(Picklerobject *self, PyObject *args, PyObject *name) {
int module_size, name_size, size, res = -1; int module_size, name_size, size, res = -1;
static char global = GLOBAL; static char global = GLOBAL;
static PyObject *__name__str = 0;
UNLESS(__name__str)
UNLESS(__name__str = PyString_FromString("__name__"))
return -1;
if (name) if (name)
{ {
...@@ -1066,7 +1064,7 @@ save_global(Picklerobject *self, PyObject *args, PyObject *name) { ...@@ -1066,7 +1064,7 @@ save_global(Picklerobject *self, PyObject *args, PyObject *name) {
} }
else else
{ {
UNLESS(global_name = PyObject_GetAttr(args, __name__str)) UNLESS(global_name = PyObject_GetAttr(args, __name___str))
goto finally; goto finally;
} }
...@@ -1199,8 +1197,6 @@ save(Picklerobject *self, PyObject *args, int pers_save) { ...@@ -1199,8 +1197,6 @@ save(Picklerobject *self, PyObject *args, int pers_save) {
*callable = 0, *state = 0, *junk = 0; *callable = 0, *state = 0, *junk = 0;
int res = -1, tmp, size; int res = -1, tmp, size;
static PyObject *__reduce__str = 0;
if (!pers_save && self->pers_func) { if (!pers_save && self->pers_func) {
if ((tmp = save_pers(self, args, self->pers_func)) != 0) { if ((tmp = save_pers(self, args, self->pers_func)) != 0) {
res = tmp; res = tmp;
...@@ -1221,7 +1217,6 @@ save(Picklerobject *self, PyObject *args, int pers_save) { ...@@ -1221,7 +1217,6 @@ save(Picklerobject *self, PyObject *args, int pers_save) {
res = save_int(self, args); res = save_int(self, args);
goto finally; goto finally;
} }
break; break;
case 'l': case 'l':
...@@ -1229,7 +1224,6 @@ save(Picklerobject *self, PyObject *args, int pers_save) { ...@@ -1229,7 +1224,6 @@ save(Picklerobject *self, PyObject *args, int pers_save) {
res = save_long(self, args); res = save_long(self, args);
goto finally; goto finally;
} }
break; break;
case 'f': case 'f':
...@@ -1237,6 +1231,14 @@ save(Picklerobject *self, PyObject *args, int pers_save) { ...@@ -1237,6 +1231,14 @@ save(Picklerobject *self, PyObject *args, int pers_save) {
res = save_float(self, args); res = save_float(self, args);
goto finally; goto finally;
} }
break;
case 't':
if (type == &PyTuple_Type && PyTuple_Size(args)==0) {
if(self->bin) res = save_empty_tuple(self, args);
else res = save_tuple(self, args);
goto finally;
}
} }
if (args->ob_refcnt > 1) { if (args->ob_refcnt > 1) {
...@@ -1334,11 +1336,7 @@ save(Picklerobject *self, PyObject *args, int pers_save) { ...@@ -1334,11 +1336,7 @@ save(Picklerobject *self, PyObject *args, int pers_save) {
else { else {
PyErr_Clear(); PyErr_Clear();
UNLESS(__reduce__str) if (__reduce__ = PyObject_GetAttr(args, __reduce___str)) {
UNLESS(__reduce__str = PyString_FromString("__reduce__"))
goto finally;
if (__reduce__ = PyObject_GetAttr(args, __reduce__str)) {
UNLESS(t = PyObject_CallObject(__reduce__, empty_tuple)) UNLESS(t = PyObject_CallObject(__reduce__, empty_tuple))
goto finally; goto finally;
} }
...@@ -1484,15 +1482,10 @@ newPicklerobject(PyObject *file, int bin) { ...@@ -1484,15 +1482,10 @@ newPicklerobject(PyObject *file, int bin) {
} }
else { else {
PyObject *write; PyObject *write;
static PyObject *write_str = 0;
self->fp = NULL; self->fp = NULL;
self->write_func = write_other; self->write_func = write_other;
UNLESS(write_str)
UNLESS(write_str = PyString_FromString("write"))
goto err;
UNLESS(write = PyObject_GetAttr(file, write_str)) UNLESS(write = PyObject_GetAttr(file, write_str))
goto err; goto err;
...@@ -1698,6 +1691,7 @@ find_class(PyObject *py_module_name, PyObject *py_class_name) { ...@@ -1698,6 +1691,7 @@ find_class(PyObject *py_module_name, PyObject *py_class_name) {
if (class = PyDict_GetItem(class_map, t)) { if (class = PyDict_GetItem(class_map, t)) {
res = class; res = class;
Py_INCREF(class);
goto finally; goto finally;
} }
...@@ -2063,11 +2057,44 @@ finally: ...@@ -2063,11 +2057,44 @@ finally:
return res; return res;
} }
static int
load_empty_tuple(Unpicklerobject *self, PyObject *args) {
PyObject *tup = 0;
int res;
UNLESS(tup=PyTuple_New(0)) return -1;
res=PyList_Append(self->stack, tup);
Py_DECREF(tup);
return res;
}
static int
load_empty_list(Unpicklerobject *self, PyObject *args) {
PyObject *list = 0;
int res;
UNLESS(list=PyList_New(0)) return -1;
res=PyList_Append(self->stack, list);
Py_DECREF(list);
return res;
}
static int
load_empty_dict(Unpicklerobject *self, PyObject *args) {
PyObject *dict = 0;
int res;
UNLESS(dict=PyDict_New()) return -1;
res=PyList_Append(self->stack, dict);
Py_DECREF(dict);
return res;
}
static int static int
load_list(Unpicklerobject *self, PyObject *args) { load_list(Unpicklerobject *self, PyObject *args) {
PyObject *list = 0, *slice = 0; PyObject *list = 0, *slice = 0;
int i, j, res = -1; int i, j, l, res = -1;
i = marker(self); i = marker(self);
...@@ -2077,15 +2104,23 @@ load_list(Unpicklerobject *self, PyObject *args) { ...@@ -2077,15 +2104,23 @@ load_list(Unpicklerobject *self, PyObject *args) {
UNLESS(slice = PyList_GetSlice(self->stack, i, j)) UNLESS(slice = PyList_GetSlice(self->stack, i, j))
goto finally; goto finally;
UNLESS(list = PyList_New(1)) if((l=PyList_Size(slice)) < 0)
goto finally; goto finally;
Py_INCREF(slice); if(l) {
if (PyList_SetItem(list, 0, slice) < 0) UNLESS(list = PyList_New(1))
goto finally; goto finally;
if (PyList_SetSlice(self->stack, i, j, list) < 0) Py_INCREF(slice);
if (PyList_SetItem(list, 0, slice) < 0)
goto finally; goto finally;
if (PyList_SetSlice(self->stack, i, j, list) < 0)
goto finally;
} else {
if(PyList_Append(self->stack,slice) < 0)
goto finally;
}
res = 0; res = 0;
...@@ -2096,7 +2131,6 @@ finally: ...@@ -2096,7 +2131,6 @@ finally:
return res; return res;
} }
static int static int
load_dict(Unpicklerobject *self, PyObject *args) { load_dict(Unpicklerobject *self, PyObject *args) {
PyObject *list = 0, *dict = 0, *key = 0, *value = 0; PyObject *list = 0, *dict = 0, *key = 0, *value = 0;
...@@ -2121,15 +2155,21 @@ load_dict(Unpicklerobject *self, PyObject *args) { ...@@ -2121,15 +2155,21 @@ load_dict(Unpicklerobject *self, PyObject *args) {
goto finally; goto finally;
} }
UNLESS(list = PyList_New(1)) if(j) {
UNLESS(list = PyList_New(1))
goto finally; goto finally;
Py_INCREF(dict); Py_INCREF(dict);
if (PyList_SetItem(list, 0, dict) < 0) if (PyList_SetItem(list, 0, dict) < 0)
goto finally; goto finally;
if (PyList_SetSlice(self->stack, i, j, list) < 0) if (PyList_SetSlice(self->stack, i, j, list) < 0)
goto finally; goto finally;
}
else
if(PyList_Append(self->stack, dict) < 0)
goto finally;
res = 0; res = 0;
...@@ -2140,6 +2180,28 @@ finally: ...@@ -2140,6 +2180,28 @@ finally:
return res; return res;
} }
static PyObject *
Instance_New(PyObject *cls, PyObject *args)
{
int has_key;
PyObject *safe=0;
if (PyClass_Check(cls)) return PyInstance_New(cls, args, NULL);
if ((has_key = PyMapping_HasKey(safe_constructors, cls)) < 0)
return NULL;
if (!has_key)
if(!(safe = PyObject_GetAttr(cls, __safe_for_unpickling___str)) ||
!PyObject_IsTrue(safe)) {
PyErr_Format(UnpicklingError, "%s is not safe for unpickling", "O", cls);
Py_XDECREF(safe);
return NULL;
}
return PyObject_CallObject(cls, args);
}
static int static int
load_obj(Unpicklerobject *self, PyObject *args) { load_obj(Unpicklerobject *self, PyObject *args) {
...@@ -2163,7 +2225,7 @@ load_obj(Unpicklerobject *self, PyObject *args) { ...@@ -2163,7 +2225,7 @@ load_obj(Unpicklerobject *self, PyObject *args) {
if (DEL_LIST_SLICE(self->stack, i, len) < 0) if (DEL_LIST_SLICE(self->stack, i, len) < 0)
goto finally; goto finally;
UNLESS(obj = PyInstance_New(class, tup, NULL)) UNLESS(obj = Instance_New(class, tup))
goto finally; goto finally;
if (PyList_Append(self->stack, obj) < 0) if (PyList_Append(self->stack, obj) < 0)
...@@ -2217,7 +2279,7 @@ load_inst(Unpicklerobject *self, PyObject *args) { ...@@ -2217,7 +2279,7 @@ load_inst(Unpicklerobject *self, PyObject *args) {
UNLESS(class = find_class(module_name, class_name)) UNLESS(class = find_class(module_name, class_name))
goto finally; goto finally;
UNLESS(obj = PyInstance_New(class, arg_tup, NULL)) UNLESS(obj = Instance_New(class, arg_tup))
goto finally; goto finally;
if (PyList_Append(self->stack, obj) < 0) if (PyList_Append(self->stack, obj) < 0)
...@@ -2578,7 +2640,8 @@ finally: ...@@ -2578,7 +2640,8 @@ finally:
} }
static int do_append(Unpicklerobject *self, int x) { static int
do_append(Unpicklerobject *self, int x) {
PyObject *value = 0, *list = 0, *append_method = 0; PyObject *value = 0, *list = 0, *append_method = 0;
int len, i; int len, i;
...@@ -2604,44 +2667,27 @@ static int do_append(Unpicklerobject *self, int x) { ...@@ -2604,44 +2667,27 @@ static int do_append(Unpicklerobject *self, int x) {
Py_DECREF(slice); Py_DECREF(slice);
} }
else { else {
static PyObject *append_str = 0;
UNLESS(append_str)
UNLESS(append_str = PyString_FromString("append"))
return -1;
UNLESS(append_method = PyObject_GetAttr(list, append_str)) UNLESS(append_method = PyObject_GetAttr(list, append_str))
return -1; return -1;
for (i = x; i < len; i++) { for (i = x; i < len; i++) {
PyObject *junk;
UNLESS(value = PyList_GetItem(self->stack, i)) UNLESS(value = PyList_GetItem(self->stack, i))
return -1; return -1;
if (PyList_Check(list)) { UNLESS(self->arg)
if (PyList_Append(list, value) < 0) UNLESS(self->arg = PyTuple_New(1))
goto err; goto err;
}
else { Py_INCREF(value);
PyObject *junk; if (PyTuple_SetItem(self->arg, 0, value) < 0)
goto err;
UNLESS(self->arg)
UNLESS(self->arg = PyTuple_New(1)) { UNLESS(junk = PyObject_CallObject(append_method, self->arg))
Py_DECREF(append_method); goto err;
goto err; Py_DECREF(junk);
}
Py_INCREF(value);
if (PyTuple_SetItem(self->arg, 0, value) < 0) {
Py_DECREF(append_method);
goto err;
}
UNLESS(junk = PyObject_CallObject(append_method, self->arg)) {
Py_DECREF(append_method);
goto err;
}
Py_DECREF(junk);
}
} }
} }
...@@ -2720,7 +2766,6 @@ static int ...@@ -2720,7 +2766,6 @@ static int
load_build(Unpicklerobject *self, PyObject *args) { load_build(Unpicklerobject *self, PyObject *args) {
PyObject *value = 0, *inst = 0, *instdict = 0, *d_key = 0, *d_value = 0, PyObject *value = 0, *inst = 0, *instdict = 0, *d_key = 0, *d_value = 0,
*junk = 0, *__setstate__ = 0; *junk = 0, *__setstate__ = 0;
static PyObject *__dict__str, *__setstate__str = 0;
int len, i, res = -1; int len, i, res = -1;
if ((len = PyList_Size(self->stack)) < 0) if ((len = PyList_Size(self->stack)) < 0)
...@@ -2736,19 +2781,11 @@ load_build(Unpicklerobject *self, PyObject *args) { ...@@ -2736,19 +2781,11 @@ load_build(Unpicklerobject *self, PyObject *args) {
UNLESS(inst = PyList_GetItem(self->stack, len - 2)) UNLESS(inst = PyList_GetItem(self->stack, len - 2))
goto finally; goto finally;
UNLESS(__setstate__str) UNLESS(__setstate__ = PyObject_GetAttr(inst, __setstate___str))
UNLESS(__setstate__str = PyString_FromString("__setstate__"))
goto finally;
UNLESS(__setstate__ = PyObject_GetAttr(inst, __setstate__str))
{ {
PyErr_Clear(); PyErr_Clear();
UNLESS(__dict__str) UNLESS(instdict = PyObject_GetAttr(inst, __dict___str))
UNLESS(__dict__str = PyString_FromString("__dict__"))
goto finally;
UNLESS(instdict = PyObject_GetAttr(inst, __dict__str))
goto finally; goto finally;
i = 0; i = 0;
...@@ -2812,13 +2849,10 @@ load_mark(Unpicklerobject *self, PyObject *args) { ...@@ -2812,13 +2849,10 @@ load_mark(Unpicklerobject *self, PyObject *args) {
return 0; return 0;
} }
static int static int
load_reduce(Unpicklerobject *self, PyObject *args) { load_reduce(Unpicklerobject *self, PyObject *args) {
PyObject *callable = 0, *arg_tup = 0, *ob = 0, *safe = 0; PyObject *callable = 0, *arg_tup = 0, *ob = 0;
int len, has_key, res = -1; int len, res = -1;
static PyObject *__safe_for_unpickling__str;
if ((len = PyList_Size(self->stack)) < 0) if ((len = PyList_Size(self->stack)) < 0)
goto finally; goto finally;
...@@ -2829,26 +2863,7 @@ load_reduce(Unpicklerobject *self, PyObject *args) { ...@@ -2829,26 +2863,7 @@ load_reduce(Unpicklerobject *self, PyObject *args) {
UNLESS(callable = PyList_GetItem(self->stack, len - 2)) UNLESS(callable = PyList_GetItem(self->stack, len - 2))
goto finally; goto finally;
if (!PyClass_Check(callable)) { UNLESS(ob = Instance_New(callable, arg_tup))
if ((has_key = PyMapping_HasKey(safe_constructors, callable)) < 0)
goto finally;
if (!has_key) {
UNLESS(__safe_for_unpickling__str)
UNLESS(__safe_for_unpickling__str =
PyString_FromString("__safe_for_unpickling__"))
goto finally;
if (!(safe = PyObject_GetAttr(callable,
__safe_for_unpickling__str)) || !PyObject_IsTrue(safe)) {
PyErr_Format(UnpicklingError,
"%s is not safe for unpickling", "O", callable);
goto finally;
}
}
}
UNLESS(ob = PyObject_CallObject(callable, arg_tup))
goto finally; goto finally;
if (PyList_Append(self->stack, ob) < 0) if (PyList_Append(self->stack, ob) < 0)
...@@ -2860,10 +2875,7 @@ load_reduce(Unpicklerobject *self, PyObject *args) { ...@@ -2860,10 +2875,7 @@ load_reduce(Unpicklerobject *self, PyObject *args) {
res = 0; res = 0;
finally: finally:
Py_XDECREF(callable);
Py_XDECREF(arg_tup);
Py_XDECREF(ob); Py_XDECREF(ob);
Py_XDECREF(safe);
return res; return res;
} }
...@@ -2941,16 +2953,31 @@ Unpickler_load(Unpicklerobject *self, PyObject *args) { ...@@ -2941,16 +2953,31 @@ Unpickler_load(Unpicklerobject *self, PyObject *args) {
break; break;
continue; continue;
case EMPTY_TUPLE:
if (load_empty_tuple(self, NULL) < 0)
break;
continue;
case TUPLE: case TUPLE:
if (load_tuple(self, NULL) < 0) if (load_tuple(self, NULL) < 0)
break; break;
continue; continue;
case EMPTY_LIST:
if (load_empty_list(self, NULL) < 0)
break;
continue;
case LIST: case LIST:
if (load_list(self, NULL) < 0) if (load_list(self, NULL) < 0)
break; break;
continue; continue;
case EMPTY_DICT:
if (load_empty_dict(self, NULL) < 0)
break;
continue;
case DICT: case DICT:
if (load_dict(self, NULL) < 0) if (load_dict(self, NULL) < 0)
break; break;
...@@ -3135,23 +3162,14 @@ newUnpicklerobject(PyObject *f) { ...@@ -3135,23 +3162,14 @@ newUnpicklerobject(PyObject *f) {
} }
else { else {
PyObject *readline, *read; PyObject *readline, *read;
static PyObject *read_str = 0, *readline_str = 0;
self->fp = NULL; self->fp = NULL;
self->read_func = read_other; self->read_func = read_other;
self->readline_func = readline_other; self->readline_func = readline_other;
UNLESS(readline_str)
UNLESS(readline_str = PyString_FromString("readline"))
goto err;
UNLESS(readline = PyObject_GetAttr(f, readline_str)) UNLESS(readline = PyObject_GetAttr(f, readline_str))
goto err; goto err;
UNLESS(read_str)
UNLESS(read_str = PyString_FromString("read"))
goto err;
UNLESS(read = PyObject_GetAttr(f, read_str)) { UNLESS(read = PyObject_GetAttr(f, read_str)) {
Py_DECREF(readline); Py_DECREF(readline);
goto err; goto err;
...@@ -3160,8 +3178,6 @@ newUnpicklerobject(PyObject *f) { ...@@ -3160,8 +3178,6 @@ newUnpicklerobject(PyObject *f) {
self->read = read; self->read = read;
self->readline = readline; self->readline = readline;
self->diddled_ptr = NULL;
self->diddled_char = '\0';
} }
Py_INCREF(f); Py_INCREF(f);
...@@ -3176,6 +3192,8 @@ newUnpicklerobject(PyObject *f) { ...@@ -3176,6 +3192,8 @@ newUnpicklerobject(PyObject *f) {
self->num_marks = 0; self->num_marks = 0;
self->marks_size = 0; self->marks_size = 0;
self->buf_size = 0; self->buf_size = 0;
self->diddled_ptr = NULL;
self->diddled_char = '\0';
return self; return self;
...@@ -3415,6 +3433,21 @@ static int ...@@ -3415,6 +3433,21 @@ static int
init_stuff(PyObject *module, PyObject *module_dict) { init_stuff(PyObject *module, PyObject *module_dict) {
PyObject *string, *copy_reg; PyObject *string, *copy_reg;
#define INIT_STR(S) UNLESS(S ## _str=PyString_FromString(#S)) return -1;
INIT_STR(__class__);
INIT_STR(__getinitargs__);
INIT_STR(__dict__);
INIT_STR(__getstate__);
INIT_STR(__setstate__);
INIT_STR(__name__);
INIT_STR(__reduce__);
INIT_STR(write);
INIT_STR(__safe_for_unpickling__);
INIT_STR(append);
INIT_STR(read);
INIT_STR(readline);
UNLESS(builtins = PyImport_ImportModule("__builtin__")) UNLESS(builtins = PyImport_ImportModule("__builtin__"))
return -1; return -1;
......
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