From c9fedc64081e1504a1bbf88be5a5dcfb9fff3652 Mon Sep 17 00:00:00 2001 From: Prashanth Pai Date: Mon, 13 Jul 2015 12:03:25 +0530 Subject: Backport ctypes.c_ssize_t support to py26 ctypes.c_ssize_t was introduced in Python 2.7 This made libgfapi-python bindings unusable in RHEL 6 which only contains Python 2.6 Change-Id: I401697004d7eecb110b8c92a3ddd27397e3d8785 Signed-off-by: Prashanth Pai --- gluster/api.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gluster/api.py b/gluster/api.py index 62135c5..d2a0840 100755 --- a/gluster/api.py +++ b/gluster/api.py @@ -11,6 +11,7 @@ import ctypes from ctypes.util import find_library +from ctypes import sizeof # LD_LIBRARY_PATH is not looked up by ctypes.util.find_library() @@ -41,6 +42,18 @@ except OSError: raise ImportError("ctypes.CDLL() cannot load {0}. You might want to set " "LD_LIBRARY_PATH env variable".format(so_file_name)) +# c_ssize_t was only added in py27. Manually backporting it here for py26 +try: + import ctypes.c_ssize_t +except ImportError: + if sizeof(ctypes.c_uint) == sizeof(ctypes.c_void_p): + setattr(ctypes, 'c_ssize_t', ctypes.c_int) + elif sizeof(ctypes.c_ulong) == sizeof(ctypes.c_void_p): + setattr(ctypes, 'c_ssize_t', ctypes.c_long) + elif sizeof(ctypes.c_ulonglong) == sizeof(ctypes.c_void_p): + setattr(ctypes, 'c_ssize_t', ctypes.c_longlong) + + # Wow, the Linux kernel folks really play nasty games with this structure. If # you look at the man page for stat(2) and then at this definition you'll note # two discrepancies. First, we seem to have st_nlink and st_mode reversed. In -- cgit