Skip to content

Commit c2264f4

Browse files
author
Ivan Dlugos
committed
update to c-api v0.10.0 + docs/script improvements
1 parent 547612c commit c2264f4

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

download-c-lib.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
import tarfile
33
import os
44

5-
version = "0.6.0" # see objectbox/c.py required_version
5+
# Script used to download objectbox-c shared libraries for all supported platforms. Execute by running `make get-lib`
6+
# on first checkout of this repo and any time after changing the objectbox-c lib version.
7+
8+
version = "0.10.0" # see objectbox/c.py required_version
69

710
conan_repo = "https://dl.bintray.com/objectbox/conan/objectbox/objectbox-c"
811
conan_channel = "testing"
@@ -11,7 +14,7 @@
1114
# see https://github.com/objectbox/objectbox-c/blob/main/download.sh for the hashes
1215
out_dir = "objectbox/lib"
1316
file_hashes = {
14-
# objectbox.h is common for all types, get it from the linux x86_64 distributable
17+
# header file is the same for all platforms, get it from the linux x86_64 distributable
1518
"objectbox.h": "4db1be536558d833e52e862fd84d64d75c2b3656",
1619

1720
# linux
@@ -53,6 +56,8 @@ def download(rel_path: str):
5356
archived_file = archive.extractfile(archive_dir + "/" + basename)
5457
with open(out_path, 'wb') as file:
5558
file.writelines(archived_file.readlines())
59+
archived_file.close()
60+
archive.close()
5661

5762

5863
# execute the download for each item in the file hashes

objectbox/box.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def _put_one(self, obj) -> int:
5454
id = obx_box_id_for_put(self._c_box, 0)
5555

5656
data = self._entity.marshal(obj, id)
57-
obx_box_put(self._c_box, id, bytes(data), len(data), OBXPutMode_PUT)
57+
obx_box_put(self._c_box, id, bytes(data), len(data))
5858

5959
if id != object_id:
6060
self._entity.set_object_id(obj, id)
@@ -82,7 +82,7 @@ def _put_many(self, objects) -> None:
8282

8383
# allocate a C bytes array structure where we will push the object data
8484
# OBX_bytes_array with .count = len(objects)
85-
c_bytes_array_p = obx_bytes_array_create(len(objects))
85+
c_bytes_array_p = obx_bytes_array(len(objects))
8686

8787
try:
8888
# we need to keep the data around until put_many is executed because obx_bytes_array_set doesn't do a copy

objectbox/c.py

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

21-
# This file contains C-API bindings based on the objectbox.h, linking to the 'objectbox' shared library
22-
required_version = "0.6.0" # don't forget to update download-c-lib.py when upgrading to a newer version
21+
# This file contains C-API bindings based on lib/objectbox.h, linking to the 'objectbox' shared library.
22+
# The bindings are implementing using ctypes, see https://docs.python.org/dev/library/ctypes.html for introduction.
23+
24+
25+
# Version of the library used by the binding. This version is checked at runtime to ensure binary compatibility.
26+
# Don't forget to update download-c-lib.py when upgrading to a newer version.
27+
required_version = "0.10.0"
2328

2429

2530
def shlib_name(library: str) -> str:
@@ -248,7 +253,7 @@ def c_voidp_as_bytes(voidp, size):
248253

249254

250255
# OBX_model* (void);
251-
obx_model_create = fn('obx_model_create', OBX_model_p, [])
256+
obx_model = fn('obx_model', OBX_model_p, [])
252257

253258
# obx_err (OBX_model* model, const char* name, obx_schema_id entity_id, obx_uid entity_uid);
254259
obx_model_entity = fn('obx_model_entity', obx_err, [OBX_model_p, ctypes.c_char_p, obx_schema_id, obx_uid])
@@ -283,10 +288,10 @@ def c_voidp_as_bytes(voidp, size):
283288
obx_opt_max_db_size_in_kb = fn('obx_opt_max_db_size_in_kb', None, [OBX_store_options_p, ctypes.c_size_t])
284289

285290
# 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])
291+
obx_opt_file_mode = fn('obx_opt_file_mode', None, [OBX_store_options_p, ctypes.c_uint])
287292

288293
# 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])
294+
obx_opt_max_readers = fn('obx_opt_max_readers', None, [OBX_store_options_p, ctypes.c_uint])
290295

291296
# obx_err (OBX_store_options* opt, OBX_model* model);
292297
obx_opt_model = fn('obx_opt_model', obx_err, [OBX_store_options_p, OBX_model_p])
@@ -332,7 +337,7 @@ def c_voidp_as_bytes(voidp, size):
332337
obx_box_ids_for_put = fn('obx_box_ids_for_put', obx_err, [OBX_box_p, ctypes.c_uint64, ctypes.POINTER(obx_id)])
333338

334339
# obx_err (OBX_box* box, obx_id id, const void* data, size_t size, OBXPutMode mode);
335-
obx_box_put = fn('obx_box_put', obx_err, [OBX_box_p, obx_id, ctypes.c_void_p, ctypes.c_size_t, OBXPutMode])
340+
obx_box_put = fn('obx_box_put', obx_err, [OBX_box_p, obx_id, ctypes.c_void_p, ctypes.c_size_t])
336341

337342
# obx_err (OBX_box* box, const OBX_bytes_array* objects, const obx_id* ids, OBXPutMode mode);
338343
obx_box_put_many = fn('obx_box_put_many', obx_err, [OBX_box_p, OBX_bytes_array_p, ctypes.POINTER(obx_id), OBXPutMode])
@@ -350,7 +355,7 @@ def c_voidp_as_bytes(voidp, size):
350355
obx_box_count = fn('obx_box_count', obx_err, [OBX_box_p, ctypes.c_uint64, ctypes.POINTER(ctypes.c_uint64)])
351356

352357
# OBX_bytes_array* (size_t count);
353-
obx_bytes_array_create = fn('obx_bytes_array_create', OBX_bytes_array_p, [ctypes.c_size_t])
358+
obx_bytes_array = fn('obx_bytes_array', OBX_bytes_array_p, [ctypes.c_size_t])
354359

355360
# obx_err (OBX_bytes_array* array, size_t index, const void* data, size_t size);
356361
obx_bytes_array_set = fn('obx_bytes_array_set', obx_err,

objectbox/model/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __bool__(self):
3131
class Model:
3232
def __init__(self):
3333
self._entities = list()
34-
self._c_model = obx_model_create()
34+
self._c_model = obx_model()
3535
self.last_entity_id = IdUid(0, 0)
3636
self.last_index_id = IdUid(0, 0)
3737
self.last_relation_id = IdUid(0, 0)

0 commit comments

Comments
 (0)