From c4726cbadbd3cc45ab8873a807d624890729502c Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Wed, 15 Nov 2006 19:40:00 +0000 Subject: [PATCH] Fix unsigned long wraparound in python binding --- libvir.c | 4 ++-- libvirt_wrap.h | 1 + types.c | 12 ++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/libvir.c b/libvir.c index a7b98dc..6d14fb2 100644 --- a/libvir.c +++ b/libvir.c @@ -261,8 +261,8 @@ libvirt_virDomainGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { } 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, 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)); diff --git a/libvirt_wrap.h b/libvirt_wrap.h index 906245a..8bcfdb3 100644 --- a/libvirt_wrap.h +++ b/libvirt_wrap.h @@ -41,6 +41,7 @@ typedef struct { 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); diff --git a/types.c b/types.c index b98beef..4ad4fa5 100644 --- a/types.c +++ b/types.c @@ -34,6 +34,18 @@ libvirt_longWrap(long val) } 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; -- 2.11.4.GIT