[Patches] fix cPickle.c for 64-bit platforms (mainly Win64)

Trent Mick trentm@activestate.com
Mon, 5 Jun 2000 16:25:49 -0700


Discussion:

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 varaibles


Legal:

I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under
copyright, patent or other rights or interests ("claims").  To
the extent that I have any such claims, I hereby grant to CNRI a
nonexclusive, irrevocable, royalty-free, worldwide license to
reproduce, distribute, perform and/or display publicly, prepare
derivative versions, and otherwise use this contribution as part
of the Python software and its related documentation, or any
derivative versions thereof, at no cost to CNRI or its licensed
users, and to authorize others to do so.

I acknowledge that CNRI may, at its sole discretion, decide
whether or not to incorporate this contribution in the Python
software and its related documentation.  I further grant CNRI
permission to use my name and other identifying information
provided to CNRI by me for use in connection with the Python
software and its related documentation.



Patch:

*** /home/trentm/main/contrib/python/dist/src/Modules/cPickle.c	Thu Jun  1 00:13:39 2000
--- /home/trentm/main/Apps/Perlium/Python/dist/src/Modules/cPickle.c	Fri Jun  2 15:53:42 2000
***************
*** 656,662 ****
      PyObject *value, *mv;
      long c_value;
      char s[30];
!     int len;
  
      UNLESS (mv = PyDict_GetItem(self->memo, id)) {
          PyErr_SetObject(PyExc_KeyError, id);
--- 656,662 ----
      PyObject *value, *mv;
      long c_value;
      char s[30];
!     size_t len;
  
      UNLESS (mv = PyDict_GetItem(self->memo, id)) {
          PyErr_SetObject(PyExc_KeyError, id);
***************
*** 717,723 ****
  static int
  put2(Picklerobject *self, PyObject *ob) {
      char c_str[30];
!     int p, len, res = -1;
      PyObject *py_ob_id = 0, *memo_len = 0, *t = 0;
  
      if (self->fast) return 0;
--- 717,725 ----
  static int
  put2(Picklerobject *self, PyObject *ob) {
      char c_str[30];
!     int p;
!     size_t len;
!     int res = -1;
      PyObject *py_ob_id = 0, *memo_len = 0, *t = 0;
  
      if (self->fast) return 0;
***************
*** 727,733 ****
  
      p++;  /* Make sure memo keys are positive! */
  
!     UNLESS (py_ob_id = PyInt_FromLong((long)ob))
          goto finally;
  
      UNLESS (memo_len = PyInt_FromLong(p))
--- 729,735 ----
  
      p++;  /* Make sure memo keys are positive! */
  
!     UNLESS (py_ob_id = PyLong_FromVoidPtr(ob))
          goto finally;
  
      UNLESS (memo_len = PyInt_FromLong(p))
***************
*** 1255,1261 ****
              goto finally;
      }
  
!     UNLESS (py_tuple_id = PyInt_FromLong((long)args))
          goto finally;
  
      if (len) {
--- 1257,1263 ----
              goto finally;
      }
  
!     UNLESS (py_tuple_id = PyLong_FromVoidPtr(args))
          goto finally;
  
      if (len) {
***************
*** 1775,1786 ****
      }
  
      if (args->ob_refcnt > 1) {
-         long ob_id;
          int  has_key;
  
!         ob_id = (long)args;
! 
!         UNLESS (py_ob_id = PyInt_FromLong(ob_id))
              goto finally;
  
          if ((has_key = cPickle_PyMapping_HasKey(self->memo, py_ob_id)) < 0)
--- 1777,1785 ----
      }
  
      if (args->ob_refcnt > 1) {
          int  has_key;
  
!         UNLESS (py_ob_id = PyLong_FromVoidPtr(args))
              goto finally;
  
          if ((has_key = cPickle_PyMapping_HasKey(self->memo, py_ob_id)) < 0)



-- 
Trent Mick
trentm@activestate.com