Commit 2f6ef4c6 authored by Martin v. Löwis's avatar Martin v. Löwis

Reindent. Break long lines. Move comments before the statements.

parent 4baedc1d
...@@ -155,7 +155,8 @@ typedef struct { ...@@ -155,7 +155,8 @@ typedef struct {
} Pdata; } Pdata;
static void static void
Pdata_dealloc(Pdata *self) { Pdata_dealloc(Pdata *self)
{
int i; int i;
PyObject **p; PyObject **p;
...@@ -175,7 +176,8 @@ static PyTypeObject PdataType = { ...@@ -175,7 +176,8 @@ static PyTypeObject PdataType = {
#define Pdata_Check(O) ((O)->ob_type == &PdataType) #define Pdata_Check(O) ((O)->ob_type == &PdataType)
static PyObject * static PyObject *
Pdata_New(void) { Pdata_New(void)
{
Pdata *self; Pdata *self;
if (!( self = PyObject_New(Pdata, &PdataType))) return NULL; if (!( self = PyObject_New(Pdata, &PdataType))) return NULL;
...@@ -188,13 +190,15 @@ Pdata_New(void) { ...@@ -188,13 +190,15 @@ Pdata_New(void) {
} }
static int static int
stackUnderflow(void) { stackUnderflow(void)
{
PyErr_SetString(UnpicklingError, "unpickling stack underflow"); PyErr_SetString(UnpicklingError, "unpickling stack underflow");
return -1; return -1;
} }
static int static int
Pdata_clear(Pdata *self, int clearto) { Pdata_clear(Pdata *self, int clearto)
{
int i; int i;
PyObject **p; PyObject **p;
...@@ -210,7 +214,8 @@ Pdata_clear(Pdata *self, int clearto) { ...@@ -210,7 +214,8 @@ Pdata_clear(Pdata *self, int clearto) {
static int static int
Pdata_grow(Pdata *self) { Pdata_grow(Pdata *self)
{
if (! self->size) { if (! self->size) {
PyErr_NoMemory(); PyErr_NoMemory();
return -1; return -1;
...@@ -235,7 +240,8 @@ Pdata_grow(Pdata *self) { ...@@ -235,7 +240,8 @@ Pdata_grow(Pdata *self) {
static PyObject * static PyObject *
Pdata_popTuple(Pdata *self, int start) { Pdata_popTuple(Pdata *self, int start)
{
PyObject *r; PyObject *r;
int i, j, l; int i, j, l;
...@@ -249,7 +255,8 @@ Pdata_popTuple(Pdata *self, int start) { ...@@ -249,7 +255,8 @@ Pdata_popTuple(Pdata *self, int start) {
} }
static PyObject * static PyObject *
Pdata_popList(Pdata *self, int start) { Pdata_popList(Pdata *self, int start)
{
PyObject *r; PyObject *r;
int i, j, l; int i, j, l;
...@@ -357,7 +364,8 @@ static int save(Picklerobject *, PyObject *, int); ...@@ -357,7 +364,8 @@ static int save(Picklerobject *, PyObject *, int);
static int put2(Picklerobject *, PyObject *); static int put2(Picklerobject *, PyObject *);
int int
cPickle_PyMapping_HasKey(PyObject *o, PyObject *key) { cPickle_PyMapping_HasKey(PyObject *o, PyObject *key)
{
PyObject *v; PyObject *v;
if ((v = PyObject_GetItem(o,key))) { if ((v = PyObject_GetItem(o,key))) {
...@@ -380,7 +388,8 @@ cPickle_ErrFormat(PyObject *ErrType, char *stringformat, char *format, ...) ...@@ -380,7 +388,8 @@ cPickle_ErrFormat(PyObject *ErrType, char *stringformat, char *format, ...)
if (format) args = Py_VaBuildValue(format, va); if (format) args = Py_VaBuildValue(format, va);
va_end(va); va_end(va);
if (format && ! args) return NULL; if (format && ! args) return NULL;
if (stringformat && !(retval=PyString_FromString(stringformat))) return NULL; if (stringformat && !(retval=PyString_FromString(stringformat)))
return NULL;
if (retval) { if (retval) {
if (args) { if (args) {
...@@ -404,7 +413,8 @@ cPickle_ErrFormat(PyObject *ErrType, char *stringformat, char *format, ...) ...@@ -404,7 +413,8 @@ cPickle_ErrFormat(PyObject *ErrType, char *stringformat, char *format, ...)
} }
static int static int
write_file(Picklerobject *self, char *s, int n) { write_file(Picklerobject *self, char *s, int n)
{
size_t nbyteswritten; size_t nbyteswritten;
if (s == NULL) { if (s == NULL) {
...@@ -423,7 +433,8 @@ write_file(Picklerobject *self, char *s, int n) { ...@@ -423,7 +433,8 @@ write_file(Picklerobject *self, char *s, int n) {
} }
static int static int
write_cStringIO(Picklerobject *self, char *s, int n) { write_cStringIO(Picklerobject *self, char *s, int n)
{
if (s == NULL) { if (s == NULL) {
return 0; return 0;
} }
...@@ -436,19 +447,22 @@ write_cStringIO(Picklerobject *self, char *s, int n) { ...@@ -436,19 +447,22 @@ write_cStringIO(Picklerobject *self, char *s, int n) {
} }
static int static int
write_none(Picklerobject *self, char *s, int n) { write_none(Picklerobject *self, char *s, int n)
{
if (s == NULL) return 0; if (s == NULL) return 0;
return n; return n;
} }
static int static int
write_other(Picklerobject *self, char *s, int n) { write_other(Picklerobject *self, char *s, int n)
{
PyObject *py_str = 0, *junk = 0; PyObject *py_str = 0, *junk = 0;
if (s == NULL) { if (s == NULL) {
if (!( self->buf_size )) return 0; if (!( self->buf_size )) return 0;
if (!( py_str = py_str = PyString_FromStringAndSize(self->write_buf,
PyString_FromStringAndSize(self->write_buf, self->buf_size))) self->buf_size);
if (!py_str)
return -1; return -1;
} }
else { else {
...@@ -488,7 +502,8 @@ write_other(Picklerobject *self, char *s, int n) { ...@@ -488,7 +502,8 @@ write_other(Picklerobject *self, char *s, int n) {
static int static int
read_file(Unpicklerobject *self, char **s, int n) { read_file(Unpicklerobject *self, char **s, int n)
{
size_t nbytesread; size_t nbytesread;
if (self->buf_size == 0) { if (self->buf_size == 0) {
...@@ -503,7 +518,8 @@ read_file(Unpicklerobject *self, char **s, int n) { ...@@ -503,7 +518,8 @@ read_file(Unpicklerobject *self, char **s, int n) {
self->buf_size = size; self->buf_size = size;
} }
else if (n > self->buf_size) { else if (n > self->buf_size) {
if (!( self->buf = (char *)realloc(self->buf, n * sizeof(char)))) { self->buf = (char *)realloc(self->buf, n * sizeof(char));
if (!self->buf) {
PyErr_NoMemory(); PyErr_NoMemory();
return -1; return -1;
} }
...@@ -531,7 +547,8 @@ read_file(Unpicklerobject *self, char **s, int n) { ...@@ -531,7 +547,8 @@ read_file(Unpicklerobject *self, char **s, int n) {
static int static int
readline_file(Unpicklerobject *self, char **s) { readline_file(Unpicklerobject *self, char **s)
{
int i; int i;
if (self->buf_size == 0) { if (self->buf_size == 0) {
...@@ -546,27 +563,28 @@ readline_file(Unpicklerobject *self, char **s) { ...@@ -546,27 +563,28 @@ readline_file(Unpicklerobject *self, char **s) {
i = 0; i = 0;
while (1) { while (1) {
for (; i < (self->buf_size - 1); i++) { for (; i < (self->buf_size - 1); i++) {
if (feof(self->fp) || (self->buf[i] = getc(self->fp)) == '\n') { if (feof(self->fp) ||
(self->buf[i] = getc(self->fp)) == '\n') {
self->buf[i + 1] = '\0'; self->buf[i + 1] = '\0';
*s = self->buf; *s = self->buf;
return i + 1; return i + 1;
} }
} }
self->buf = (char *)realloc(self->buf,
if (!( self->buf = (char *)realloc(self->buf, (self->buf_size * 2) * sizeof(char));
(self->buf_size * 2) * sizeof(char)))) { if (!self->buf) {
PyErr_NoMemory(); PyErr_NoMemory();
return -1; return -1;
} }
self->buf_size *= 2; self->buf_size *= 2;
} }
} }
static int static int
read_cStringIO(Unpicklerobject *self, char **s, int n) { read_cStringIO(Unpicklerobject *self, char **s, int n)
{
char *ptr; char *ptr;
if (PycStringIO->cread((PyObject *)self->file, &ptr, n) != n) { if (PycStringIO->cread((PyObject *)self->file, &ptr, n) != n) {
...@@ -581,7 +599,8 @@ read_cStringIO(Unpicklerobject *self, char **s, int n) { ...@@ -581,7 +599,8 @@ read_cStringIO(Unpicklerobject *self, char **s, int n) {
static int static int
readline_cStringIO(Unpicklerobject *self, char **s) { readline_cStringIO(Unpicklerobject *self, char **s)
{
int n; int n;
char *ptr; char *ptr;
...@@ -596,7 +615,8 @@ readline_cStringIO(Unpicklerobject *self, char **s) { ...@@ -596,7 +615,8 @@ readline_cStringIO(Unpicklerobject *self, char **s) {
static int static int
read_other(Unpicklerobject *self, char **s, int n) { read_other(Unpicklerobject *self, char **s, int n)
{
PyObject *bytes, *str=0; PyObject *bytes, *str=0;
if (!( bytes = PyInt_FromLong(n))) return -1; if (!( bytes = PyInt_FromLong(n))) return -1;
...@@ -617,7 +637,8 @@ read_other(Unpicklerobject *self, char **s, int n) { ...@@ -617,7 +637,8 @@ read_other(Unpicklerobject *self, char **s, int n) {
static int static int
readline_other(Unpicklerobject *self, char **s) { readline_other(Unpicklerobject *self, char **s)
{
PyObject *str; PyObject *str;
int str_size; int str_size;
...@@ -639,7 +660,8 @@ readline_other(Unpicklerobject *self, char **s) { ...@@ -639,7 +660,8 @@ readline_other(Unpicklerobject *self, char **s) {
static char * static char *
pystrndup(char *s, int l) { pystrndup(char *s, int l)
{
char *r; char *r;
if (!( r=malloc((l+1)*sizeof(char)))) return (char*)PyErr_NoMemory(); if (!( r=malloc((l+1)*sizeof(char)))) return (char*)PyErr_NoMemory();
memcpy(r,s,l); memcpy(r,s,l);
...@@ -649,7 +671,8 @@ pystrndup(char *s, int l) { ...@@ -649,7 +671,8 @@ pystrndup(char *s, int l) {
static int static int
get(Picklerobject *self, PyObject *id) { get(Picklerobject *self, PyObject *id)
{
PyObject *value, *mv; PyObject *value, *mv;
long c_value; long c_value;
char s[30]; char s[30];
...@@ -703,7 +726,8 @@ get(Picklerobject *self, PyObject *id) { ...@@ -703,7 +726,8 @@ get(Picklerobject *self, PyObject *id) {
static int static int
put(Picklerobject *self, PyObject *ob) { put(Picklerobject *self, PyObject *ob)
{
if (ob->ob_refcnt < 2 || self->fast) if (ob->ob_refcnt < 2 || self->fast)
return 0; return 0;
...@@ -712,7 +736,8 @@ put(Picklerobject *self, PyObject *ob) { ...@@ -712,7 +736,8 @@ put(Picklerobject *self, PyObject *ob) {
static int static int
put2(Picklerobject *self, PyObject *ob) { put2(Picklerobject *self, PyObject *ob)
{
char c_str[30]; char c_str[30];
int p; int p;
size_t len; size_t len;
...@@ -725,7 +750,8 @@ put2(Picklerobject *self, PyObject *ob) { ...@@ -725,7 +750,8 @@ put2(Picklerobject *self, PyObject *ob) {
if ((p = PyDict_Size(self->memo)) < 0) if ((p = PyDict_Size(self->memo)) < 0)
goto finally; goto finally;
p++; /* Make sure memo keys are positive! */ /* Make sure memo keys are positive! */
p++;
if (!( py_ob_id = PyLong_FromVoidPtr(ob))) if (!( py_ob_id = PyLong_FromVoidPtr(ob)))
goto finally; goto finally;
...@@ -776,7 +802,7 @@ put2(Picklerobject *self, PyObject *ob) { ...@@ -776,7 +802,7 @@ put2(Picklerobject *self, PyObject *ob) {
res = 0; res = 0;
finally: finally:
Py_XDECREF(py_ob_id); Py_XDECREF(py_ob_id);
Py_XDECREF(memo_len); Py_XDECREF(memo_len);
Py_XDECREF(t); Py_XDECREF(t);
...@@ -787,7 +813,8 @@ finally: ...@@ -787,7 +813,8 @@ finally:
#define PyImport_Import cPickle_Import #define PyImport_Import cPickle_Import
static PyObject * static PyObject *
PyImport_Import(PyObject *module_name) { PyImport_Import(PyObject *module_name)
{
static PyObject *silly_list=0, *__builtins___str=0, *__import___str; static PyObject *silly_list=0, *__builtins___str=0, *__import___str;
static PyObject *standard_builtins=0; static PyObject *standard_builtins=0;
PyObject *globals=0, *__import__=0, *__builtins__=0, *r=0; PyObject *globals=0, *__import__=0, *__builtins__=0, *r=0;
...@@ -803,31 +830,36 @@ PyImport_Import(PyObject *module_name) { ...@@ -803,31 +830,36 @@ PyImport_Import(PyObject *module_name) {
if ((globals=PyEval_GetGlobals())) { if ((globals=PyEval_GetGlobals())) {
Py_INCREF(globals); Py_INCREF(globals);
if (!( __builtins__=PyObject_GetItem(globals,__builtins___str))) __builtins__=PyObject_GetItem(globals,__builtins___str);
if (!__builtins__)
goto err; goto err;
} }
else { else {
PyErr_Clear(); PyErr_Clear();
if (!( standard_builtins || if (!(standard_builtins ||
(standard_builtins=PyImport_ImportModule("__builtin__")))) (standard_builtins=PyImport_ImportModule("__builtin__"))))
return NULL; return NULL;
__builtins__=standard_builtins; __builtins__=standard_builtins;
Py_INCREF(__builtins__); Py_INCREF(__builtins__);
if (!( globals = Py_BuildValue("{sO}", "__builtins__", __builtins__))) globals = Py_BuildValue("{sO}", "__builtins__", __builtins__);
if (!globals)
goto err; goto err;
} }
if (PyDict_Check(__builtins__)) { if (PyDict_Check(__builtins__)) {
if (!( __import__=PyObject_GetItem(__builtins__,__import___str))) goto err; __import__=PyObject_GetItem(__builtins__,__import___str);
if (!__import__) goto err;
} }
else { else {
if (!( __import__=PyObject_GetAttr(__builtins__,__import___str))) goto err; __import__=PyObject_GetAttr(__builtins__,__import___str);
if (!__import__) goto err;
} }
if (!( r=PyObject_CallFunction(__import__,"OOOO", r=PyObject_CallFunction(__import__,"OOOO",
module_name, globals, globals, silly_list))) module_name, globals, globals, silly_list);
if (!r)
goto err; goto err;
Py_DECREF(globals); Py_DECREF(globals);
...@@ -835,7 +867,7 @@ PyImport_Import(PyObject *module_name) { ...@@ -835,7 +867,7 @@ PyImport_Import(PyObject *module_name) {
Py_DECREF(__import__); Py_DECREF(__import__);
return r; return r;
err: err:
Py_XDECREF(globals); Py_XDECREF(globals);
Py_XDECREF(__builtins__); Py_XDECREF(__builtins__);
Py_XDECREF(__import__); Py_XDECREF(__import__);
...@@ -843,7 +875,8 @@ err: ...@@ -843,7 +875,8 @@ err:
} }
static PyObject * static PyObject *
whichmodule(PyObject *global, PyObject *global_name) { whichmodule(PyObject *global, PyObject *global_name)
{
int i, j; int i, j;
PyObject *module = 0, *modules_dict = 0, PyObject *module = 0, *modules_dict = 0,
*global_name_attr = 0, *name = 0; *global_name_attr = 0, *name = 0;
...@@ -860,7 +893,8 @@ whichmodule(PyObject *global, PyObject *global_name) { ...@@ -860,7 +893,8 @@ whichmodule(PyObject *global, PyObject *global_name) {
if (PyObject_Compare(name, __main___str)==0) continue; if (PyObject_Compare(name, __main___str)==0) continue;
if (!( global_name_attr = PyObject_GetAttr(module, global_name))) { global_name_attr = PyObject_GetAttr(module, global_name);
if (!global_name_attr) {
PyErr_Clear(); PyErr_Clear();
continue; continue;
} }
...@@ -935,7 +969,8 @@ fast_save_leave(Picklerobject *self, PyObject *obj) ...@@ -935,7 +969,8 @@ fast_save_leave(Picklerobject *self, PyObject *obj)
} }
static int static int
save_none(Picklerobject *self, PyObject *args) { save_none(Picklerobject *self, PyObject *args)
{
static char none = NONE; static char none = NONE;
if ((*self->write_func)(self, &none, 1) < 0) if ((*self->write_func)(self, &none, 1) < 0)
return -1; return -1;
...@@ -945,7 +980,8 @@ save_none(Picklerobject *self, PyObject *args) { ...@@ -945,7 +980,8 @@ save_none(Picklerobject *self, PyObject *args) {
static int static int
save_int(Picklerobject *self, PyObject *args) { save_int(Picklerobject *self, PyObject *args)
{
char c_str[32]; char c_str[32];
long l = PyInt_AS_LONG((PyIntObject *)args); long l = PyInt_AS_LONG((PyIntObject *)args);
int len = 0; int len = 0;
...@@ -995,7 +1031,8 @@ save_int(Picklerobject *self, PyObject *args) { ...@@ -995,7 +1031,8 @@ save_int(Picklerobject *self, PyObject *args) {
static int static int
save_long(Picklerobject *self, PyObject *args) { save_long(Picklerobject *self, PyObject *args)
{
int size, res = -1; int size, res = -1;
PyObject *repr = 0; PyObject *repr = 0;
...@@ -1011,7 +1048,8 @@ save_long(Picklerobject *self, PyObject *args) { ...@@ -1011,7 +1048,8 @@ save_long(Picklerobject *self, PyObject *args) {
goto finally; goto finally;
if ((*self->write_func)(self, if ((*self->write_func)(self,
PyString_AS_STRING((PyStringObject *)repr), size) < 0) PyString_AS_STRING((PyStringObject *)repr),
size) < 0)
goto finally; goto finally;
if ((*self->write_func)(self, "\n", 1) < 0) if ((*self->write_func)(self, "\n", 1) < 0)
...@@ -1019,7 +1057,7 @@ save_long(Picklerobject *self, PyObject *args) { ...@@ -1019,7 +1057,7 @@ save_long(Picklerobject *self, PyObject *args) {
res = 0; res = 0;
finally: finally:
Py_XDECREF(repr); Py_XDECREF(repr);
return res; return res;
...@@ -1027,7 +1065,8 @@ finally: ...@@ -1027,7 +1065,8 @@ finally:
static int static int
save_float(Picklerobject *self, PyObject *args) { save_float(Picklerobject *self, PyObject *args)
{
double x = PyFloat_AS_DOUBLE((PyFloatObject *)args); double x = PyFloat_AS_DOUBLE((PyFloatObject *)args);
if (self->bin) { if (self->bin) {
...@@ -1079,7 +1118,8 @@ save_float(Picklerobject *self, PyObject *args) { ...@@ -1079,7 +1118,8 @@ save_float(Picklerobject *self, PyObject *args) {
f -= 1.0; /* Get rid of leading 1 */ f -= 1.0; /* Get rid of leading 1 */
} }
/* fhi receives the high 28 bits; flo the low 24 bits (== 52 bits) */ /* fhi receives the high 28 bits;
flo the low 24 bits (== 52 bits) */
f *= 268435456.0; /* 2**28 */ f *= 268435456.0; /* 2**28 */
fhi = (long) floor(f); /* Truncate */ fhi = (long) floor(f); /* Truncate */
f -= (double)fhi; f -= (double)fhi;
...@@ -1134,7 +1174,8 @@ save_float(Picklerobject *self, PyObject *args) { ...@@ -1134,7 +1174,8 @@ save_float(Picklerobject *self, PyObject *args) {
static int static int
save_string(Picklerobject *self, PyObject *args, int doput) { save_string(Picklerobject *self, PyObject *args, int doput)
{
int size, len; int size, len;
PyObject *repr=0; PyObject *repr=0;
...@@ -1203,7 +1244,7 @@ save_string(Picklerobject *self, PyObject *args, int doput) { ...@@ -1203,7 +1244,7 @@ save_string(Picklerobject *self, PyObject *args, int doput) {
return 0; return 0;
err: err:
Py_XDECREF(repr); Py_XDECREF(repr);
return -1; return -1;
} }
...@@ -1256,7 +1297,8 @@ modified_EncodeRawUnicodeEscape(const Py_UNICODE *s, int size) ...@@ -1256,7 +1297,8 @@ modified_EncodeRawUnicodeEscape(const Py_UNICODE *s, int size)
static int static int
save_unicode(Picklerobject *self, PyObject *args, int doput) { save_unicode(Picklerobject *self, PyObject *args, int doput)
{
int size, len; int size, len;
PyObject *repr=0; PyObject *repr=0;
...@@ -1267,8 +1309,9 @@ save_unicode(Picklerobject *self, PyObject *args, int doput) { ...@@ -1267,8 +1309,9 @@ save_unicode(Picklerobject *self, PyObject *args, int doput) {
char *repr_str; char *repr_str;
static char string = UNICODE; static char string = UNICODE;
if (!( repr = modified_EncodeRawUnicodeEscape( repr = modified_EncodeRawUnicodeEscape(
PyUnicode_AS_UNICODE(args), PyUnicode_GET_SIZE(args)))) PyUnicode_AS_UNICODE(args), PyUnicode_GET_SIZE(args));
if (!repr)
return -1; return -1;
if ((len = PyString_Size(repr)) < 0) if ((len = PyString_Size(repr)) < 0)
...@@ -1310,7 +1353,8 @@ save_unicode(Picklerobject *self, PyObject *args, int doput) { ...@@ -1310,7 +1353,8 @@ save_unicode(Picklerobject *self, PyObject *args, int doput) {
PDATA_APPEND(self->file, repr, -1); PDATA_APPEND(self->file, repr, -1);
} }
else { else {
if ((*self->write_func)(self, PyString_AS_STRING(repr), size) < 0) if ((*self->write_func)(self, PyString_AS_STRING(repr),
size) < 0)
goto err; goto err;
} }
...@@ -1323,7 +1367,7 @@ save_unicode(Picklerobject *self, PyObject *args, int doput) { ...@@ -1323,7 +1367,7 @@ save_unicode(Picklerobject *self, PyObject *args, int doput) {
return 0; return 0;
err: err:
Py_XDECREF(repr); Py_XDECREF(repr);
return -1; return -1;
} }
...@@ -1331,7 +1375,8 @@ err: ...@@ -1331,7 +1375,8 @@ err:
static int static int
save_tuple(Picklerobject *self, PyObject *args) { save_tuple(Picklerobject *self, PyObject *args)
{
PyObject *element = 0, *py_tuple_id = 0; PyObject *element = 0, *py_tuple_id = 0;
int len, i, res = -1; int len, i, res = -1;
...@@ -1388,14 +1433,15 @@ save_tuple(Picklerobject *self, PyObject *args) { ...@@ -1388,14 +1433,15 @@ save_tuple(Picklerobject *self, PyObject *args) {
res = 0; res = 0;
finally: finally:
Py_XDECREF(py_tuple_id); Py_XDECREF(py_tuple_id);
return res; return res;
} }
static int static int
save_empty_tuple(Picklerobject *self, PyObject *args) { save_empty_tuple(Picklerobject *self, PyObject *args)
{
static char tuple = EMPTY_TUPLE; static char tuple = EMPTY_TUPLE;
return (*self->write_func)(self, &tuple, 1); return (*self->write_func)(self, &tuple, 1);
...@@ -1403,7 +1449,8 @@ save_empty_tuple(Picklerobject *self, PyObject *args) { ...@@ -1403,7 +1449,8 @@ save_empty_tuple(Picklerobject *self, PyObject *args) {
static int static int
save_list(Picklerobject *self, PyObject *args) { save_list(Picklerobject *self, PyObject *args)
{
PyObject *element = 0; PyObject *element = 0;
int s_len, len, i, using_appends, res = -1; int s_len, len, i, using_appends, res = -1;
char s[3]; char s[3];
...@@ -1462,7 +1509,7 @@ save_list(Picklerobject *self, PyObject *args) { ...@@ -1462,7 +1509,7 @@ save_list(Picklerobject *self, PyObject *args) {
res = 0; res = 0;
finally: finally:
if (self->fast && !fast_save_leave(self, args)) if (self->fast && !fast_save_leave(self, args))
res = -1; res = -1;
...@@ -1471,7 +1518,8 @@ finally: ...@@ -1471,7 +1518,8 @@ finally:
static int static int
save_dict(Picklerobject *self, PyObject *args) { save_dict(Picklerobject *self, PyObject *args)
{
PyObject *key = 0, *value = 0; PyObject *key = 0, *value = 0;
int i, len, res = -1, using_setitems; int i, len, res = -1, using_setitems;
char s[3]; char s[3];
...@@ -1531,7 +1579,7 @@ save_dict(Picklerobject *self, PyObject *args) { ...@@ -1531,7 +1579,7 @@ save_dict(Picklerobject *self, PyObject *args) {
res = 0; res = 0;
finally: finally:
if (self->fast && !fast_save_leave(self, args)) if (self->fast && !fast_save_leave(self, args))
res = -1; res = -1;
...@@ -1540,7 +1588,8 @@ finally: ...@@ -1540,7 +1588,8 @@ finally:
static int static int
save_inst(Picklerobject *self, PyObject *args) { save_inst(Picklerobject *self, PyObject *args)
{
PyObject *class = 0, *module = 0, *name = 0, *state = 0, PyObject *class = 0, *module = 0, *name = 0, *state = 0,
*getinitargs_func = 0, *getstate_func = 0, *class_args = 0; *getinitargs_func = 0, *getstate_func = 0, *class_args = 0;
char *module_str, *name_str; char *module_str, *name_str;
...@@ -1626,7 +1675,8 @@ save_inst(Picklerobject *self, PyObject *args) { ...@@ -1626,7 +1675,8 @@ save_inst(Picklerobject *self, PyObject *args) {
} }
if ((getstate_func = PyObject_GetAttr(args, __getstate___str))) { if ((getstate_func = PyObject_GetAttr(args, __getstate___str))) {
if (!( state = PyObject_Call(getstate_func, empty_tuple, NULL))) state = PyObject_Call(getstate_func, empty_tuple, NULL);
if (!state)
goto finally; goto finally;
} }
else { else {
...@@ -1656,7 +1706,7 @@ save_inst(Picklerobject *self, PyObject *args) { ...@@ -1656,7 +1706,7 @@ save_inst(Picklerobject *self, PyObject *args) {
res = 0; res = 0;
finally: finally:
if (self->fast && !fast_save_leave(self, args)) if (self->fast && !fast_save_leave(self, args))
res = -1; res = -1;
...@@ -1672,7 +1722,8 @@ finally: ...@@ -1672,7 +1722,8 @@ finally:
static int static int
save_global(Picklerobject *self, PyObject *args, PyObject *name) { save_global(Picklerobject *self, PyObject *args, PyObject *name)
{
PyObject *global_name = 0, *module = 0, *mod = 0, *moddict = 0, *klass = 0; PyObject *global_name = 0, *module = 0, *mod = 0, *moddict = 0, *klass = 0;
char *name_str, *module_str; char *name_str, *module_str;
int module_size, name_size, res = -1; int module_size, name_size, res = -1;
...@@ -1706,8 +1757,10 @@ save_global(Picklerobject *self, PyObject *args, PyObject *name) { ...@@ -1706,8 +1757,10 @@ save_global(Picklerobject *self, PyObject *args, PyObject *name) {
"OSS", args, module, global_name); "OSS", args, module, global_name);
goto finally; goto finally;
} }
moddict = PyModule_GetDict(mod); /* borrowed ref */ /* borrowed ref */
klass = PyDict_GetItemString(moddict, name_str); /* borrowed ref */ moddict = PyModule_GetDict(mod);
/* borrowed ref */
klass = PyDict_GetItemString(moddict, name_str);
if (klass == NULL) { if (klass == NULL) {
cPickle_ErrFormat(PicklingError, cPickle_ErrFormat(PicklingError,
"Can't pickle %s: it's not found as %s.%s", "Can't pickle %s: it's not found as %s.%s",
...@@ -1741,7 +1794,7 @@ save_global(Picklerobject *self, PyObject *args, PyObject *name) { ...@@ -1741,7 +1794,7 @@ save_global(Picklerobject *self, PyObject *args, PyObject *name) {
res = 0; res = 0;
finally: finally:
Py_XDECREF(module); Py_XDECREF(module);
Py_XDECREF(global_name); Py_XDECREF(global_name);
Py_XDECREF(mod); Py_XDECREF(mod);
...@@ -1750,7 +1803,8 @@ finally: ...@@ -1750,7 +1803,8 @@ finally:
} }
static int static int
save_pers(Picklerobject *self, PyObject *args, PyObject *f) { save_pers(Picklerobject *self, PyObject *args, PyObject *f)
{
PyObject *pid = 0; PyObject *pid = 0;
int size, res = -1; int size, res = -1;
...@@ -1800,7 +1854,7 @@ save_pers(Picklerobject *self, PyObject *args, PyObject *f) { ...@@ -1800,7 +1854,7 @@ save_pers(Picklerobject *self, PyObject *args, PyObject *f) {
res = 0; res = 0;
finally: finally:
Py_XDECREF(pid); Py_XDECREF(pid);
return res; return res;
...@@ -1809,7 +1863,8 @@ finally: ...@@ -1809,7 +1863,8 @@ finally:
static int static int
save_reduce(Picklerobject *self, PyObject *callable, save_reduce(Picklerobject *self, PyObject *callable,
PyObject *tup, PyObject *state, PyObject *ob) { PyObject *tup, PyObject *state, PyObject *ob)
{
static char reduce = REDUCE, build = BUILD; static char reduce = REDUCE, build = BUILD;
if (save(self, callable, 0) < 0) if (save(self, callable, 0) < 0)
...@@ -1844,7 +1899,8 @@ save_reduce(Picklerobject *self, PyObject *callable, ...@@ -1844,7 +1899,8 @@ save_reduce(Picklerobject *self, PyObject *callable,
} }
static int static int
save(Picklerobject *self, PyObject *args, int pers_save) { save(Picklerobject *self, PyObject *args, int pers_save)
{
PyTypeObject *type; PyTypeObject *type;
PyObject *py_ob_id = 0, *__reduce__ = 0, *t = 0, *arg_tup = 0, PyObject *py_ob_id = 0, *__reduce__ = 0, *t = 0, *arg_tup = 0,
*callable = 0, *state = 0; *callable = 0, *state = 0;
...@@ -2019,7 +2075,8 @@ save(Picklerobject *self, PyObject *args, int pers_save) { ...@@ -2019,7 +2075,8 @@ save(Picklerobject *self, PyObject *args, int pers_save) {
PyErr_Clear(); PyErr_Clear();
if ((__reduce__ = PyObject_GetAttr(args, __reduce___str))) { if ((__reduce__ = PyObject_GetAttr(args, __reduce___str))) {
if (!( t = PyObject_Call(__reduce__, empty_tuple, NULL))) t = PyObject_Call(__reduce__, empty_tuple, NULL);
if (!t)
goto finally; goto finally;
} }
else { else {
...@@ -2067,7 +2124,7 @@ save(Picklerobject *self, PyObject *args, int pers_save) { ...@@ -2067,7 +2124,7 @@ save(Picklerobject *self, PyObject *args, int pers_save) {
PyErr_SetObject(UnpickleableError, args); PyErr_SetObject(UnpickleableError, args);
finally: finally:
Py_XDECREF(py_ob_id); Py_XDECREF(py_ob_id);
Py_XDECREF(__reduce__); Py_XDECREF(__reduce__);
Py_XDECREF(t); Py_XDECREF(t);
...@@ -2077,7 +2134,8 @@ finally: ...@@ -2077,7 +2134,8 @@ finally:
static int static int
dump(Picklerobject *self, PyObject *args) { dump(Picklerobject *self, PyObject *args)
{
static char stop = STOP; static char stop = STOP;
if (save(self, args, 0) < 0) if (save(self, args, 0) < 0)
...@@ -2093,7 +2151,8 @@ dump(Picklerobject *self, PyObject *args) { ...@@ -2093,7 +2151,8 @@ dump(Picklerobject *self, PyObject *args) {
} }
static PyObject * static PyObject *
Pickle_clear_memo(Picklerobject *self, PyObject *args) { Pickle_clear_memo(Picklerobject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args,":clear_memo")) if (!PyArg_ParseTuple(args,":clear_memo"))
return NULL; return NULL;
if (self->memo) if (self->memo)
...@@ -2103,7 +2162,8 @@ Pickle_clear_memo(Picklerobject *self, PyObject *args) { ...@@ -2103,7 +2162,8 @@ Pickle_clear_memo(Picklerobject *self, PyObject *args) {
} }
static PyObject * static PyObject *
Pickle_getvalue(Picklerobject *self, PyObject *args) { Pickle_getvalue(Picklerobject *self, PyObject *args)
{
int l, i, rsize, ssize, clear=1, lm; int l, i, rsize, ssize, clear=1, lm;
long ik; long ik;
PyObject *k, *r; PyObject *k, *r;
...@@ -2234,13 +2294,14 @@ Pickle_getvalue(Picklerobject *self, PyObject *args) { ...@@ -2234,13 +2294,14 @@ Pickle_getvalue(Picklerobject *self, PyObject *args) {
free(have_get); free(have_get);
return r; return r;
err: err:
free(have_get); free(have_get);
return NULL; return NULL;
} }
static PyObject * static PyObject *
Pickler_dump(Picklerobject *self, PyObject *args) { Pickler_dump(Picklerobject *self, PyObject *args)
{
PyObject *ob; PyObject *ob;
int get=0; int get=0;
...@@ -2258,7 +2319,8 @@ Pickler_dump(Picklerobject *self, PyObject *args) { ...@@ -2258,7 +2319,8 @@ Pickler_dump(Picklerobject *self, PyObject *args) {
} }
static struct PyMethodDef Pickler_methods[] = { static struct PyMethodDef Pickler_methods[] =
{
{"dump", (PyCFunction)Pickler_dump, METH_VARARGS, {"dump", (PyCFunction)Pickler_dump, METH_VARARGS,
"dump(object) --" "dump(object) --"
"Write an object in pickle format to the object's pickle stream\n" "Write an object in pickle format to the object's pickle stream\n"
...@@ -2272,7 +2334,8 @@ static struct PyMethodDef Pickler_methods[] = { ...@@ -2272,7 +2334,8 @@ static struct PyMethodDef Pickler_methods[] = {
static Picklerobject * static Picklerobject *
newPicklerobject(PyObject *file, int bin) { newPicklerobject(PyObject *file, int bin)
{
Picklerobject *self; Picklerobject *self;
if (!( self = PyObject_New(Picklerobject, &Picklertype))) if (!( self = PyObject_New(Picklerobject, &Picklertype)))
...@@ -2321,9 +2384,11 @@ newPicklerobject(PyObject *file, int bin) { ...@@ -2321,9 +2384,11 @@ newPicklerobject(PyObject *file, int bin) {
self->write_func = write_other; self->write_func = write_other;
if (! Pdata_Check(file)) { if (! Pdata_Check(file)) {
if (!( self->write = PyObject_GetAttr(file, write_str))) { self->write = PyObject_GetAttr(file, write_str);
if (!self->write) {
PyErr_Clear(); PyErr_Clear();
PyErr_SetString(PyExc_TypeError, "argument must have 'write' " PyErr_SetString(PyExc_TypeError,
"argument must have 'write' "
"attribute"); "attribute");
goto err; goto err;
} }
...@@ -2352,14 +2417,15 @@ newPicklerobject(PyObject *file, int bin) { ...@@ -2352,14 +2417,15 @@ newPicklerobject(PyObject *file, int bin) {
return self; return self;
err: err:
Py_DECREF((PyObject *)self); Py_DECREF((PyObject *)self);
return NULL; return NULL;
} }
static PyObject * static PyObject *
get_Pickler(PyObject *self, PyObject *args) { get_Pickler(PyObject *self, PyObject *args)
{
PyObject *file = NULL; PyObject *file = NULL;
int bin = 1; int bin = 1;
...@@ -2374,7 +2440,8 @@ get_Pickler(PyObject *self, PyObject *args) { ...@@ -2374,7 +2440,8 @@ get_Pickler(PyObject *self, PyObject *args) {
static void static void
Pickler_dealloc(Picklerobject *self) { Pickler_dealloc(Picklerobject *self)
{
Py_XDECREF(self->write); Py_XDECREF(self->write);
Py_XDECREF(self->memo); Py_XDECREF(self->memo);
Py_XDECREF(self->fast_memo); Py_XDECREF(self->fast_memo);
...@@ -2518,7 +2585,8 @@ static PyTypeObject Picklertype = { ...@@ -2518,7 +2585,8 @@ static PyTypeObject Picklertype = {
}; };
static PyObject * static PyObject *
find_class(PyObject *py_module_name, PyObject *py_global_name, PyObject *fc) { find_class(PyObject *py_module_name, PyObject *py_global_name, PyObject *fc)
{
PyObject *global = 0, *module; PyObject *global = 0, *module;
if (fc) { if (fc) {
...@@ -2527,7 +2595,8 @@ find_class(PyObject *py_module_name, PyObject *py_global_name, PyObject *fc) { ...@@ -2527,7 +2595,8 @@ find_class(PyObject *py_module_name, PyObject *py_global_name, PyObject *fc) {
"Global and instance pickles are not supported."); "Global and instance pickles are not supported.");
return NULL; return NULL;
} }
return PyObject_CallFunction(fc, "OO", py_module_name, py_global_name); return PyObject_CallFunction(fc, "OO", py_module_name,
py_global_name);
} }
module = PySys_GetObject("modules"); module = PySys_GetObject("modules");
...@@ -2548,7 +2617,8 @@ find_class(PyObject *py_module_name, PyObject *py_global_name, PyObject *fc) { ...@@ -2548,7 +2617,8 @@ find_class(PyObject *py_module_name, PyObject *py_global_name, PyObject *fc) {
} }
static int static int
marker(Unpicklerobject *self) { marker(Unpicklerobject *self)
{
if (self->num_marks < 1) { if (self->num_marks < 1) {
PyErr_SetString(UnpicklingError, "could not find MARK"); PyErr_SetString(UnpicklingError, "could not find MARK");
return -1; return -1;
...@@ -2559,19 +2629,22 @@ marker(Unpicklerobject *self) { ...@@ -2559,19 +2629,22 @@ marker(Unpicklerobject *self) {
static int static int
load_none(Unpicklerobject *self) { load_none(Unpicklerobject *self)
{
PDATA_APPEND(self->stack, Py_None, -1); PDATA_APPEND(self->stack, Py_None, -1);
return 0; return 0;
} }
static int static int
bad_readline(void) { bad_readline(void)
{
PyErr_SetString(UnpicklingError, "pickle data was truncated"); PyErr_SetString(UnpicklingError, "pickle data was truncated");
return -1; return -1;
} }
static int static int
load_int(Unpicklerobject *self) { load_int(Unpicklerobject *self)
{
PyObject *py_int = 0; PyObject *py_int = 0;
char *endptr, *s; char *endptr, *s;
int len, res = -1; int len, res = -1;
...@@ -2603,7 +2676,7 @@ load_int(Unpicklerobject *self) { ...@@ -2603,7 +2676,7 @@ load_int(Unpicklerobject *self) {
PDATA_PUSH(self->stack, py_int, -1); PDATA_PUSH(self->stack, py_int, -1);
return 0; return 0;
finally: finally:
free(s); free(s);
return res; return res;
...@@ -2611,7 +2684,8 @@ finally: ...@@ -2611,7 +2684,8 @@ finally:
static long static long
calc_binint(char *s, int x) { calc_binint(char *s, int x)
{
unsigned char c; unsigned char c;
int i; int i;
long l; long l;
...@@ -2633,7 +2707,8 @@ calc_binint(char *s, int x) { ...@@ -2633,7 +2707,8 @@ calc_binint(char *s, int x) {
static int static int
load_binintx(Unpicklerobject *self, char *s, int x) { load_binintx(Unpicklerobject *self, char *s, int x)
{
PyObject *py_int = 0; PyObject *py_int = 0;
long l; long l;
...@@ -2648,7 +2723,8 @@ load_binintx(Unpicklerobject *self, char *s, int x) { ...@@ -2648,7 +2723,8 @@ load_binintx(Unpicklerobject *self, char *s, int x) {
static int static int
load_binint(Unpicklerobject *self) { load_binint(Unpicklerobject *self)
{
char *s; char *s;
if ((*self->read_func)(self, &s, 4) < 0) if ((*self->read_func)(self, &s, 4) < 0)
...@@ -2659,7 +2735,8 @@ load_binint(Unpicklerobject *self) { ...@@ -2659,7 +2735,8 @@ load_binint(Unpicklerobject *self) {
static int static int
load_binint1(Unpicklerobject *self) { load_binint1(Unpicklerobject *self)
{
char *s; char *s;
if ((*self->read_func)(self, &s, 1) < 0) if ((*self->read_func)(self, &s, 1) < 0)
...@@ -2670,7 +2747,8 @@ load_binint1(Unpicklerobject *self) { ...@@ -2670,7 +2747,8 @@ load_binint1(Unpicklerobject *self) {
static int static int
load_binint2(Unpicklerobject *self) { load_binint2(Unpicklerobject *self)
{
char *s; char *s;
if ((*self->read_func)(self, &s, 2) < 0) if ((*self->read_func)(self, &s, 2) < 0)
...@@ -2680,7 +2758,8 @@ load_binint2(Unpicklerobject *self) { ...@@ -2680,7 +2758,8 @@ load_binint2(Unpicklerobject *self) {
} }
static int static int
load_long(Unpicklerobject *self) { load_long(Unpicklerobject *self)
{
PyObject *l = 0; PyObject *l = 0;
char *end, *s; char *end, *s;
int len, res = -1; int len, res = -1;
...@@ -2696,7 +2775,7 @@ load_long(Unpicklerobject *self) { ...@@ -2696,7 +2775,7 @@ load_long(Unpicklerobject *self) {
PDATA_PUSH(self->stack, l, -1); PDATA_PUSH(self->stack, l, -1);
return 0; return 0;
finally: finally:
free(s); free(s);
return res; return res;
...@@ -2704,7 +2783,8 @@ finally: ...@@ -2704,7 +2783,8 @@ finally:
static int static int
load_float(Unpicklerobject *self) { load_float(Unpicklerobject *self)
{
PyObject *py_float = 0; PyObject *py_float = 0;
char *endptr, *s; char *endptr, *s;
int len, res = -1; int len, res = -1;
...@@ -2730,14 +2810,15 @@ load_float(Unpicklerobject *self) { ...@@ -2730,14 +2810,15 @@ load_float(Unpicklerobject *self) {
PDATA_PUSH(self->stack, py_float, -1); PDATA_PUSH(self->stack, py_float, -1);
return 0; return 0;
finally: finally:
free(s); free(s);
return res; return res;
} }
static int static int
load_binfloat(Unpicklerobject *self) { load_binfloat(Unpicklerobject *self)
{
PyObject *py_float = 0; PyObject *py_float = 0;
int s, e; int s, e;
long fhi, flo; long fhi, flo;
...@@ -2802,7 +2883,8 @@ load_binfloat(Unpicklerobject *self) { ...@@ -2802,7 +2883,8 @@ load_binfloat(Unpicklerobject *self) {
} }
static int static int
load_string(Unpicklerobject *self) { load_string(Unpicklerobject *self)
{
PyObject *str = 0; PyObject *str = 0;
int len, res = -1, nslash; int len, res = -1, nslash;
char *s, q, *p; char *s, q, *p;
...@@ -2841,12 +2923,12 @@ load_string(Unpicklerobject *self) { ...@@ -2841,12 +2923,12 @@ load_string(Unpicklerobject *self) {
PDATA_PUSH(self->stack, str, -1); PDATA_PUSH(self->stack, str, -1);
return 0; return 0;
finally: finally:
free(s); free(s);
return res; return res;
insecure: insecure:
free(s); free(s);
PyErr_SetString(PyExc_ValueError,"insecure string pickle"); PyErr_SetString(PyExc_ValueError,"insecure string pickle");
return -1; return -1;
...@@ -2854,7 +2936,8 @@ insecure: ...@@ -2854,7 +2936,8 @@ insecure:
static int static int
load_binstring(Unpicklerobject *self) { load_binstring(Unpicklerobject *self)
{
PyObject *py_string = 0; PyObject *py_string = 0;
long l; long l;
char *s; char *s;
...@@ -2875,7 +2958,8 @@ load_binstring(Unpicklerobject *self) { ...@@ -2875,7 +2958,8 @@ load_binstring(Unpicklerobject *self) {
static int static int
load_short_binstring(Unpicklerobject *self) { load_short_binstring(Unpicklerobject *self)
{
PyObject *py_string = 0; PyObject *py_string = 0;
unsigned char l; unsigned char l;
char *s; char *s;
...@@ -2896,7 +2980,8 @@ load_short_binstring(Unpicklerobject *self) { ...@@ -2896,7 +2980,8 @@ load_short_binstring(Unpicklerobject *self) {
#ifdef Py_USING_UNICODE #ifdef Py_USING_UNICODE
static int static int
load_unicode(Unpicklerobject *self) { load_unicode(Unpicklerobject *self)
{
PyObject *str = 0; PyObject *str = 0;
int len, res = -1; int len, res = -1;
char *s; char *s;
...@@ -2910,7 +2995,7 @@ load_unicode(Unpicklerobject *self) { ...@@ -2910,7 +2995,7 @@ load_unicode(Unpicklerobject *self) {
PDATA_PUSH(self->stack, str, -1); PDATA_PUSH(self->stack, str, -1);
return 0; return 0;
finally: finally:
return res; return res;
} }
#endif #endif
...@@ -2918,7 +3003,8 @@ finally: ...@@ -2918,7 +3003,8 @@ finally:
#ifdef Py_USING_UNICODE #ifdef Py_USING_UNICODE
static int static int
load_binunicode(Unpicklerobject *self) { load_binunicode(Unpicklerobject *self)
{
PyObject *unicode; PyObject *unicode;
long l; long l;
char *s; char *s;
...@@ -2940,7 +3026,8 @@ load_binunicode(Unpicklerobject *self) { ...@@ -2940,7 +3026,8 @@ load_binunicode(Unpicklerobject *self) {
static int static int
load_tuple(Unpicklerobject *self) { load_tuple(Unpicklerobject *self)
{
PyObject *tup; PyObject *tup;
int i; int i;
...@@ -2951,7 +3038,8 @@ load_tuple(Unpicklerobject *self) { ...@@ -2951,7 +3038,8 @@ load_tuple(Unpicklerobject *self) {
} }
static int static int
load_empty_tuple(Unpicklerobject *self) { load_empty_tuple(Unpicklerobject *self)
{
PyObject *tup; PyObject *tup;
if (!( tup=PyTuple_New(0))) return -1; if (!( tup=PyTuple_New(0))) return -1;
...@@ -2960,7 +3048,8 @@ load_empty_tuple(Unpicklerobject *self) { ...@@ -2960,7 +3048,8 @@ load_empty_tuple(Unpicklerobject *self) {
} }
static int static int
load_empty_list(Unpicklerobject *self) { load_empty_list(Unpicklerobject *self)
{
PyObject *list; PyObject *list;
if (!( list=PyList_New(0))) return -1; if (!( list=PyList_New(0))) return -1;
...@@ -2969,7 +3058,8 @@ load_empty_list(Unpicklerobject *self) { ...@@ -2969,7 +3058,8 @@ load_empty_list(Unpicklerobject *self) {
} }
static int static int
load_empty_dict(Unpicklerobject *self) { load_empty_dict(Unpicklerobject *self)
{
PyObject *dict; PyObject *dict;
if (!( dict=PyDict_New())) return -1; if (!( dict=PyDict_New())) return -1;
...@@ -2979,7 +3069,8 @@ load_empty_dict(Unpicklerobject *self) { ...@@ -2979,7 +3069,8 @@ load_empty_dict(Unpicklerobject *self) {
static int static int
load_list(Unpicklerobject *self) { load_list(Unpicklerobject *self)
{
PyObject *list = 0; PyObject *list = 0;
int i; int i;
...@@ -2990,7 +3081,8 @@ load_list(Unpicklerobject *self) { ...@@ -2990,7 +3081,8 @@ load_list(Unpicklerobject *self) {
} }
static int static int
load_dict(Unpicklerobject *self) { load_dict(Unpicklerobject *self)
{
PyObject *dict, *key, *value; PyObject *dict, *key, *value;
int i, j, k; int i, j, k;
...@@ -3013,7 +3105,8 @@ load_dict(Unpicklerobject *self) { ...@@ -3013,7 +3105,8 @@ load_dict(Unpicklerobject *self) {
} }
static PyObject * static PyObject *
Instance_New(PyObject *cls, PyObject *args) { Instance_New(PyObject *cls, PyObject *args)
{
int has_key; int has_key;
PyObject *safe=0, *r=0; PyObject *safe=0, *r=0;
...@@ -3024,9 +3117,11 @@ Instance_New(PyObject *cls, PyObject *args) { ...@@ -3024,9 +3117,11 @@ Instance_New(PyObject *cls, PyObject *args) {
if (!( l )) { if (!( l )) {
PyObject *__getinitargs__; PyObject *__getinitargs__;
if (!( __getinitargs__=PyObject_GetAttr(cls, __getinitargs___str))) { __getinitargs__ = PyObject_GetAttr(cls,
/* We have a class with no __getinitargs__, so bypass usual __getinitargs___str);
construction */ if (!__getinitargs__) {
/* We have a class with no __getinitargs__,
so bypass usual construction */
PyObject *inst; PyObject *inst;
PyErr_Clear(); PyErr_Clear();
...@@ -3043,20 +3138,24 @@ Instance_New(PyObject *cls, PyObject *args) { ...@@ -3043,20 +3138,24 @@ Instance_New(PyObject *cls, PyObject *args) {
/* Is safe_constructors always a dict? */ /* Is safe_constructors always a dict? */
has_key = cPickle_PyMapping_HasKey(safe_constructors, cls); has_key = cPickle_PyMapping_HasKey(safe_constructors, cls);
if (!has_key) if (!has_key) {
if (!(safe = PyObject_GetAttr(cls, __safe_for_unpickling___str)) || safe = PyObject_GetAttr(cls, __safe_for_unpickling___str);
if (!safe ||
!PyObject_IsTrue(safe)) { !PyObject_IsTrue(safe)) {
cPickle_ErrFormat(UnpicklingError, cPickle_ErrFormat(UnpicklingError,
"%s is not safe for unpickling", "O", cls); "%s is not safe for unpickling",
"O", cls);
Py_XDECREF(safe); Py_XDECREF(safe);
return NULL; return NULL;
} }
}
if (args==Py_None) { if (args==Py_None) {
/* Special case, call cls.__basicnew__() */ /* Special case, call cls.__basicnew__() */
PyObject *basicnew; PyObject *basicnew;
if (!( basicnew=PyObject_GetAttr(cls, __basicnew___str))) return NULL; basicnew = PyObject_GetAttr(cls, __basicnew___str);
if (!basicnew) return NULL;
r=PyObject_CallObject(basicnew, NULL); r=PyObject_CallObject(basicnew, NULL);
Py_DECREF(basicnew); Py_DECREF(basicnew);
if (r) return r; if (r) return r;
...@@ -3064,7 +3163,7 @@ Instance_New(PyObject *cls, PyObject *args) { ...@@ -3064,7 +3163,7 @@ Instance_New(PyObject *cls, PyObject *args) {
if ((r=PyObject_CallObject(cls, args))) return r; if ((r=PyObject_CallObject(cls, args))) return r;
err: err:
{ {
PyObject *tp, *v, *tb; PyObject *tp, *v, *tb;
...@@ -3080,7 +3179,8 @@ err: ...@@ -3080,7 +3179,8 @@ err:
static int static int
load_obj(Unpicklerobject *self) { load_obj(Unpicklerobject *self)
{
PyObject *class, *tup, *obj=0; PyObject *class, *tup, *obj=0;
int i; int i;
...@@ -3100,7 +3200,8 @@ load_obj(Unpicklerobject *self) { ...@@ -3100,7 +3200,8 @@ load_obj(Unpicklerobject *self) {
static int static int
load_inst(Unpicklerobject *self) { load_inst(Unpicklerobject *self)
{
PyObject *tup, *class=0, *obj=0, *module_name, *class_name; PyObject *tup, *class=0, *obj=0, *module_name, *class_name;
int i, len; int i, len;
char *s; char *s;
...@@ -3109,12 +3210,14 @@ load_inst(Unpicklerobject *self) { ...@@ -3109,12 +3210,14 @@ load_inst(Unpicklerobject *self) {
if ((len = (*self->readline_func)(self, &s)) < 0) return -1; if ((len = (*self->readline_func)(self, &s)) < 0) return -1;
if (len < 2) return bad_readline(); if (len < 2) return bad_readline();
if (!( module_name = PyString_FromStringAndSize(s, len - 1))) return -1; module_name = PyString_FromStringAndSize(s, len - 1);
if (!module_name) return -1;
if ((len = (*self->readline_func)(self, &s)) >= 0) { if ((len = (*self->readline_func)(self, &s)) >= 0) {
if (len < 2) return bad_readline(); if (len < 2) return bad_readline();
if ((class_name = PyString_FromStringAndSize(s, len - 1))) { if ((class_name = PyString_FromStringAndSize(s, len - 1))) {
class = find_class(module_name, class_name, self->find_class); class = find_class(module_name, class_name,
self->find_class);
Py_DECREF(class_name); Py_DECREF(class_name);
} }
} }
...@@ -3136,19 +3239,22 @@ load_inst(Unpicklerobject *self) { ...@@ -3136,19 +3239,22 @@ load_inst(Unpicklerobject *self) {
static int static int
load_global(Unpicklerobject *self) { load_global(Unpicklerobject *self)
{
PyObject *class = 0, *module_name = 0, *class_name = 0; PyObject *class = 0, *module_name = 0, *class_name = 0;
int len; int len;
char *s; char *s;
if ((len = (*self->readline_func)(self, &s)) < 0) return -1; if ((len = (*self->readline_func)(self, &s)) < 0) return -1;
if (len < 2) return bad_readline(); if (len < 2) return bad_readline();
if (!( module_name = PyString_FromStringAndSize(s, len - 1))) return -1; module_name = PyString_FromStringAndSize(s, len - 1);
if (!module_name) return -1;
if ((len = (*self->readline_func)(self, &s)) >= 0) { if ((len = (*self->readline_func)(self, &s)) >= 0) {
if (len < 2) return bad_readline(); if (len < 2) return bad_readline();
if ((class_name = PyString_FromStringAndSize(s, len - 1))) { if ((class_name = PyString_FromStringAndSize(s, len - 1))) {
class = find_class(module_name, class_name, self->find_class); class = find_class(module_name, class_name,
self->find_class);
Py_DECREF(class_name); Py_DECREF(class_name);
} }
} }
...@@ -3161,7 +3267,8 @@ load_global(Unpicklerobject *self) { ...@@ -3161,7 +3267,8 @@ load_global(Unpicklerobject *self) {
static int static int
load_persid(Unpicklerobject *self) { load_persid(Unpicklerobject *self)
{
PyObject *pid = 0; PyObject *pid = 0;
int len; int len;
char *s; char *s;
...@@ -3170,7 +3277,8 @@ load_persid(Unpicklerobject *self) { ...@@ -3170,7 +3277,8 @@ load_persid(Unpicklerobject *self) {
if ((len = (*self->readline_func)(self, &s)) < 0) return -1; if ((len = (*self->readline_func)(self, &s)) < 0) return -1;
if (len < 2) return bad_readline(); if (len < 2) return bad_readline();
if (!( pid = PyString_FromStringAndSize(s, len - 1))) return -1; pid = PyString_FromStringAndSize(s, len - 1);
if (!pid) return -1;
if (PyList_Check(self->pers_func)) { if (PyList_Check(self->pers_func)) {
if (PyList_Append(self->pers_func, pid) < 0) { if (PyList_Append(self->pers_func, pid) < 0) {
...@@ -3181,7 +3289,8 @@ load_persid(Unpicklerobject *self) { ...@@ -3181,7 +3289,8 @@ load_persid(Unpicklerobject *self) {
else { else {
ARG_TUP(self, pid); ARG_TUP(self, pid);
if (self->arg) { if (self->arg) {
pid = PyObject_Call(self->pers_func, self->arg, NULL); pid = PyObject_Call(self->pers_func, self->arg,
NULL);
FREE_ARG_TUP(self); FREE_ARG_TUP(self);
} }
} }
...@@ -3200,7 +3309,8 @@ load_persid(Unpicklerobject *self) { ...@@ -3200,7 +3309,8 @@ load_persid(Unpicklerobject *self) {
} }
static int static int
load_binpersid(Unpicklerobject *self) { load_binpersid(Unpicklerobject *self)
{
PyObject *pid = 0; PyObject *pid = 0;
if (self->pers_func) { if (self->pers_func) {
...@@ -3216,7 +3326,8 @@ load_binpersid(Unpicklerobject *self) { ...@@ -3216,7 +3326,8 @@ load_binpersid(Unpicklerobject *self) {
else { else {
ARG_TUP(self, pid); ARG_TUP(self, pid);
if (self->arg) { if (self->arg) {
pid = PyObject_Call(self->pers_func, self->arg, NULL); pid = PyObject_Call(self->pers_func, self->arg,
NULL);
FREE_ARG_TUP(self); FREE_ARG_TUP(self);
} }
if (! pid) return -1; if (! pid) return -1;
...@@ -3235,7 +3346,8 @@ load_binpersid(Unpicklerobject *self) { ...@@ -3235,7 +3346,8 @@ load_binpersid(Unpicklerobject *self) {
static int static int
load_pop(Unpicklerobject *self) { load_pop(Unpicklerobject *self)
{
int len; int len;
if (!( (len=self->stack->length) > 0 )) return stackUnderflow(); if (!( (len=self->stack->length) > 0 )) return stackUnderflow();
...@@ -3260,7 +3372,8 @@ load_pop(Unpicklerobject *self) { ...@@ -3260,7 +3372,8 @@ load_pop(Unpicklerobject *self) {
static int static int
load_pop_mark(Unpicklerobject *self) { load_pop_mark(Unpicklerobject *self)
{
int i; int i;
if ((i = marker(self)) < 0) if ((i = marker(self)) < 0)
...@@ -3273,7 +3386,8 @@ load_pop_mark(Unpicklerobject *self) { ...@@ -3273,7 +3386,8 @@ load_pop_mark(Unpicklerobject *self) {
static int static int
load_dup(Unpicklerobject *self) { load_dup(Unpicklerobject *self)
{
PyObject *last; PyObject *last;
int len; int len;
...@@ -3286,7 +3400,8 @@ load_dup(Unpicklerobject *self) { ...@@ -3286,7 +3400,8 @@ load_dup(Unpicklerobject *self) {
static int static int
load_get(Unpicklerobject *self) { load_get(Unpicklerobject *self)
{
PyObject *py_str = 0, *value = 0; PyObject *py_str = 0, *value = 0;
int len; int len;
char *s; char *s;
...@@ -3312,7 +3427,8 @@ load_get(Unpicklerobject *self) { ...@@ -3312,7 +3427,8 @@ load_get(Unpicklerobject *self) {
static int static int
load_binget(Unpicklerobject *self) { load_binget(Unpicklerobject *self)
{
PyObject *py_key = 0, *value = 0; PyObject *py_key = 0, *value = 0;
unsigned char key; unsigned char key;
char *s; char *s;
...@@ -3338,7 +3454,8 @@ load_binget(Unpicklerobject *self) { ...@@ -3338,7 +3454,8 @@ load_binget(Unpicklerobject *self) {
static int static int
load_long_binget(Unpicklerobject *self) { load_long_binget(Unpicklerobject *self)
{
PyObject *py_key = 0, *value = 0; PyObject *py_key = 0, *value = 0;
unsigned char c; unsigned char c;
char *s; char *s;
...@@ -3373,7 +3490,8 @@ load_long_binget(Unpicklerobject *self) { ...@@ -3373,7 +3490,8 @@ load_long_binget(Unpicklerobject *self) {
static int static int
load_put(Unpicklerobject *self) { load_put(Unpicklerobject *self)
{
PyObject *py_str = 0, *value = 0; PyObject *py_str = 0, *value = 0;
int len, l; int len, l;
char *s; char *s;
...@@ -3390,7 +3508,8 @@ load_put(Unpicklerobject *self) { ...@@ -3390,7 +3508,8 @@ load_put(Unpicklerobject *self) {
static int static int
load_binput(Unpicklerobject *self) { load_binput(Unpicklerobject *self)
{
PyObject *py_key = 0, *value = 0; PyObject *py_key = 0, *value = 0;
unsigned char key; unsigned char key;
char *s; char *s;
...@@ -3410,7 +3529,8 @@ load_binput(Unpicklerobject *self) { ...@@ -3410,7 +3529,8 @@ load_binput(Unpicklerobject *self) {
static int static int
load_long_binput(Unpicklerobject *self) { load_long_binput(Unpicklerobject *self)
{
PyObject *py_key = 0, *value = 0; PyObject *py_key = 0, *value = 0;
long key; long key;
unsigned char c; unsigned char c;
...@@ -3438,12 +3558,15 @@ load_long_binput(Unpicklerobject *self) { ...@@ -3438,12 +3558,15 @@ load_long_binput(Unpicklerobject *self) {
static int static int
do_append(Unpicklerobject *self, int x) { 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;
if (!( (len=self->stack->length) >= x && x > 0 )) return stackUnderflow(); len=self->stack->length;
if (len==x) return 0; /* nothing to do */ if (!( len >= x && x > 0 )) return stackUnderflow();
/* nothing to do */
if (len==x) return 0;
list=self->stack->data[x-1]; list=self->stack->data[x-1];
...@@ -3469,7 +3592,8 @@ do_append(Unpicklerobject *self, int x) { ...@@ -3469,7 +3592,8 @@ do_append(Unpicklerobject *self, int x) {
junk=0; junk=0;
ARG_TUP(self, value); ARG_TUP(self, value);
if (self->arg) { if (self->arg) {
junk = PyObject_Call(append_method, self->arg, NULL); junk = PyObject_Call(append_method, self->arg,
NULL);
FREE_ARG_TUP(self); FREE_ARG_TUP(self);
} }
if (! junk) { if (! junk) {
...@@ -3489,19 +3613,22 @@ do_append(Unpicklerobject *self, int x) { ...@@ -3489,19 +3613,22 @@ do_append(Unpicklerobject *self, int x) {
static int static int
load_append(Unpicklerobject *self) { load_append(Unpicklerobject *self)
{
return do_append(self, self->stack->length - 1); return do_append(self, self->stack->length - 1);
} }
static int static int
load_appends(Unpicklerobject *self) { load_appends(Unpicklerobject *self)
{
return do_append(self, marker(self)); return do_append(self, marker(self));
} }
static int static int
do_setitems(Unpicklerobject *self, int x) { do_setitems(Unpicklerobject *self, int x)
{
PyObject *value = 0, *key = 0, *dict = 0; PyObject *value = 0, *key = 0, *dict = 0;
int len, i, r=0; int len, i, r=0;
...@@ -3526,18 +3653,21 @@ do_setitems(Unpicklerobject *self, int x) { ...@@ -3526,18 +3653,21 @@ do_setitems(Unpicklerobject *self, int x) {
static int static int
load_setitem(Unpicklerobject *self) { load_setitem(Unpicklerobject *self)
{
return do_setitems(self, self->stack->length - 2); return do_setitems(self, self->stack->length - 2);
} }
static int static int
load_setitems(Unpicklerobject *self) { load_setitems(Unpicklerobject *self)
{
return do_setitems(self, marker(self)); return do_setitems(self, marker(self));
} }
static int static int
load_build(Unpicklerobject *self) { load_build(Unpicklerobject *self)
{
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;
int i, r = 0; int i, r = 0;
...@@ -3579,7 +3709,8 @@ load_build(Unpicklerobject *self) { ...@@ -3579,7 +3709,8 @@ load_build(Unpicklerobject *self) {
static int static int
load_mark(Unpicklerobject *self) { load_mark(Unpicklerobject *self)
{
int s; int s;
/* Note that we split the (pickle.py) stack into two stacks, an /* Note that we split the (pickle.py) stack into two stacks, an
...@@ -3593,7 +3724,8 @@ load_mark(Unpicklerobject *self) { ...@@ -3593,7 +3724,8 @@ load_mark(Unpicklerobject *self) {
if (self->marks == NULL) if (self->marks == NULL)
self->marks=(int *)malloc(s * sizeof(int)); self->marks=(int *)malloc(s * sizeof(int));
else else
self->marks=(int *)realloc(self->marks, s * sizeof(int)); self->marks=(int *)realloc(self->marks,
s * sizeof(int));
if (! self->marks) { if (! self->marks) {
PyErr_NoMemory(); PyErr_NoMemory();
return -1; return -1;
...@@ -3607,7 +3739,8 @@ load_mark(Unpicklerobject *self) { ...@@ -3607,7 +3739,8 @@ load_mark(Unpicklerobject *self) {
} }
static int static int
load_reduce(Unpicklerobject *self) { load_reduce(Unpicklerobject *self)
{
PyObject *callable = 0, *arg_tup = 0, *ob = 0; PyObject *callable = 0, *arg_tup = 0, *ob = 0;
PDATA_POP(self->stack, arg_tup); PDATA_POP(self->stack, arg_tup);
...@@ -3626,7 +3759,8 @@ load_reduce(Unpicklerobject *self) { ...@@ -3626,7 +3759,8 @@ load_reduce(Unpicklerobject *self) {
} }
static PyObject * static PyObject *
load(Unpicklerobject *self) { load(Unpicklerobject *self)
{
PyObject *err = 0, *val = 0; PyObject *err = 0, *val = 0;
char *s; char *s;
...@@ -3849,7 +3983,8 @@ load(Unpicklerobject *self) { ...@@ -3849,7 +3983,8 @@ load(Unpicklerobject *self) {
break; break;
default: default:
cPickle_ErrFormat(UnpicklingError, "invalid load key, '%s'.", cPickle_ErrFormat(UnpicklingError,
"invalid load key, '%s'.",
"c", s[0]); "c", s[0]);
return NULL; return NULL;
} }
...@@ -3873,7 +4008,8 @@ load(Unpicklerobject *self) { ...@@ -3873,7 +4008,8 @@ load(Unpicklerobject *self) {
find persistent references. */ find persistent references. */
static int static int
noload_obj(Unpicklerobject *self) { noload_obj(Unpicklerobject *self)
{
int i; int i;
if ((i = marker(self)) < 0) return -1; if ((i = marker(self)) < 0) return -1;
...@@ -3882,7 +4018,8 @@ noload_obj(Unpicklerobject *self) { ...@@ -3882,7 +4018,8 @@ noload_obj(Unpicklerobject *self) {
static int static int
noload_inst(Unpicklerobject *self) { noload_inst(Unpicklerobject *self)
{
int i; int i;
char *s; char *s;
...@@ -3895,7 +4032,8 @@ noload_inst(Unpicklerobject *self) { ...@@ -3895,7 +4032,8 @@ noload_inst(Unpicklerobject *self) {
} }
static int static int
noload_global(Unpicklerobject *self) { noload_global(Unpicklerobject *self)
{
char *s; char *s;
if ((*self->readline_func)(self, &s) < 0) return -1; if ((*self->readline_func)(self, &s) < 0) return -1;
...@@ -3905,7 +4043,8 @@ noload_global(Unpicklerobject *self) { ...@@ -3905,7 +4043,8 @@ noload_global(Unpicklerobject *self) {
} }
static int static int
noload_reduce(Unpicklerobject *self) { noload_reduce(Unpicklerobject *self)
{
if (self->stack->length < 2) return stackUnderflow(); if (self->stack->length < 2) return stackUnderflow();
Pdata_clear(self->stack, self->stack->length-2); Pdata_clear(self->stack, self->stack->length-2);
...@@ -3923,7 +4062,8 @@ noload_build(Unpicklerobject *self) { ...@@ -3923,7 +4062,8 @@ noload_build(Unpicklerobject *self) {
static PyObject * static PyObject *
noload(Unpicklerobject *self) { noload(Unpicklerobject *self)
{
PyObject *err = 0, *val = 0; PyObject *err = 0, *val = 0;
char *s; char *s;
...@@ -4141,7 +4281,8 @@ noload(Unpicklerobject *self) { ...@@ -4141,7 +4281,8 @@ noload(Unpicklerobject *self) {
continue; continue;
default: default:
cPickle_ErrFormat(UnpicklingError, "invalid load key, '%s'.", cPickle_ErrFormat(UnpicklingError,
"invalid load key, '%s'.",
"c", s[0]); "c", s[0]);
return NULL; return NULL;
} }
...@@ -4162,7 +4303,8 @@ noload(Unpicklerobject *self) { ...@@ -4162,7 +4303,8 @@ noload(Unpicklerobject *self) {
static PyObject * static PyObject *
Unpickler_load(Unpicklerobject *self, PyObject *args) { Unpickler_load(Unpicklerobject *self, PyObject *args)
{
if (!( PyArg_ParseTuple(args, ":load"))) if (!( PyArg_ParseTuple(args, ":load")))
return NULL; return NULL;
...@@ -4170,7 +4312,8 @@ Unpickler_load(Unpicklerobject *self, PyObject *args) { ...@@ -4170,7 +4312,8 @@ Unpickler_load(Unpicklerobject *self, PyObject *args) {
} }
static PyObject * static PyObject *
Unpickler_noload(Unpicklerobject *self, PyObject *args) { Unpickler_noload(Unpicklerobject *self, PyObject *args)
{
if (!( PyArg_ParseTuple(args, ":noload"))) if (!( PyArg_ParseTuple(args, ":noload")))
return NULL; return NULL;
...@@ -4195,7 +4338,8 @@ static struct PyMethodDef Unpickler_methods[] = { ...@@ -4195,7 +4338,8 @@ static struct PyMethodDef Unpickler_methods[] = {
static Unpicklerobject * static Unpicklerobject *
newUnpicklerobject(PyObject *f) { newUnpicklerobject(PyObject *f)
{
Unpicklerobject *self; Unpicklerobject *self;
if (!( self = PyObject_New(Unpicklerobject, &Unpicklertype))) if (!( self = PyObject_New(Unpicklerobject, &Unpicklertype)))
...@@ -4225,7 +4369,8 @@ newUnpicklerobject(PyObject *f) { ...@@ -4225,7 +4369,8 @@ newUnpicklerobject(PyObject *f) {
if (PyFile_Check(f)) { if (PyFile_Check(f)) {
self->fp = PyFile_AsFile(f); self->fp = PyFile_AsFile(f);
if (self->fp == NULL) { if (self->fp == NULL) {
PyErr_SetString(PyExc_ValueError, "I/O operation on closed file"); PyErr_SetString(PyExc_ValueError,
"I/O operation on closed file");
goto err; goto err;
} }
self->read_func = read_file; self->read_func = read_file;
...@@ -4245,7 +4390,8 @@ newUnpicklerobject(PyObject *f) { ...@@ -4245,7 +4390,8 @@ newUnpicklerobject(PyObject *f) {
if (!( (self->readline = PyObject_GetAttr(f, readline_str)) && if (!( (self->readline = PyObject_GetAttr(f, readline_str)) &&
(self->read = PyObject_GetAttr(f, read_str)))) { (self->read = PyObject_GetAttr(f, read_str)))) {
PyErr_Clear(); PyErr_Clear();
PyErr_SetString( PyExc_TypeError, "argument must have 'read' and " PyErr_SetString( PyExc_TypeError,
"argument must have 'read' and "
"'readline' attributes" ); "'readline' attributes" );
goto err; goto err;
} }
...@@ -4256,7 +4402,8 @@ newUnpicklerobject(PyObject *f) { ...@@ -4256,7 +4402,8 @@ newUnpicklerobject(PyObject *f) {
PyObject *m; PyObject *m;
if (!( m=PyImport_Import(copy_reg_str))) goto err; if (!( m=PyImport_Import(copy_reg_str))) goto err;
self->safe_constructors=PyObject_GetAttr(m, safe_constructors_str); self->safe_constructors=PyObject_GetAttr(m,
safe_constructors_str);
Py_DECREF(m); Py_DECREF(m);
if (!( self->safe_constructors )) goto err; if (!( self->safe_constructors )) goto err;
} }
...@@ -4267,14 +4414,15 @@ newUnpicklerobject(PyObject *f) { ...@@ -4267,14 +4414,15 @@ newUnpicklerobject(PyObject *f) {
return self; return self;
err: err:
Py_DECREF((PyObject *)self); Py_DECREF((PyObject *)self);
return NULL; return NULL;
} }
static PyObject * static PyObject *
get_Unpickler(PyObject *self, PyObject *args) { get_Unpickler(PyObject *self, PyObject *args)
{
PyObject *file; PyObject *file;
if (!( PyArg_ParseTuple(args, "O:Unpickler", &file))) if (!( PyArg_ParseTuple(args, "O:Unpickler", &file)))
...@@ -4284,7 +4432,8 @@ get_Unpickler(PyObject *self, PyObject *args) { ...@@ -4284,7 +4432,8 @@ get_Unpickler(PyObject *self, PyObject *args) {
static void static void
Unpickler_dealloc(Unpicklerobject *self) { Unpickler_dealloc(Unpicklerobject *self)
{
Py_XDECREF(self->readline); Py_XDECREF(self->readline);
Py_XDECREF(self->read); Py_XDECREF(self->read);
Py_XDECREF(self->file); Py_XDECREF(self->file);
...@@ -4308,7 +4457,8 @@ Unpickler_dealloc(Unpicklerobject *self) { ...@@ -4308,7 +4457,8 @@ Unpickler_dealloc(Unpicklerobject *self) {
static PyObject * static PyObject *
Unpickler_getattr(Unpicklerobject *self, char *name) { Unpickler_getattr(Unpicklerobject *self, char *name)
{
if (!strcmp(name, "persistent_load")) { if (!strcmp(name, "persistent_load")) {
if (!self->pers_func) { if (!self->pers_func) {
PyErr_SetString(PyExc_AttributeError, name); PyErr_SetString(PyExc_AttributeError, name);
...@@ -4349,7 +4499,8 @@ Unpickler_getattr(Unpicklerobject *self, char *name) { ...@@ -4349,7 +4499,8 @@ Unpickler_getattr(Unpicklerobject *self, char *name) {
static int static int
Unpickler_setattr(Unpicklerobject *self, char *name, PyObject *value) { Unpickler_setattr(Unpicklerobject *self, char *name, PyObject *value)
{
if (!strcmp(name, "persistent_load")) { if (!strcmp(name, "persistent_load")) {
Py_XDECREF(self->pers_func); Py_XDECREF(self->pers_func);
...@@ -4373,7 +4524,8 @@ Unpickler_setattr(Unpicklerobject *self, char *name, PyObject *value) { ...@@ -4373,7 +4524,8 @@ Unpickler_setattr(Unpicklerobject *self, char *name, PyObject *value) {
if (strcmp(name, "memo") == 0) { if (strcmp(name, "memo") == 0) {
if (!PyDict_Check(value)) { if (!PyDict_Check(value)) {
PyErr_SetString(PyExc_TypeError, "memo must be a dictionary"); PyErr_SetString(PyExc_TypeError,
"memo must be a dictionary");
return -1; return -1;
} }
Py_XDECREF(self->memo); Py_XDECREF(self->memo);
...@@ -4388,7 +4540,8 @@ Unpickler_setattr(Unpicklerobject *self, char *name, PyObject *value) { ...@@ -4388,7 +4540,8 @@ Unpickler_setattr(Unpicklerobject *self, char *name, PyObject *value) {
static PyObject * static PyObject *
cpm_dump(PyObject *self, PyObject *args) { cpm_dump(PyObject *self, PyObject *args)
{
PyObject *ob, *file, *res = NULL; PyObject *ob, *file, *res = NULL;
Picklerobject *pickler = 0; Picklerobject *pickler = 0;
int bin = 0; int bin = 0;
...@@ -4405,7 +4558,7 @@ cpm_dump(PyObject *self, PyObject *args) { ...@@ -4405,7 +4558,7 @@ cpm_dump(PyObject *self, PyObject *args) {
Py_INCREF(Py_None); Py_INCREF(Py_None);
res = Py_None; res = Py_None;
finally: finally:
Py_XDECREF(pickler); Py_XDECREF(pickler);
return res; return res;
...@@ -4413,7 +4566,8 @@ finally: ...@@ -4413,7 +4566,8 @@ finally:
static PyObject * static PyObject *
cpm_dumps(PyObject *self, PyObject *args) { cpm_dumps(PyObject *self, PyObject *args)
{
PyObject *ob, *file = 0, *res = NULL; PyObject *ob, *file = 0, *res = NULL;
Picklerobject *pickler = 0; Picklerobject *pickler = 0;
int bin = 0; int bin = 0;
...@@ -4432,7 +4586,7 @@ cpm_dumps(PyObject *self, PyObject *args) { ...@@ -4432,7 +4586,7 @@ cpm_dumps(PyObject *self, PyObject *args) {
res = PycStringIO->cgetvalue(file); res = PycStringIO->cgetvalue(file);
finally: finally:
Py_XDECREF(pickler); Py_XDECREF(pickler);
Py_XDECREF(file); Py_XDECREF(file);
...@@ -4441,7 +4595,8 @@ finally: ...@@ -4441,7 +4595,8 @@ finally:
static PyObject * static PyObject *
cpm_load(PyObject *self, PyObject *args) { cpm_load(PyObject *self, PyObject *args)
{
Unpicklerobject *unpickler = 0; Unpicklerobject *unpickler = 0;
PyObject *ob, *res = NULL; PyObject *ob, *res = NULL;
...@@ -4453,7 +4608,7 @@ cpm_load(PyObject *self, PyObject *args) { ...@@ -4453,7 +4608,7 @@ cpm_load(PyObject *self, PyObject *args) {
res = load(unpickler); res = load(unpickler);
finally: finally:
Py_XDECREF(unpickler); Py_XDECREF(unpickler);
return res; return res;
...@@ -4461,7 +4616,8 @@ finally: ...@@ -4461,7 +4616,8 @@ finally:
static PyObject * static PyObject *
cpm_loads(PyObject *self, PyObject *args) { cpm_loads(PyObject *self, PyObject *args)
{
PyObject *ob, *file = 0, *res = NULL; PyObject *ob, *file = 0, *res = NULL;
Unpicklerobject *unpickler = 0; Unpicklerobject *unpickler = 0;
...@@ -4476,7 +4632,7 @@ cpm_loads(PyObject *self, PyObject *args) { ...@@ -4476,7 +4632,7 @@ cpm_loads(PyObject *self, PyObject *args) {
res = load(unpickler); res = load(unpickler);
finally: finally:
Py_XDECREF(file); Py_XDECREF(file);
Py_XDECREF(unpickler); Py_XDECREF(unpickler);
...@@ -4546,7 +4702,8 @@ static struct PyMethodDef cPickle_methods[] = { ...@@ -4546,7 +4702,8 @@ static struct PyMethodDef cPickle_methods[] = {
}; };
static int static int
init_stuff(PyObject *module_dict) { init_stuff(PyObject *module_dict)
{
PyObject *copy_reg, *t, *r; PyObject *copy_reg, *t, *r;
#define INIT_STR(S) if (!( S ## _str=PyString_InternFromString(#S))) return -1; #define INIT_STR(S) if (!( S ## _str=PyString_InternFromString(#S))) return -1;
...@@ -4574,8 +4731,8 @@ init_stuff(PyObject *module_dict) { ...@@ -4574,8 +4731,8 @@ init_stuff(PyObject *module_dict) {
/* These next few are special because we want to use different /* These next few are special because we want to use different
ones in restricted mode. */ ones in restricted mode. */
dispatch_table = PyObject_GetAttr(copy_reg, dispatch_table_str);
if (!( dispatch_table = PyObject_GetAttr(copy_reg, dispatch_table_str))) if (!dispatch_table)
return -1; return -1;
if (!( safe_constructors = PyObject_GetAttr(copy_reg, if (!( safe_constructors = PyObject_GetAttr(copy_reg,
...@@ -4603,14 +4760,15 @@ init_stuff(PyObject *module_dict) { ...@@ -4603,14 +4760,15 @@ init_stuff(PyObject *module_dict) {
module_dict, t) )) return -1; module_dict, t) )) return -1;
Py_DECREF(r); Py_DECREF(r);
if (!( PickleError = PyErr_NewException("cPickle.PickleError", NULL, t))) PickleError = PyErr_NewException("cPickle.PickleError", NULL, t);
if (!PickleError)
return -1; return -1;
Py_DECREF(t); Py_DECREF(t);
PicklingError = PyErr_NewException("cPickle.PicklingError",
if (!( PicklingError = PyErr_NewException("cPickle.PicklingError", PickleError, NULL);
PickleError, NULL))) if (!PicklingError)
return -1; return -1;
if (!( t=PyDict_New())) return -1; if (!( t=PyDict_New())) return -1;
...@@ -4666,7 +4824,8 @@ init_stuff(PyObject *module_dict) { ...@@ -4666,7 +4824,8 @@ init_stuff(PyObject *module_dict) {
#define DL_EXPORT(RTYPE) RTYPE #define DL_EXPORT(RTYPE) RTYPE
#endif #endif
DL_EXPORT(void) DL_EXPORT(void)
initcPickle(void) { initcPickle(void)
{
PyObject *m, *d, *di, *v, *k; PyObject *m, *d, *di, *v, *k;
int i; int i;
char *rev="1.71"; char *rev="1.71";
......
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