Skip to content

Commit 57027f4

Browse files
author
Ivan Dlugos
committed
update c-api to 0.5.104 (options builder)
1 parent c0addc9 commit 57027f4

2 files changed

Lines changed: 36 additions & 17 deletions

File tree

objectbox/builder.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,16 @@ def model(self, model: Model) -> 'Builder':
3333
return self
3434

3535
def build(self) -> 'ObjectBox':
36-
c_options = OBX_store_options()
37-
if len(self._directory) > 0:
38-
c_options.directory = c_str(self._directory)
36+
c_options = obx_opt()
3937

40-
c_store = obx_store_open(self._model._c_model, c_options.p())
38+
try:
39+
if len(self._directory) > 0:
40+
obx_opt_directory(c_options, c_str(self._directory))
41+
42+
obx_opt_model(c_options, self._model._c_model)
43+
except CoreException:
44+
obx_opt_free(c_options)
45+
raise
46+
47+
c_store = obx_store_open(c_options)
4148
return ObjectBox(c_store)

objectbox/c.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import platform
1919
from objectbox.version import Version
2020

21-
2221
# This file contains C-API bindings based on the objectbox.h, linking to the 'objectbox' shared library
22+
required_version = "0.5.104"
2323

2424

2525
def shlib_name(library: str) -> str:
@@ -48,7 +48,6 @@ def shlib_name(library: str) -> str:
4848
# C-api (core library) version
4949
version_core = Version(__major.value, __minor.value, __patch.value)
5050

51-
required_version = "0.5.103"
5251
assert str(version_core) == required_version, \
5352
"Incorrect ObjectBox version loaded: %s instead of expected %s " % (str(version_core), required_version)
5453

@@ -82,15 +81,7 @@ class OBX_store(ctypes.Structure):
8281

8382

8483
class OBX_store_options(ctypes.Structure):
85-
_fields_ = [
86-
('directory', ctypes.c_char_p),
87-
('maxDbSizeInKByte', ctypes.c_uint64),
88-
('fileMode', ctypes.c_uint),
89-
('maxReaders', ctypes.c_uint)
90-
]
91-
92-
def p(self) -> 'ctypes.POINTER(OBX_store_options)':
93-
return ctypes.byref(self)
84+
pass
9485

9586

9687
OBX_store_options_p = ctypes.POINTER(OBX_store_options)
@@ -282,8 +273,29 @@ def c_voidp_as_bytes(voidp, size):
282273
obx_model_entity_last_property_id = fn('obx_model_entity_last_property_id', obx_err,
283274
[OBX_model_p, obx_schema_id, obx_uid])
284275

285-
# OBX_store* (OBX_model* model, const OBX_store_options* options);
286-
obx_store_open = fn('obx_store_open', OBX_store_p, [OBX_model_p, OBX_store_options_p])
276+
# OBX_store_options* ();
277+
obx_opt = fn('obx_opt', OBX_store_options_p, [])
278+
279+
# obx_err (OBX_store_options* opt, const char* dir);
280+
obx_opt_directory = fn('obx_opt_directory', obx_err, [OBX_store_options_p, ctypes.c_char_p])
281+
282+
# void (OBX_store_options* opt, size_t size_in_kb);
283+
obx_opt_max_db_size_in_kb = fn('obx_opt_max_db_size_in_kb', None, [OBX_store_options_p, ctypes.c_size_t])
284+
285+
# void (OBX_store_options* opt, int file_mode);
286+
obx_opt_file_mode = fn('obx_opt_file_mode', None, [OBX_store_options_p, ctypes.c_int])
287+
288+
# void (OBX_store_options* opt, int max_readers);
289+
obx_opt_max_readers = fn('obx_opt_max_readers', None, [OBX_store_options_p, ctypes.c_int])
290+
291+
# obx_err (OBX_store_options* opt, OBX_model* model);
292+
obx_opt_model = fn('obx_opt_model', obx_err, [OBX_store_options_p, OBX_model_p])
293+
294+
# void (OBX_store_options* opt);
295+
obx_opt_free = fn('obx_opt_free', None, [OBX_store_options_p])
296+
297+
# OBX_store* (const OBX_store_options* options);
298+
obx_store_open = fn('obx_store_open', OBX_store_p, [OBX_store_options_p])
287299

288300
# obx_err (OBX_store* store);
289301
obx_store_close = fn('obx_store_close', obx_err, [OBX_store_p])

0 commit comments

Comments
 (0)