https://bugs.openldap.org/show_bug.cgi?id=10260
Sascha Brawer sascha@brawer.ch changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |UNCONFIRMED Resolution|INVALID |---
--- Comment #2 from Sascha Brawer sascha@brawer.ch --- Would you be open to documenting this in the public documentation, not only in internals? See below for a proposed patch.
Apologies for the nuisance, but from reading the public LMDB documentation, it's really not obvious that LMDB keys and values have different memory alignment than malloc(), which aligns to the platform’s largest primitive type (typically 8 bytes these days). Looking at some applications that use LMDB in the wild, they're happily reading mv_data pointers as int32_t*, uint64_t*, or as pointers to custom structs with i32/i64/float members. If LMDB’s mv_data is aligned to a 2-byte boundary, these applications will either crash or be very slow on non-Intel CPUs.
Just to clarify, I'm not asking LMDB to change its implementation. But I think it would be good to document the unusual alignment in the public lmdb.h header, not just in internals.
From c35b5e80d19e649a90ab23437ce69cff176c02c3 Mon Sep 17 00:00:00 2001 From: Sascha Brawer sascha@brawer.ch Date: Mon, 30 Sep 2024 10:39:10 +0200 Subject: [PATCH] Add a note about (lack of) alignment to public API documentations
https://bugs.openldap.org/show_bug.cgi?id=10260 --- libraries/liblmdb/lmdb.h | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/libraries/liblmdb/lmdb.h b/libraries/liblmdb/lmdb.h index 199382a14c..04ceca13f8 100644 --- a/libraries/liblmdb/lmdb.h +++ b/libraries/liblmdb/lmdb.h @@ -1272,6 +1272,10 @@ int mdb_set_relctx(MDB_txn *txn, MDB_dbi dbi, void *ctx\ ); * database. The caller need not dispose of the memory, and may not * modify it in any way. For values returned in a read-only transaction * any modification attempts will cause a SIGSEGV. + * @note Starting with LMDB 1.0, the memory address of returned + * values is aligned to a 2-byte boundary; earlier versions make + * no alignment guarantees. On some processor architectures, + * such as ARM or PowerPC, misaligned reads will cause a SIGBUS. * @note Values returned from the database are valid only until a * subsequent update operation, or the end of the transaction. * @param[in] txn A transaction handle returned by #mdb_txn_begin()