Skip to content

Commit

Permalink
Fixed library loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuzu-Typ committed Dec 19, 2019
1 parent de31f2c commit d2860ab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
24 changes: 12 additions & 12 deletions pyogg/library_loader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ctypes
import ctypes.util
import os
import sys
import platform
Expand Down Expand Up @@ -30,7 +31,7 @@ class ExternalLibraryError(Exception):

class ExternalLibrary:
@staticmethod
def load(name, paths = None, tests=[]):
def load(name, paths = None, tests = []):
if name in _loaded_libraries:
return _loaded_libraries[name]
if sys.platform == "win32":
Expand All @@ -43,23 +44,23 @@ def load(name, paths = None, tests=[]):
return lib

@staticmethod
def load_other(name, paths = None, tests=[]):
def load_other(name, paths = None, tests = []):
os.environ["PATH"] += ";" + ";".join((os.getcwd(), _here))
if paths: os.environ["PATH"] += ";" + ";".join(paths)

for style in _other_styles:
for name in (name.upper(), name.lower()):
candidate = style.format(name)
library = ctypes.util.find_library(candidate)
candidate = style.format(name)
library = ctypes.util.find_library(candidate)
if library:
try:
lib = ctypes.CDLL(library)
if all(run_tests(lib,tests)):
if tests and all(run_tests(lib, tests)):
return lib
except:
pass

@staticmethod
def load_windows(name, paths = None, tests=[]):
def load_windows(name, paths = None, tests = []):
os.environ["PATH"] += ";" + ";".join((os.getcwd(), _here))
if paths: os.environ["PATH"] += ";" + ";".join(paths)

Expand All @@ -69,15 +70,14 @@ def load_windows(name, paths = None, tests=[]):
library = ctypes.util.find_library(candidate)
if library:
try:
lib = ctypes.CDLL(candidate)
if all(run_tests(lib,tests)):
lib = ctypes.CDLL(library)
if tests and all(run_tests(lib, tests)):
return lib
else:
not_supported.append(candidate)
not_supported.append(library)
except WindowsError:
pass
except OSError:
not_supported.append(candidate)
not_supported.append(library)


if not_supported:
Expand Down
9 changes: 5 additions & 4 deletions pyogg/ogg.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ def get_raw_libname(name):
for x in "0123456789._- ":name=name.replace(x,"")
return name

if sys.version_info.major > 2:
to_char_p = lambda s: s.encode('utf-8')
else:
to_char_p = lambda s: s

__here = os.getcwd()

libogg = None
Expand All @@ -66,10 +71,6 @@ def get_raw_libname(name):
PYOGG_OGG_AVAIL = False

if PYOGG_OGG_AVAIL:
if sys.version_info.major > 2:
to_char_p = lambda s: s.encode('utf-8')
else:
to_char_p = lambda s: s

# ctypes
c_ubyte_p = POINTER(c_ubyte)
Expand Down

0 comments on commit d2860ab

Please sign in to comment.