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