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
This commit is contained in:
Guido van Rossum 2000-06-28 22:23:56 +00:00
parent 1c44e28766
commit 534b7c5c96
1 changed files with 7 additions and 8 deletions

View File

@ -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)