diff options
author | Leonid Yuriev <leo@yuriev.ru> | 2020-10-08 02:02:18 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-10-09 16:50:37 +0300 |
commit | a519d4617ed83a2167a693ae87934e56889fef05 (patch) | |
tree | 85c3aea76fe15268fc0891cf18c328913c6d4347 /libs/libmdbx/src/example/example-mdbx.c | |
parent | bc58e7ec8ef67c37b6d302eaa2e76deedec03106 (diff) |
libmdbx: switch to original amalgamated source code (v0.9.1.18)
Amalgamated source code is the recommended form for
embedding libmdbx in non-CMake build systems. This amalgamated
version contains a minimum of files, is fully ready for use,
and make impossible a number of errors.
To upgrade or switch to a different version, just unpack
to the `src` subdirectory a corresponding `libmdbx-amalgamated-X_Y_Z.zip`
at the https://github.com/erthink/libmdbx/releases.
For instance, the https://github.com/erthink/libmdbx/releases/download/v0.9.2/libmdbx-amalgamated-0_9_2.zip
for the next release.
--
Minimal changes have been made to the build configuration:
1. For use the standard `DllMain()` entry of libmdbx:
- added the `MDBX_BUILD_SHARED_LIBRARY=1` option;
- removed the `MDBX_CONFIG_MANUAL_TLS_CALLBACK` option;
- deleted the `miranda.c` file containing only `DllMain()`
with the `mdbx_dll_handle()` call, now this is done by the library itself.
2. Removed refs to extra files (that missing in the amalgamated source code):
- for building `libmdbx.dll` only the `mdbx.h` and `mdbx.c` are used,
but not `mdbx.c++` for a C++ API;
- for building the `mdbx_chk`, `mdbx_load`, and `mdbx_dump` utilities
only it own sources are used.
--
Last libmdbx changes:
- Fixed missing installation of `mdbx.h++`.
- Fixed use of obsolete `__noreturn`.
- Fixed use of `yield` instruction on ARM if unsupported.
- Added pthread workaround for buggy toolchain/cmake/buildroot.
- Fixed use of `pthread_yield()` for non-GLIBC.
- Fixed use of `RegGetValueA()` on Windows 2000/XP.
- Fixed use of `GetTickCount64()` on Windows 2000/XP.
- Fixed opening DB on a network shares (in the exclusive mode).
- Fixed copy&paste typos.
- Fixed minor false-positive GCC warning.
Diffstat (limited to 'libs/libmdbx/src/example/example-mdbx.c')
-rw-r--r-- | libs/libmdbx/src/example/example-mdbx.c | 112 |
1 files changed, 0 insertions, 112 deletions
diff --git a/libs/libmdbx/src/example/example-mdbx.c b/libs/libmdbx/src/example/example-mdbx.c deleted file mode 100644 index 0a9e7ed601..0000000000 --- a/libs/libmdbx/src/example/example-mdbx.c +++ /dev/null @@ -1,112 +0,0 @@ -/* MDBX usage examle - * - * Do a line-by-line comparison of this and sample-bdb.txt - */ - -/* - * Copyright 2015-2020 Leonid Yuriev <leo@yuriev.ru>. - * Copyright 2017 Ilya Shipitsin <chipitsine@gmail.com>. - * Copyright 2012-2015 Howard Chu, Symas Corp. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted only as authorized by the OpenLDAP - * Public License. - * - * A copy of this license is available in the file LICENSE in the - * top-level directory of the distribution or, alternatively, at - * <http://www.OpenLDAP.org/license.html>. - */ - -#include "mdbx.h" -#include <stdio.h> -#include <stdlib.h> - -int main(int argc, char *argv[]) { - (void)argc; - (void)argv; - - int rc; - MDBX_env *env = NULL; - MDBX_dbi dbi = 0; - MDBX_val key, data; - MDBX_txn *txn = NULL; - MDBX_cursor *cursor = NULL; - char sval[32]; - - rc = mdbx_env_create(&env); - if (rc != MDBX_SUCCESS) { - fprintf(stderr, "mdbx_env_create: (%d) %s\n", rc, mdbx_strerror(rc)); - goto bailout; - } - rc = mdbx_env_open(env, "./example-db", - MDBX_NOSUBDIR | MDBX_COALESCE | MDBX_LIFORECLAIM, 0664); - if (rc != MDBX_SUCCESS) { - fprintf(stderr, "mdbx_env_open: (%d) %s\n", rc, mdbx_strerror(rc)); - goto bailout; - } - - rc = mdbx_txn_begin(env, NULL, 0, &txn); - if (rc != MDBX_SUCCESS) { - fprintf(stderr, "mdbx_txn_begin: (%d) %s\n", rc, mdbx_strerror(rc)); - goto bailout; - } - rc = mdbx_dbi_open(txn, NULL, 0, &dbi); - if (rc != MDBX_SUCCESS) { - fprintf(stderr, "mdbx_dbi_open: (%d) %s\n", rc, mdbx_strerror(rc)); - goto bailout; - } - - key.iov_len = sizeof(int); - key.iov_base = sval; - data.iov_len = sizeof(sval); - data.iov_base = sval; - - sprintf(sval, "%03x %d foo bar", 32, 3141592); - rc = mdbx_put(txn, dbi, &key, &data, 0); - if (rc != MDBX_SUCCESS) { - fprintf(stderr, "mdbx_put: (%d) %s\n", rc, mdbx_strerror(rc)); - goto bailout; - } - rc = mdbx_txn_commit(txn); - if (rc) { - fprintf(stderr, "mdbx_txn_commit: (%d) %s\n", rc, mdbx_strerror(rc)); - goto bailout; - } - txn = NULL; - - rc = mdbx_txn_begin(env, NULL, MDBX_RDONLY, &txn); - if (rc != MDBX_SUCCESS) { - fprintf(stderr, "mdbx_txn_begin: (%d) %s\n", rc, mdbx_strerror(rc)); - goto bailout; - } - rc = mdbx_cursor_open(txn, dbi, &cursor); - if (rc != MDBX_SUCCESS) { - fprintf(stderr, "mdbx_cursor_open: (%d) %s\n", rc, mdbx_strerror(rc)); - goto bailout; - } - - int found = 0; - while ((rc = mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT)) == 0) { - printf("key: %p %.*s, data: %p %.*s\n", key.iov_base, (int)key.iov_len, - (char *)key.iov_base, data.iov_base, (int)data.iov_len, - (char *)data.iov_base); - found += 1; - } - if (rc != MDBX_NOTFOUND || found == 0) { - fprintf(stderr, "mdbx_cursor_get: (%d) %s\n", rc, mdbx_strerror(rc)); - goto bailout; - } else { - rc = MDBX_SUCCESS; - } -bailout: - if (cursor) - mdbx_cursor_close(cursor); - if (txn) - mdbx_txn_abort(txn); - if (dbi) - mdbx_dbi_close(env, dbi); - if (env) - mdbx_env_close(env); - return (rc != MDBX_SUCCESS) ? EXIT_FAILURE : EXIT_SUCCESS; -} |