[pygobject] Fix conversion from pointers to hashfunc return values.



commit d031e1700816836366989ece0eda486c77543c3b
Author: Christoph Reiter <creiter src gnome org>
Date:   Mon Mar 27 14:48:08 2017 +0200

    Fix conversion from pointers to hashfunc return values.
    
    Fixes comiler warnings on 64bit Windows.
    
    Python 3 now uses Py_hash_t as return value for hashfunc. Use
    a compat define so we can use the right type depending on the
    Python version.
    
    On Python 2 + 64bit Windows the pointer doesn't fit the long
    return type. Add a macro which handles the casting for that case
    to prevent compiler warnings.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=780591

 gi/pygboxed.c             |    4 ++--
 gi/pyglib-python-compat.h |    6 ++++++
 gi/pygobject-object.c     |    4 ++--
 gi/pygparamspec.c         |    4 ++--
 gi/pygpointer.c           |    4 ++--
 5 files changed, 14 insertions(+), 8 deletions(-)
---
diff --git a/gi/pygboxed.c b/gi/pygboxed.c
index 6bf2376..e521c96 100644
--- a/gi/pygboxed.c
+++ b/gi/pygboxed.c
@@ -63,10 +63,10 @@ pyg_boxed_richcompare(PyObject *self, PyObject *other, int op)
 }
 
 
-static long
+static PYGLIB_Py_hash_t
 pyg_boxed_hash(PyGBoxed *self)
 {
-    return (long)pyg_boxed_get_ptr (self);
+    return PYGLIB_Py_hash_t_FromVoidPtr (pyg_boxed_get_ptr (self));
 }
 
 static PyObject *
diff --git a/gi/pyglib-python-compat.h b/gi/pyglib-python-compat.h
index 7b67d55..7f18452 100644
--- a/gi/pyglib-python-compat.h
+++ b/gi/pyglib-python-compat.h
@@ -68,6 +68,8 @@
 #define PYGLIB_PyLong_AS_LONG PyInt_AS_LONG
 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
 
+#define PYGLIB_Py_hash_t long
+
 /* Python 2.7 lacks a PyInt_FromUnsignedLong function; use signed longs, and
  * rely on PyInt_AsUnsignedLong() to interpret them correctly */
 #define PYGLIB_PyLong_FromUnsignedLong PyInt_FromLong
@@ -192,6 +194,10 @@ PyTypeObject symbol = {                                 \
 
 #define PYGLIB_PyNumber_Long PyNumber_Long
 
+#define PYGLIB_Py_hash_t Py_hash_t
+
 #endif
 
+#define PYGLIB_Py_hash_t_FromVoidPtr(ptr) ((PYGLIB_Py_hash_t)(gintptr)(ptr))
+
 #endif /* __PYGLIB_PYTHON_COMPAT_H__ */
diff --git a/gi/pygobject-object.c b/gi/pygobject-object.c
index 1c97594..0166a60 100644
--- a/gi/pygobject-object.c
+++ b/gi/pygobject-object.c
@@ -1115,10 +1115,10 @@ pygobject_richcompare(PyObject *self, PyObject *other, int op)
                                            op);
 }
 
-static long
+static PYGLIB_Py_hash_t
 pygobject_hash(PyGObject *self)
 {
-    return (long)self->obj;
+    return PYGLIB_Py_hash_t_FromVoidPtr (self->obj);
 }
 
 static PyObject *
diff --git a/gi/pygparamspec.c b/gi/pygparamspec.c
index 0982b99..4ace96c 100644
--- a/gi/pygparamspec.c
+++ b/gi/pygparamspec.c
@@ -46,10 +46,10 @@ pyg_param_spec_richcompare(PyObject *self, PyObject *other, int op)
     }
 }
 
-static long
+static PYGLIB_Py_hash_t
 pyg_param_spec_hash(PyGParamSpec *self)
 {
-    return (long)pyg_param_spec_get (self);
+    return PYGLIB_Py_hash_t_FromVoidPtr (pyg_param_spec_get (self));
 }
 
 static PyObject *
diff --git a/gi/pygpointer.c b/gi/pygpointer.c
index c7cae19..d876aad 100644
--- a/gi/pygpointer.c
+++ b/gi/pygpointer.c
@@ -53,10 +53,10 @@ pyg_pointer_richcompare(PyObject *self, PyObject *other, int op)
     }
 }
 
-static long
+static PYGLIB_Py_hash_t
 pyg_pointer_hash(PyGPointer *self)
 {
-    return (long)pyg_pointer_get_ptr (self);
+    return PYGLIB_Py_hash_t_FromVoidPtr (pyg_pointer_get_ptr (self));
 }
 
 static PyObject *


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