Skip to content

Commit

Permalink
python: Remove all uses of find_library. Fixes #1450593
Browse files Browse the repository at this point in the history
`find_library()` doesn't consider LD_LIBRARY_PATH on Python < 3.6.
  • Loading branch information
nh2 committed May 13, 2017
1 parent dc4aa17 commit d321df3
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 20 deletions.
2 changes: 1 addition & 1 deletion api/examples/getvolfile.py
Expand Up @@ -3,7 +3,7 @@
import ctypes
import ctypes.util

api = ctypes.CDLL(ctypes.util.find_library("gfapi"))
api = ctypes.CDLL("libgfapi.so")
api.glfs_get_volfile.argtypes = [ctypes.c_void_p,
ctypes.c_void_p,
ctypes.c_ulong]
Expand Down
3 changes: 1 addition & 2 deletions geo-replication/syncdaemon/libcxattr.py
Expand Up @@ -10,7 +10,6 @@

import os
from ctypes import CDLL, create_string_buffer, get_errno
from ctypes.util import find_library


class Xattr(object):
Expand All @@ -25,7 +24,7 @@ class Xattr(object):
sizes we expect
"""

libc = CDLL(find_library("c"), use_errno=True)
libc = CDLL("libc.so.6", use_errno=True)

@classmethod
def geterrno(cls):
Expand Down
3 changes: 1 addition & 2 deletions geo-replication/syncdaemon/libgfchangelog.py
Expand Up @@ -10,12 +10,11 @@

import os
from ctypes import CDLL, RTLD_GLOBAL, create_string_buffer, get_errno, byref, c_ulong
from ctypes.util import find_library
from syncdutils import ChangelogException, ChangelogHistoryNotAvailable


class Changes(object):
libgfc = CDLL(find_library("gfchangelog"), mode=RTLD_GLOBAL, use_errno=True)
libgfc = CDLL("libgfchangelog.so", mode=RTLD_GLOBAL, use_errno=True)

@classmethod
def geterrno(cls):
Expand Down
10 changes: 2 additions & 8 deletions tests/features/ipctest.py
@@ -1,14 +1,8 @@
#!/usr/bin/python

import ctypes
import ctypes.util

# find_library does not lookup LD_LIBRARY_PATH and may miss the
# function. In that case, retry with less portable but explicit name.
libgfapi = ctypes.util.find_library("gfapi")
if libgfapi == None:
libgfapi = "libgfapi.so"
api = ctypes.CDLL(libgfapi,mode=ctypes.RTLD_GLOBAL)

api = ctypes.CDLL("libgfapi.so",mode=ctypes.RTLD_GLOBAL)

api.glfs_ipc.argtypes = [ ctypes.c_void_p, ctypes.c_int, ctypes.c_void_p, ctypes.c_void_p ]
api.glfs_ipc.restype = ctypes.c_int
Expand Down
5 changes: 2 additions & 3 deletions tests/utils/libcxattr.py
Expand Up @@ -11,7 +11,6 @@
import os
import sys
from ctypes import CDLL, c_int, create_string_buffer
from ctypes.util import find_library


class Xattr(object):
Expand All @@ -28,9 +27,9 @@ class Xattr(object):

if sys.hexversion >= 0x02060000:
from ctypes import DEFAULT_MODE
libc = CDLL(find_library("libc"), DEFAULT_MODE, None, True)
libc = CDLL("libc.so.6", DEFAULT_MODE, None, True)
else:
libc = CDLL(find_library("libc"))
libc = CDLL("libc.so.6")

@classmethod
def geterrno(cls):
Expand Down
3 changes: 1 addition & 2 deletions tools/glusterfind/src/libgfchangelog.py
Expand Up @@ -12,14 +12,13 @@
import os
from ctypes import CDLL, get_errno, create_string_buffer, c_ulong, byref
from ctypes import RTLD_GLOBAL
from ctypes.util import find_library


class ChangelogException(OSError):
pass


libgfc = CDLL(find_library("gfchangelog"), use_errno=True, mode=RTLD_GLOBAL)
libgfc = CDLL("libgfchangelog.so", use_errno=True, mode=RTLD_GLOBAL)


def raise_oserr():
Expand Down
@@ -1,9 +1,8 @@
import os
from ctypes import *
from ctypes.util import find_library

class Changes(object):
libgfc = CDLL(find_library("gfchangelog"), mode=RTLD_GLOBAL, use_errno=True)
libgfc = CDLL("libgfchangelog.so", mode=RTLD_GLOBAL, use_errno=True)

@classmethod
def geterrno(cls):
Expand Down

0 comments on commit d321df3

Please sign in to comment.