Skip to content

Commit

Permalink
Conditionally enable module loading by default
Browse files Browse the repository at this point in the history
Enabling module loading by default doesn't work when there are multiple
Lua modules because the symbols collide with each other when loaded with
RTLD_GLOBAL.
Make the default use of the dlopenflags conditional on there only being
one available Lua module.
  • Loading branch information
riconnon committed Nov 1, 2023
1 parent 50f1f0c commit 6d1e877
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lupa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ def _import_newest_lib():
# prefer Lua over LuaJIT and high versions over low versions.
module_name = max(modules, key=lambda m: (m[1] == 'lua', tuple(map(int, m[2] or '0'))))

# We need to enable global symbol visibility for lupa in order to
# support binary module loading in Lua. If we can enable it here, we
# do it temporarily.
with eager_global_linking():
# Allowing module loading using dlopenflags by default doesn't work when there are multiple
# Lua modules because the symbols collide with each other when loaded with RTLD_GLOBAL.
# Enable this by default only if there is exactly one lua module available.
if len(modules) == 1:
with allow_lua_module_loading():
_newest_lib = __import__(module_name[0], level=1, fromlist="*", globals=globals())
else:
_newest_lib = __import__(module_name[0], level=1, fromlist="*", globals=globals())

return _newest_lib
Expand Down

0 comments on commit 6d1e877

Please sign in to comment.