Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FreeBSD support using the same API as on Linux #5

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
A very small Python library to list the DLLs loaded by the current process.
This is equivalent to the [`dllist`](https://docs.julialang.org/en/v1/stdlib/Libdl/#Base.Libc.Libdl.dllist) function in Julia.

*Note*: This library is intended to work on macOS, Linux, and Windows. Other platforms will return an empty list and raise a warning.
*Note*: This library is tested on macOS, Linux, and Windows.

Some platforms which provide the same API as Linux (e.g. FreeBSD) may also work.

Any other platform will return an empty list and raise a warning.

## Installation

Expand Down
20 changes: 13 additions & 7 deletions dllist/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
import warnings
from typing import List

__version__ = "1.1.0"

_system = platform.system()
if _system.startswith("Linux"):
from .linux import _platform_specific_dllist
elif _system.startswith("Darwin"):
__version__ = "1.2.0"

_system = platform.system().lower()
if (
_system.startswith("linux")
or _system.startswith("freebsd")
or _system.startswith("openbsd")
or _system.startswith("sunos")
or _system.startswith("solaris")
):
from .unix_like import _platform_specific_dllist
elif _system.startswith("darwin"):
from .macos import _platform_specific_dllist
elif _system.startswith("Windows"):
elif _system.startswith("windows"):
from .windows import _platform_specific_dllist
else:

Expand Down
4 changes: 4 additions & 0 deletions dllist/linux.py → dllist/unix_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
from ctypes.util import find_library
from typing import List

# this uses functions common to Linux and a few other Unix-like systems
# https://man7.org/linux/man-pages/man3/dl_iterate_phdr.3.html
# https://man.freebsd.org/cgi/man.cgi?query=dl_iterate_phdr
# https://man.openbsd.org/dl_iterate_phdr
# https://docs.oracle.com/cd/E88353_01/html/E37843/dl-iterate-phdr-3c.html


class dl_phdr_info(ctypes.Structure):
Expand Down
5 changes: 3 additions & 2 deletions test/test_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import pytest

if not platform.system().startswith("Linux"):
pytest.skip(reason="Linux only", allow_module_level=True)
system = platform.system()
if not (system.startswith("Linux") or system.startswith("FreeBSD")):
pytest.skip(reason="Linux and FreeBSD only", allow_module_level=True)


from test import print_list
Expand Down
1 change: 1 addition & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

if (
system.startswith("Linux")
or system.startswith("FreeBSD")
or system.startswith("Darwin")
or system.startswith("Windows")
):
Expand Down
Loading