Skip to content

Commit 910ba15

Browse files
committedMar 4, 2022
Changed load_* to return the libraries they load
1 parent 4cad7f7 commit 910ba15

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed
 

‎CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [0.3.0] - 2022-03-04
2+
3+
- Changed `load_*` to return the libraries that have been loaded.
4+
15
## [0.2.1] - 2022-03-04
26

37
- Added `minimum_allocation` and `header_size` properties to the `Cobhan` class

‎cobhan/cobhan.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111

1212
# Pending https://github.com/python/typing/issues/593
1313
CBuf = bytearray # Cobhan buffer -- returned from ffi.new()
14+
FFILibrary = Any
1415

1516

1617
class Cobhan:
1718
"""Class representing the Cobhan translation layer"""
1819

1920
def __init__(self):
20-
self._lib: Optional[Any] = None
21+
self._lib: Optional[FFILibrary] = None
2122
self.__ffi: FFI = FFI()
2223
self.__sizeof_int32: int = self.__ffi.sizeof("int32_t")
2324
self.__sizeof_int64: int = self.__ffi.sizeof("int64_t")
@@ -37,7 +38,9 @@ def header_size(self):
3738
"""The size, in bytes, of a buffer's header"""
3839
return self.__sizeof_header
3940

40-
def load_library(self, library_path: str, library_name: str, cdefines: str) -> None:
41+
def load_library(
42+
self, library_path: str, library_name: str, cdefines: str
43+
) -> FFILibrary:
4144
"""Locate and load a library based on the current platform.
4245
4346
:param library_path: The filesystem path where the library is located
@@ -90,7 +93,9 @@ def load_library(self, library_path: str, library_name: str, cdefines: str) -> N
9093
if need_chdir:
9194
os.chdir(old_dir)
9295

93-
def load_library_direct(self, library_file_path: str, cdefines: str) -> None:
96+
return self._lib
97+
98+
def load_library_direct(self, library_file_path: str, cdefines: str) -> FFILibrary:
9499
"""Directly load a specific library file.
95100
96101
Generally speaking, you probably don't want this. Instead, you probably
@@ -104,6 +109,7 @@ def load_library_direct(self, library_file_path: str, cdefines: str) -> None:
104109
"""
105110
self.__ffi.cdef(cdefines)
106111
self._lib = self.__ffi.dlopen(library_file_path)
112+
return self._lib
107113

108114
def to_json_buf(self, obj: Any) -> CBuf:
109115
"""Serialize an object into JSON in a Cobhan buffer.

‎pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "cobhan"
3-
version = "0.2.1"
3+
version = "0.3.0"
44
description = "Cobhan FFI"
55
authors = [
66
"Jeremiah Gowdy <jeremiah@gowdy.me>",

0 commit comments

Comments
 (0)
Please sign in to comment.