Merge lp:~gqmelo/pyopengl/load-library-linux into lp:pyopengl

Proposed by Guilherme Quentel Melo
Status: Needs review
Proposed branch: lp:~gqmelo/pyopengl/load-library-linux
Merge into: lp:pyopengl
Diff against target: 51 lines (+41/-0)
1 file modified
OpenGL/platform/ctypesloader.py (+41/-0)
To merge this branch: bzr merge lp:~gqmelo/pyopengl/load-library-linux
Reviewer Review Type Date Requested Status
Mike C. Fletcher Pending
Review via email: mp+293927@code.launchpad.net

Description of the change

Fix library loading on Linux

The function util.find_library does not respect variables like
LD_LIBRARY_PATH.

Also files ending with .so are intended to be used at compilation time
and therefore are normally shipped by a dev package on most Linux
distributions.

At runtime, applications should use the filename with major version
(.so.x)

To post a comment you must log in.
Revision history for this message
Mike C. Fletcher (mcfletch) wrote :

Okay, merged. Sorry it took so long, but it just failed when I merged and I didn't have the time to investigate (it would load a non-functional DLL when the base_name was loaded (i.e. it would load libOpenGL.so and that would have no visuals etc), so it would completely bomb out on my (Kubuntu) box).

We really do mean "the latest version" here, so the .so really is what we *mean*, but ld-preload and the like should be respected, and while I don't like the arbitrary "up to 9" thing, we're currently in the 1-3 range for our used dlls, so we'll look at it again when they get up to api version 9 I suppose.

Thanks,
Mike

Revision history for this message
Guilherme Quentel Melo (gqmelo) wrote :

Thanks for the feedback!

> and while I don't like the arbitrary "up to 9" thing, we're currently in the 1-3 range for our used > dlls, so we'll look at it again when they get up to api version 9

Yeah, I don't like it either, but I don't see a better way to dynamically load the last version of a library.

I checked the code you merged, and it seems fine except that I think it breaks OSX, don't it? It is not trying any name for OSX

Revision history for this message
Mike C. Fletcher (mcfletch) wrote :

Good point, added base name if we're on darwin.

Revision history for this message
Guilherme Quentel Melo (gqmelo) wrote :

> Good point, added base name if we're on darwin.

Great! Should I do something about this pull request? Mark as merged?

Revision history for this message
Mike C. Fletcher (mcfletch) wrote :

Weird, I thought it would automatically mark it as merged... ah, no, because I wound up doing a revert and then re-applying as I was debugging it wound up unmarked.

Have Mac people trying to figure out how to make it work on Mac now...

Unmerged revisions

1000. By Guilherme Quentel Melo

Fix library loading on Linux

The function util.find_library does not respect variables like
LD_LIBRARY_PATH.

Also files ending with .so are intended to be used at compilation time
and therefore are normally shipped by a dev package on most Linux
distributions.

At runtime, applications should use the filename with major version
(.so.x)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'OpenGL/platform/ctypesloader.py'
2--- OpenGL/platform/ctypesloader.py 2014-04-08 04:04:23 +0000
3+++ OpenGL/platform/ctypesloader.py 2016-05-05 18:27:25 +0000
4@@ -30,6 +30,47 @@
5 """
6 if isinstance( dllType, ctypes.LibraryLoader ):
7 dllType = dllType._dlltype
8+ if os.name == 'posix':
9+ return _loadLibraryPosix(dllType, name, mode)
10+ else:
11+ return _loadLibraryWindows(dllType, name, mode)
12+
13+
14+def _loadLibraryPosix(dllType, name, mode):
15+ """Load a given library for posix systems
16+
17+ The problem with util.find_library is that it does not respect linker runtime variables like
18+ LD_LIBRARY_PATH.
19+
20+ Also we cannot rely on libGLU.so to be available, for example. Most of Linux distributions will
21+ ship only libGLU.so.1 by default. Files ending with .so are normally used when compiling and are
22+ provided by dev packages.
23+
24+ returns the ctypes C-module object
25+ """
26+ prefix = 'lib'
27+ if sys.platform == 'darwin':
28+ suffix = '.dylib'
29+ else:
30+ suffix = '.so'
31+ base_name = prefix + name + suffix
32+ filenames_to_try = [base_name]
33+
34+ # If a .so is missing, let's try libs with so version (e.g libGLU.so.9, libGLU.so.8 and so on)
35+ if sys.platform.startswith('linux'):
36+ filenames_to_try.extend(list(reversed([base_name + '.%i' % i for i in range(0, 10)])))
37+
38+ for filename in filenames_to_try:
39+ try:
40+ return dllType(filename, mode)
41+ except Exception, err:
42+ _log.info('''Failed to load library ( %r ): %s''', filename, err)
43+
44+def _loadLibraryWindows(dllType, name, mode):
45+ """Load a given library for Windows systems
46+
47+ returns the ctypes C-module object
48+ """
49 fullName = None
50 try:
51 fullName = util.find_library( name )

Subscribers

People subscribed via source and target branches