[PATCH] Fixed integer wraparound in python binding

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The attached patch fixes a problem with integrate wraparound in the python
bindings. THe problem is thus:

 - the memory & max-memory fields in the virDomainInfo struct are
   of type  'unsigned long'.
 - The python bindings, however, then stick this into a python 'Int'
   which is signed.

Now, on 64-bit this is not an issue. For DomU guests on 32-bit it is not
an issue either, but for Dom0 XenD sets the max-memory field to be 
2^32-1  whcih causes wraparound when converting to python int.

This patch simply switches the python binding over to using a python Long
which is 64 bits on all platforms.

Dan.
-- 
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
Index: libvir.c
===================================================================
RCS file: /data/cvs/libvirt/python/libvir.c,v
retrieving revision 1.15
diff -c -r1.15 libvir.c
*** libvir.c	7 Nov 2006 23:18:56 -0000	1.15
--- libvir.c	13 Nov 2006 20:25:12 -0000
***************
*** 261,268 ****
      }
      py_retval = PyList_New(5);
      PyList_SetItem(py_retval, 0, libvirt_intWrap((int) info.state));
!     PyList_SetItem(py_retval, 1, libvirt_longWrap((long) info.maxMem));
!     PyList_SetItem(py_retval, 2, libvirt_longWrap((long) info.memory));
      PyList_SetItem(py_retval, 3, libvirt_intWrap((int) info.nrVirtCpu));
      PyList_SetItem(py_retval, 4,
                     libvirt_longlongWrap((unsigned long long) info.cpuTime));
--- 261,268 ----
      }
      py_retval = PyList_New(5);
      PyList_SetItem(py_retval, 0, libvirt_intWrap((int) info.state));
!     PyList_SetItem(py_retval, 1, libvirt_ulongWrap(info.maxMem));
!     PyList_SetItem(py_retval, 2, libvirt_ulongWrap(info.memory));
      PyList_SetItem(py_retval, 3, libvirt_intWrap((int) info.nrVirtCpu));
      PyList_SetItem(py_retval, 4,
                     libvirt_longlongWrap((unsigned long long) info.cpuTime));
Index: libvirt_wrap.h
===================================================================
RCS file: /data/cvs/libvirt/python/libvirt_wrap.h,v
retrieving revision 1.4
diff -c -r1.4 libvirt_wrap.h
*** libvirt_wrap.h	24 Oct 2006 20:28:16 -0000	1.4
--- libvirt_wrap.h	13 Nov 2006 20:25:12 -0000
***************
*** 41,46 ****
--- 41,47 ----
  
  PyObject * libvirt_intWrap(int val);
  PyObject * libvirt_longWrap(long val);
+ PyObject * libvirt_ulongWrap(unsigned long val);
  PyObject * libvirt_longlongWrap(long long val);
  PyObject * libvirt_charPtrWrap(char *str);
  PyObject * libvirt_constcharPtrWrap(const char *str);
Index: types.c
===================================================================
RCS file: /data/cvs/libvirt/python/types.c,v
retrieving revision 1.3
diff -c -r1.3 types.c
*** types.c	9 Feb 2006 17:45:12 -0000	1.3
--- types.c	13 Nov 2006 20:25:12 -0000
***************
*** 34,39 ****
--- 34,51 ----
  }
  
  PyObject *
+ libvirt_ulongWrap(unsigned long val)
+ {
+     PyObject *ret;
+ 
+ #ifdef DEBUG
+     printf("libvirt_ulongWrap: val = %lu\n", val);
+ #endif
+     ret = PyLong_FromLong(val);
+     return (ret);
+ }   
+ 
+ PyObject *
  libvirt_longlongWrap(long long val)
  {
      PyObject *ret;

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]