Skip to content

Commit

Permalink
Linking: Use import to locate _core
Browse files Browse the repository at this point in the history
Related to #8
  • Loading branch information
Mike Boers committed Feb 20, 2013
1 parent c2a2331 commit 25e4730
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions tomcrypt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@

import os
import ctypes

# We need to manually load the _core SO the first time so that we can specify
# that it use the RTLD_GLOBAL flag. Otherwise (when not on a Mac) the runtime
# linker will not be able to resolve undefined symbols in the other modules.
_core_handle = ctypes.CDLL(
os.path.join(os.path.dirname(os.path.abspath(__file__)), '_core.so'),
ctypes.RTLD_GLOBAL
)


class Error(ValueError):
def __init__(self, *args, **kwargs):
Expand All @@ -19,3 +10,11 @@ def __init__(self, *args, **kwargs):
class LibError(Error):
pass


# We need to manually load the _core the first time so that we can specify
# that it use the RTLD_GLOBAL flag. Otherwise (when not on a Mac) the runtime
# linker will not be able to resolve undefined symbols in the other modules.
# This must also be done after the above exceptions are defined so that they
# are availible to the core.
from . import _core
ctypes.PyDLL(_core.__file__, mode=ctypes.RTLD_GLOBAL)

0 comments on commit 25e4730

Please sign in to comment.