From 5a64885c600ddca2ef1ca1a22570c1782f07b5d8 Mon Sep 17 00:00:00 2001 From: Richard Connon Date: Wed, 1 Nov 2023 18:29:44 +0000 Subject: [PATCH] Conditionally enable module loading by default 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. --- lupa/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lupa/__init__.py b/lupa/__init__.py index 41e091e9..da93aefe 100644 --- a/lupa/__init__.py +++ b/lupa/__init__.py @@ -51,10 +51,10 @@ 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(): + 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