Val is now passed to helpers directly instead of through extra pointer. (#31)

Co-authored-by: Zachary Levy <zachary@sunforge.is>
Reviewed-on: #31
This commit was merged in pull request #31.
This commit is contained in:
2026-06-04 21:50:55 +00:00
parent 6ac41b22f8
commit f2da356580
2 changed files with 5 additions and 5 deletions
+1 -1
View File
@@ -80,7 +80,7 @@ main :: proc() {
data_val: mdb.Val data_val: mdb.Val
mdb.panic_on_err(mdb.txn_begin(environment, nil, {}, &txn_handle)) mdb.panic_on_err(mdb.txn_begin(environment, nil, {}, &txn_handle))
mdb.panic_on_err(mdb.get(txn_handle, db_handle, &key_val, &data_val)) mdb.panic_on_err(mdb.get(txn_handle, db_handle, &key_val, &data_val))
data_cpy := mdb.blittable_copy(&data_val, int) data_cpy := mdb.blittable_copy(data_val, int)
mdb.panic_on_err(mdb.txn_commit(txn_handle)) mdb.panic_on_err(mdb.txn_commit(txn_handle))
fmt.println("Get result:", data_cpy) fmt.println("Get result:", data_cpy)
} }
+4 -4
View File
@@ -186,7 +186,7 @@ blittable_val :: #force_inline proc(val_ptr: ^$T) -> Val {
// Reads a blittable T out of the LMDB memory map by copying it into caller // Reads a blittable T out of the LMDB memory map by copying it into caller
// storage. The returned T has no lifetime tie to the transaction. // storage. The returned T has no lifetime tie to the transaction.
blittable_copy :: #force_inline proc(val: ^Val, $T: typeid) -> T { blittable_copy :: #force_inline proc(val: Val, $T: typeid) -> T {
fmt.assertf( fmt.assertf(
reflect.has_no_indirections(type_info_of(T)), reflect.has_no_indirections(type_info_of(T)),
"blitval_copy: type '%v' contains indirection and cannot be read directly from LMDB", "blitval_copy: type '%v' contains indirection and cannot be read directly from LMDB",
@@ -202,7 +202,7 @@ blittable_copy :: #force_inline proc(val: ^Val, $T: typeid) -> T {
// or silently corrupt the database (ENV_WRITEMAP). // or silently corrupt the database (ENV_WRITEMAP).
// MUST NOT be retained past txn_commit, txn_abort, or any subsequent write // MUST NOT be retained past txn_commit, txn_abort, or any subsequent write
// operation on the same env — the pointer is invalidated. // operation on the same env — the pointer is invalidated.
blittable_view :: #force_inline proc(val: ^Val, $T: typeid) -> ^T { blittable_view :: #force_inline proc(val: Val, $T: typeid) -> ^T {
fmt.assertf( fmt.assertf(
reflect.has_no_indirections(type_info_of(T)), reflect.has_no_indirections(type_info_of(T)),
"blitval_view: type '%v' contains indirection and cannot be viewed directly from LMDB", "blitval_view: type '%v' contains indirection and cannot be viewed directly from LMDB",
@@ -231,7 +231,7 @@ slice_val :: #force_inline proc(s: []$T) -> Val {
// MUST be copied (e.g. slice.clone) if it needs to outlive the current // MUST be copied (e.g. slice.clone) if it needs to outlive the current
// transaction; the view is invalidated by txn_commit, txn_abort, or any // transaction; the view is invalidated by txn_commit, txn_abort, or any
// subsequent write operation on the same env. // subsequent write operation on the same env.
slice_view :: #force_inline proc(val: ^Val, $T: typeid) -> []T { slice_view :: #force_inline proc(val: Val, $T: typeid) -> []T {
fmt.assertf( fmt.assertf(
reflect.has_no_indirections(type_info_of(T)), reflect.has_no_indirections(type_info_of(T)),
"slice_view: element type '%v' contains indirection and cannot be read directly from LMDB", "slice_view: element type '%v' contains indirection and cannot be read directly from LMDB",
@@ -253,7 +253,7 @@ string_val :: #force_inline proc(s: string) -> Val {
// MUST be copied (e.g. strings.clone) if it needs to outlive the current // MUST be copied (e.g. strings.clone) if it needs to outlive the current
// transaction; the view is invalidated by txn_commit, txn_abort, or any // transaction; the view is invalidated by txn_commit, txn_abort, or any
// subsequent write operation on the same env. // subsequent write operation on the same env.
string_view :: #force_inline proc(val: ^Val) -> string { string_view :: #force_inline proc(val: Val) -> string {
return string((cast([^]u8)val.data)[:val.size]) return string((cast([^]u8)val.data)[:val.size])
} }