11
11
12
12
# Pending https://github.com/python/typing/issues/593
13
13
CBuf = bytearray # Cobhan buffer -- returned from ffi.new()
14
+ FFILibrary = Any
14
15
15
16
16
17
class Cobhan :
17
18
"""Class representing the Cobhan translation layer"""
18
19
19
20
def __init__ (self ):
20
- self ._lib : Optional [Any ] = None
21
+ self ._lib : Optional [FFILibrary ] = None
21
22
self .__ffi : FFI = FFI ()
22
23
self .__sizeof_int32 : int = self .__ffi .sizeof ("int32_t" )
23
24
self .__sizeof_int64 : int = self .__ffi .sizeof ("int64_t" )
@@ -37,7 +38,9 @@ def header_size(self):
37
38
"""The size, in bytes, of a buffer's header"""
38
39
return self .__sizeof_header
39
40
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 :
41
44
"""Locate and load a library based on the current platform.
42
45
43
46
: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
90
93
if need_chdir :
91
94
os .chdir (old_dir )
92
95
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 :
94
99
"""Directly load a specific library file.
95
100
96
101
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:
104
109
"""
105
110
self .__ffi .cdef (cdefines )
106
111
self ._lib = self .__ffi .dlopen (library_file_path )
112
+ return self ._lib
107
113
108
114
def to_json_buf (self , obj : Any ) -> CBuf :
109
115
"""Serialize an object into JSON in a Cobhan buffer.
0 commit comments