Skip to content

Commit

Permalink
Fix: Avoid RTLD_GLOBAL on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ashvardanian committed Oct 10, 2024
1 parent ca58134 commit 77d20c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
23 changes: 18 additions & 5 deletions python/usearch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
import os
import sys
import ctypes
import platform
import warnings
import urllib.request
from typing import Optional, Tuple
from urllib.error import HTTPError

#! Load SimSIMD before the USearch compiled module
#! We can't just use the `import simsimd` as on Linux and Windows (unlike MacOS),
#! the symbols are not automatically loaded into the global namespace.
try:
import ctypes
import simsimd

#! We can't just use the `import simsimd` as on Linux and Windows (unlike MacOS),
#! the symbols are not automatically loaded into the global namespace.
simsimd_lib = ctypes.CDLL(simsimd.__file__, mode=ctypes.RTLD_GLOBAL)
# Cross-platform check for Windows
if sys.platform == "win32":
# Add the directory where the `.dll` is located
dll_directory = os.path.dirname(simsimd.__file__)
os.add_dll_directory(dll_directory)

# Load SimSIMD library using `ctypes` without `RTLD_GLOBAL`
simsimd_lib = ctypes.CDLL(simsimd.__file__)

else:
# Non-Windows: Use `RTLD_GLOBAL` for Unix-based systems (Linux/macOS)
simsimd_lib = ctypes.CDLL(simsimd.__file__, mode=ctypes.RTLD_GLOBAL)

except ImportError:
pass # Well, the user doesn't want SimSIMD, I assume :)
pass # If the user doesn't want SimSIMD, we assume they know what they're doing


from usearch.compiled import (
Expand Down
11 changes: 0 additions & 11 deletions python/usearch/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@
import numpy as np
from tqdm import tqdm

#! Load SimSIMD before the USearch compiled module
try:
import ctypes
import simsimd

#! We can't just use the `import simsimd` as on Linux and Windows (unlike MacOS),
#! the symbols are not automatically loaded into the global namespace.
simsimd_lib = ctypes.CDLL(simsimd.__file__, mode=ctypes.RTLD_GLOBAL)
except ImportError:
pass # Well, the user doesn't want SimSIMD, I assume :)

# Precompiled symbols that won't be exposed directly:
from usearch.compiled import (
Index as _CompiledIndex,
Expand Down

0 comments on commit 77d20c6

Please sign in to comment.