heed
heed copied to clipboard
Q: would you be interested in writing rust bindings for libmdbx?
Why not, I think it is not far from a fork of the mozilla lmdb-rkv-sys library, a replacement of the git submodule and some API modifications to make it fit libmdbx. Even some features flags could be added to enable some specific libmdbx features (e.g. MDBX_UTTERLY_NOSYNC) or a feature that disable TLS and enable read only transactions to be shared between thread safely.
By the way if I do so I will make it a repository for only this library not as a sub folder like the mozilla/lmdb-rs one does.
I have a little question about the mdbx cursors, are those reusable or not? Because in the following sentence it is specified that "any opened cursors can be reused" but also "and must be freed explicitly".
(!) An important difference between MDBX and LMDB is that MDBX required that any opened cursors can be reused and must be freed explicitly, regardless ones was opened in a read-only or write transaction. The REASON for this is eliminates ambiguity which helps to avoid errors such as: use-after-free, double-free, i.e. memory corruption and segfaults.
Probably my English is not very good:
- Any cursor created by
mdb_cursor_open(), when it becomes unnecessary, must be explicitly freed bymdbx_cursor_close(). - Any cursor created by
mdb_cursor_open(), may be reused bymdbx_cursor_renew(), until it explicitly freed bymdbx_cursor_close().
Hi, I made some progress on building the mdbx bindings in Rust and found out that Rust doesn't like overflowing number like MDBX_RESULT_TRUE: c_uint = 18446744073709551615. And found strange that a c_uint is in fact an unsigned int and is attributed the max value of an unsigned long instead of the unsigned int one. Is it normal? I understand that it work but...
Variables concerned are MDBX_RESULT_TRUE, MDBX_PROBLEM, MDBX_BUSY, MDBX_EMULTIVAL, MDBX_EBADSIGN, MDBX_WANNA_RECOVERY, MDBX_EKEYMISMATCH, MDBX_TOO_LARGE and MDBX_THREAD_MISMATCH.
There is also many defines that Rust doesn't like because those are not upper cased and are translated into Rust consts which should be upper cased: MDBX_subpage_dupfixed_leaf, MDBX_subpage_leaf, MDBX_page_dupfixed_leaf, MDBX_page_leaf, MDBX_page_branch, MDBX_page_large, MDBX_page_meta and MDBX_page_void.
EDIT: I found out how to fix the -1 issue, it is absolutely not related to your code, sorry.
Ok so here is the mdbx-sys repository with most of all the bindings generated in Rust. I blacklisted (for now) the MDBX_page_type_t, MDBX_pgvisitor_func, mdbx_env_pgwalk types/functions, because of the upper cased problem and will probably #[allow(non_upper_case_globals)].
EDIT: Done!
-
The
MDBX_page_type_t,MDBX_pgvisitor_funcandmdbx_env_pgwalkare an internal/auxiliary API, i.e. shouldn't be used in a regular application. -
The problems with error codes since libmdbx defines an aliases for some system error codes:
- are system-depended, i.e. differ on Linux, *BSD, MacOS, Windows, etc.
- may be defined as signed integers (Linux, Unix, MacOS) or unsigned (Windows), but
signed intis preferable since mdbx functions returnsinttype.
- I will blacklist those like I did before.
- Do you think that I will need to define those by hand? like this part of the lib? Strange because the lmdb-rs repository doesn't seems to take care of the
mdb_filehandle_ttype on windows.