From 534b7c5c96006365a713a808022363b057a0bf12 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 28 Jun 2000 22:23:56 +0000 Subject: [PATCH] Trent Mick: This patch fixes cPickle.c for 64-bit platforms. - The false assumption sizeof(long) == size(void*) exists where PyInt_FromLong is used to represent a pointer. The safe Python call for this is PyLong_FromVoidPtr. (On platforms where the above assumption *is* true a PyInt is returned as before so there is no effective change.) - use size_t instead of int for some variables --- Modules/cPickle.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Modules/cPickle.c b/Modules/cPickle.c index 6eeb0a40c10..0d919368762 100644 --- a/Modules/cPickle.c +++ b/Modules/cPickle.c @@ -656,7 +656,7 @@ get(Picklerobject *self, PyObject *id) { PyObject *value, *mv; long c_value; char s[30]; - int len; + size_t len; UNLESS (mv = PyDict_GetItem(self->memo, id)) { PyErr_SetObject(PyExc_KeyError, id); @@ -717,7 +717,9 @@ put(Picklerobject *self, PyObject *ob) { static int put2(Picklerobject *self, PyObject *ob) { char c_str[30]; - int p, len, res = -1; + int p; + size_t len; + int res = -1; PyObject *py_ob_id = 0, *memo_len = 0, *t = 0; if (self->fast) return 0; @@ -727,7 +729,7 @@ put2(Picklerobject *self, PyObject *ob) { p++; /* Make sure memo keys are positive! */ - UNLESS (py_ob_id = PyInt_FromLong((long)ob)) + UNLESS (py_ob_id = PyLong_FromVoidPtr(ob)) goto finally; UNLESS (memo_len = PyInt_FromLong(p)) @@ -1255,7 +1257,7 @@ save_tuple(Picklerobject *self, PyObject *args) { goto finally; } - UNLESS (py_tuple_id = PyInt_FromLong((long)args)) + UNLESS (py_tuple_id = PyLong_FromVoidPtr(args)) goto finally; if (len) { @@ -1775,12 +1777,9 @@ save(Picklerobject *self, PyObject *args, int pers_save) { } if (args->ob_refcnt > 1) { - long ob_id; int has_key; - ob_id = (long)args; - - UNLESS (py_ob_id = PyInt_FromLong(ob_id)) + UNLESS (py_ob_id = PyLong_FromVoidPtr(args)) goto finally; if ((has_key = cPickle_PyMapping_HasKey(self->memo, py_ob_id)) < 0)