Previously, even when an error occurred in an operation acting on the source database, `bdb_handle_error(ctbdb)` was being called. This change tracks whether an error occurs during operations on `sbdb` or `tbdb`, and raises an exception using the correct database accordingly.
In order to allow for multi-threaded read access to the database, the OCaml runtime lock should be released when entering TokyoCabinet. In turn, this requires some string copying. This change releases the runtime lock, and adds the required copying, while avoiding `malloc` calls for keys smaller than 1kB.
Since we allocate a new string right before copying the source data into this freshly-allocated memory, the 2 regions can't overlap. In turn, this allows using `memcpy` instead of `memmove`, which is cheaper.