diff options
author | Guido van Rossum <guido@python.org> | 2000-06-28 22:23:56 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-06-28 22:23:56 (GMT) |
commit | 534b7c5c96006365a713a808022363b057a0bf12 (patch) | |
tree | c02831a328c071d53306248e28f3717e4da160c5 | |
parent | 1c44e287669c27f4e4f5df6925899d15d8999c12 (diff) | |
download | cpython-534b7c5c96006365a713a808022363b057a0bf12.zip cpython-534b7c5c96006365a713a808022363b057a0bf12.tar.gz cpython-534b7c5c96006365a713a808022363b057a0bf12.tar.bz2 |
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
-rw-r--r-- | Modules/cPickle.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/Modules/cPickle.c b/Modules/cPickle.c index 6eeb0a4..0d91936 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) |