├── .github
└── workflows
│ ├── prebuild.yml
│ ├── test-arm64.yml
│ ├── test-arm7.yml
│ ├── test-install.yml
│ ├── test-integration.yml
│ └── test.yml
├── .gitignore
├── .jshintrc
├── .npmignore
├── .npmrc
├── LICENSE
├── README.md
├── SECURITY.md
├── assets
├── gatsby.png
├── harperdb.png
├── parcel.png
├── performance.png
└── powers-dre.png
├── benchmark
├── index.js
├── low-level.js
└── read-async.js
├── bin
└── download-prebuilds.js
├── binding.gyp
├── caching.js
├── dependencies
├── lmdb-data-v1
│ └── libraries
│ │ └── liblmdb
│ │ ├── .gitignore
│ │ ├── CHANGES
│ │ ├── COPYRIGHT
│ │ ├── Doxyfile
│ │ ├── LICENSE
│ │ ├── intro.doc
│ │ ├── lmdb.h
│ │ ├── mdb.c
│ │ ├── mdb_copy.1
│ │ ├── mdb_copy.c
│ │ ├── mdb_dump.1
│ │ ├── mdb_dump.c
│ │ ├── mdb_load.1
│ │ ├── mdb_load.c
│ │ ├── mdb_stat.1
│ │ ├── mdb_stat.c
│ │ ├── midl.c
│ │ ├── midl.h
│ │ ├── mtest.c
│ │ ├── mtest2.c
│ │ ├── mtest3.c
│ │ ├── mtest4.c
│ │ ├── mtest5.c
│ │ ├── mtest6.c
│ │ ├── sample-bdb.txt
│ │ ├── sample-mdb.txt
│ │ └── tooltag
├── lmdb
│ └── libraries
│ │ └── liblmdb
│ │ ├── .gitignore
│ │ ├── COPYRIGHT
│ │ ├── Doxyfile
│ │ ├── LICENSE
│ │ ├── Makefile
│ │ ├── chacha8.c
│ │ ├── chacha8.h
│ │ ├── crypto.c
│ │ ├── intro.doc
│ │ ├── lmdb.h
│ │ ├── mdb.c
│ │ ├── mdb_copy.1
│ │ ├── mdb_copy.c
│ │ ├── mdb_drop.1
│ │ ├── mdb_drop.c
│ │ ├── mdb_dump.1
│ │ ├── mdb_dump.c
│ │ ├── mdb_load.1
│ │ ├── mdb_load.c
│ │ ├── mdb_stat.1
│ │ ├── mdb_stat.c
│ │ ├── midl-sparse.c
│ │ ├── midl.c
│ │ ├── midl.h
│ │ ├── module.c
│ │ ├── module.h
│ │ ├── mtest.c
│ │ ├── mtest2.c
│ │ ├── mtest3.c
│ │ ├── mtest4.c
│ │ ├── mtest5.c
│ │ ├── mtest6.c
│ │ ├── mtest_enc.c
│ │ ├── mtest_enc2.c
│ │ ├── mtest_remap.c
│ │ ├── sample-bdb.txt
│ │ ├── sample-mdb.txt
│ │ └── tooltag
├── lz4
│ ├── LICENSE
│ └── lib
│ │ ├── .gitignore
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── dll
│ │ ├── example
│ │ │ ├── README.md
│ │ │ ├── fullbench-dll.sln
│ │ │ └── fullbench-dll.vcxproj
│ │ └── liblz4.def
│ │ ├── liblz4-dll.rc.in
│ │ ├── liblz4.pc.in
│ │ ├── lz4.c
│ │ ├── lz4.h
│ │ ├── lz4file.c
│ │ ├── lz4file.h
│ │ ├── lz4frame.c
│ │ ├── lz4frame.h
│ │ ├── lz4frame_static.h
│ │ ├── lz4hc.c
│ │ ├── lz4hc.h
│ │ ├── xxhash.c
│ │ └── xxhash.h
└── v8
│ ├── v8-fast-api-calls-v16.h
│ └── v8-fast-api-calls.h
├── dict
├── dict.txt
└── dict2.txt
├── index.d.ts
├── index.js
├── keys.js
├── level.js
├── native.js
├── node-index.js
├── open.js
├── package.json
├── read.js
├── rollup.config.js
├── src
├── .npmignore
├── compression.cpp
├── cursor.cpp
├── dbi.cpp
├── env.cpp
├── lmdb-js.cpp
├── lmdb-js.h
├── misc.cpp
├── ordered-binary.cpp
├── txn.cpp
├── v8-functions.cpp
├── windows.c
└── writer.cpp
├── test
├── bun.js
├── check-commit.js
├── cluster.js
├── deno.js
├── deno.sh
├── deno.ts
├── index.test.js
├── lock-test.js
├── performance.js
├── readonly-threads.cjs
├── threads.cjs
└── types
│ └── index.test-d.ts
├── util
├── RangeIterable.js
├── remove-optional-deps.cjs
├── set-optional-deps.cjs
└── when.js
└── write.js
/.github/workflows/test-arm64.yml:
--------------------------------------------------------------------------------
1 | name: Test ARM64
2 | on:
3 | workflow_dispatch:
4 | jobs:
5 | test-arm7:
6 | runs-on: ubuntu-latest
7 | steps:
8 | - uses: actions/checkout@v2.1.0
9 | - run: sudo apt-get update
10 | - run: sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
11 | - name: Setup node
12 | uses: actions/setup-node@v2
13 | with:
14 | node-version: 18.6
15 | - run: npm install --ignore-scripts
16 | - run: npm run build-js
17 | - run: npm run prebuildify
18 | env:
19 | PREBUILD_ARCH: arm64
20 | CC: aarch64-linux-gnu-gcc
21 | CXX: aarch64-linux-gnu-g++
22 | - uses: uraimo/run-on-arch-action@v2
23 | name: Run commands
24 | id: runcmd
25 | with:
26 | arch: aarch64
27 | distro: ubuntu20.04
28 |
29 | # Not required, but speeds up builds by storing container images in
30 | # a GitHub package registry.
31 | githubToken: ${{ github.token }}
32 |
33 | # Set an output parameter `uname` for use in subsequent steps
34 | install: |
35 | apt-get update
36 | apt-get install -y curl libatomic1 python3 gcc g++ make
37 | curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
38 | export NVM_DIR="$HOME/.nvm"
39 | [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
40 | nvm install 18.6
41 | run: |
42 | export NVM_DIR="$HOME/.nvm"
43 | [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
44 | node_modules/.bin/mocha test/**.test.js --recursive
--------------------------------------------------------------------------------
/.github/workflows/test-arm7.yml:
--------------------------------------------------------------------------------
1 | name: Test ARM7
2 | on:
3 | workflow_dispatch:
4 | jobs:
5 | test-arm7:
6 | runs-on: ubuntu-latest
7 | steps:
8 | - uses: actions/checkout@v2.1.0
9 | - run: sudo apt-get update
10 | - run: sudo apt-get install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
11 | - name: Setup node
12 | uses: actions/setup-node@v2
13 | with:
14 | node-version: 16
15 | - run: npm install --ignore-scripts
16 | - run: npm run build-js
17 | - run: npm run prebuildify
18 | env:
19 | PREBUILD_ARCH: arm
20 | PREBUILD_ARMV: 7
21 | CC: arm-linux-gnueabihf-gcc
22 | CXX: arm-linux-gnueabihf-g++
23 | - uses: uraimo/run-on-arch-action@v2
24 | name: Run commands
25 | id: runcmd
26 | with:
27 | arch: armv7
28 | distro: ubuntu20.04
29 |
30 | # Not required, but speeds up builds by storing container images in
31 | # a GitHub package registry.
32 | githubToken: ${{ github.token }}
33 |
34 | # Set an output parameter `uname` for use in subsequent steps
35 | install: |
36 | apt-get update
37 | apt-get install -y curl libatomic1 python3 gcc g++ make
38 | curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
39 | export NVM_DIR="$HOME/.nvm"
40 | [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
41 | nvm install 16
42 | run: |
43 | export NVM_DIR="$HOME/.nvm"
44 | [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
45 | node_modules/.bin/mocha test/**.test.js --recursive
--------------------------------------------------------------------------------
/.github/workflows/test-install.yml:
--------------------------------------------------------------------------------
1 | name: Test Install
2 | on:
3 | workflow_dispatch:
4 |
5 | jobs:
6 | build-alpine:
7 | runs-on: ubuntu-latest
8 | container: node:18-alpine
9 | steps:
10 | - run: apk update && apk add --no-cache nodejs npm python3 py3-pip build-base
11 | - run: npm install lmdb --ignore-scripts --verbose
12 | - run: node -e "console.log(require('lmdb'))"
13 | - run: npm install lmdb --verbose
14 | - run: node -e "console.log(require('lmdb'))"
--------------------------------------------------------------------------------
/.github/workflows/test-integration.yml:
--------------------------------------------------------------------------------
1 | name: Test Parcel
2 | on:
3 | workflow_dispatch:
4 | jobs:
5 | test-parcel:
6 | runs-on: ubuntu-latest
7 | container: node:14-stretch
8 | steps:
9 | - uses: actions/checkout@v2.1.0
10 | - run: git clone https://github.com/kriszyp/parcel-segfault-repro.git
11 | - run: npm install
12 | - run: npm run build-js
13 | - run: npm run recompile
14 | - run: npm link
15 | - run: cd parcel-segfault-repro && npm install && npm link lmdb && chmod 777 multiple.sh && ./multiple.sh
16 |
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: Tests
2 |
3 | on: [pull_request]
4 |
5 | concurrency:
6 | cancel-in-progress: ${{ github.event_name == 'pull_request' }}
7 | group: ${{ github.workflow }}-${{ github.ref }}
8 |
9 | jobs:
10 | test:
11 | name: Test on Node.js ${{ matrix.node }} and ${{ matrix.os }}
12 | runs-on: ${{ matrix.os }}
13 | strategy:
14 | fail-fast: false
15 | matrix:
16 | node: [16, 18, 20, 22]
17 | os: [ubuntu-latest, windows-latest, macos-latest]
18 |
19 | steps:
20 | - name: Checkout repository
21 | uses: actions/checkout@v4
22 |
23 | - name: Setup node
24 | uses: actions/setup-node@v4
25 | with:
26 | node-version: ${{ matrix.node }}
27 |
28 | - name: Install dependencies
29 | if: |
30 | !(matrix.node == 16 && matrix.os == 'macos-latest') || (matrix.node == 22 && matrix.os == 'windows-latest'))
31 | run: npm install
32 |
33 | - name: Build
34 | if: |
35 | !(matrix.node == 16 && matrix.os == 'macos-latest') || (matrix.node == 22 && matrix.os == 'windows-latest'))
36 | run: npm run build
37 |
38 | - name: Run tests
39 | if: |
40 | !(matrix.node == 16 && matrix.os == 'macos-latest') || (matrix.node == 22 && matrix.os == 'windows-latest'))
41 | run: npm test
42 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Build and test data
2 | build
3 | prebuilds
4 | testdata
5 | test/testdata*
6 | benchmark/benchdata*
7 | dist
8 | index.d.cts
9 |
10 | # qmake autogenerated files
11 | moc_*
12 | qrc_*
13 | ui_*
14 | Makefile
15 |
16 | # Qt Creator's stuff
17 | *.pro.user
18 | qtc_packaging
19 |
20 | # Other generated files
21 | *.o
22 | *.slo
23 | *.lo
24 | *.core
25 | MANIFEST
26 |
27 | # gedit's temp files
28 | *~
29 | .goutputstream*
30 |
31 | # Compiled Dynamic libraries
32 | *.so
33 | *.dylib
34 |
35 | # Compiled Static libraries
36 | *.lai
37 | *.la
38 | *.a
39 |
40 | # NPM dependencies
41 | node_modules/
42 | yarn.lock
43 |
44 | # Visual Studio Code directory
45 | .vscode
46 | .vs
47 | .idea
48 |
49 | package-lock.json
50 | yarn.lock
51 |
52 | tests/db/
53 | test/db/
54 |
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "bitwise": false,
3 | "browser": true,
4 | "camelcase": false,
5 | "curly": true,
6 | "devel": false,
7 | "eqeqeq": true,
8 | "esnext": true,
9 | "freeze": true,
10 | "immed": true,
11 | "indent": 2,
12 | "latedef": true,
13 | "newcap": false,
14 | "noarg": true,
15 | "node": true,
16 | "noempty": true,
17 | "nonew": true,
18 | "quotmark": "single",
19 | "regexp": true,
20 | "smarttabs": false,
21 | "strict": true,
22 | "trailing": true,
23 | "undef": true,
24 | "unused": true,
25 | "maxparams": 4,
26 | "maxstatements": 15,
27 | "maxcomplexity": 10,
28 | "maxdepth": 3,
29 | "maxlen": 120,
30 | "multistr": true,
31 | "predef": [
32 | "after",
33 | "afterEach",
34 | "before",
35 | "beforeEach",
36 | "describe",
37 | "exports",
38 | "it",
39 | "module",
40 | "require"
41 | ]
42 | }
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 |
2 | # Build and test data
3 | build
4 | tests
5 | testdata
6 | test/testdata*
7 | benchmark/benchdata
8 | .github
9 | .gitignore
10 | *.sln
11 | *.vcxproj
12 |
13 | # qmake autogenerated files
14 | moc_*
15 | qrc_*
16 | ui_*
17 | Makefile
18 |
19 | # Qt Creator's stuff
20 | *.pro.user
21 | qtc_packaging
22 |
23 | # Other generated files
24 | *.o
25 | *.slo
26 | *.lo
27 | *.core
28 | MANIFEST
29 |
30 | # gedit's temp files
31 | *~
32 | .goutputstream*
33 |
34 | # Compiled Dynamic libraries
35 | *.so
36 | *.dylib
37 |
38 | # Compiled Static libraries
39 | *.lai
40 | *.la
41 | *.a
42 |
43 | # NPM dependencies
44 | node_modules/
45 |
46 | # Visual Studio Code directory
47 | .vscode
48 | .vs
49 |
50 | package-lock.json
51 |
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | loglevel=error
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | This project contains is based on the code from the node-lmdb project ([Copyright (c) 2014 Timur Kristóf](https://github.com/venemo/node-lmdb/)) and LMDB, which has a specific [OpenLDAP license](dependencies/lmdb/libraries/liblmdb/LICENSE),
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security Policy
2 |
3 | ## Supported Versions
4 |
5 | | Version | Supported |
6 | | ------- | ------------------ |
7 | | 1.6.x | :white_check_mark: |
8 | | 2.0.x | :white_check_mark: |
9 |
10 | ## Reporting a Vulnerability
11 |
12 | Please report security vulnerabilities to kriszyp@gmail.com.
13 |
--------------------------------------------------------------------------------
/assets/gatsby.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kriszyp/lmdb-js/21086a6864f1a189e7f3899e20956b3d3d0a4ae8/assets/gatsby.png
--------------------------------------------------------------------------------
/assets/harperdb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kriszyp/lmdb-js/21086a6864f1a189e7f3899e20956b3d3d0a4ae8/assets/harperdb.png
--------------------------------------------------------------------------------
/assets/parcel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kriszyp/lmdb-js/21086a6864f1a189e7f3899e20956b3d3d0a4ae8/assets/parcel.png
--------------------------------------------------------------------------------
/assets/performance.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kriszyp/lmdb-js/21086a6864f1a189e7f3899e20956b3d3d0a4ae8/assets/performance.png
--------------------------------------------------------------------------------
/assets/powers-dre.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kriszyp/lmdb-js/21086a6864f1a189e7f3899e20956b3d3d0a4ae8/assets/powers-dre.png
--------------------------------------------------------------------------------
/benchmark/low-level.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | var inspector = require('inspector')
3 | //inspector.open(9330, null, true)
4 |
5 | var crypto = require('crypto');
6 | var path = require('path');
7 | var testDirPath = path.resolve(__dirname, './benchdata');
8 |
9 | var fs =require('fs');
10 | var rimraf = require('rimraf');
11 | var mkdirp = require('mkdirp');
12 | var benchmark = require('benchmark');
13 | var suite = new benchmark.Suite();
14 |
15 | var lmdb = require('..');
16 |
17 | var env;
18 | var dbi;
19 | var keys = [];
20 | var total = 10000;
21 | var store;
22 |
23 | function cleanup(done) {
24 | // cleanup previous test directory
25 | rimraf(testDirPath, function(err) {
26 | if (err) {
27 | return done(err);
28 | }
29 | // setup clean directory
30 | mkdirp(testDirPath).then(() => {
31 | done();
32 | }, error => done(error));
33 | });
34 | }
35 |
36 | function setup() {
37 | env = new lmdb.Env();
38 | env.open({
39 | path: testDirPath,
40 | maxDbs: 10,
41 | mapSize: 1024 * 1024 * 1024
42 | });
43 | dbi = env.openDbi({
44 | name: 'benchmarks',
45 | create: true,
46 | compression: new lmdb.Compression({
47 | threshold: 1000,
48 | dictionary: fs.readFileSync(require.resolve('../dict/dict.txt')),
49 | })
50 | });
51 |
52 | var txn = env.beginTxn();
53 | var c = 0;
54 | let value = 'hello world!'
55 | for (let i = 0; i < 6; i++) {
56 | value += value
57 | }
58 | while(c < total) {
59 | var key = new Buffer(new Array(8));
60 | key.writeDoubleBE(c);
61 | keys.push(key.toString('hex'));
62 | txn.putUtf8(dbi, key.toString('hex'), 'testing small');
63 | c++;
64 | }
65 | txn.commit();
66 | store = lmdb.open(testDirPath + '.mdb', {
67 | encoding: 'string'
68 | })
69 | var c= 0;
70 | let lastPromise
71 | while(c < total) {
72 | var key = new Buffer(new Array(8));
73 | key.writeDoubleBE(c);
74 | keys.push(key.toString('hex'));
75 | lastPromise = store.put(key.toString('hex'), 'testing small');
76 | c++;
77 | }
78 | return lastPromise.then(() => {
79 | console.log('all committed');
80 | })
81 | }
82 |
83 | var txn;
84 | var c = 0;
85 |
86 | function getIndex() {
87 | if (c < total - 1) {
88 | c++;
89 | } else {
90 | c = 0;
91 | }
92 | return c;
93 | }
94 |
95 | function getBinary() {
96 | var data = txn.getBinary(dbi, keys[getIndex()]);
97 | }
98 |
99 | function getBinaryUnsafe() {
100 | //try {
101 | //txn.renew()
102 | var data = txn.getBinaryUnsafe(dbi, keys[getIndex()]);
103 | //var b = dbi.unsafeBuffer
104 | //txn.reset()
105 | //}catch(error){console.error(error)}
106 | }
107 | function getStringFromStore() {
108 | var data = store.get(keys[getIndex()]);
109 | }
110 |
111 | function getString() {
112 | var data = txn.getUtf8(dbi, keys[getIndex()]);
113 | }
114 |
115 | function getStringUnsafe() {
116 | var data = txn.getStringUnsafe(dbi, keys[getIndex()]);
117 | }
118 |
119 | let cursor;
120 |
121 | function cursorGoToNext() {
122 | let readed = 0;
123 |
124 | return () => {
125 | let c = cursor.goToNext();
126 | readed++;
127 | if (readed >= total) {
128 | c = cursor.goToRange(keys[0]);
129 | readed = 0; // reset to prevent goToRange on every loop
130 | }
131 | }
132 | }
133 |
134 | function cursorGoToNextgetCurrentString() {
135 | let readed = 0;
136 | return () => {
137 | const c = cursor.goToNext();
138 | readed++;
139 | if (readed >= total) {
140 | cursor.goToRange(keys[0]);
141 | readed = 0; // reset to prevent goToRange on every loop
142 | }
143 | const v = cursor.getCurrentUtf8();
144 | }
145 | }
146 | let b = Buffer.from('Hi there!');
147 | function bufferToKeyValue() {
148 | if (lmdb.bufferToKeyValue(b) != 'Hi there!')
149 | throw new Error('wrong string')
150 |
151 | }
152 | function keyValueToBuffer() {
153 | if (!lmdb.keyValueToBuffer('Hi there!').equals(b))
154 | throw new Error('wrong string')
155 |
156 | }
157 |
158 | cleanup(async function (err) {
159 | if (err) {
160 | throw err;
161 | }
162 |
163 | await setup();
164 |
165 | // suite.add('getBinary', getBinary);
166 | suite.add('getStringFromStore', getStringFromStore);
167 | //suite.add('bufferToKeyValue', bufferToKeyValue)
168 | //suite.add('keyValueToBuffer', keyValueToBuffer)
169 | suite.add('getString', getString);
170 | suite.add('getBinaryUnsafe', getBinaryUnsafe);
171 | suite.add('getStringUnsafe', getStringUnsafe);
172 | //suite.add('cursorGoToNext', cursorGoToNext());
173 | suite.add('cursorGoToNextgetCurrentString', cursorGoToNextgetCurrentString());
174 |
175 | suite.on('start', function () {
176 | txn = env.beginTxn({
177 | readOnly: true
178 | });
179 | });
180 |
181 | suite.on('cycle', function (event) {
182 | txn.abort();
183 | txn = env.beginTxn({
184 | readOnly: true
185 | });
186 | if (cursor) cursor.close();
187 | cursor = new lmdb.Cursor(txn, dbi);
188 | console.log(String(event.target));
189 | });
190 |
191 | suite.on('complete', function () {
192 | txn.abort();
193 | dbi.close();
194 | env.close();
195 | if (cursor)
196 | cursor.close();
197 | console.log('Fastest is ' + this.filter('fastest').map('name'));
198 | });
199 |
200 | suite.run();
201 |
202 | });
--------------------------------------------------------------------------------
/benchmark/read-async.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 | import { Worker, isMainThread, parentPort, threadId } from'worker_threads';
3 | import { isMaster, fork } from 'cluster';
4 | import inspector from 'inspector'
5 | //inspector.open(9229, null, true);
6 | debugger;
7 | var testDirPath = new URL('./benchdata', import.meta.url).toString().slice(8);
8 | import fs from 'fs';
9 | import rimraf from 'rimraf';
10 |
11 | import { open } from '../index.js';
12 | import { nativeAddon } from '../native.js';
13 | let { noop } = nativeAddon;
14 | var env;
15 | var dbi;
16 | var keys = [];
17 | var total = 100;
18 | var store
19 | let data = {
20 | name: 'test',
21 | greeting: 'Hello, World!',
22 | flag: true,
23 | littleNum: 3,
24 | biggerNum: 32254435,
25 | decimal:1.332232,
26 | bigDecimal: 3.5522E102,
27 | negative: -54,
28 | aNull: null,
29 | more: 'string',
30 | }
31 | let bigString = 'big'
32 | for (let i = 0; i < 14; i++) {
33 | bigString += bigString
34 | }
35 | //data.more = bigString
36 | console.log(bigString.length)
37 | var c = 0
38 | let result
39 |
40 | let start;
41 | let outstanding = 0
42 | let iteration = 1
43 | function getAsync() {
44 | console.log('getAsync');
45 | outstanding++;
46 | store.getAsync((c += 357) % total, {}, function() {
47 | outstanding--;
48 | });
49 | }
50 |
51 | function setup() {
52 | console.log('opening', testDirPath)
53 | let rootStore = open(testDirPath, {
54 | //noMemInit: true,
55 | //pageSize: 0x4000,
56 | //compression: true,
57 | //noSync: true,
58 | //winMemoryPriority: 4,
59 | //eventTurnBatching: false,
60 | //overlappingSync: true,
61 | })
62 | store = rootStore.openDB('testing', {
63 | //create: true,
64 | sharedStructuresKey: 100000000,
65 | keyIsUint32: true,
66 | //compression: true,
67 | })
68 | let lastPromise
69 | for (let i = 0; i < total; i++) {
70 | lastPromise = store.put(i, data)
71 | }
72 | return lastPromise?.then(() => {
73 | console.log('setup completed');
74 | })
75 | }
76 | var txn;
77 | (async function() {
78 | await setup();
79 |
80 | start = performance.now();
81 | for (let i = 0; i < 1000000; i++) {
82 | outstanding++;
83 | //if (i % 100 == 0)
84 | //console.log({outstanding})
85 | if (i % 1000 == 0)
86 | await new Promise(r => setImmediate(r));
87 | store.getAsync((i * 357) % total, {}, function (result) {
88 | outstanding--;
89 | //if (i % 100000 == 0)
90 | //console.log(i, result, outstanding)
91 | if (i == 999999) {
92 | console.log('done', outstanding, performance.now() - start)
93 | }
94 | });
95 | }
96 | console.log('finished enqueuing', outstanding, performance.now() - start)
97 | })();
--------------------------------------------------------------------------------
/bin/download-prebuilds.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | import { dirname } from 'path';
4 | import { fileURLToPath } from 'url';
5 | import { exec } from 'child_process';
6 |
7 | exec('download-msgpackr-prebuilds', propagateOutput);
8 | process.chdir(fileURLToPath(dirname(dirname(import.meta.url))));
9 | exec('prebuildify-ci download', propagateOutput);
10 | function propagateOutput(error, stdout, stderr) {
11 | console.error(stderr);
12 | console.log(stdout);
13 | if (error?.code)
14 | process.exit(error.code);
15 | }
--------------------------------------------------------------------------------
/binding.gyp:
--------------------------------------------------------------------------------
1 | {
2 | "variables": {
3 | "os_linux_compiler%": "gcc",
4 | "use_robust%": "true",
5 | "use_data_v1%": "false",
6 | "enable_v8%": "true",
7 | "enable_fast_api_calls%": "true",
8 | "enable_pointer_compression%": "false",
9 | "openssl_fips": "X",
10 | "target%": "",
11 | "build_v8_with_gn": "false",
12 | "runtime%": "node"
13 | },
14 | "conditions": [
15 | ['OS=="win"', {
16 | "variables": {
17 | "enable_fast_api_calls%": ".
11 |
12 | OpenLDAP is a registered trademark of the OpenLDAP Foundation.
13 |
14 | Individual files and/or contributed packages may be copyright by
15 | other parties and/or subject to additional restrictions.
16 |
17 | This work also contains materials derived from public sources.
18 |
19 | Additional information about OpenLDAP can be obtained at
20 | .
21 |
--------------------------------------------------------------------------------
/dependencies/lmdb-data-v1/libraries/liblmdb/LICENSE:
--------------------------------------------------------------------------------
1 | The OpenLDAP Public License
2 | Version 2.8, 17 August 2003
3 |
4 | Redistribution and use of this software and associated documentation
5 | ("Software"), with or without modification, are permitted provided
6 | that the following conditions are met:
7 |
8 | 1. Redistributions in source form must retain copyright statements
9 | and notices,
10 |
11 | 2. Redistributions in binary form must reproduce applicable copyright
12 | statements and notices, this list of conditions, and the following
13 | disclaimer in the documentation and/or other materials provided
14 | with the distribution, and
15 |
16 | 3. Redistributions must contain a verbatim copy of this document.
17 |
18 | The OpenLDAP Foundation may revise this license from time to time.
19 | Each revision is distinguished by a version number. You may use
20 | this Software under terms of this license revision or under the
21 | terms of any subsequent revision of the license.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE OPENLDAP FOUNDATION AND ITS
24 | CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27 | SHALL THE OPENLDAP FOUNDATION, ITS CONTRIBUTORS, OR THE AUTHOR(S)
28 | OR OWNER(S) OF THE SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | POSSIBILITY OF SUCH DAMAGE.
36 |
37 | The names of the authors and copyright holders must not be used in
38 | advertising or otherwise to promote the sale, use or other dealing
39 | in this Software without specific, written prior permission. Title
40 | to copyright in this Software shall at all times remain with copyright
41 | holders.
42 |
43 | OpenLDAP is a registered trademark of the OpenLDAP Foundation.
44 |
45 | Copyright 1999-2003 The OpenLDAP Foundation, Redwood City,
46 | California, USA. All Rights Reserved. Permission to copy and
47 | distribute verbatim copies of this document is granted.
48 |
--------------------------------------------------------------------------------
/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_copy.1:
--------------------------------------------------------------------------------
1 | .TH MDB_COPY 1 "2014/07/01" "LMDB 0.9.14"
2 | .\" Copyright 2012-2021 Howard Chu, Symas Corp. All Rights Reserved.
3 | .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
4 | .SH NAME
5 | mdb_copy \- LMDB environment copy tool
6 | .SH SYNOPSIS
7 | .B mdb_copy
8 | [\c
9 | .BR \-V ]
10 | [\c
11 | .BR \-c ]
12 | [\c
13 | .BR \-n ]
14 | .B srcpath
15 | [\c
16 | .BR dstpath ]
17 | .SH DESCRIPTION
18 | The
19 | .B mdb_copy
20 | utility copies an LMDB environment. The environment can
21 | be copied regardless of whether it is currently in use.
22 | No lockfile is created, since it gets recreated at need.
23 |
24 | If
25 | .I dstpath
26 | is specified it must be the path of an empty directory
27 | for storing the backup. Otherwise, the backup will be
28 | written to stdout.
29 |
30 | .SH OPTIONS
31 | .TP
32 | .BR \-V
33 | Write the library version number to the standard output, and exit.
34 | .TP
35 | .BR \-c
36 | Compact while copying. Only current data pages will be copied; freed
37 | or unused pages will be omitted from the copy. This option will
38 | slow down the backup process as it is more CPU-intensive.
39 | Currently it fails if the environment has suffered a page leak.
40 | .TP
41 | .BR \-n
42 | Open LDMB environment(s) which do not use subdirectories.
43 |
44 | .SH DIAGNOSTICS
45 | Exit status is zero if no errors occur.
46 | Errors result in a non-zero exit status and
47 | a diagnostic message being written to standard error.
48 | .SH CAVEATS
49 | This utility can trigger significant file size growth if run
50 | in parallel with write transactions, because pages which they
51 | free during copying cannot be reused until the copy is done.
52 | .SH "SEE ALSO"
53 | .BR mdb_stat (1)
54 | .SH AUTHOR
55 | Howard Chu of Symas Corporation
56 |
--------------------------------------------------------------------------------
/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_copy.c:
--------------------------------------------------------------------------------
1 | /* mdb_copy.c - memory-mapped database backup tool */
2 | /*
3 | * Copyright 2012-2021 Howard Chu, Symas Corp.
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted only as authorized by the OpenLDAP
8 | * Public License.
9 | *
10 | * A copy of this license is available in the file LICENSE in the
11 | * top-level directory of the distribution or, alternatively, at
12 | * .
13 | */
14 | #ifdef _WIN32
15 | #include
16 | #define MDB_STDOUT GetStdHandle(STD_OUTPUT_HANDLE)
17 | #else
18 | #define MDB_STDOUT 1
19 | #endif
20 | #include
21 | #include
22 | #include
23 | #include "lmdb.h"
24 |
25 | static void
26 | sighandle(int sig)
27 | {
28 | }
29 |
30 | int main(int argc,char * argv[])
31 | {
32 | int rc;
33 | MDB_env *env;
34 | const char *progname = argv[0], *act;
35 | unsigned flags = MDB_RDONLY;
36 | unsigned cpflags = 0;
37 |
38 | for (; argc > 1 && argv[1][0] == '-'; argc--, argv++) {
39 | if (argv[1][1] == 'n' && argv[1][2] == '\0')
40 | flags |= MDB_NOSUBDIR;
41 | else if (argv[1][1] == 'c' && argv[1][2] == '\0')
42 | cpflags |= MDB_CP_COMPACT;
43 | else if (argv[1][1] == 'V' && argv[1][2] == '\0') {
44 | printf("%s\n", MDB_VERSION_STRING);
45 | exit(0);
46 | } else
47 | argc = 0;
48 | }
49 |
50 | if (argc<2 || argc>3) {
51 | fprintf(stderr, "usage: %s [-V] [-c] [-n] srcpath [dstpath]\n", progname);
52 | exit(EXIT_FAILURE);
53 | }
54 |
55 | #ifdef SIGPIPE
56 | signal(SIGPIPE, sighandle);
57 | #endif
58 | #ifdef SIGHUP
59 | signal(SIGHUP, sighandle);
60 | #endif
61 | signal(SIGINT, sighandle);
62 | signal(SIGTERM, sighandle);
63 |
64 | act = "opening environment";
65 | rc = mdb_env_create(&env);
66 | if (rc == MDB_SUCCESS) {
67 | rc = mdb_env_open(env, argv[1], flags, 0600);
68 | }
69 | if (rc == MDB_SUCCESS) {
70 | act = "copying";
71 | if (argc == 2)
72 | rc = mdb_env_copyfd2(env, MDB_STDOUT, cpflags);
73 | else
74 | rc = mdb_env_copy2(env, argv[2], cpflags);
75 | }
76 | if (rc)
77 | fprintf(stderr, "%s: %s failed, error %d (%s)\n",
78 | progname, act, rc, mdb_strerror(rc));
79 | mdb_env_close(env);
80 |
81 | return rc ? EXIT_FAILURE : EXIT_SUCCESS;
82 | }
83 |
--------------------------------------------------------------------------------
/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_dump.1:
--------------------------------------------------------------------------------
1 | .TH MDB_DUMP 1 "2015/09/30" "LMDB 0.9.17"
2 | .\" Copyright 2014-2021 Howard Chu, Symas Corp. All Rights Reserved.
3 | .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
4 | .SH NAME
5 | mdb_dump \- LMDB environment export tool
6 | .SH SYNOPSIS
7 | .B mdb_dump
8 | [\c
9 | .BR \-V ]
10 | [\c
11 | .BI \-f \ file\fR]
12 | [\c
13 | .BR \-l ]
14 | [\c
15 | .BR \-n ]
16 | [\c
17 | .BR \-p ]
18 | [\c
19 | .BR \-a \ |
20 | .BI \-s \ subdb\fR]
21 | .BR \ envpath
22 | .SH DESCRIPTION
23 | The
24 | .B mdb_dump
25 | utility reads a database and writes its contents to the
26 | standard output using a portable flat-text format
27 | understood by the
28 | .BR mdb_load (1)
29 | utility.
30 | .SH OPTIONS
31 | .TP
32 | .BR \-V
33 | Write the library version number to the standard output, and exit.
34 | .TP
35 | .BR \-f \ file
36 | Write to the specified file instead of to the standard output.
37 | .TP
38 | .BR \-l
39 | List the databases stored in the environment. Just the
40 | names will be listed, no data will be output.
41 | .TP
42 | .BR \-n
43 | Dump an LMDB database which does not use subdirectories.
44 | .TP
45 | .BR \-p
46 | If characters in either the key or data items are printing characters (as
47 | defined by isprint(3)), output them directly. This option permits users to
48 | use standard text editors and tools to modify the contents of databases.
49 |
50 | Note: different systems may have different notions about what characters
51 | are considered printing characters, and databases dumped in this manner may
52 | be less portable to external systems.
53 | .TP
54 | .BR \-a
55 | Dump all of the subdatabases in the environment.
56 | .TP
57 | .BR \-s \ subdb
58 | Dump a specific subdatabase. If no database is specified, only the main database is dumped.
59 | .SH DIAGNOSTICS
60 | Exit status is zero if no errors occur.
61 | Errors result in a non-zero exit status and
62 | a diagnostic message being written to standard error.
63 |
64 | Dumping and reloading databases that use user-defined comparison functions
65 | will result in new databases that use the default comparison functions.
66 | \fBIn this case it is quite likely that the reloaded database will be
67 | damaged beyond repair permitting neither record storage nor retrieval.\fP
68 |
69 | The only available workaround is to modify the source for the
70 | .BR mdb_load (1)
71 | utility to load the database using the correct comparison functions.
72 | .SH "SEE ALSO"
73 | .BR mdb_load (1)
74 | .SH AUTHOR
75 | Howard Chu of Symas Corporation
76 |
--------------------------------------------------------------------------------
/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_load.1:
--------------------------------------------------------------------------------
1 | .TH MDB_LOAD 1 "2015/09/30" "LMDB 0.9.17"
2 | .\" Copyright 2014-2021 Howard Chu, Symas Corp. All Rights Reserved.
3 | .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
4 | .SH NAME
5 | mdb_load \- LMDB environment import tool
6 | .SH SYNOPSIS
7 | .B mdb_load
8 | [\c
9 | .BR \-V ]
10 | [\c
11 | .BI \-f \ file\fR]
12 | [\c
13 | .BR \-n ]
14 | [\c
15 | .BI \-s \ subdb\fR]
16 | [\c
17 | .BR \-N ]
18 | [\c
19 | .BR \-T ]
20 | .BR \ envpath
21 | .SH DESCRIPTION
22 | The
23 | .B mdb_load
24 | utility reads from the standard input and loads it into the
25 | LMDB environment
26 | .BR envpath .
27 |
28 | The input to
29 | .B mdb_load
30 | must be in the output format specified by the
31 | .BR mdb_dump (1)
32 | utility or as specified by the
33 | .B -T
34 | option below.
35 | .SH OPTIONS
36 | .TP
37 | .BR \-V
38 | Write the library version number to the standard output, and exit.
39 | .TP
40 | .BR \-a
41 | Append all records in the order they appear in the input. The input is assumed to already be
42 | in correctly sorted order and no sorting or checking for redundant values will be performed.
43 | This option must be used to reload data that was produced by running
44 | .B mdb_dump
45 | on a database that uses custom compare functions.
46 | .TP
47 | .BR \-f \ file
48 | Read from the specified file instead of from the standard input.
49 | .TP
50 | .BR \-n
51 | Load an LMDB database which does not use subdirectories.
52 | .TP
53 | .BR \-s \ subdb
54 | Load a specific subdatabase. If no database is specified, data is loaded into the main database.
55 | .TP
56 | .BR \-N
57 | Don't overwrite existing records when loading into an already existing database; just skip them.
58 | .TP
59 | .BR \-T
60 | Load data from simple text files. The input must be paired lines of text, where the first
61 | line of the pair is the key item, and the second line of the pair is its corresponding
62 | data item.
63 |
64 | A simple escape mechanism, where newline and backslash (\\) characters are special, is
65 | applied to the text input. Newline characters are interpreted as record separators.
66 | Backslash characters in the text will be interpreted in one of two ways: If the backslash
67 | character precedes another backslash character, the pair will be interpreted as a literal
68 | backslash. If the backslash character precedes any other character, the two characters
69 | following the backslash will be interpreted as a hexadecimal specification of a single
70 | character; for example, \\0a is a newline character in the ASCII character set.
71 |
72 | For this reason, any backslash or newline characters that naturally occur in the text
73 | input must be escaped to avoid misinterpretation by
74 | .BR mdb_load .
75 |
76 | .SH DIAGNOSTICS
77 | Exit status is zero if no errors occur.
78 | Errors result in a non-zero exit status and
79 | a diagnostic message being written to standard error.
80 |
81 | .SH "SEE ALSO"
82 | .BR mdb_dump (1)
83 | .SH AUTHOR
84 | Howard Chu of Symas Corporation
85 |
--------------------------------------------------------------------------------
/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_stat.1:
--------------------------------------------------------------------------------
1 | .TH MDB_STAT 1 "2015/09/30" "LMDB 0.9.17"
2 | .\" Copyright 2012-2021 Howard Chu, Symas Corp. All Rights Reserved.
3 | .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
4 | .SH NAME
5 | mdb_stat \- LMDB environment status tool
6 | .SH SYNOPSIS
7 | .B mdb_stat
8 | [\c
9 | .BR \-V ]
10 | [\c
11 | .BR \-e ]
12 | [\c
13 | .BR \-f [ f [ f ]]]
14 | [\c
15 | .BR \-n ]
16 | [\c
17 | .BR \-r [ r ]]
18 | [\c
19 | .BR \-a \ |
20 | .BI \-s \ subdb\fR]
21 | .BR \ envpath
22 | .SH DESCRIPTION
23 | The
24 | .B mdb_stat
25 | utility displays the status of an LMDB environment.
26 | .SH OPTIONS
27 | .TP
28 | .BR \-V
29 | Write the library version number to the standard output, and exit.
30 | .TP
31 | .BR \-e
32 | Display information about the database environment.
33 | .TP
34 | .BR \-f
35 | Display information about the environment freelist.
36 | If \fB\-ff\fP is given, summarize each freelist entry.
37 | If \fB\-fff\fP is given, display the full list of page IDs in the freelist.
38 | .TP
39 | .BR \-n
40 | Display the status of an LMDB database which does not use subdirectories.
41 | .TP
42 | .BR \-r
43 | Display information about the environment reader table.
44 | Shows the process ID, thread ID, and transaction ID for each active
45 | reader slot. The process ID and transaction ID are in decimal, the
46 | thread ID is in hexadecimal. The transaction ID is displayed as "-"
47 | if the reader does not currently have a read transaction open.
48 | If \fB\-rr\fP is given, check for stale entries in the reader
49 | table and clear them. The reader table will be printed again
50 | after the check is performed.
51 | .TP
52 | .BR \-a
53 | Display the status of all of the subdatabases in the environment.
54 | .TP
55 | .BR \-s \ subdb
56 | Display the status of a specific subdatabase.
57 | .SH DIAGNOSTICS
58 | Exit status is zero if no errors occur.
59 | Errors result in a non-zero exit status and
60 | a diagnostic message being written to standard error.
61 | .SH "SEE ALSO"
62 | .BR mdb_copy (1)
63 | .SH AUTHOR
64 | Howard Chu of Symas Corporation
65 |
--------------------------------------------------------------------------------
/dependencies/lmdb-data-v1/libraries/liblmdb/mtest.c:
--------------------------------------------------------------------------------
1 | /* mtest.c - memory-mapped database tester/toy */
2 | /*
3 | * Copyright 2011-2021 Howard Chu, Symas Corp.
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted only as authorized by the OpenLDAP
8 | * Public License.
9 | *
10 | * A copy of this license is available in the file LICENSE in the
11 | * top-level directory of the distribution or, alternatively, at
12 | * .
13 | */
14 | #include
15 | #include
16 | #include
17 | #include "lmdb.h"
18 |
19 | #define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
20 | #define RES(err, expr) ((rc = expr) == (err) || (CHECK(!rc, #expr), 0))
21 | #define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
22 | "%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
23 |
24 | int main(int argc,char * argv[])
25 | {
26 | int i = 0, j = 0, rc;
27 | MDB_env *env;
28 | MDB_dbi dbi;
29 | MDB_val key, data;
30 | MDB_txn *txn;
31 | MDB_stat mst;
32 | MDB_cursor *cursor, *cur2;
33 | MDB_cursor_op op;
34 | int count;
35 | int *values;
36 | char sval[32] = "";
37 |
38 | srand(time(NULL));
39 |
40 | count = (rand()%384) + 64;
41 | values = (int *)malloc(count*sizeof(int));
42 |
43 | for(i = 0;i in each iteration, since MDB_NOOVERWRITE may modify it */
62 | data.mv_size = sizeof(sval);
63 | data.mv_data = sval;
64 | if (RES(MDB_KEYEXIST, mdb_put(txn, dbi, &key, &data, MDB_NOOVERWRITE))) {
65 | j++;
66 | data.mv_size = sizeof(sval);
67 | data.mv_data = sval;
68 | }
69 | }
70 | if (j) printf("%d duplicates skipped\n", j);
71 | E(mdb_txn_commit(txn));
72 | E(mdb_env_stat(env, &mst));
73 |
74 | E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
75 | E(mdb_cursor_open(txn, dbi, &cursor));
76 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
77 | printf("key: %p %.*s, data: %p %.*s\n",
78 | key.mv_data, (int) key.mv_size, (char *) key.mv_data,
79 | data.mv_data, (int) data.mv_size, (char *) data.mv_data);
80 | }
81 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
82 | mdb_cursor_close(cursor);
83 | mdb_txn_abort(txn);
84 |
85 | j=0;
86 | key.mv_data = sval;
87 | for (i= count - 1; i > -1; i-= (rand()%5)) {
88 | j++;
89 | txn=NULL;
90 | E(mdb_txn_begin(env, NULL, 0, &txn));
91 | sprintf(sval, "%03x ", values[i]);
92 | if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, NULL))) {
93 | j--;
94 | mdb_txn_abort(txn);
95 | } else {
96 | E(mdb_txn_commit(txn));
97 | }
98 | }
99 | free(values);
100 | printf("Deleted %d values\n", j);
101 |
102 | E(mdb_env_stat(env, &mst));
103 | E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
104 | E(mdb_cursor_open(txn, dbi, &cursor));
105 | printf("Cursor next\n");
106 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
107 | printf("key: %.*s, data: %.*s\n",
108 | (int) key.mv_size, (char *) key.mv_data,
109 | (int) data.mv_size, (char *) data.mv_data);
110 | }
111 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
112 | printf("Cursor last\n");
113 | E(mdb_cursor_get(cursor, &key, &data, MDB_LAST));
114 | printf("key: %.*s, data: %.*s\n",
115 | (int) key.mv_size, (char *) key.mv_data,
116 | (int) data.mv_size, (char *) data.mv_data);
117 | printf("Cursor prev\n");
118 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
119 | printf("key: %.*s, data: %.*s\n",
120 | (int) key.mv_size, (char *) key.mv_data,
121 | (int) data.mv_size, (char *) data.mv_data);
122 | }
123 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
124 | printf("Cursor last/prev\n");
125 | E(mdb_cursor_get(cursor, &key, &data, MDB_LAST));
126 | printf("key: %.*s, data: %.*s\n",
127 | (int) key.mv_size, (char *) key.mv_data,
128 | (int) data.mv_size, (char *) data.mv_data);
129 | E(mdb_cursor_get(cursor, &key, &data, MDB_PREV));
130 | printf("key: %.*s, data: %.*s\n",
131 | (int) key.mv_size, (char *) key.mv_data,
132 | (int) data.mv_size, (char *) data.mv_data);
133 |
134 | mdb_cursor_close(cursor);
135 | mdb_txn_abort(txn);
136 |
137 | printf("Deleting with cursor\n");
138 | E(mdb_txn_begin(env, NULL, 0, &txn));
139 | E(mdb_cursor_open(txn, dbi, &cur2));
140 | for (i=0; i<50; i++) {
141 | if (RES(MDB_NOTFOUND, mdb_cursor_get(cur2, &key, &data, MDB_NEXT)))
142 | break;
143 | printf("key: %p %.*s, data: %p %.*s\n",
144 | key.mv_data, (int) key.mv_size, (char *) key.mv_data,
145 | data.mv_data, (int) data.mv_size, (char *) data.mv_data);
146 | E(mdb_del(txn, dbi, &key, NULL));
147 | }
148 |
149 | printf("Restarting cursor in txn\n");
150 | for (op=MDB_FIRST, i=0; i<=32; op=MDB_NEXT, i++) {
151 | if (RES(MDB_NOTFOUND, mdb_cursor_get(cur2, &key, &data, op)))
152 | break;
153 | printf("key: %p %.*s, data: %p %.*s\n",
154 | key.mv_data, (int) key.mv_size, (char *) key.mv_data,
155 | data.mv_data, (int) data.mv_size, (char *) data.mv_data);
156 | }
157 | mdb_cursor_close(cur2);
158 | E(mdb_txn_commit(txn));
159 |
160 | printf("Restarting cursor outside txn\n");
161 | E(mdb_txn_begin(env, NULL, 0, &txn));
162 | E(mdb_cursor_open(txn, dbi, &cursor));
163 | for (op=MDB_FIRST, i=0; i<=32; op=MDB_NEXT, i++) {
164 | if (RES(MDB_NOTFOUND, mdb_cursor_get(cursor, &key, &data, op)))
165 | break;
166 | printf("key: %p %.*s, data: %p %.*s\n",
167 | key.mv_data, (int) key.mv_size, (char *) key.mv_data,
168 | data.mv_data, (int) data.mv_size, (char *) data.mv_data);
169 | }
170 | mdb_cursor_close(cursor);
171 | mdb_txn_abort(txn);
172 |
173 | mdb_dbi_close(env, dbi);
174 | mdb_env_close(env);
175 |
176 | return 0;
177 | }
178 |
--------------------------------------------------------------------------------
/dependencies/lmdb-data-v1/libraries/liblmdb/mtest2.c:
--------------------------------------------------------------------------------
1 | /* mtest2.c - memory-mapped database tester/toy */
2 | /*
3 | * Copyright 2011-2021 Howard Chu, Symas Corp.
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted only as authorized by the OpenLDAP
8 | * Public License.
9 | *
10 | * A copy of this license is available in the file LICENSE in the
11 | * top-level directory of the distribution or, alternatively, at
12 | * .
13 | */
14 |
15 | /* Just like mtest.c, but using a subDB instead of the main DB */
16 |
17 | #include
18 | #include
19 | #include
20 | #include "lmdb.h"
21 |
22 | #define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
23 | #define RES(err, expr) ((rc = expr) == (err) || (CHECK(!rc, #expr), 0))
24 | #define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
25 | "%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
26 |
27 | int main(int argc,char * argv[])
28 | {
29 | int i = 0, j = 0, rc;
30 | MDB_env *env;
31 | MDB_dbi dbi;
32 | MDB_val key, data;
33 | MDB_txn *txn;
34 | MDB_stat mst;
35 | MDB_cursor *cursor;
36 | int count;
37 | int *values;
38 | char sval[32] = "";
39 |
40 | srand(time(NULL));
41 |
42 | count = (rand()%384) + 64;
43 | values = (int *)malloc(count*sizeof(int));
44 |
45 | for(i = 0;i -1; i-= (rand()%5)) {
87 | j++;
88 | txn=NULL;
89 | E(mdb_txn_begin(env, NULL, 0, &txn));
90 | sprintf(sval, "%03x ", values[i]);
91 | if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, NULL))) {
92 | j--;
93 | mdb_txn_abort(txn);
94 | } else {
95 | E(mdb_txn_commit(txn));
96 | }
97 | }
98 | free(values);
99 | printf("Deleted %d values\n", j);
100 |
101 | E(mdb_env_stat(env, &mst));
102 | E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
103 | E(mdb_cursor_open(txn, dbi, &cursor));
104 | printf("Cursor next\n");
105 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
106 | printf("key: %.*s, data: %.*s\n",
107 | (int) key.mv_size, (char *) key.mv_data,
108 | (int) data.mv_size, (char *) data.mv_data);
109 | }
110 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
111 | printf("Cursor prev\n");
112 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
113 | printf("key: %.*s, data: %.*s\n",
114 | (int) key.mv_size, (char *) key.mv_data,
115 | (int) data.mv_size, (char *) data.mv_data);
116 | }
117 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
118 | mdb_cursor_close(cursor);
119 | mdb_txn_abort(txn);
120 |
121 | mdb_dbi_close(env, dbi);
122 | mdb_env_close(env);
123 | return 0;
124 | }
125 |
--------------------------------------------------------------------------------
/dependencies/lmdb-data-v1/libraries/liblmdb/mtest3.c:
--------------------------------------------------------------------------------
1 | /* mtest3.c - memory-mapped database tester/toy */
2 | /*
3 | * Copyright 2011-2021 Howard Chu, Symas Corp.
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted only as authorized by the OpenLDAP
8 | * Public License.
9 | *
10 | * A copy of this license is available in the file LICENSE in the
11 | * top-level directory of the distribution or, alternatively, at
12 | * .
13 | */
14 |
15 | /* Tests for sorted duplicate DBs */
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include "lmdb.h"
21 |
22 | #define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
23 | #define RES(err, expr) ((rc = expr) == (err) || (CHECK(!rc, #expr), 0))
24 | #define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
25 | "%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
26 |
27 | int main(int argc,char * argv[])
28 | {
29 | int i = 0, j = 0, rc;
30 | MDB_env *env;
31 | MDB_dbi dbi;
32 | MDB_val key, data;
33 | MDB_txn *txn;
34 | MDB_stat mst;
35 | MDB_cursor *cursor;
36 | int count;
37 | int *values;
38 | char sval[32];
39 | char kval[sizeof(int)];
40 |
41 | srand(time(NULL));
42 |
43 | memset(sval, 0, sizeof(sval));
44 |
45 | count = (rand()%384) + 64;
46 | values = (int *)malloc(count*sizeof(int));
47 |
48 | for(i = 0;i -1; i-= (rand()%5)) {
91 | j++;
92 | txn=NULL;
93 | E(mdb_txn_begin(env, NULL, 0, &txn));
94 | sprintf(kval, "%03x", values[i & ~0x0f]);
95 | sprintf(sval, "%03x %d foo bar", values[i], values[i]);
96 | key.mv_size = sizeof(int);
97 | key.mv_data = kval;
98 | data.mv_size = sizeof(sval);
99 | data.mv_data = sval;
100 | if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, &data))) {
101 | j--;
102 | mdb_txn_abort(txn);
103 | } else {
104 | E(mdb_txn_commit(txn));
105 | }
106 | }
107 | free(values);
108 | printf("Deleted %d values\n", j);
109 |
110 | E(mdb_env_stat(env, &mst));
111 | E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
112 | E(mdb_cursor_open(txn, dbi, &cursor));
113 | printf("Cursor next\n");
114 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
115 | printf("key: %.*s, data: %.*s\n",
116 | (int) key.mv_size, (char *) key.mv_data,
117 | (int) data.mv_size, (char *) data.mv_data);
118 | }
119 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
120 | printf("Cursor prev\n");
121 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
122 | printf("key: %.*s, data: %.*s\n",
123 | (int) key.mv_size, (char *) key.mv_data,
124 | (int) data.mv_size, (char *) data.mv_data);
125 | }
126 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
127 | mdb_cursor_close(cursor);
128 | mdb_txn_abort(txn);
129 |
130 | mdb_dbi_close(env, dbi);
131 | mdb_env_close(env);
132 | return 0;
133 | }
134 |
--------------------------------------------------------------------------------
/dependencies/lmdb-data-v1/libraries/liblmdb/mtest4.c:
--------------------------------------------------------------------------------
1 | /* mtest4.c - memory-mapped database tester/toy */
2 | /*
3 | * Copyright 2011-2021 Howard Chu, Symas Corp.
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted only as authorized by the OpenLDAP
8 | * Public License.
9 | *
10 | * A copy of this license is available in the file LICENSE in the
11 | * top-level directory of the distribution or, alternatively, at
12 | * .
13 | */
14 |
15 | /* Tests for sorted duplicate DBs with fixed-size keys */
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include "lmdb.h"
21 |
22 | #define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
23 | #define RES(err, expr) ((rc = expr) == (err) || (CHECK(!rc, #expr), 0))
24 | #define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
25 | "%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
26 |
27 | int main(int argc,char * argv[])
28 | {
29 | int i = 0, j = 0, rc;
30 | MDB_env *env;
31 | MDB_dbi dbi;
32 | MDB_val key, data;
33 | MDB_txn *txn;
34 | MDB_stat mst;
35 | MDB_cursor *cursor;
36 | int count;
37 | int *values;
38 | char sval[8];
39 | char kval[sizeof(int)];
40 |
41 | memset(sval, 0, sizeof(sval));
42 |
43 | count = 510;
44 | values = (int *)malloc(count*sizeof(int));
45 |
46 | for(i = 0;i -1; i-= (rand()%3)) {
127 | j++;
128 | txn=NULL;
129 | E(mdb_txn_begin(env, NULL, 0, &txn));
130 | sprintf(sval, "%07x", values[i]);
131 | key.mv_size = sizeof(int);
132 | key.mv_data = kval;
133 | data.mv_size = sizeof(sval);
134 | data.mv_data = sval;
135 | if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, &data))) {
136 | j--;
137 | mdb_txn_abort(txn);
138 | } else {
139 | E(mdb_txn_commit(txn));
140 | }
141 | }
142 | free(values);
143 | printf("Deleted %d values\n", j);
144 |
145 | E(mdb_env_stat(env, &mst));
146 | E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
147 | E(mdb_cursor_open(txn, dbi, &cursor));
148 | printf("Cursor next\n");
149 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
150 | printf("key: %.*s, data: %.*s\n",
151 | (int) key.mv_size, (char *) key.mv_data,
152 | (int) data.mv_size, (char *) data.mv_data);
153 | }
154 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
155 | printf("Cursor prev\n");
156 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
157 | printf("key: %.*s, data: %.*s\n",
158 | (int) key.mv_size, (char *) key.mv_data,
159 | (int) data.mv_size, (char *) data.mv_data);
160 | }
161 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
162 | mdb_cursor_close(cursor);
163 | mdb_txn_abort(txn);
164 |
165 | mdb_dbi_close(env, dbi);
166 | mdb_env_close(env);
167 | return 0;
168 | }
169 |
--------------------------------------------------------------------------------
/dependencies/lmdb-data-v1/libraries/liblmdb/mtest5.c:
--------------------------------------------------------------------------------
1 | /* mtest5.c - memory-mapped database tester/toy */
2 | /*
3 | * Copyright 2011-2021 Howard Chu, Symas Corp.
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted only as authorized by the OpenLDAP
8 | * Public License.
9 | *
10 | * A copy of this license is available in the file LICENSE in the
11 | * top-level directory of the distribution or, alternatively, at
12 | * .
13 | */
14 |
15 | /* Tests for sorted duplicate DBs using cursor_put */
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include "lmdb.h"
21 |
22 | #define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
23 | #define RES(err, expr) ((rc = expr) == (err) || (CHECK(!rc, #expr), 0))
24 | #define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
25 | "%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
26 |
27 | int main(int argc,char * argv[])
28 | {
29 | int i = 0, j = 0, rc;
30 | MDB_env *env;
31 | MDB_dbi dbi;
32 | MDB_val key, data;
33 | MDB_txn *txn;
34 | MDB_stat mst;
35 | MDB_cursor *cursor;
36 | int count;
37 | int *values;
38 | char sval[32];
39 | char kval[sizeof(int)];
40 |
41 | srand(time(NULL));
42 |
43 | memset(sval, 0, sizeof(sval));
44 |
45 | count = (rand()%384) + 64;
46 | values = (int *)malloc(count*sizeof(int));
47 |
48 | for(i = 0;i -1; i-= (rand()%5)) {
93 | j++;
94 | txn=NULL;
95 | E(mdb_txn_begin(env, NULL, 0, &txn));
96 | sprintf(kval, "%03x", values[i & ~0x0f]);
97 | sprintf(sval, "%03x %d foo bar", values[i], values[i]);
98 | key.mv_size = sizeof(int);
99 | key.mv_data = kval;
100 | data.mv_size = sizeof(sval);
101 | data.mv_data = sval;
102 | if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, &data))) {
103 | j--;
104 | mdb_txn_abort(txn);
105 | } else {
106 | E(mdb_txn_commit(txn));
107 | }
108 | }
109 | free(values);
110 | printf("Deleted %d values\n", j);
111 |
112 | E(mdb_env_stat(env, &mst));
113 | E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
114 | E(mdb_cursor_open(txn, dbi, &cursor));
115 | printf("Cursor next\n");
116 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
117 | printf("key: %.*s, data: %.*s\n",
118 | (int) key.mv_size, (char *) key.mv_data,
119 | (int) data.mv_size, (char *) data.mv_data);
120 | }
121 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
122 | printf("Cursor prev\n");
123 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
124 | printf("key: %.*s, data: %.*s\n",
125 | (int) key.mv_size, (char *) key.mv_data,
126 | (int) data.mv_size, (char *) data.mv_data);
127 | }
128 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
129 | mdb_cursor_close(cursor);
130 | mdb_txn_abort(txn);
131 |
132 | mdb_dbi_close(env, dbi);
133 | mdb_env_close(env);
134 | return 0;
135 | }
136 |
--------------------------------------------------------------------------------
/dependencies/lmdb-data-v1/libraries/liblmdb/mtest6.c:
--------------------------------------------------------------------------------
1 | /* mtest6.c - memory-mapped database tester/toy */
2 | /*
3 | * Copyright 2011-2021 Howard Chu, Symas Corp.
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted only as authorized by the OpenLDAP
8 | * Public License.
9 | *
10 | * A copy of this license is available in the file LICENSE in the
11 | * top-level directory of the distribution or, alternatively, at
12 | * .
13 | */
14 |
15 | /* Tests for DB splits and merges */
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include "lmdb.h"
21 |
22 | #define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
23 | #define RES(err, expr) ((rc = expr) == (err) || (CHECK(!rc, #expr), 0))
24 | #define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
25 | "%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
26 |
27 | char dkbuf[1024];
28 |
29 | int main(int argc,char * argv[])
30 | {
31 | int i = 0, j = 0, rc;
32 | MDB_env *env;
33 | MDB_dbi dbi;
34 | MDB_val key, data, sdata;
35 | MDB_txn *txn;
36 | MDB_stat mst;
37 | MDB_cursor *cursor;
38 | int count;
39 | int *values;
40 | long kval;
41 | char *sval;
42 |
43 | srand(time(NULL));
44 |
45 | E(mdb_env_create(&env));
46 | E(mdb_env_set_mapsize(env, 10485760));
47 | E(mdb_env_set_maxdbs(env, 4));
48 | E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));
49 |
50 | E(mdb_txn_begin(env, NULL, 0, &txn));
51 | E(mdb_dbi_open(txn, "id6", MDB_CREATE|MDB_INTEGERKEY, &dbi));
52 | E(mdb_cursor_open(txn, dbi, &cursor));
53 | E(mdb_stat(txn, dbi, &mst));
54 |
55 | sval = calloc(1, mst.ms_psize / 4);
56 | key.mv_size = sizeof(long);
57 | key.mv_data = &kval;
58 | sdata.mv_size = mst.ms_psize / 4 - 30;
59 | sdata.mv_data = sval;
60 |
61 | printf("Adding 12 values, should yield 3 splits\n");
62 | for (i=0;i<12;i++) {
63 | kval = i*5;
64 | sprintf(sval, "%08x", kval);
65 | data = sdata;
66 | (void)RES(MDB_KEYEXIST, mdb_cursor_put(cursor, &key, &data, MDB_NOOVERWRITE));
67 | }
68 | printf("Adding 12 more values, should yield 3 splits\n");
69 | for (i=0;i<12;i++) {
70 | kval = i*5+4;
71 | sprintf(sval, "%08x", kval);
72 | data = sdata;
73 | (void)RES(MDB_KEYEXIST, mdb_cursor_put(cursor, &key, &data, MDB_NOOVERWRITE));
74 | }
75 | printf("Adding 12 more values, should yield 3 splits\n");
76 | for (i=0;i<12;i++) {
77 | kval = i*5+1;
78 | sprintf(sval, "%08x", kval);
79 | data = sdata;
80 | (void)RES(MDB_KEYEXIST, mdb_cursor_put(cursor, &key, &data, MDB_NOOVERWRITE));
81 | }
82 | E(mdb_cursor_get(cursor, &key, &data, MDB_FIRST));
83 |
84 | do {
85 | printf("key: %p %s, data: %p %.*s\n",
86 | key.mv_data, mdb_dkey(&key, dkbuf),
87 | data.mv_data, (int) data.mv_size, (char *) data.mv_data);
88 | } while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0);
89 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
90 | mdb_cursor_close(cursor);
91 | mdb_txn_commit(txn);
92 |
93 | #if 0
94 | j=0;
95 |
96 | for (i= count - 1; i > -1; i-= (rand()%5)) {
97 | j++;
98 | txn=NULL;
99 | E(mdb_txn_begin(env, NULL, 0, &txn));
100 | sprintf(kval, "%03x", values[i & ~0x0f]);
101 | sprintf(sval, "%03x %d foo bar", values[i], values[i]);
102 | key.mv_size = sizeof(int);
103 | key.mv_data = kval;
104 | data.mv_size = sizeof(sval);
105 | data.mv_data = sval;
106 | if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, &data))) {
107 | j--;
108 | mdb_txn_abort(txn);
109 | } else {
110 | E(mdb_txn_commit(txn));
111 | }
112 | }
113 | free(values);
114 | printf("Deleted %d values\n", j);
115 |
116 | E(mdb_env_stat(env, &mst));
117 | E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
118 | E(mdb_cursor_open(txn, dbi, &cursor));
119 | printf("Cursor next\n");
120 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
121 | printf("key: %.*s, data: %.*s\n",
122 | (int) key.mv_size, (char *) key.mv_data,
123 | (int) data.mv_size, (char *) data.mv_data);
124 | }
125 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
126 | printf("Cursor prev\n");
127 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
128 | printf("key: %.*s, data: %.*s\n",
129 | (int) key.mv_size, (char *) key.mv_data,
130 | (int) data.mv_size, (char *) data.mv_data);
131 | }
132 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
133 | mdb_cursor_close(cursor);
134 | mdb_txn_abort(txn);
135 |
136 | mdb_dbi_close(env, dbi);
137 | #endif
138 | mdb_env_close(env);
139 |
140 | return 0;
141 | }
142 |
--------------------------------------------------------------------------------
/dependencies/lmdb-data-v1/libraries/liblmdb/sample-bdb.txt:
--------------------------------------------------------------------------------
1 | /* sample-bdb.txt - BerkeleyDB toy/sample
2 | *
3 | * Do a line-by-line comparison of this and sample-mdb.txt
4 | */
5 | /*
6 | * Copyright 2012-2021 Howard Chu, Symas Corp.
7 | * All rights reserved.
8 | *
9 | * Redistribution and use in source and binary forms, with or without
10 | * modification, are permitted only as authorized by the OpenLDAP
11 | * Public License.
12 | *
13 | * A copy of this license is available in the file LICENSE in the
14 | * top-level directory of the distribution or, alternatively, at
15 | * .
16 | */
17 | #include
18 | #include
19 | #include
20 |
21 | int main(int argc,char * argv[])
22 | {
23 | int rc;
24 | DB_ENV *env;
25 | DB *dbi;
26 | DBT key, data;
27 | DB_TXN *txn;
28 | DBC *cursor;
29 | char sval[32], kval[32];
30 |
31 | /* Note: Most error checking omitted for simplicity */
32 |
33 | #define FLAGS (DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_INIT_MPOOL|DB_CREATE|DB_THREAD)
34 | rc = db_env_create(&env, 0);
35 | rc = env->open(env, "./testdb", FLAGS, 0664);
36 | rc = db_create(&dbi, env, 0);
37 | rc = env->txn_begin(env, NULL, &txn, 0);
38 | rc = dbi->open(dbi, txn, "test.bdb", NULL, DB_BTREE, DB_CREATE, 0664);
39 |
40 | memset(&key, 0, sizeof(DBT));
41 | memset(&data, 0, sizeof(DBT));
42 | key.size = sizeof(int);
43 | key.data = sval;
44 | data.size = sizeof(sval);
45 | data.data = sval;
46 |
47 | sprintf(sval, "%03x %d foo bar", 32, 3141592);
48 | rc = dbi->put(dbi, txn, &key, &data, 0);
49 | rc = txn->commit(txn, 0);
50 | if (rc) {
51 | fprintf(stderr, "txn->commit: (%d) %s\n", rc, db_strerror(rc));
52 | goto leave;
53 | }
54 | rc = env->txn_begin(env, NULL, &txn, 0);
55 | rc = dbi->cursor(dbi, txn, &cursor, 0);
56 | key.flags = DB_DBT_USERMEM;
57 | key.data = kval;
58 | key.ulen = sizeof(kval);
59 | data.flags = DB_DBT_USERMEM;
60 | data.data = sval;
61 | data.ulen = sizeof(sval);
62 | while ((rc = cursor->c_get(cursor, &key, &data, DB_NEXT)) == 0) {
63 | printf("key: %p %.*s, data: %p %.*s\n",
64 | key.data, (int) key.size, (char *) key.data,
65 | data.data, (int) data.size, (char *) data.data);
66 | }
67 | rc = cursor->c_close(cursor);
68 | rc = txn->abort(txn);
69 | leave:
70 | rc = dbi->close(dbi, 0);
71 | rc = env->close(env, 0);
72 | return rc;
73 | }
74 |
--------------------------------------------------------------------------------
/dependencies/lmdb-data-v1/libraries/liblmdb/sample-mdb.txt:
--------------------------------------------------------------------------------
1 | /* sample-mdb.txt - MDB toy/sample
2 | *
3 | * Do a line-by-line comparison of this and sample-bdb.txt
4 | */
5 | /*
6 | * Copyright 2012-2021 Howard Chu, Symas Corp.
7 | * All rights reserved.
8 | *
9 | * Redistribution and use in source and binary forms, with or without
10 | * modification, are permitted only as authorized by the OpenLDAP
11 | * Public License.
12 | *
13 | * A copy of this license is available in the file LICENSE in the
14 | * top-level directory of the distribution or, alternatively, at
15 | * .
16 | */
17 | #include
18 | #include "lmdb.h"
19 |
20 | int main(int argc,char * argv[])
21 | {
22 | int rc;
23 | MDB_env *env;
24 | MDB_dbi dbi;
25 | MDB_val key, data;
26 | MDB_txn *txn;
27 | MDB_cursor *cursor;
28 | char sval[32];
29 |
30 | /* Note: Most error checking omitted for simplicity */
31 |
32 | rc = mdb_env_create(&env);
33 | rc = mdb_env_open(env, "./testdb", 0, 0664);
34 | rc = mdb_txn_begin(env, NULL, 0, &txn);
35 | rc = mdb_dbi_open(txn, NULL, 0, &dbi);
36 |
37 | key.mv_size = sizeof(int);
38 | key.mv_data = sval;
39 | data.mv_size = sizeof(sval);
40 | data.mv_data = sval;
41 |
42 | sprintf(sval, "%03x %d foo bar", 32, 3141592);
43 | rc = mdb_put(txn, dbi, &key, &data, 0);
44 | rc = mdb_txn_commit(txn);
45 | if (rc) {
46 | fprintf(stderr, "mdb_txn_commit: (%d) %s\n", rc, mdb_strerror(rc));
47 | goto leave;
48 | }
49 | rc = mdb_txn_begin(env, NULL, MDB_RDONLY, &txn);
50 | rc = mdb_cursor_open(txn, dbi, &cursor);
51 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
52 | printf("key: %p %.*s, data: %p %.*s\n",
53 | key.mv_data, (int) key.mv_size, (char *) key.mv_data,
54 | data.mv_data, (int) data.mv_size, (char *) data.mv_data);
55 | }
56 | mdb_cursor_close(cursor);
57 | mdb_txn_abort(txn);
58 | leave:
59 | mdb_dbi_close(env, dbi);
60 | mdb_env_close(env);
61 | return 0;
62 | }
63 |
--------------------------------------------------------------------------------
/dependencies/lmdb-data-v1/libraries/liblmdb/tooltag:
--------------------------------------------------------------------------------
1 |
2 |
3 | mdb_copy_1
4 | mdb_copy - environment copy tool
5 | mdb_copy.1
6 |
7 |
8 | mdb_dump_1
9 | mdb_dump - environment export tool
10 | mdb_dump.1
11 |
12 |
13 | mdb_load_1
14 | mdb_load - environment import tool
15 | mdb_load.1
16 |
17 |
18 | mdb_stat_1
19 | mdb_stat - environment status tool
20 | mdb_stat.1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/.gitignore:
--------------------------------------------------------------------------------
1 | mtest
2 | mtest[23456]
3 | testdb
4 | mdb_copy
5 | mdb_stat
6 | mdb_dump
7 | mdb_load
8 | *.lo
9 | *.[ao]
10 | *.so
11 | *.exe
12 | *[~#]
13 | *.bak
14 | *.orig
15 | *.rej
16 | *.gcov
17 | *.gcda
18 | *.gcno
19 | core
20 | core.*
21 | valgrind.*
22 | man/
23 | html/
24 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/COPYRIGHT:
--------------------------------------------------------------------------------
1 | Copyright 2011-2021 Howard Chu, Symas Corp.
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted only as authorized by the OpenLDAP
6 | Public License.
7 |
8 | A copy of this license is available in the file LICENSE in the
9 | top-level directory of the distribution or, alternatively, at
10 | .
11 |
12 | OpenLDAP is a registered trademark of the OpenLDAP Foundation.
13 |
14 | Individual files and/or contributed packages may be copyright by
15 | other parties and/or subject to additional restrictions.
16 |
17 | This work also contains materials derived from public sources.
18 |
19 | Additional information about OpenLDAP can be obtained at
20 | .
21 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/LICENSE:
--------------------------------------------------------------------------------
1 | The OpenLDAP Public License
2 | Version 2.8, 17 August 2003
3 |
4 | Redistribution and use of this software and associated documentation
5 | ("Software"), with or without modification, are permitted provided
6 | that the following conditions are met:
7 |
8 | 1. Redistributions in source form must retain copyright statements
9 | and notices,
10 |
11 | 2. Redistributions in binary form must reproduce applicable copyright
12 | statements and notices, this list of conditions, and the following
13 | disclaimer in the documentation and/or other materials provided
14 | with the distribution, and
15 |
16 | 3. Redistributions must contain a verbatim copy of this document.
17 |
18 | The OpenLDAP Foundation may revise this license from time to time.
19 | Each revision is distinguished by a version number. You may use
20 | this Software under terms of this license revision or under the
21 | terms of any subsequent revision of the license.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE OPENLDAP FOUNDATION AND ITS
24 | CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27 | SHALL THE OPENLDAP FOUNDATION, ITS CONTRIBUTORS, OR THE AUTHOR(S)
28 | OR OWNER(S) OF THE SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | POSSIBILITY OF SUCH DAMAGE.
36 |
37 | The names of the authors and copyright holders must not be used in
38 | advertising or otherwise to promote the sale, use or other dealing
39 | in this Software without specific, written prior permission. Title
40 | to copyright in this Software shall at all times remain with copyright
41 | holders.
42 |
43 | OpenLDAP is a registered trademark of the OpenLDAP Foundation.
44 |
45 | Copyright 1999-2003 The OpenLDAP Foundation, Redwood City,
46 | California, USA. All Rights Reserved. Permission to copy and
47 | distribute verbatim copies of this document is granted.
48 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/Makefile:
--------------------------------------------------------------------------------
1 | # Makefile for liblmdb (Lightning memory-mapped database library).
2 |
3 | ########################################################################
4 | # Configuration. The compiler options must enable threaded compilation.
5 | #
6 | # Preprocessor macros (for CPPFLAGS) of interest...
7 | # Note that the defaults should already be correct for most
8 | # platforms; you should not need to change any of these.
9 | # Read their descriptions in mdb.c if you do:
10 | #
11 | # - MDB_USE_POSIX_MUTEX, MDB_USE_POSIX_SEM, MDB_USE_SYSV_SEM
12 | # - MDB_DSYNC
13 | # - MDB_FDATASYNC
14 | # - MDB_FDATASYNC_WORKS
15 | # - MDB_USE_PWRITEV
16 | # - MDB_USE_ROBUST
17 | #
18 | # There may be other macros in mdb.c of interest. You should
19 | # read mdb.c before changing any of them.
20 | #
21 | CC = gcc
22 | AR = ar
23 | W = -W -Wall -Wno-unused-parameter -Wbad-function-cast -Wuninitialized
24 | THREADS = -pthread
25 | OPT = -O2 -g
26 | CFLAGS = $(THREADS) $(OPT) $(W) $(XCFLAGS)
27 | LDFLAGS = $(THREADS)
28 | LDLIBS =
29 | SOLIBS =
30 | SOEXT = .so
31 | LDL = -ldl
32 | prefix = /usr/local
33 | exec_prefix = $(prefix)
34 | bindir = $(exec_prefix)/bin
35 | libdir = $(exec_prefix)/lib
36 | includedir = $(prefix)/include
37 | datarootdir = $(prefix)/share
38 | mandir = $(datarootdir)/man
39 |
40 | ########################################################################
41 |
42 | IHDRS = lmdb.h
43 | ILIBS = liblmdb.a liblmdb$(SOEXT)
44 | IPROGS = mdb_stat mdb_copy mdb_dump mdb_load mdb_drop
45 | IDOCS = mdb_stat.1 mdb_copy.1 mdb_dump.1 mdb_load.1 mdb_drop.1
46 | PROGS = $(IPROGS) mtest mtest2 mtest3 mtest4 mtest5
47 | RPROGS = mtest_remap mtest_enc mtest_enc2
48 |
49 | all: $(ILIBS) $(PROGS)
50 | # Requires CPPFLAGS=-DMDB_VL32 and/or -DMDB_RPAGE_CACHE
51 | rall: all $(RPROGS)
52 |
53 | install: $(ILIBS) $(IPROGS) $(IHDRS)
54 | mkdir -p $(DESTDIR)$(bindir)
55 | mkdir -p $(DESTDIR)$(libdir)
56 | mkdir -p $(DESTDIR)$(includedir)
57 | mkdir -p $(DESTDIR)$(mandir)/man1
58 | for f in $(IPROGS); do cp $$f $(DESTDIR)$(bindir); done
59 | for f in $(ILIBS); do cp $$f $(DESTDIR)$(libdir); done
60 | for f in $(IHDRS); do cp $$f $(DESTDIR)$(includedir); done
61 | for f in $(IDOCS); do cp $$f $(DESTDIR)$(mandir)/man1; done
62 |
63 | clean:
64 | rm -rf $(PROGS) $(RPROGS) *.[ao] *.[ls]o *~ testdb
65 |
66 | test: all
67 | rm -rf testdb && mkdir testdb
68 | ./mtest && ./mdb_stat testdb
69 |
70 | liblmdb.a: mdb.o midl.o
71 | $(AR) rs $@ mdb.o midl.o
72 |
73 | liblmdb$(SOEXT): mdb.lo midl.lo
74 | # $(CC) $(LDFLAGS) -pthread -shared -Wl,-Bsymbolic -o $@ mdb.o midl.o $(SOLIBS)
75 | $(CC) $(LDFLAGS) -pthread -shared -o $@ mdb.lo midl.lo $(SOLIBS)
76 |
77 | mdb_stat: mdb_stat.o module.o liblmdb.a
78 | $(CC) $(LDFLAGS) -o $@ $^ $(LDL)
79 | mdb_copy: mdb_copy.o module.o liblmdb.a
80 | $(CC) $(LDFLAGS) -o $@ $^ $(LDL)
81 | mdb_dump: mdb_dump.o module.o liblmdb.a
82 | $(CC) $(LDFLAGS) -o $@ $^ $(LDL)
83 | mdb_load: mdb_load.o module.o liblmdb.a
84 | $(CC) $(LDFLAGS) -o $@ $^ $(LDL)
85 | mdb_drop: mdb_drop.o module.o liblmdb.a
86 | $(CC) $(LDFLAGS) -o $@ $^ $(LDL)
87 | mtest: mtest.o liblmdb.a
88 | mtest2: mtest2.o liblmdb.a
89 | mtest3: mtest3.o liblmdb.a
90 | mtest4: mtest4.o liblmdb.a
91 | mtest5: mtest5.o liblmdb.a
92 | mtest6: mtest6.o liblmdb.a
93 | mtest_remap: mtest_remap.o liblmdb.a
94 | mtest_enc: mtest_enc.o chacha8.o liblmdb.a
95 | mtest_enc2: mtest_enc2.o module.o liblmdb.a crypto.lm
96 | $(CC) $(LDFLAGS) -pthread -o $@ mtest_enc2.o module.o liblmdb.a $(LDL)
97 |
98 | crypto.lm: crypto.c
99 | $(CC) -shared -o $@ -lcrypto
100 |
101 | mdb.o: mdb.c lmdb.h midl.h
102 | $(CC) $(CFLAGS) $(CPPFLAGS) -c mdb.c
103 |
104 | midl.o: midl.c midl.h
105 | $(CC) $(CFLAGS) $(CPPFLAGS) -c midl.c
106 |
107 | mdb.lo: mdb.c lmdb.h midl.h
108 | $(CC) $(CFLAGS) -fPIC $(CPPFLAGS) -c mdb.c -o $@
109 |
110 | midl.lo: midl.c midl.h
111 | $(CC) $(CFLAGS) -fPIC $(CPPFLAGS) -c midl.c -o $@
112 |
113 | %: %.o
114 | $(CC) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
115 |
116 | %.o: %.c lmdb.h
117 | $(CC) $(CFLAGS) $(CPPFLAGS) -c $<
118 |
119 | COV_FLAGS=-fprofile-arcs -ftest-coverage
120 | COV_OBJS=xmdb.o xmidl.o
121 |
122 | coverage: xmtest
123 | for i in mtest*.c [0-9]*.c; do j=`basename \$$i .c`; $(MAKE) $$j.o; \
124 | gcc -o x$$j $$j.o $(COV_OBJS) -pthread $(COV_FLAGS); \
125 | rm -rf testdb; mkdir testdb; ./x$$j; done
126 | gcov xmdb.c
127 | gcov xmidl.c
128 |
129 | xmtest: mtest.o xmdb.o xmidl.o
130 | gcc -o xmtest mtest.o xmdb.o xmidl.o -pthread $(COV_FLAGS)
131 |
132 | xmdb.o: mdb.c lmdb.h midl.h
133 | $(CC) $(CFLAGS) -fPIC $(CPPFLAGS) -O0 $(COV_FLAGS) -c mdb.c -o $@
134 |
135 | xmidl.o: midl.c midl.h
136 | $(CC) $(CFLAGS) -fPIC $(CPPFLAGS) -O0 $(COV_FLAGS) -c midl.c -o $@
137 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/chacha8.c:
--------------------------------------------------------------------------------
1 | /*
2 | chacha-merged.c version 20080118
3 | D. J. Bernstein
4 | Public domain.
5 | */
6 |
7 | #include
8 | #include
9 | //#include
10 |
11 | #include "chacha8.h"
12 | #if 0
13 | #include "common/int-util.h"
14 | #include "warnings.h"
15 | #endif
16 |
17 | #if BYTE_ORDER == LITTLE_ENDIAN
18 | #define SWAP32LE(x) (x)
19 | #else
20 | #define SWAP32LE(x) ((((uint32_t) (x) & 0x000000ff) << 24) | \
21 | (((uint32_t) (x) & 0x0000ff00) << 8) | \
22 | (((uint32_t) (x) & 0x00ff0000) >> 8) | \
23 | (((uint32_t) (x) & 0xff000000) >> 24))
24 | #endif
25 |
26 | /*
27 | * The following macros are used to obtain exact-width results.
28 | */
29 | #define U8V(v) ((uint8_t)(v) & UINT8_C(0xFF))
30 | #define U32V(v) ((uint32_t)(v) & UINT32_C(0xFFFFFFFF))
31 |
32 | /*
33 | * The following macros load words from an array of bytes with
34 | * different types of endianness, and vice versa.
35 | */
36 | #define U8TO32_LITTLE(p) SWAP32LE(((uint32_t*)(p))[0])
37 | #define U32TO8_LITTLE(p, v) (((uint32_t*)(p))[0] = SWAP32LE(v))
38 |
39 | #define ROTATE(v,c) (rol32(v,c))
40 | #define XOR(v,w) ((v) ^ (w))
41 | #define PLUS(v,w) (U32V((v) + (w)))
42 | #define PLUSONE(v) (PLUS((v),1))
43 |
44 | #define QUARTERROUND(a,b,c,d) \
45 | a = PLUS(a,b); d = ROTATE(XOR(d,a),16); \
46 | c = PLUS(c,d); b = ROTATE(XOR(b,c),12); \
47 | a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \
48 | c = PLUS(c,d); b = ROTATE(XOR(b,c), 7);
49 |
50 | static const char sigma[] = "expand 32-byte k";
51 |
52 | static uint32_t rol32(uint32_t x, int r) {
53 | return (x << (r & 31)) | (x >> (-r & 31));
54 | }
55 |
56 | void chacha8(const void* data, size_t length, const uint8_t* key, const uint8_t* iv, char* cipher) {
57 | uint32_t x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
58 | uint32_t j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
59 | char* ctarget = 0;
60 | char tmp[64];
61 | int i;
62 |
63 | if (!length) return;
64 |
65 | j0 = U8TO32_LITTLE(sigma + 0);
66 | j1 = U8TO32_LITTLE(sigma + 4);
67 | j2 = U8TO32_LITTLE(sigma + 8);
68 | j3 = U8TO32_LITTLE(sigma + 12);
69 | j4 = U8TO32_LITTLE(key + 0);
70 | j5 = U8TO32_LITTLE(key + 4);
71 | j6 = U8TO32_LITTLE(key + 8);
72 | j7 = U8TO32_LITTLE(key + 12);
73 | j8 = U8TO32_LITTLE(key + 16);
74 | j9 = U8TO32_LITTLE(key + 20);
75 | j10 = U8TO32_LITTLE(key + 24);
76 | j11 = U8TO32_LITTLE(key + 28);
77 | j12 = 0;
78 | j13 = 0;
79 | j14 = U8TO32_LITTLE(iv + 0);
80 | j15 = U8TO32_LITTLE(iv + 4);
81 |
82 | for (;;) {
83 | if (length < 64) {
84 | memcpy(tmp, data, length);
85 | data = tmp;
86 | ctarget = cipher;
87 | cipher = tmp;
88 | }
89 | x0 = j0;
90 | x1 = j1;
91 | x2 = j2;
92 | x3 = j3;
93 | x4 = j4;
94 | x5 = j5;
95 | x6 = j6;
96 | x7 = j7;
97 | x8 = j8;
98 | x9 = j9;
99 | x10 = j10;
100 | x11 = j11;
101 | x12 = j12;
102 | x13 = j13;
103 | x14 = j14;
104 | x15 = j15;
105 | for (i = 8;i > 0;i -= 2) {
106 | QUARTERROUND( x0, x4, x8,x12)
107 | QUARTERROUND( x1, x5, x9,x13)
108 | QUARTERROUND( x2, x6,x10,x14)
109 | QUARTERROUND( x3, x7,x11,x15)
110 | QUARTERROUND( x0, x5,x10,x15)
111 | QUARTERROUND( x1, x6,x11,x12)
112 | QUARTERROUND( x2, x7, x8,x13)
113 | QUARTERROUND( x3, x4, x9,x14)
114 | }
115 | x0 = PLUS( x0, j0);
116 | x1 = PLUS( x1, j1);
117 | x2 = PLUS( x2, j2);
118 | x3 = PLUS( x3, j3);
119 | x4 = PLUS( x4, j4);
120 | x5 = PLUS( x5, j5);
121 | x6 = PLUS( x6, j6);
122 | x7 = PLUS( x7, j7);
123 | x8 = PLUS( x8, j8);
124 | x9 = PLUS( x9, j9);
125 | x10 = PLUS(x10,j10);
126 | x11 = PLUS(x11,j11);
127 | x12 = PLUS(x12,j12);
128 | x13 = PLUS(x13,j13);
129 | x14 = PLUS(x14,j14);
130 | x15 = PLUS(x15,j15);
131 |
132 | x0 = XOR( x0,U8TO32_LITTLE((uint8_t*)data + 0));
133 | x1 = XOR( x1,U8TO32_LITTLE((uint8_t*)data + 4));
134 | x2 = XOR( x2,U8TO32_LITTLE((uint8_t*)data + 8));
135 | x3 = XOR( x3,U8TO32_LITTLE((uint8_t*)data + 12));
136 | x4 = XOR( x4,U8TO32_LITTLE((uint8_t*)data + 16));
137 | x5 = XOR( x5,U8TO32_LITTLE((uint8_t*)data + 20));
138 | x6 = XOR( x6,U8TO32_LITTLE((uint8_t*)data + 24));
139 | x7 = XOR( x7,U8TO32_LITTLE((uint8_t*)data + 28));
140 | x8 = XOR( x8,U8TO32_LITTLE((uint8_t*)data + 32));
141 | x9 = XOR( x9,U8TO32_LITTLE((uint8_t*)data + 36));
142 | x10 = XOR(x10,U8TO32_LITTLE((uint8_t*)data + 40));
143 | x11 = XOR(x11,U8TO32_LITTLE((uint8_t*)data + 44));
144 | x12 = XOR(x12,U8TO32_LITTLE((uint8_t*)data + 48));
145 | x13 = XOR(x13,U8TO32_LITTLE((uint8_t*)data + 52));
146 | x14 = XOR(x14,U8TO32_LITTLE((uint8_t*)data + 56));
147 | x15 = XOR(x15,U8TO32_LITTLE((uint8_t*)data + 60));
148 |
149 | j12 = PLUSONE(j12);
150 | if (!j12)
151 | {
152 | j13 = PLUSONE(j13);
153 | /* stopping at 2^70 bytes per iv is user's responsibility */
154 | }
155 |
156 | U32TO8_LITTLE(cipher + 0,x0);
157 | U32TO8_LITTLE(cipher + 4,x1);
158 | U32TO8_LITTLE(cipher + 8,x2);
159 | U32TO8_LITTLE(cipher + 12,x3);
160 | U32TO8_LITTLE(cipher + 16,x4);
161 | U32TO8_LITTLE(cipher + 20,x5);
162 | U32TO8_LITTLE(cipher + 24,x6);
163 | U32TO8_LITTLE(cipher + 28,x7);
164 | U32TO8_LITTLE(cipher + 32,x8);
165 | U32TO8_LITTLE(cipher + 36,x9);
166 | U32TO8_LITTLE(cipher + 40,x10);
167 | U32TO8_LITTLE(cipher + 44,x11);
168 | U32TO8_LITTLE(cipher + 48,x12);
169 | U32TO8_LITTLE(cipher + 52,x13);
170 | U32TO8_LITTLE(cipher + 56,x14);
171 | U32TO8_LITTLE(cipher + 60,x15);
172 |
173 | if (length <= 64) {
174 | if (length < 64) {
175 | memcpy(ctarget, cipher, length);
176 | }
177 | return;
178 | }
179 | length -= 64;
180 | cipher += 64;
181 | data = (uint8_t*)data + 64;
182 | }
183 | }
184 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/chacha8.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #ifdef __cplusplus
4 | extern "C" {
5 | #endif
6 | void chacha8(const void* data, size_t length, const uint8_t* key, const uint8_t* iv, char* cipher);
7 |
8 | #define CHACHA8_KEY_SIZE 32
9 | #define CHACHA8_IV_SIZE 8
10 |
11 | #ifdef __cplusplus
12 | }
13 | #endif
14 |
15 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/crypto.c:
--------------------------------------------------------------------------------
1 | /* crypto.c - LMDB encryption helper module */
2 | /*
3 | * Copyright 2020-2021 Howard Chu, Symas Corp.
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted only as authorized by the Symas
8 | * Dual-Use License.
9 | *
10 | * A copy of this license is available in the file LICENSE in the
11 | * source distribution.
12 | */
13 | #include
14 |
15 | #include
16 |
17 | #include "lmdb.h"
18 |
19 | MDB_crypto_hooks MDB_crypto;
20 |
21 | static EVP_CIPHER *cipher;
22 |
23 | static int mcf_str2key(const char *passwd, MDB_val *key)
24 | {
25 | unsigned int size;
26 | EVP_MD_CTX *mdctx = EVP_MD_CTX_new();
27 | EVP_DigestInit_ex(mdctx, EVP_sha256(), NULL);
28 | EVP_DigestUpdate(mdctx, "Just a Constant", sizeof("Just a Constant"));
29 | EVP_DigestUpdate(mdctx, passwd, strlen(passwd));
30 | EVP_DigestFinal_ex(mdctx, key->mv_data, &size);
31 | EVP_MD_CTX_free(mdctx);
32 | return 0;
33 | }
34 |
35 | /* cheats - internal OpenSSL 1.1 structures */
36 | typedef struct evp_cipher_ctx_st {
37 | const EVP_CIPHER *cipher;
38 | ENGINE *engine; /* functional reference if 'cipher' is
39 | * ENGINE-provided */
40 | int encrypt; /* encrypt or decrypt */
41 | int buf_len; /* number we have left */
42 | unsigned char oiv[EVP_MAX_IV_LENGTH]; /* original iv */
43 | unsigned char iv[EVP_MAX_IV_LENGTH]; /* working iv */
44 | unsigned char buf[EVP_MAX_BLOCK_LENGTH]; /* saved partial block */
45 | int num; /* used by cfb/ofb/ctr mode */
46 | /* FIXME: Should this even exist? It appears unused */
47 | void *app_data; /* application stuff */
48 | int key_len; /* May change for variable length cipher */
49 | unsigned long flags; /* Various flags */
50 | void *cipher_data; /* per EVP data */
51 | int final_used;
52 | int block_mask;
53 | unsigned char final[EVP_MAX_BLOCK_LENGTH]; /* possible final block */
54 | } EVP_CIPHER_CTX;
55 |
56 | #define CHACHA_KEY_SIZE 32
57 | #define CHACHA_CTR_SIZE 16
58 | #define CHACHA_BLK_SIZE 64
59 | #define POLY1305_BLOCK_SIZE 16
60 |
61 | typedef struct {
62 | union {
63 | double align; /* this ensures even sizeof(EVP_CHACHA_KEY)%8==0 */
64 | unsigned int d[CHACHA_KEY_SIZE / 4];
65 | } key;
66 | unsigned int counter[CHACHA_CTR_SIZE / 4];
67 | unsigned char buf[CHACHA_BLK_SIZE];
68 | unsigned int partial_len;
69 | } EVP_CHACHA_KEY;
70 |
71 | typedef struct {
72 | EVP_CHACHA_KEY key;
73 | unsigned int nonce[12/4];
74 | unsigned char tag[POLY1305_BLOCK_SIZE];
75 | unsigned char tls_aad[POLY1305_BLOCK_SIZE];
76 | struct { uint64_t aad, text; } len;
77 | int aad, mac_inited, tag_len, nonce_len;
78 | size_t tls_payload_length;
79 | } EVP_CHACHA_AEAD_CTX;
80 |
81 | static int mcf_encfunc(const MDB_val *src, MDB_val *dst, const MDB_val *key, int encdec)
82 | {
83 | unsigned char iv[12];
84 | int ivl, outl, rc;
85 | mdb_size_t *ptr;
86 | EVP_CIPHER_CTX ctx = {0};
87 | EVP_CHACHA_AEAD_CTX cactx;
88 |
89 | ctx.cipher_data = &cactx;
90 | ptr = key[1].mv_data;
91 | ivl = ptr[0] & 0xffffffff;
92 | memcpy(iv, &ivl, 4);
93 | memcpy(iv+4, ptr+1, sizeof(mdb_size_t));
94 | EVP_CipherInit_ex(&ctx, cipher, NULL, key[0].mv_data, iv, encdec);
95 | EVP_CIPHER_CTX_set_padding(&ctx, 0);
96 | if (!encdec) {
97 | EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_AEAD_SET_TAG, key[2].mv_size, key[2].mv_data);
98 | }
99 | rc = EVP_CipherUpdate(&ctx, dst->mv_data, &outl, src->mv_data, src->mv_size);
100 | if (rc)
101 | rc = EVP_CipherFinal_ex(&ctx, key[2].mv_data, &outl);
102 | if (rc && encdec) {
103 | EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_AEAD_GET_TAG, key[2].mv_size, key[2].mv_data);
104 | }
105 | return rc == 0;
106 | }
107 |
108 | static const MDB_crypto_funcs mcf_table = {
109 | mcf_str2key,
110 | mcf_encfunc,
111 | NULL,
112 | CHACHA_KEY_SIZE,
113 | POLY1305_BLOCK_SIZE,
114 | 0
115 | };
116 |
117 | MDB_crypto_funcs *MDB_crypto()
118 | {
119 | cipher = (EVP_CIPHER *)EVP_chacha20_poly1305();
120 | return (MDB_crypto_funcs *)&mcf_table;
121 | }
122 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/mdb_copy.1:
--------------------------------------------------------------------------------
1 | .TH MDB_COPY 1 "2017/07/31" "LMDB 0.9.90"
2 | .\" Copyright 2012-2021 Howard Chu, Symas Corp. All Rights Reserved.
3 | .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
4 | .SH NAME
5 | mdb_copy \- LMDB environment copy tool
6 | .SH SYNOPSIS
7 | .B mdb_copy
8 | [\c
9 | .BR \-V ]
10 | [\c
11 | .BR \-c ]
12 | [\c
13 | .BR \-n ]
14 | [\c
15 | .BR \-v ]
16 | [\c
17 | .BI \-m \ module
18 | [\c
19 | .BI \-w \ password\fR]]
20 | .B srcpath
21 | [\c
22 | .BR dstpath ]
23 | .SH DESCRIPTION
24 | The
25 | .B mdb_copy
26 | utility copies an LMDB environment. The environment can
27 | be copied regardless of whether it is currently in use.
28 | No lockfile is created, since it gets recreated at need.
29 |
30 | If
31 | .I dstpath
32 | is specified it must be the path of an empty directory
33 | for storing the backup. Otherwise, the backup will be
34 | written to stdout.
35 |
36 | .SH OPTIONS
37 | .TP
38 | .BR \-V
39 | Write the library version number to the standard output, and exit.
40 | .TP
41 | .BR \-c
42 | Compact while copying. Only current data pages will be copied; freed
43 | or unused pages will be omitted from the copy. This option will
44 | slow down the backup process as it is more CPU-intensive.
45 | Currently it fails if the environment has suffered a page leak.
46 | .TP
47 | .BR \-n
48 | Open LDMB environment(s) which do not use subdirectories.
49 | .TP
50 | .BR \-v
51 | Use the previous environment state instead of the latest state.
52 | This may be useful if the latest state has been corrupted.
53 | .TP
54 | .BI \-m \ module
55 | Load the specified dynamic module to utilize cryptographic functions.
56 | This is required to operate on environments that have been configured
57 | with page-level checksums or encryption.
58 | .TP
59 | .BI \-w \ password
60 | Specify the password for an encrypted environment. This is only
61 | used if a cryptography module has been loaded.
62 |
63 | .SH DIAGNOSTICS
64 | Exit status is zero if no errors occur.
65 | Errors result in a non-zero exit status and
66 | a diagnostic message being written to standard error.
67 | .SH CAVEATS
68 | This utility can trigger significant file size growth if run
69 | in parallel with write transactions, because pages which they
70 | free during copying cannot be reused until the copy is done.
71 | .SH "SEE ALSO"
72 | .BR mdb_stat (1)
73 | .SH AUTHOR
74 | Howard Chu of Symas Corporation
75 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/mdb_copy.c:
--------------------------------------------------------------------------------
1 | /* mdb_copy.c - memory-mapped database backup tool */
2 | /*
3 | * Copyright 2012-2021 Howard Chu, Symas Corp.
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted only as authorized by the OpenLDAP
8 | * Public License.
9 | *
10 | * A copy of this license is available in the file LICENSE in the
11 | * top-level directory of the distribution or, alternatively, at
12 | * .
13 | */
14 | #ifdef _WIN32
15 | #include
16 | #define MDB_STDOUT GetStdHandle(STD_OUTPUT_HANDLE)
17 | #else
18 | #define MDB_STDOUT 1
19 | #endif
20 | #include
21 | #include
22 | #include
23 | #include "lmdb.h"
24 | #include "module.h"
25 |
26 | static void
27 | sighandle(int sig)
28 | {
29 | }
30 |
31 | int main(int argc,char * argv[])
32 | {
33 | int rc;
34 | MDB_env *env;
35 | const char *progname = argv[0], *act;
36 | unsigned flags = MDB_RDONLY;
37 | unsigned cpflags = 0;
38 | char *module = NULL, *password = NULL;
39 | void *mlm = NULL;
40 | char *errmsg;
41 |
42 | for (; argc > 1 && argv[1][0] == '-'; argc--, argv++) {
43 | if (argv[1][1] == 'n' && argv[1][2] == '\0')
44 | flags |= MDB_NOSUBDIR;
45 | else if (argv[1][1] == 'v' && argv[1][2] == '\0')
46 | flags |= MDB_PREVSNAPSHOT;
47 | else if (argv[1][1] == 'c' && argv[1][2] == '\0')
48 | cpflags |= MDB_CP_COMPACT;
49 | else if (argv[1][1] == 'V' && argv[1][2] == '\0') {
50 | printf("%s\n", MDB_VERSION_STRING);
51 | exit(0);
52 | } else if (argv[1][1] == 'm' && argv[1][2] == '\0') {
53 | module = argv[2];
54 | argc--;
55 | argv++;
56 | } else if (argv[1][1] == 'w' && argv[1][2] == '\0') {
57 | password = argv[2];
58 | argc--;
59 | argv++;
60 | } else
61 | argc = 0;
62 | }
63 |
64 | if (argc<2 || argc>3) {
65 | fprintf(stderr, "usage: %s [-V] [-c] [-n] [-v] [-m module [-w password]] srcpath [dstpath]\n", progname);
66 | exit(EXIT_FAILURE);
67 | }
68 |
69 |
70 | #ifdef SIGPIPE
71 | signal(SIGPIPE, sighandle);
72 | #endif
73 | #ifdef SIGHUP
74 | signal(SIGHUP, sighandle);
75 | #endif
76 | signal(SIGINT, sighandle);
77 | signal(SIGTERM, sighandle);
78 |
79 | act = "opening environment";
80 | rc = mdb_env_create(&env);
81 | if (rc == MDB_SUCCESS) {
82 | if (module) {
83 | mlm = mlm_setup(env, module, password, &errmsg);
84 | if (!mlm) {
85 | fprintf(stderr, "Failed to load crypto module: %s\n", errmsg);
86 | exit(EXIT_FAILURE);
87 | }
88 | }
89 | rc = mdb_env_open(env, argv[1], flags, 0600);
90 | }
91 | if (rc == MDB_SUCCESS) {
92 | act = "copying";
93 | if (argc == 2)
94 | rc = mdb_env_copyfd2(env, MDB_STDOUT, cpflags);
95 | else
96 | rc = mdb_env_copy2(env, argv[2], cpflags);
97 | }
98 | if (rc)
99 | fprintf(stderr, "%s: %s failed, error %d (%s)\n",
100 | progname, act, rc, mdb_strerror(rc));
101 | mdb_env_close(env);
102 | if (mlm)
103 | mlm_unload(mlm);
104 |
105 | return rc ? EXIT_FAILURE : EXIT_SUCCESS;
106 | }
107 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/mdb_drop.1:
--------------------------------------------------------------------------------
1 | .TH MDB_DROP 1 "2017/11/19" "LMDB 0.9.90"
2 | .\" Copyright 2014-2021 Howard Chu, Symas Corp. All Rights Reserved.
3 | .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
4 | .SH NAME
5 | mdb_drop \- LMDB database delete tool
6 | .SH SYNOPSIS
7 | .B mdb_drop
8 | [\c
9 | .BR \-V ]
10 | [\c
11 | .BR \-n ]
12 | [\c
13 | .BR \-d ]
14 | [\c
15 | .BI \-m \ module
16 | [\c
17 | .BI \-w \ password\fR]]
18 | [\c
19 | .BI \-s \ subdb\fR]
20 | .BR \ envpath
21 | .SH DESCRIPTION
22 | The
23 | .B mdb_drop
24 | utility empties or deletes a database in the specified
25 | environment.
26 | .SH OPTIONS
27 | .TP
28 | .BR \-V
29 | Write the library version number to the standard output, and exit.
30 | .TP
31 | .BR \-n
32 | Operate on an LMDB database which does not use subdirectories.
33 | .TP
34 | .BR \-d
35 | Delete the specified database, don't just empty it.
36 | .TP
37 | .BI \-m \ module
38 | Load the specified dynamic module to utilize cryptographic functions.
39 | This is required to operate on environments that have been configured
40 | with page-level checksums or encryption.
41 | .TP
42 | .BI \-w \ password
43 | Specify the password for an encrypted environment. This is only
44 | used if a cryptography module has been loaded.
45 | .TP
46 | .BR \-s \ subdb
47 | Operate on a specific subdatabase. If no database is specified, only the main database is dropped.
48 | .SH DIAGNOSTICS
49 | Exit status is zero if no errors occur.
50 | Errors result in a non-zero exit status and
51 | a diagnostic message being written to standard error.
52 | .SH AUTHOR
53 | Howard Chu of Symas Corporation
54 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/mdb_drop.c:
--------------------------------------------------------------------------------
1 | /* mdb_drop.c - memory-mapped database delete tool */
2 | /*
3 | * Copyright 2016-2021 Howard Chu, Symas Corp.
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted only as authorized by the OpenLDAP
8 | * Public License.
9 | *
10 | * A copy of this license is available in the file LICENSE in the
11 | * top-level directory of the distribution or, alternatively, at
12 | * .
13 | */
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include "lmdb.h"
22 | #include "module.h"
23 |
24 | static volatile sig_atomic_t gotsig;
25 |
26 | static void dumpsig( int sig )
27 | {
28 | gotsig=1;
29 | }
30 |
31 | static void usage(char *prog)
32 | {
33 | fprintf(stderr, "usage: %s [-V] [-n] [-d] [-m module [-w password]] [-s subdb] dbpath\n", prog);
34 | exit(EXIT_FAILURE);
35 | }
36 |
37 | int main(int argc, char *argv[])
38 | {
39 | int i, rc;
40 | MDB_env *env;
41 | MDB_txn *txn;
42 | MDB_dbi dbi;
43 | char *prog = argv[0];
44 | char *envname;
45 | char *subname = NULL;
46 | int envflags = 0, delete = 0;
47 | char *module = NULL, *password = NULL;
48 | void *mlm = NULL;
49 | char *errmsg;
50 |
51 | if (argc < 2) {
52 | usage(prog);
53 | }
54 |
55 | /* -d: delete the db, don't just empty it
56 | * -s: drop the named subDB
57 | * -n: use NOSUBDIR flag on env_open
58 | * -V: print version and exit
59 | * (default) empty the main DB
60 | */
61 | while ((i = getopt(argc, argv, "dm:ns:w:V")) != EOF) {
62 | switch(i) {
63 | case 'V':
64 | printf("%s\n", MDB_VERSION_STRING);
65 | exit(0);
66 | break;
67 | case 'd':
68 | delete = 1;
69 | break;
70 | case 'n':
71 | envflags |= MDB_NOSUBDIR;
72 | break;
73 | case 's':
74 | subname = optarg;
75 | break;
76 | case 'm':
77 | module = optarg;
78 | break;
79 | case 'w':
80 | password = optarg;
81 | break;
82 | default:
83 | usage(prog);
84 | }
85 | }
86 |
87 | if (optind != argc - 1)
88 | usage(prog);
89 |
90 | #ifdef SIGPIPE
91 | signal(SIGPIPE, dumpsig);
92 | #endif
93 | #ifdef SIGHUP
94 | signal(SIGHUP, dumpsig);
95 | #endif
96 | signal(SIGINT, dumpsig);
97 | signal(SIGTERM, dumpsig);
98 |
99 | envname = argv[optind];
100 | rc = mdb_env_create(&env);
101 | if (rc) {
102 | fprintf(stderr, "mdb_env_create failed, error %d %s\n", rc, mdb_strerror(rc));
103 | return EXIT_FAILURE;
104 | }
105 | if (module) {
106 | mlm = mlm_setup(env, module, password, &errmsg);
107 | if (!mlm) {
108 | fprintf(stderr, "Failed to load crypto module: %s\n", errmsg);
109 | goto env_close;
110 | }
111 | }
112 |
113 | mdb_env_set_maxdbs(env, 2);
114 |
115 | rc = mdb_env_open(env, envname, envflags, 0664);
116 | if (rc) {
117 | fprintf(stderr, "mdb_env_open failed, error %d %s\n", rc, mdb_strerror(rc));
118 | goto env_close;
119 | }
120 |
121 | rc = mdb_txn_begin(env, NULL, 0, &txn);
122 | if (rc) {
123 | fprintf(stderr, "mdb_txn_begin failed, error %d %s\n", rc, mdb_strerror(rc));
124 | goto env_close;
125 | }
126 |
127 | rc = mdb_open(txn, subname, 0, &dbi);
128 | if (rc) {
129 | fprintf(stderr, "mdb_open failed, error %d %s\n", rc, mdb_strerror(rc));
130 | goto txn_abort;
131 | }
132 |
133 | rc = mdb_drop(txn, dbi, delete);
134 | if (rc) {
135 | fprintf(stderr, "mdb_drop failed, error %d %s\n", rc, mdb_strerror(rc));
136 | goto txn_abort;
137 | }
138 | rc = mdb_txn_commit(txn);
139 | if (rc) {
140 | fprintf(stderr, "mdb_txn_commit failed, error %d %s\n", rc, mdb_strerror(rc));
141 | goto txn_abort;
142 | }
143 | txn = NULL;
144 |
145 | txn_abort:
146 | if (txn)
147 | mdb_txn_abort(txn);
148 | env_close:
149 | mdb_env_close(env);
150 | if (mlm)
151 | mlm_unload(mlm);
152 |
153 | return rc ? EXIT_FAILURE : EXIT_SUCCESS;
154 | }
155 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/mdb_dump.1:
--------------------------------------------------------------------------------
1 | .TH MDB_DUMP 1 "2017/07/31" "LMDB 0.9.90"
2 | .\" Copyright 2014-2021 Howard Chu, Symas Corp. All Rights Reserved.
3 | .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
4 | .SH NAME
5 | mdb_dump \- LMDB environment export tool
6 | .SH SYNOPSIS
7 | .B mdb_dump
8 | [\c
9 | .BR \-V ]
10 | [\c
11 | .BI \-f \ file\fR]
12 | [\c
13 | .BR \-l ]
14 | [\c
15 | .BR \-n ]
16 | [\c
17 | .BR \-v ]
18 | [\c
19 | .BR \-p ]
20 | [\c
21 | .BI \-m \ module
22 | [\c
23 | .BI \-w \ password\fR]]
24 | [\c
25 | .BR \-a \ |
26 | .BI \-s \ subdb\fR]
27 | .BR \ envpath
28 | .SH DESCRIPTION
29 | The
30 | .B mdb_dump
31 | utility reads a database and writes its contents to the
32 | standard output using a portable flat-text format
33 | understood by the
34 | .BR mdb_load (1)
35 | utility.
36 | .SH OPTIONS
37 | .TP
38 | .BR \-V
39 | Write the library version number to the standard output, and exit.
40 | .TP
41 | .BR \-f \ file
42 | Write to the specified file instead of to the standard output.
43 | .TP
44 | .BR \-l
45 | List the databases stored in the environment. Just the
46 | names will be listed, no data will be output.
47 | .TP
48 | .BR \-n
49 | Dump an LMDB database which does not use subdirectories.
50 | .TP
51 | .BR \-v
52 | Use the previous environment state instead of the latest state.
53 | This may be useful if the latest state has been corrupted.
54 | .TP
55 | .BR \-p
56 | If characters in either the key or data items are printing characters (as
57 | defined by isprint(3)), output them directly. This option permits users to
58 | use standard text editors and tools to modify the contents of databases.
59 |
60 | Note: different systems may have different notions about what characters
61 | are considered printing characters, and databases dumped in this manner may
62 | be less portable to external systems.
63 | .TP
64 | .BI \-m \ module
65 | Load the specified dynamic module to utilize cryptographic functions.
66 | This is required to operate on environments that have been configured
67 | with page-level checksums or encryption.
68 | .TP
69 | .BI \-w \ password
70 | Specify the password for an encrypted environment. This is only
71 | used if a cryptography module has been loaded.
72 | .TP
73 | .BR \-a
74 | Dump all of the subdatabases in the environment.
75 | .TP
76 | .BR \-s \ subdb
77 | Dump a specific subdatabase. If no database is specified, only the main database is dumped.
78 | .SH DIAGNOSTICS
79 | Exit status is zero if no errors occur.
80 | Errors result in a non-zero exit status and
81 | a diagnostic message being written to standard error.
82 |
83 | Dumping and reloading databases that use user-defined comparison functions
84 | will result in new databases that use the default comparison functions.
85 | \fBIn this case it is quite likely that the reloaded database will be
86 | damaged beyond repair permitting neither record storage nor retrieval.\fP
87 |
88 | The only available workaround is to modify the source for the
89 | .BR mdb_load (1)
90 | utility to load the database using the correct comparison functions.
91 | .SH "SEE ALSO"
92 | .BR mdb_load (1)
93 | .SH AUTHOR
94 | Howard Chu of Symas Corporation
95 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/mdb_load.1:
--------------------------------------------------------------------------------
1 | .TH MDB_LOAD 1 "2015/09/30" "LMDB 0.9.90"
2 | .\" Copyright 2014-2021 Howard Chu, Symas Corp. All Rights Reserved.
3 | .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
4 | .SH NAME
5 | mdb_load \- LMDB environment import tool
6 | .SH SYNOPSIS
7 | .B mdb_load
8 | [\c
9 | .BR \-V ]
10 | [\c
11 | .BI \-f \ file\fR]
12 | [\c
13 | .BR \-n ]
14 | [\c
15 | .BI \-m \ module
16 | [\c
17 | .BI \-w \ password\fR]]
18 | [\c
19 | .BI \-s \ subdb\fR]
20 | [\c
21 | .BR \-N ]
22 | [\c
23 | .BR \-T ]
24 | .BR \ envpath
25 | .SH DESCRIPTION
26 | The
27 | .B mdb_load
28 | utility reads from the standard input and loads it into the
29 | LMDB environment
30 | .BR envpath .
31 |
32 | The input to
33 | .B mdb_load
34 | must be in the output format specified by the
35 | .BR mdb_dump (1)
36 | utility or as specified by the
37 | .B -T
38 | option below.
39 | .SH OPTIONS
40 | .TP
41 | .BR \-V
42 | Write the library version number to the standard output, and exit.
43 | .TP
44 | .BR \-a
45 | Append all records in the order they appear in the input. The input is assumed to already be
46 | in correctly sorted order and no sorting or checking for redundant values will be performed.
47 | This option must be used to reload data that was produced by running
48 | .B mdb_dump
49 | on a database that uses custom compare functions.
50 | .TP
51 | .BR \-f \ file
52 | Read from the specified file instead of from the standard input.
53 | .TP
54 | .BR \-n
55 | Load an LMDB database which does not use subdirectories.
56 | .TP
57 | .BI \-m \ module
58 | Load the specified dynamic module to utilize cryptographic functions.
59 | This is required to operate on environments that have been configured
60 | with page-level checksums or encryption.
61 | .TP
62 | .BI \-w \ password
63 | Specify the password for an encrypted environment. This is only
64 | used if a cryptography module has been loaded.
65 | .TP
66 | .BR \-s \ subdb
67 | Load a specific subdatabase. If no database is specified, data is loaded into the main database.
68 | .TP
69 | .BR \-N
70 | Don't overwrite existing records when loading into an already existing database; just skip them.
71 | .TP
72 | .BR \-T
73 | Load data from simple text files. The input must be paired lines of text, where the first
74 | line of the pair is the key item, and the second line of the pair is its corresponding
75 | data item.
76 |
77 | A simple escape mechanism, where newline and backslash (\\) characters are special, is
78 | applied to the text input. Newline characters are interpreted as record separators.
79 | Backslash characters in the text will be interpreted in one of two ways: If the backslash
80 | character precedes another backslash character, the pair will be interpreted as a literal
81 | backslash. If the backslash character precedes any other character, the two characters
82 | following the backslash will be interpreted as a hexadecimal specification of a single
83 | character; for example, \\0a is a newline character in the ASCII character set.
84 |
85 | For this reason, any backslash or newline characters that naturally occur in the text
86 | input must be escaped to avoid misinterpretation by
87 | .BR mdb_load .
88 |
89 | .SH DIAGNOSTICS
90 | Exit status is zero if no errors occur.
91 | Errors result in a non-zero exit status and
92 | a diagnostic message being written to standard error.
93 |
94 | .SH "SEE ALSO"
95 | .BR mdb_dump (1)
96 | .SH AUTHOR
97 | Howard Chu of Symas Corporation
98 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/mdb_stat.1:
--------------------------------------------------------------------------------
1 | .TH MDB_STAT 1 "2017/07/31" "LMDB 0.9.90"
2 | .\" Copyright 2012-2021 Howard Chu, Symas Corp. All Rights Reserved.
3 | .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
4 | .SH NAME
5 | mdb_stat \- LMDB environment status tool
6 | .SH SYNOPSIS
7 | .B mdb_stat
8 | [\c
9 | .BR \-V ]
10 | [\c
11 | .BR \-e ]
12 | [\c
13 | .BR \-f [ f [ f ]]]
14 | [\c
15 | .BR \-n ]
16 | [\c
17 | .BR \-v ]
18 | [\c
19 | .BI \-m \ module
20 | [\c
21 | .BI \-w \ password\fR]]
22 | [\c
23 | .BR \-r [ r ]]
24 | [\c
25 | .BR \-a \ |
26 | .BI \-s \ subdb\fR]
27 | .BR \ envpath
28 | .SH DESCRIPTION
29 | The
30 | .B mdb_stat
31 | utility displays the status of an LMDB environment.
32 | .SH OPTIONS
33 | .TP
34 | .BR \-V
35 | Write the library version number to the standard output, and exit.
36 | .TP
37 | .BR \-e
38 | Display information about the database environment.
39 | .TP
40 | .BR \-f
41 | Display information about the environment freelist.
42 | If \fB\-ff\fP is given, summarize each freelist entry.
43 | If \fB\-fff\fP is given, display the full list of page IDs in the freelist.
44 | .TP
45 | .BR \-n
46 | Display the status of an LMDB database which does not use subdirectories.
47 | .TP
48 | .BR \-v
49 | Use the previous environment state instead of the latest state.
50 | This may be useful if the latest state has been corrupted.
51 | .TP
52 | .BI \-m \ module
53 | Load the specified dynamic module to utilize cryptographic functions.
54 | This is required to operate on environments that have been configured
55 | with page-level checksums or encryption.
56 | .TP
57 | .BI \-w \ password
58 | Specify the password for an encrypted environment. This is only
59 | used if a cryptography module has been loaded.
60 | .TP
61 | .BR \-r
62 | Display information about the environment reader table.
63 | Shows the process ID, thread ID, and transaction ID for each active
64 | reader slot. The process ID and transaction ID are in decimal, the
65 | thread ID is in hexadecimal. The transaction ID is displayed as "-"
66 | if the reader does not currently have a read transaction open.
67 | If \fB\-rr\fP is given, check for stale entries in the reader
68 | table and clear them. The reader table will be printed again
69 | after the check is performed.
70 | .TP
71 | .BR \-a
72 | Display the status of all of the subdatabases in the environment.
73 | .TP
74 | .BR \-s \ subdb
75 | Display the status of a specific subdatabase.
76 | .SH DIAGNOSTICS
77 | Exit status is zero if no errors occur.
78 | Errors result in a non-zero exit status and
79 | a diagnostic message being written to standard error.
80 | .SH "SEE ALSO"
81 | .BR mdb_copy (1)
82 | .SH AUTHOR
83 | Howard Chu of Symas Corporation
84 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/module.c:
--------------------------------------------------------------------------------
1 | /* module.c - helper for dynamically loading crypto module */
2 | /*
3 | * Copyright 2020-2021 Howard Chu, Symas Corp.
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted only as authorized by the Symas
8 | * Dual-Use License.
9 | *
10 | * A copy of this license is available in the file LICENSE in the
11 | * source distribution.
12 | */
13 | #ifdef _WIN32
14 | #include
15 | #else
16 | #include
17 | #endif
18 |
19 | #include
20 | #include
21 |
22 | #include "lmdb.h"
23 | #include "module.h"
24 |
25 | void *mlm_load(const char *file, const char *name, MDB_crypto_funcs **mcf_ptr, char **errmsg)
26 | {
27 | MDB_crypto_hooks *hookfunc;
28 | void *ret = NULL;
29 | if (!name)
30 | name = "MDB_crypto";
31 |
32 | #ifdef _WIN32
33 | {
34 | HINSTANCE mlm = LoadLibrary(file);
35 | if (mlm) {
36 | hookfunc = GetProcAddress(mlm, name);
37 | if (hookfunc)
38 | *mcf_ptr = hookfunc();
39 | else {
40 | *errmsg = "Crypto hook function not found";
41 | FreeLibrary(mlm);
42 | mlm = NULL;
43 | }
44 | } else {
45 | *errmsg = GetLastError();
46 | }
47 | ret = (void *)mlm;
48 | }
49 | #else
50 | {
51 | void *mlm = dlopen(file, RTLD_NOW);
52 | if (mlm) {
53 | hookfunc = dlsym(mlm, name);
54 | if (hookfunc)
55 | *mcf_ptr = hookfunc();
56 | else {
57 | *errmsg = "Crypto hook function not found";
58 | dlclose(mlm);
59 | mlm = NULL;
60 | }
61 | } else {
62 | *errmsg = dlerror();
63 | }
64 | ret = mlm;
65 | }
66 | #endif
67 | return ret;
68 | }
69 |
70 | void mlm_unload(void *mlm)
71 | {
72 | #ifdef _WIN32
73 | FreeLibrary((HINSTANCE)mlm);
74 | #else
75 | dlclose(mlm);
76 | #endif
77 | }
78 |
79 | void *mlm_setup(MDB_env *env, const char *file, const char *password, char **errmsg)
80 | {
81 | MDB_crypto_funcs *cf;
82 | MDB_val enckey = {0};
83 | void *mlm = mlm_load(file, NULL, &cf, errmsg);
84 | if (mlm) {
85 | if (cf->mcf_sumfunc) {
86 | mdb_env_set_checksum(env, cf->mcf_sumfunc, cf->mcf_sumsize);
87 | }
88 | if (cf->mcf_encfunc && password) {
89 | char keybuf[2048];
90 | enckey.mv_data = keybuf;
91 | enckey.mv_size = cf->mcf_keysize;
92 | if (cf->mcf_str2key)
93 | cf->mcf_str2key(password, &enckey);
94 | else
95 | strncpy(enckey.mv_data, password, enckey.mv_size);
96 | mdb_env_set_encrypt(env, cf->mcf_encfunc, &enckey, cf->mcf_esumsize);
97 | memset(enckey.mv_data, 0, enckey.mv_size);
98 | }
99 | }
100 | return mlm;
101 | }
102 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/module.h:
--------------------------------------------------------------------------------
1 | /* module.h - helper for dynamically loading crypto module */
2 | /*
3 | * Copyright 2020-2021 Howard Chu, Symas Corp.
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted only as authorized by the Symas
8 | * Dual-Use License.
9 | *
10 | * A copy of this license is available in the file LICENSE in the
11 | * source distribution.
12 | */
13 |
14 | void *mlm_load(const char *file, const char *name, MDB_crypto_funcs **mcf_ptr, char **errmsg);
15 | void mlm_unload(void *lm);
16 | void *mlm_setup(MDB_env *env, const char *file, const char *password, char **errmsg);
17 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/mtest.c:
--------------------------------------------------------------------------------
1 | /* mtest.c - memory-mapped database tester/toy */
2 | /*
3 | * Copyright 2011-2021 Howard Chu, Symas Corp.
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted only as authorized by the OpenLDAP
8 | * Public License.
9 | *
10 | * A copy of this license is available in the file LICENSE in the
11 | * top-level directory of the distribution or, alternatively, at
12 | * .
13 | */
14 | #include
15 | #include
16 | #include
17 | #include "lmdb.h"
18 |
19 | #define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
20 | #define RES(err, expr) ((rc = expr) == (err) || (CHECK(!rc, #expr), 0))
21 | #define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
22 | "%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
23 |
24 | int main(int argc,char * argv[])
25 | {
26 | int i = 0, j = 0, rc;
27 | MDB_env *env;
28 | MDB_dbi dbi;
29 | MDB_val key, data;
30 | MDB_txn *txn;
31 | MDB_stat mst;
32 | MDB_cursor *cursor, *cur2;
33 | MDB_cursor_op op;
34 | int count;
35 | int *values;
36 | char sval[32] = "";
37 |
38 | srand(time(NULL));
39 |
40 | count = (rand()%384) + 64;
41 | values = (int *)malloc(count*sizeof(int));
42 |
43 | for(i = 0;i in each iteration, since MDB_NOOVERWRITE may modify it */
63 | data.mv_size = sizeof(sval);
64 | data.mv_data = sval;
65 | if (RES(MDB_KEYEXIST, mdb_put(txn, dbi, &key, &data, MDB_NOOVERWRITE))) {
66 | j++;
67 | data.mv_size = sizeof(sval);
68 | data.mv_data = sval;
69 | }
70 | }
71 | if (j) printf("%d duplicates skipped\n", j);
72 | E(mdb_txn_commit(txn));
73 | E(mdb_env_stat(env, &mst));
74 |
75 | E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
76 | E(mdb_cursor_open(txn, dbi, &cursor));
77 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
78 | printf("key: %p %.*s, data: %p %.*s\n",
79 | key.mv_data, (int) key.mv_size, (char *) key.mv_data,
80 | data.mv_data, (int) data.mv_size, (char *) data.mv_data);
81 | }
82 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
83 | mdb_cursor_close(cursor);
84 | mdb_txn_abort(txn);
85 |
86 | j=0;
87 | key.mv_data = sval;
88 | for (i= count - 1; i > -1; i-= (rand()%5)) {
89 | j++;
90 | txn=NULL;
91 | E(mdb_txn_begin(env, NULL, 0, &txn));
92 | sprintf(sval, "%03x ", values[i]);
93 | if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, NULL))) {
94 | j--;
95 | mdb_txn_abort(txn);
96 | } else {
97 | E(mdb_txn_commit(txn));
98 | }
99 | }
100 | free(values);
101 | printf("Deleted %d values\n", j);
102 |
103 | E(mdb_env_stat(env, &mst));
104 | E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
105 | E(mdb_cursor_open(txn, dbi, &cursor));
106 | printf("Cursor next\n");
107 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
108 | printf("key: %.*s, data: %.*s\n",
109 | (int) key.mv_size, (char *) key.mv_data,
110 | (int) data.mv_size, (char *) data.mv_data);
111 | }
112 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
113 | printf("Cursor last\n");
114 | E(mdb_cursor_get(cursor, &key, &data, MDB_LAST));
115 | printf("key: %.*s, data: %.*s\n",
116 | (int) key.mv_size, (char *) key.mv_data,
117 | (int) data.mv_size, (char *) data.mv_data);
118 | printf("Cursor prev\n");
119 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
120 | printf("key: %.*s, data: %.*s\n",
121 | (int) key.mv_size, (char *) key.mv_data,
122 | (int) data.mv_size, (char *) data.mv_data);
123 | }
124 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
125 | printf("Cursor last/prev\n");
126 | E(mdb_cursor_get(cursor, &key, &data, MDB_LAST));
127 | printf("key: %.*s, data: %.*s\n",
128 | (int) key.mv_size, (char *) key.mv_data,
129 | (int) data.mv_size, (char *) data.mv_data);
130 | E(mdb_cursor_get(cursor, &key, &data, MDB_PREV));
131 | printf("key: %.*s, data: %.*s\n",
132 | (int) key.mv_size, (char *) key.mv_data,
133 | (int) data.mv_size, (char *) data.mv_data);
134 |
135 | mdb_cursor_close(cursor);
136 | mdb_txn_abort(txn);
137 |
138 | printf("Deleting with cursor\n");
139 | E(mdb_txn_begin(env, NULL, 0, &txn));
140 | E(mdb_cursor_open(txn, dbi, &cur2));
141 | for (i=0; i<50; i++) {
142 | if (RES(MDB_NOTFOUND, mdb_cursor_get(cur2, &key, &data, MDB_NEXT)))
143 | break;
144 | printf("key: %p %.*s, data: %p %.*s\n",
145 | key.mv_data, (int) key.mv_size, (char *) key.mv_data,
146 | data.mv_data, (int) data.mv_size, (char *) data.mv_data);
147 | E(mdb_del(txn, dbi, &key, NULL));
148 | }
149 |
150 | printf("Restarting cursor in txn\n");
151 | for (op=MDB_FIRST, i=0; i<=32; op=MDB_NEXT, i++) {
152 | if (RES(MDB_NOTFOUND, mdb_cursor_get(cur2, &key, &data, op)))
153 | break;
154 | printf("key: %p %.*s, data: %p %.*s\n",
155 | key.mv_data, (int) key.mv_size, (char *) key.mv_data,
156 | data.mv_data, (int) data.mv_size, (char *) data.mv_data);
157 | }
158 | mdb_cursor_close(cur2);
159 | E(mdb_txn_commit(txn));
160 |
161 | printf("Restarting cursor outside txn\n");
162 | E(mdb_txn_begin(env, NULL, 0, &txn));
163 | E(mdb_cursor_open(txn, dbi, &cursor));
164 | for (op=MDB_FIRST, i=0; i<=32; op=MDB_NEXT, i++) {
165 | if (RES(MDB_NOTFOUND, mdb_cursor_get(cursor, &key, &data, op)))
166 | break;
167 | printf("key: %p %.*s, data: %p %.*s\n",
168 | key.mv_data, (int) key.mv_size, (char *) key.mv_data,
169 | data.mv_data, (int) data.mv_size, (char *) data.mv_data);
170 | }
171 | mdb_cursor_close(cursor);
172 | mdb_txn_abort(txn);
173 |
174 | mdb_dbi_close(env, dbi);
175 | mdb_env_close(env);
176 |
177 | return 0;
178 | }
179 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/mtest2.c:
--------------------------------------------------------------------------------
1 | /* mtest2.c - memory-mapped database tester/toy */
2 | /*
3 | * Copyright 2011-2021 Howard Chu, Symas Corp.
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted only as authorized by the OpenLDAP
8 | * Public License.
9 | *
10 | * A copy of this license is available in the file LICENSE in the
11 | * top-level directory of the distribution or, alternatively, at
12 | * .
13 | */
14 |
15 | /* Just like mtest.c, but using a subDB instead of the main DB */
16 |
17 | #include
18 | #include
19 | #include
20 | #include "lmdb.h"
21 |
22 | #define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
23 | #define RES(err, expr) ((rc = expr) == (err) || (CHECK(!rc, #expr), 0))
24 | #define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
25 | "%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
26 |
27 | int main(int argc,char * argv[])
28 | {
29 | int i = 0, j = 0, rc;
30 | MDB_env *env;
31 | MDB_dbi dbi;
32 | MDB_val key, data;
33 | MDB_txn *txn;
34 | MDB_stat mst;
35 | MDB_cursor *cursor;
36 | int count;
37 | int *values;
38 | char sval[32] = "";
39 |
40 | srand(time(NULL));
41 |
42 | count = (rand()%384) + 64;
43 | values = (int *)malloc(count*sizeof(int));
44 |
45 | for(i = 0;i -1; i-= (rand()%5)) {
87 | j++;
88 | txn=NULL;
89 | E(mdb_txn_begin(env, NULL, 0, &txn));
90 | sprintf(sval, "%03x ", values[i]);
91 | if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, NULL))) {
92 | j--;
93 | mdb_txn_abort(txn);
94 | } else {
95 | E(mdb_txn_commit(txn));
96 | }
97 | }
98 | free(values);
99 | printf("Deleted %d values\n", j);
100 |
101 | E(mdb_env_stat(env, &mst));
102 | E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
103 | E(mdb_cursor_open(txn, dbi, &cursor));
104 | printf("Cursor next\n");
105 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
106 | printf("key: %.*s, data: %.*s\n",
107 | (int) key.mv_size, (char *) key.mv_data,
108 | (int) data.mv_size, (char *) data.mv_data);
109 | }
110 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
111 | printf("Cursor prev\n");
112 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
113 | printf("key: %.*s, data: %.*s\n",
114 | (int) key.mv_size, (char *) key.mv_data,
115 | (int) data.mv_size, (char *) data.mv_data);
116 | }
117 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
118 | mdb_cursor_close(cursor);
119 | mdb_txn_abort(txn);
120 |
121 | mdb_dbi_close(env, dbi);
122 | mdb_env_close(env);
123 | return 0;
124 | }
125 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/mtest3.c:
--------------------------------------------------------------------------------
1 | /* mtest3.c - memory-mapped database tester/toy */
2 | /*
3 | * Copyright 2011-2021 Howard Chu, Symas Corp.
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted only as authorized by the OpenLDAP
8 | * Public License.
9 | *
10 | * A copy of this license is available in the file LICENSE in the
11 | * top-level directory of the distribution or, alternatively, at
12 | * .
13 | */
14 |
15 | /* Tests for sorted duplicate DBs */
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include "lmdb.h"
21 |
22 | #define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
23 | #define RES(err, expr) ((rc = expr) == (err) || (CHECK(!rc, #expr), 0))
24 | #define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
25 | "%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
26 |
27 | int main(int argc,char * argv[])
28 | {
29 | int i = 0, j = 0, rc;
30 | MDB_env *env;
31 | MDB_dbi dbi;
32 | MDB_val key, data;
33 | MDB_txn *txn;
34 | MDB_stat mst;
35 | MDB_cursor *cursor;
36 | int count;
37 | int *values;
38 | char sval[32];
39 | char kval[sizeof(int)];
40 |
41 | srand(time(NULL));
42 |
43 | memset(sval, 0, sizeof(sval));
44 |
45 | count = (rand()%384) + 64;
46 | values = (int *)malloc(count*sizeof(int));
47 |
48 | for(i = 0;i -1; i-= (rand()%5)) {
91 | j++;
92 | txn=NULL;
93 | E(mdb_txn_begin(env, NULL, 0, &txn));
94 | sprintf(kval, "%03x", values[i & ~0x0f]);
95 | sprintf(sval, "%03x %d foo bar", values[i], values[i]);
96 | key.mv_size = sizeof(int);
97 | key.mv_data = kval;
98 | data.mv_size = sizeof(sval);
99 | data.mv_data = sval;
100 | if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, &data))) {
101 | j--;
102 | mdb_txn_abort(txn);
103 | } else {
104 | E(mdb_txn_commit(txn));
105 | }
106 | }
107 | free(values);
108 | printf("Deleted %d values\n", j);
109 |
110 | E(mdb_env_stat(env, &mst));
111 | E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
112 | E(mdb_cursor_open(txn, dbi, &cursor));
113 | printf("Cursor next\n");
114 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
115 | printf("key: %.*s, data: %.*s\n",
116 | (int) key.mv_size, (char *) key.mv_data,
117 | (int) data.mv_size, (char *) data.mv_data);
118 | }
119 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
120 | printf("Cursor prev\n");
121 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
122 | printf("key: %.*s, data: %.*s\n",
123 | (int) key.mv_size, (char *) key.mv_data,
124 | (int) data.mv_size, (char *) data.mv_data);
125 | }
126 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
127 | mdb_cursor_close(cursor);
128 | mdb_txn_abort(txn);
129 |
130 | mdb_dbi_close(env, dbi);
131 | mdb_env_close(env);
132 | return 0;
133 | }
134 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/mtest4.c:
--------------------------------------------------------------------------------
1 | /* mtest4.c - memory-mapped database tester/toy */
2 | /*
3 | * Copyright 2011-2021 Howard Chu, Symas Corp.
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted only as authorized by the OpenLDAP
8 | * Public License.
9 | *
10 | * A copy of this license is available in the file LICENSE in the
11 | * top-level directory of the distribution or, alternatively, at
12 | * .
13 | */
14 |
15 | /* Tests for sorted duplicate DBs with fixed-size keys */
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include "lmdb.h"
21 |
22 | #define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
23 | #define RES(err, expr) ((rc = expr) == (err) || (CHECK(!rc, #expr), 0))
24 | #define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
25 | "%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
26 |
27 | int main(int argc,char * argv[])
28 | {
29 | int i = 0, j = 0, rc;
30 | MDB_env *env;
31 | MDB_dbi dbi;
32 | MDB_val key, data;
33 | MDB_txn *txn;
34 | MDB_stat mst;
35 | MDB_cursor *cursor;
36 | int count;
37 | int *values;
38 | char sval[8];
39 | char kval[sizeof(int)];
40 |
41 | memset(sval, 0, sizeof(sval));
42 |
43 | count = 510;
44 | values = (int *)malloc(count*sizeof(int));
45 |
46 | for(i = 0;i -1; i-= (rand()%3)) {
127 | j++;
128 | txn=NULL;
129 | E(mdb_txn_begin(env, NULL, 0, &txn));
130 | sprintf(sval, "%07x", values[i]);
131 | key.mv_size = sizeof(int);
132 | key.mv_data = kval;
133 | data.mv_size = sizeof(sval);
134 | data.mv_data = sval;
135 | if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, &data))) {
136 | j--;
137 | mdb_txn_abort(txn);
138 | } else {
139 | E(mdb_txn_commit(txn));
140 | }
141 | }
142 | free(values);
143 | printf("Deleted %d values\n", j);
144 |
145 | E(mdb_env_stat(env, &mst));
146 | E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
147 | E(mdb_cursor_open(txn, dbi, &cursor));
148 | printf("Cursor next\n");
149 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
150 | printf("key: %.*s, data: %.*s\n",
151 | (int) key.mv_size, (char *) key.mv_data,
152 | (int) data.mv_size, (char *) data.mv_data);
153 | }
154 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
155 | printf("Cursor prev\n");
156 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
157 | printf("key: %.*s, data: %.*s\n",
158 | (int) key.mv_size, (char *) key.mv_data,
159 | (int) data.mv_size, (char *) data.mv_data);
160 | }
161 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
162 | mdb_cursor_close(cursor);
163 | mdb_txn_abort(txn);
164 |
165 | mdb_dbi_close(env, dbi);
166 | mdb_env_close(env);
167 | return 0;
168 | }
169 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/mtest5.c:
--------------------------------------------------------------------------------
1 | /* mtest5.c - memory-mapped database tester/toy */
2 | /*
3 | * Copyright 2011-2021 Howard Chu, Symas Corp.
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted only as authorized by the OpenLDAP
8 | * Public License.
9 | *
10 | * A copy of this license is available in the file LICENSE in the
11 | * top-level directory of the distribution or, alternatively, at
12 | * .
13 | */
14 |
15 | /* Tests for sorted duplicate DBs using cursor_put */
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include "lmdb.h"
21 |
22 | #define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
23 | #define RES(err, expr) ((rc = expr) == (err) || (CHECK(!rc, #expr), 0))
24 | #define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
25 | "%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
26 |
27 | int main(int argc,char * argv[])
28 | {
29 | int i = 0, j = 0, rc;
30 | MDB_env *env;
31 | MDB_dbi dbi;
32 | MDB_val key, data;
33 | MDB_txn *txn;
34 | MDB_stat mst;
35 | MDB_cursor *cursor;
36 | int count;
37 | int *values;
38 | char sval[32];
39 | char kval[sizeof(int)];
40 |
41 | srand(time(NULL));
42 |
43 | memset(sval, 0, sizeof(sval));
44 |
45 | count = (rand()%384) + 64;
46 | values = (int *)malloc(count*sizeof(int));
47 |
48 | for(i = 0;i -1; i-= (rand()%5)) {
93 | j++;
94 | txn=NULL;
95 | E(mdb_txn_begin(env, NULL, 0, &txn));
96 | sprintf(kval, "%03x", values[i & ~0x0f]);
97 | sprintf(sval, "%03x %d foo bar", values[i], values[i]);
98 | key.mv_size = sizeof(int);
99 | key.mv_data = kval;
100 | data.mv_size = sizeof(sval);
101 | data.mv_data = sval;
102 | if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, &data))) {
103 | j--;
104 | mdb_txn_abort(txn);
105 | } else {
106 | E(mdb_txn_commit(txn));
107 | }
108 | }
109 | free(values);
110 | printf("Deleted %d values\n", j);
111 |
112 | E(mdb_env_stat(env, &mst));
113 | E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
114 | E(mdb_cursor_open(txn, dbi, &cursor));
115 | printf("Cursor next\n");
116 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
117 | printf("key: %.*s, data: %.*s\n",
118 | (int) key.mv_size, (char *) key.mv_data,
119 | (int) data.mv_size, (char *) data.mv_data);
120 | }
121 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
122 | printf("Cursor prev\n");
123 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
124 | printf("key: %.*s, data: %.*s\n",
125 | (int) key.mv_size, (char *) key.mv_data,
126 | (int) data.mv_size, (char *) data.mv_data);
127 | }
128 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
129 | mdb_cursor_close(cursor);
130 | mdb_txn_abort(txn);
131 |
132 | mdb_dbi_close(env, dbi);
133 | mdb_env_close(env);
134 | return 0;
135 | }
136 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/mtest6.c:
--------------------------------------------------------------------------------
1 | /* mtest6.c - memory-mapped database tester/toy */
2 | /*
3 | * Copyright 2011-2021 Howard Chu, Symas Corp.
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted only as authorized by the OpenLDAP
8 | * Public License.
9 | *
10 | * A copy of this license is available in the file LICENSE in the
11 | * top-level directory of the distribution or, alternatively, at
12 | * .
13 | */
14 |
15 | /* Tests for DB splits and merges */
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include "lmdb.h"
21 |
22 | #define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
23 | #define RES(err, expr) ((rc = expr) == (err) || (CHECK(!rc, #expr), 0))
24 | #define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
25 | "%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
26 |
27 | char dkbuf[1024];
28 |
29 | int main(int argc,char * argv[])
30 | {
31 | int i = 0, j = 0, rc;
32 | MDB_env *env;
33 | MDB_dbi dbi;
34 | MDB_val key, data, sdata;
35 | MDB_txn *txn;
36 | MDB_stat mst;
37 | MDB_cursor *cursor;
38 | int count;
39 | int *values;
40 | long kval;
41 | char *sval;
42 |
43 | srand(time(NULL));
44 |
45 | E(mdb_env_create(&env));
46 | E(mdb_env_set_mapsize(env, 10485760));
47 | E(mdb_env_set_maxdbs(env, 4));
48 | E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));
49 |
50 | E(mdb_txn_begin(env, NULL, 0, &txn));
51 | E(mdb_dbi_open(txn, "id6", MDB_CREATE|MDB_INTEGERKEY, &dbi));
52 | E(mdb_cursor_open(txn, dbi, &cursor));
53 | E(mdb_stat(txn, dbi, &mst));
54 |
55 | sval = calloc(1, mst.ms_psize / 4);
56 | key.mv_size = sizeof(long);
57 | key.mv_data = &kval;
58 | sdata.mv_size = mst.ms_psize / 4 - 30;
59 | sdata.mv_data = sval;
60 |
61 | printf("Adding 12 values, should yield 3 splits\n");
62 | for (i=0;i<12;i++) {
63 | kval = i*5;
64 | sprintf(sval, "%08x", kval);
65 | data = sdata;
66 | (void)RES(MDB_KEYEXIST, mdb_cursor_put(cursor, &key, &data, MDB_NOOVERWRITE));
67 | }
68 | printf("Adding 12 more values, should yield 3 splits\n");
69 | for (i=0;i<12;i++) {
70 | kval = i*5+4;
71 | sprintf(sval, "%08x", kval);
72 | data = sdata;
73 | (void)RES(MDB_KEYEXIST, mdb_cursor_put(cursor, &key, &data, MDB_NOOVERWRITE));
74 | }
75 | printf("Adding 12 more values, should yield 3 splits\n");
76 | for (i=0;i<12;i++) {
77 | kval = i*5+1;
78 | sprintf(sval, "%08x", kval);
79 | data = sdata;
80 | (void)RES(MDB_KEYEXIST, mdb_cursor_put(cursor, &key, &data, MDB_NOOVERWRITE));
81 | }
82 | E(mdb_cursor_get(cursor, &key, &data, MDB_FIRST));
83 |
84 | do {
85 | printf("key: %p %s, data: %p %.*s\n",
86 | key.mv_data, mdb_dkey(&key, dkbuf),
87 | data.mv_data, (int) data.mv_size, (char *) data.mv_data);
88 | } while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0);
89 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
90 | mdb_cursor_close(cursor);
91 | mdb_txn_commit(txn);
92 |
93 | #if 0
94 | j=0;
95 |
96 | for (i= count - 1; i > -1; i-= (rand()%5)) {
97 | j++;
98 | txn=NULL;
99 | E(mdb_txn_begin(env, NULL, 0, &txn));
100 | sprintf(kval, "%03x", values[i & ~0x0f]);
101 | sprintf(sval, "%03x %d foo bar", values[i], values[i]);
102 | key.mv_size = sizeof(int);
103 | key.mv_data = kval;
104 | data.mv_size = sizeof(sval);
105 | data.mv_data = sval;
106 | if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, &data))) {
107 | j--;
108 | mdb_txn_abort(txn);
109 | } else {
110 | E(mdb_txn_commit(txn));
111 | }
112 | }
113 | free(values);
114 | printf("Deleted %d values\n", j);
115 |
116 | E(mdb_env_stat(env, &mst));
117 | E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
118 | E(mdb_cursor_open(txn, dbi, &cursor));
119 | printf("Cursor next\n");
120 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
121 | printf("key: %.*s, data: %.*s\n",
122 | (int) key.mv_size, (char *) key.mv_data,
123 | (int) data.mv_size, (char *) data.mv_data);
124 | }
125 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
126 | printf("Cursor prev\n");
127 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
128 | printf("key: %.*s, data: %.*s\n",
129 | (int) key.mv_size, (char *) key.mv_data,
130 | (int) data.mv_size, (char *) data.mv_data);
131 | }
132 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
133 | mdb_cursor_close(cursor);
134 | mdb_txn_abort(txn);
135 |
136 | mdb_dbi_close(env, dbi);
137 | #endif
138 | mdb_env_close(env);
139 |
140 | return 0;
141 | }
142 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/mtest_remap.c:
--------------------------------------------------------------------------------
1 | /* mtest_remap.c - memory-mapped database tester/toy with page remapping */
2 | /*
3 | * Copyright 2011-2021 Howard Chu, Symas Corp.
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted only as authorized by the Symas
8 | * Dual-Use License.
9 | *
10 | * A copy of this license is available in the file LICENSE in the
11 | * source distribution.
12 | */
13 | #include
14 | #include
15 | #include
16 | #include "lmdb.h"
17 | #include "chacha8.h"
18 |
19 | #define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
20 | #define RES(err, expr) ((rc = expr) == (err) || (CHECK(!rc, #expr), 0))
21 | #define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
22 | "%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
23 |
24 | int main(int argc,char * argv[])
25 | {
26 | int i = 0, j = 0, rc;
27 | MDB_env *env;
28 | MDB_dbi dbi;
29 | MDB_val key, data;
30 | MDB_txn *txn;
31 | MDB_stat mst;
32 | MDB_cursor *cursor, *cur2;
33 | MDB_cursor_op op;
34 | int count;
35 | int *values;
36 | char sval[32] = "";
37 |
38 | srand(time(NULL));
39 |
40 | count = (rand()%384) + 64;
41 | values = (int *)malloc(count*sizeof(int));
42 |
43 | for(i = 0;i in each iteration, since MDB_NOOVERWRITE may modify it */
62 | data.mv_size = sizeof(sval);
63 | data.mv_data = sval;
64 | if (RES(MDB_KEYEXIST, mdb_put(txn, dbi, &key, &data, MDB_NOOVERWRITE))) {
65 | j++;
66 | data.mv_size = sizeof(sval);
67 | data.mv_data = sval;
68 | }
69 | }
70 | if (j) printf("%d duplicates skipped\n", j);
71 | E(mdb_txn_commit(txn));
72 | E(mdb_env_stat(env, &mst));
73 |
74 | E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
75 | E(mdb_cursor_open(txn, dbi, &cursor));
76 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
77 | printf("key: %p %.*s, data: %p %.*s\n",
78 | key.mv_data, (int) key.mv_size, (char *) key.mv_data,
79 | data.mv_data, (int) data.mv_size, (char *) data.mv_data);
80 | }
81 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
82 | mdb_cursor_close(cursor);
83 | mdb_txn_abort(txn);
84 |
85 | j=0;
86 | key.mv_data = sval;
87 | for (i= count - 1; i > -1; i-= (rand()%5)) {
88 | j++;
89 | txn=NULL;
90 | E(mdb_txn_begin(env, NULL, 0, &txn));
91 | sprintf(sval, "%03x ", values[i]);
92 | if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, NULL))) {
93 | j--;
94 | mdb_txn_abort(txn);
95 | } else {
96 | E(mdb_txn_commit(txn));
97 | }
98 | }
99 | free(values);
100 | printf("Deleted %d values\n", j);
101 |
102 | E(mdb_env_stat(env, &mst));
103 | E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn));
104 | E(mdb_cursor_open(txn, dbi, &cursor));
105 | printf("Cursor next\n");
106 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
107 | printf("key: %.*s, data: %.*s\n",
108 | (int) key.mv_size, (char *) key.mv_data,
109 | (int) data.mv_size, (char *) data.mv_data);
110 | }
111 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
112 | printf("Cursor last\n");
113 | E(mdb_cursor_get(cursor, &key, &data, MDB_LAST));
114 | printf("key: %.*s, data: %.*s\n",
115 | (int) key.mv_size, (char *) key.mv_data,
116 | (int) data.mv_size, (char *) data.mv_data);
117 | printf("Cursor prev\n");
118 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
119 | printf("key: %.*s, data: %.*s\n",
120 | (int) key.mv_size, (char *) key.mv_data,
121 | (int) data.mv_size, (char *) data.mv_data);
122 | }
123 | CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
124 | printf("Cursor last/prev\n");
125 | E(mdb_cursor_get(cursor, &key, &data, MDB_LAST));
126 | printf("key: %.*s, data: %.*s\n",
127 | (int) key.mv_size, (char *) key.mv_data,
128 | (int) data.mv_size, (char *) data.mv_data);
129 | E(mdb_cursor_get(cursor, &key, &data, MDB_PREV));
130 | printf("key: %.*s, data: %.*s\n",
131 | (int) key.mv_size, (char *) key.mv_data,
132 | (int) data.mv_size, (char *) data.mv_data);
133 |
134 | mdb_cursor_close(cursor);
135 | mdb_txn_abort(txn);
136 |
137 | printf("Deleting with cursor\n");
138 | E(mdb_txn_begin(env, NULL, 0, &txn));
139 | E(mdb_cursor_open(txn, dbi, &cur2));
140 | for (i=0; i<50; i++) {
141 | if (RES(MDB_NOTFOUND, mdb_cursor_get(cur2, &key, &data, MDB_NEXT)))
142 | break;
143 | printf("key: %p %.*s, data: %p %.*s\n",
144 | key.mv_data, (int) key.mv_size, (char *) key.mv_data,
145 | data.mv_data, (int) data.mv_size, (char *) data.mv_data);
146 | E(mdb_del(txn, dbi, &key, NULL));
147 | }
148 |
149 | printf("Restarting cursor in txn\n");
150 | for (op=MDB_FIRST, i=0; i<=32; op=MDB_NEXT, i++) {
151 | if (RES(MDB_NOTFOUND, mdb_cursor_get(cur2, &key, &data, op)))
152 | break;
153 | printf("key: %p %.*s, data: %p %.*s\n",
154 | key.mv_data, (int) key.mv_size, (char *) key.mv_data,
155 | data.mv_data, (int) data.mv_size, (char *) data.mv_data);
156 | }
157 | mdb_cursor_close(cur2);
158 | E(mdb_txn_commit(txn));
159 |
160 | printf("Restarting cursor outside txn\n");
161 | E(mdb_txn_begin(env, NULL, 0, &txn));
162 | E(mdb_cursor_open(txn, dbi, &cursor));
163 | for (op=MDB_FIRST, i=0; i<=32; op=MDB_NEXT, i++) {
164 | if (RES(MDB_NOTFOUND, mdb_cursor_get(cursor, &key, &data, op)))
165 | break;
166 | printf("key: %p %.*s, data: %p %.*s\n",
167 | key.mv_data, (int) key.mv_size, (char *) key.mv_data,
168 | data.mv_data, (int) data.mv_size, (char *) data.mv_data);
169 | }
170 | mdb_cursor_close(cursor);
171 | mdb_txn_abort(txn);
172 |
173 | mdb_dbi_close(env, dbi);
174 | mdb_env_close(env);
175 |
176 | return 0;
177 | }
178 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/sample-bdb.txt:
--------------------------------------------------------------------------------
1 | /* sample-bdb.txt - BerkeleyDB toy/sample
2 | *
3 | * Do a line-by-line comparison of this and sample-mdb.txt
4 | */
5 | /*
6 | * Copyright 2012-2021 Howard Chu, Symas Corp.
7 | * All rights reserved.
8 | *
9 | * Redistribution and use in source and binary forms, with or without
10 | * modification, are permitted only as authorized by the OpenLDAP
11 | * Public License.
12 | *
13 | * A copy of this license is available in the file LICENSE in the
14 | * top-level directory of the distribution or, alternatively, at
15 | * .
16 | */
17 | #include
18 | #include
19 | #include
20 |
21 | int main(int argc,char * argv[])
22 | {
23 | int rc;
24 | DB_ENV *env;
25 | DB *dbi;
26 | DBT key, data;
27 | DB_TXN *txn;
28 | DBC *cursor;
29 | char sval[32], kval[32];
30 |
31 | /* Note: Most error checking omitted for simplicity */
32 |
33 | #define FLAGS (DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_INIT_MPOOL|DB_CREATE|DB_THREAD)
34 | rc = db_env_create(&env, 0);
35 | rc = env->open(env, "./testdb", FLAGS, 0664);
36 | rc = db_create(&dbi, env, 0);
37 | rc = env->txn_begin(env, NULL, &txn, 0);
38 | rc = dbi->open(dbi, txn, "test.bdb", NULL, DB_BTREE, DB_CREATE, 0664);
39 |
40 | memset(&key, 0, sizeof(DBT));
41 | memset(&data, 0, sizeof(DBT));
42 | key.size = sizeof(int);
43 | key.data = sval;
44 | data.size = sizeof(sval);
45 | data.data = sval;
46 |
47 | sprintf(sval, "%03x %d foo bar", 32, 3141592);
48 | rc = dbi->put(dbi, txn, &key, &data, 0);
49 | rc = txn->commit(txn, 0);
50 | if (rc) {
51 | fprintf(stderr, "txn->commit: (%d) %s\n", rc, db_strerror(rc));
52 | goto leave;
53 | }
54 | rc = env->txn_begin(env, NULL, &txn, 0);
55 | rc = dbi->cursor(dbi, txn, &cursor, 0);
56 | key.flags = DB_DBT_USERMEM;
57 | key.data = kval;
58 | key.ulen = sizeof(kval);
59 | data.flags = DB_DBT_USERMEM;
60 | data.data = sval;
61 | data.ulen = sizeof(sval);
62 | while ((rc = cursor->c_get(cursor, &key, &data, DB_NEXT)) == 0) {
63 | printf("key: %p %.*s, data: %p %.*s\n",
64 | key.data, (int) key.size, (char *) key.data,
65 | data.data, (int) data.size, (char *) data.data);
66 | }
67 | rc = cursor->c_close(cursor);
68 | rc = txn->abort(txn);
69 | leave:
70 | rc = dbi->close(dbi, 0);
71 | rc = env->close(env, 0);
72 | return rc;
73 | }
74 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/sample-mdb.txt:
--------------------------------------------------------------------------------
1 | /* sample-mdb.txt - MDB toy/sample
2 | *
3 | * Do a line-by-line comparison of this and sample-bdb.txt
4 | */
5 | /*
6 | * Copyright 2012-2021 Howard Chu, Symas Corp.
7 | * All rights reserved.
8 | *
9 | * Redistribution and use in source and binary forms, with or without
10 | * modification, are permitted only as authorized by the OpenLDAP
11 | * Public License.
12 | *
13 | * A copy of this license is available in the file LICENSE in the
14 | * top-level directory of the distribution or, alternatively, at
15 | * .
16 | */
17 | #include
18 | #include "lmdb.h"
19 |
20 | int main(int argc,char * argv[])
21 | {
22 | int rc;
23 | MDB_env *env;
24 | MDB_dbi dbi;
25 | MDB_val key, data;
26 | MDB_txn *txn;
27 | MDB_cursor *cursor;
28 | char sval[32];
29 |
30 | /* Note: Most error checking omitted for simplicity */
31 |
32 | rc = mdb_env_create(&env);
33 | rc = mdb_env_open(env, "./testdb", 0, 0664);
34 | rc = mdb_txn_begin(env, NULL, 0, &txn);
35 | rc = mdb_dbi_open(txn, NULL, 0, &dbi);
36 |
37 | key.mv_size = sizeof(int);
38 | key.mv_data = sval;
39 | data.mv_size = sizeof(sval);
40 | data.mv_data = sval;
41 |
42 | sprintf(sval, "%03x %d foo bar", 32, 3141592);
43 | rc = mdb_put(txn, dbi, &key, &data, 0);
44 | rc = mdb_txn_commit(txn);
45 | if (rc) {
46 | fprintf(stderr, "mdb_txn_commit: (%d) %s\n", rc, mdb_strerror(rc));
47 | goto leave;
48 | }
49 | rc = mdb_txn_begin(env, NULL, MDB_RDONLY, &txn);
50 | rc = mdb_cursor_open(txn, dbi, &cursor);
51 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
52 | printf("key: %p %.*s, data: %p %.*s\n",
53 | key.mv_data, (int) key.mv_size, (char *) key.mv_data,
54 | data.mv_data, (int) data.mv_size, (char *) data.mv_data);
55 | }
56 | mdb_cursor_close(cursor);
57 | mdb_txn_abort(txn);
58 | leave:
59 | mdb_dbi_close(env, dbi);
60 | mdb_env_close(env);
61 | return 0;
62 | }
63 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/tooltag:
--------------------------------------------------------------------------------
1 |
2 |
3 | mdb_copy_1
4 | mdb_copy - environment copy tool
5 | mdb_copy.1
6 |
7 |
8 | mdb_drop_1
9 | mdb_drop - database delete tool
10 | mdb_drop.1
11 |
12 |
13 | mdb_dump_1
14 | mdb_dump - environment export tool
15 | mdb_dump.1
16 |
17 |
18 | mdb_load_1
19 | mdb_load - environment import tool
20 | mdb_load.1
21 |
22 |
23 | mdb_stat_1
24 | mdb_stat - environment status tool
25 | mdb_stat.1
26 |
27 |
28 |
--------------------------------------------------------------------------------
/dependencies/lz4/LICENSE:
--------------------------------------------------------------------------------
1 | This repository uses 2 different licenses :
2 | - all files in the `lib` directory use a BSD 2-Clause license
3 | - all other files use a GPLv2 license, unless explicitly stated otherwise
4 |
5 | Relevant license is reminded at the top of each source file,
6 | and with presence of COPYING or LICENSE file in associated directories.
7 |
8 | This model is selected to emphasize that
9 | files in the `lib` directory are designed to be included into 3rd party applications,
10 | while all other files, in `programs`, `tests` or `examples`,
11 | receive more limited attention and support for such scenario.
12 |
--------------------------------------------------------------------------------
/dependencies/lz4/lib/.gitignore:
--------------------------------------------------------------------------------
1 | # make install artefact
2 | liblz4.pc
3 |
--------------------------------------------------------------------------------
/dependencies/lz4/lib/LICENSE:
--------------------------------------------------------------------------------
1 | LZ4 Library
2 | Copyright (c) 2011-2020, Yann Collet
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without modification,
6 | are permitted provided that the following conditions are met:
7 |
8 | * Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | * Redistributions in binary form must reproduce the above copyright notice, this
12 | list of conditions and the following disclaimer in the documentation and/or
13 | other materials provided with the distribution.
14 |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
19 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
22 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 |
--------------------------------------------------------------------------------
/dependencies/lz4/lib/dll/example/README.md:
--------------------------------------------------------------------------------
1 | LZ4 Windows binary package
2 | ====================================
3 |
4 | #### The package contents
5 |
6 | - `lz4.exe` : Command Line Utility, supporting gzip-like arguments
7 | - `dll\msys-lz4-1.dll` : The DLL of LZ4 library, compiled by msys
8 | - `dll\liblz4.dll.a` : The import library of LZ4 library for Visual C++
9 | - `example\` : The example of usage of LZ4 library
10 | - `include\` : Header files required with LZ4 library
11 | - `static\liblz4_static.lib` : The static LZ4 library
12 |
13 |
14 | #### Usage of Command Line Interface
15 |
16 | Command Line Interface (CLI) supports gzip-like arguments.
17 | By default CLI takes an input file and compresses it to an output file:
18 | ```
19 | Usage: lz4 [arg] [input] [output]
20 | ```
21 | The full list of commands for CLI can be obtained with `-h` or `-H`. The ratio can
22 | be improved with commands from `-3` to `-16` but higher levels also have slower
23 | compression. CLI includes in-memory compression benchmark module with compression
24 | levels starting from `-b` and ending with `-e` with iteration time of `-i` seconds.
25 | CLI supports aggregation of parameters i.e. `-b1`, `-e18`, and `-i1` can be joined
26 | into `-b1e18i1`.
27 |
28 |
29 | #### The example of usage of static and dynamic LZ4 libraries with gcc/MinGW
30 |
31 | Use `cd example` and `make` to build `fullbench-dll` and `fullbench-lib`.
32 | `fullbench-dll` uses a dynamic LZ4 library from the `dll` directory.
33 | `fullbench-lib` uses a static LZ4 library from the `lib` directory.
34 |
35 |
36 | #### Using LZ4 DLL with gcc/MinGW
37 |
38 | The header files from `include\` and the dynamic library `dll\msys-lz4-1.dll`
39 | are required to compile a project using gcc/MinGW.
40 | The dynamic library has to be added to linking options.
41 | It means that if a project that uses LZ4 consists of a single `test-dll.c`
42 | file it should be linked with `dll\msys-lz4-1.dll`. For example:
43 | ```
44 | gcc $(CFLAGS) -Iinclude\ test-dll.c -o test-dll dll\msys-lz4-1.dll
45 | ```
46 | The compiled executable will require LZ4 DLL which is available at `dll\msys-lz4-1.dll`.
47 |
48 |
49 | #### The example of usage of static and dynamic LZ4 libraries with Visual C++
50 |
51 | Open `example\fullbench-dll.sln` to compile `fullbench-dll` that uses a
52 | dynamic LZ4 library from the `dll` directory. The solution works with Visual C++
53 | 2010 or newer. When one will open the solution with Visual C++ newer than 2010
54 | then the solution will be upgraded to the current version.
55 |
56 |
57 | #### Using LZ4 DLL with Visual C++
58 |
59 | The header files from `include\` and the import library `dll\liblz4.dll.a`
60 | are required to compile a project using Visual C++.
61 |
62 | 1. The header files should be added to `Additional Include Directories` that can
63 | be found in project properties `C/C++` then `General`.
64 | 2. The import library has to be added to `Additional Dependencies` that can
65 | be found in project properties `Linker` then `Input`.
66 | If one will provide only the name `liblz4.dll.a` without a full path to the library
67 | the directory has to be added to `Linker\General\Additional Library Directories`.
68 |
69 | The compiled executable will require LZ4 DLL which is available at `dll\msys-lz4-1.dll`.
70 |
--------------------------------------------------------------------------------
/dependencies/lz4/lib/dll/example/fullbench-dll.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 12.00
2 | # Visual Studio Express 2012 for Windows Desktop
3 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fullbench-dll", "fullbench-dll.vcxproj", "{13992FD2-077E-4954-B065-A428198201A9}"
4 | EndProject
5 | Global
6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
7 | Debug|Win32 = Debug|Win32
8 | Debug|x64 = Debug|x64
9 | Release|Win32 = Release|Win32
10 | Release|x64 = Release|x64
11 | EndGlobalSection
12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
13 | {13992FD2-077E-4954-B065-A428198201A9}.Debug|Win32.ActiveCfg = Debug|Win32
14 | {13992FD2-077E-4954-B065-A428198201A9}.Debug|Win32.Build.0 = Debug|Win32
15 | {13992FD2-077E-4954-B065-A428198201A9}.Debug|x64.ActiveCfg = Debug|x64
16 | {13992FD2-077E-4954-B065-A428198201A9}.Debug|x64.Build.0 = Debug|x64
17 | {13992FD2-077E-4954-B065-A428198201A9}.Release|Win32.ActiveCfg = Release|Win32
18 | {13992FD2-077E-4954-B065-A428198201A9}.Release|Win32.Build.0 = Release|Win32
19 | {13992FD2-077E-4954-B065-A428198201A9}.Release|x64.ActiveCfg = Release|x64
20 | {13992FD2-077E-4954-B065-A428198201A9}.Release|x64.Build.0 = Release|x64
21 | EndGlobalSection
22 | GlobalSection(SolutionProperties) = preSolution
23 | HideSolutionNode = FALSE
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/dependencies/lz4/lib/dll/liblz4.def:
--------------------------------------------------------------------------------
1 | LIBRARY liblz4.dll
2 | EXPORTS
3 | LZ4F_compressBegin
4 | LZ4F_compressBound
5 | LZ4F_compressEnd
6 | LZ4F_compressFrame
7 | LZ4F_compressFrameBound
8 | LZ4F_compressUpdate
9 | LZ4F_createCompressionContext
10 | LZ4F_createDecompressionContext
11 | LZ4F_decompress
12 | LZ4F_flush
13 | LZ4F_freeCompressionContext
14 | LZ4F_freeDecompressionContext
15 | LZ4F_getErrorName
16 | LZ4F_getFrameInfo
17 | LZ4F_getVersion
18 | LZ4F_isError
19 | LZ4_compress
20 | LZ4_compressBound
21 | LZ4_compressHC
22 | LZ4_compressHC_continue
23 | LZ4_compressHC_limitedOutput
24 | LZ4_compressHC_limitedOutput_continue
25 | LZ4_compressHC_limitedOutput_withStateHC
26 | LZ4_compressHC_withStateHC
27 | LZ4_compress_HC
28 | LZ4_compress_HC_continue
29 | LZ4_compress_HC_extStateHC
30 | LZ4_compress_continue
31 | LZ4_compress_default
32 | LZ4_compress_destSize
33 | LZ4_compress_fast
34 | LZ4_compress_fast_continue
35 | LZ4_compress_fast_extState
36 | LZ4_compress_limitedOutput
37 | LZ4_compress_limitedOutput_continue
38 | LZ4_compress_limitedOutput_withState
39 | LZ4_compress_withState
40 | LZ4_createStream
41 | LZ4_createStreamDecode
42 | LZ4_createStreamHC
43 | LZ4_decompress_fast
44 | LZ4_decompress_fast_continue
45 | LZ4_decompress_fast_usingDict
46 | LZ4_decompress_safe
47 | LZ4_decompress_safe_continue
48 | LZ4_decompress_safe_partial
49 | LZ4_decompress_safe_usingDict
50 | LZ4_freeStream
51 | LZ4_freeStreamDecode
52 | LZ4_freeStreamHC
53 | LZ4_loadDict
54 | LZ4_loadDictHC
55 | LZ4_resetStream
56 | LZ4_resetStreamHC
57 | LZ4_saveDict
58 | LZ4_saveDictHC
59 | LZ4_setStreamDecode
60 | LZ4_sizeofState
61 | LZ4_sizeofStateHC
62 | LZ4_versionNumber
63 |
--------------------------------------------------------------------------------
/dependencies/lz4/lib/liblz4-dll.rc.in:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | // DLL version information.
4 | 1 VERSIONINFO
5 | FILEVERSION @LIBVER_MAJOR@,@LIBVER_MINOR@,@LIBVER_PATCH@,0
6 | PRODUCTVERSION @LIBVER_MAJOR@,@LIBVER_MINOR@,@LIBVER_PATCH@,0
7 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
8 | #ifdef _DEBUG
9 | FILEFLAGS VS_FF_DEBUG | VS_FF_PRERELEASE
10 | #else
11 | FILEFLAGS 0
12 | #endif
13 | FILEOS VOS_NT_WINDOWS32
14 | FILETYPE VFT_DLL
15 | FILESUBTYPE VFT2_UNKNOWN
16 | BEGIN
17 | BLOCK "StringFileInfo"
18 | BEGIN
19 | BLOCK "040904B0"
20 | BEGIN
21 | VALUE "CompanyName", "Yann Collet"
22 | VALUE "FileDescription", "Extremely fast compression"
23 | VALUE "FileVersion", "@LIBVER_MAJOR@.@LIBVER_MINOR@.@LIBVER_PATCH@.0"
24 | VALUE "InternalName", "@LIBLZ4@"
25 | VALUE "LegalCopyright", "Copyright (C) 2013-2020, Yann Collet"
26 | VALUE "OriginalFilename", "@LIBLZ4@.dll"
27 | VALUE "ProductName", "LZ4"
28 | VALUE "ProductVersion", "@LIBVER_MAJOR@.@LIBVER_MINOR@.@LIBVER_PATCH@.0"
29 | END
30 | END
31 | BLOCK "VarFileInfo"
32 | BEGIN
33 | VALUE "Translation", 0x0409, 1200
34 | END
35 | END
36 |
--------------------------------------------------------------------------------
/dependencies/lz4/lib/liblz4.pc.in:
--------------------------------------------------------------------------------
1 | # LZ4 - Fast LZ compression algorithm
2 | # Copyright (C) 2011-2020, Yann Collet.
3 | # BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
4 |
5 | prefix=@PREFIX@
6 | libdir=@LIBDIR@
7 | includedir=@INCLUDEDIR@
8 |
9 | Name: lz4
10 | Description: extremely fast lossless compression algorithm library
11 | URL: http://www.lz4.org/
12 | Version: @VERSION@
13 | Libs: -L${libdir} -llz4
14 | Cflags: -I${includedir}
15 |
--------------------------------------------------------------------------------
/dependencies/lz4/lib/lz4file.h:
--------------------------------------------------------------------------------
1 | /*
2 | LZ4 file library
3 | Header File
4 | Copyright (C) 2022, Xiaomi Inc.
5 | BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6 |
7 | Redistribution and use in source and binary forms, with or without
8 | modification, are permitted provided that the following conditions are
9 | met:
10 |
11 | * Redistributions of source code must retain the above copyright
12 | notice, this list of conditions and the following disclaimer.
13 | * Redistributions in binary form must reproduce the above
14 | copyright notice, this list of conditions and the following disclaimer
15 | in the documentation and/or other materials provided with the
16 | distribution.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
30 | You can contact the author at :
31 | - LZ4 source repository : https://github.com/lz4/lz4
32 | - LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c
33 | */
34 | #if defined (__cplusplus)
35 | extern "C" {
36 | #endif
37 |
38 | #ifndef LZ4FILE_H
39 | #define LZ4FILE_H
40 |
41 | #include
42 | #include "lz4frame_static.h"
43 |
44 | typedef struct LZ4_readFile_s LZ4_readFile_t;
45 | typedef struct LZ4_writeFile_s LZ4_writeFile_t;
46 |
47 | /*! LZ4F_readOpen() :
48 | * Set read lz4file handle.
49 | * `lz4f` will set a lz4file handle.
50 | * `fp` must be the return value of the lz4 file opened by fopen.
51 | */
52 | LZ4FLIB_STATIC_API LZ4F_errorCode_t LZ4F_readOpen(LZ4_readFile_t** lz4fRead, FILE* fp);
53 |
54 | /*! LZ4F_read() :
55 | * Read lz4file content to buffer.
56 | * `lz4f` must use LZ4_readOpen to set first.
57 | * `buf` read data buffer.
58 | * `size` read data buffer size.
59 | */
60 | LZ4FLIB_STATIC_API size_t LZ4F_read(LZ4_readFile_t* lz4fRead, void* buf, size_t size);
61 |
62 | /*! LZ4F_readClose() :
63 | * Close lz4file handle.
64 | * `lz4f` must use LZ4_readOpen to set first.
65 | */
66 | LZ4FLIB_STATIC_API LZ4F_errorCode_t LZ4F_readClose(LZ4_readFile_t* lz4fRead);
67 |
68 | /*! LZ4F_writeOpen() :
69 | * Set write lz4file handle.
70 | * `lz4f` will set a lz4file handle.
71 | * `fp` must be the return value of the lz4 file opened by fopen.
72 | */
73 | LZ4FLIB_STATIC_API LZ4F_errorCode_t LZ4F_writeOpen(LZ4_writeFile_t** lz4fWrite, FILE* fp, const LZ4F_preferences_t* prefsPtr);
74 |
75 | /*! LZ4F_write() :
76 | * Write buffer to lz4file.
77 | * `lz4f` must use LZ4F_writeOpen to set first.
78 | * `buf` write data buffer.
79 | * `size` write data buffer size.
80 | */
81 | LZ4FLIB_STATIC_API size_t LZ4F_write(LZ4_writeFile_t* lz4fWrite, void* buf, size_t size);
82 |
83 | /*! LZ4F_writeClose() :
84 | * Close lz4file handle.
85 | * `lz4f` must use LZ4F_writeOpen to set first.
86 | */
87 | LZ4FLIB_STATIC_API LZ4F_errorCode_t LZ4F_writeClose(LZ4_writeFile_t* lz4fWrite);
88 |
89 | #endif /* LZ4FILE_H */
90 |
91 | #if defined (__cplusplus)
92 | }
93 | #endif
94 |
--------------------------------------------------------------------------------
/dependencies/lz4/lib/lz4frame_static.h:
--------------------------------------------------------------------------------
1 | /*
2 | LZ4 auto-framing library
3 | Header File for static linking only
4 | Copyright (C) 2011-2020, Yann Collet.
5 |
6 | BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
7 |
8 | Redistribution and use in source and binary forms, with or without
9 | modification, are permitted provided that the following conditions are
10 | met:
11 |
12 | * Redistributions of source code must retain the above copyright
13 | notice, this list of conditions and the following disclaimer.
14 | * Redistributions in binary form must reproduce the above
15 | copyright notice, this list of conditions and the following disclaimer
16 | in the documentation and/or other materials provided with the
17 | distribution.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
31 | You can contact the author at :
32 | - LZ4 source repository : https://github.com/lz4/lz4
33 | - LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c
34 | */
35 |
36 | #ifndef LZ4FRAME_STATIC_H_0398209384
37 | #define LZ4FRAME_STATIC_H_0398209384
38 |
39 | /* The declarations that formerly were made here have been merged into
40 | * lz4frame.h, protected by the LZ4F_STATIC_LINKING_ONLY macro. Going forward,
41 | * it is recommended to simply include that header directly.
42 | */
43 |
44 | #define LZ4F_STATIC_LINKING_ONLY
45 | #include "lz4frame.h"
46 |
47 | #endif /* LZ4FRAME_STATIC_H_0398209384 */
48 |
--------------------------------------------------------------------------------
/dict/dict.txt:
--------------------------------------------------------------------------------
1 | {"text":"that with they have this from word what some other were which their time will said each tell does three want well also play small home read hand port large spell even land here must high such follow change went light kind need house picture again animal point mother world near build self earth father work part take place made live where after back little only round year came show every good give under name very through just form sentence great think help line differ turn cause much mean before move right same there when your about many then them write would like these long make thing look more could come number sound most people over know water than call first down side been find head stand page should country found answer school grow study still learn plant cover food four between state keep never last thought city tree cross farm hard start might story draw left late don’t while press close night real life north book carry took science room friend began idea fish mountain stop once base hear horse sure watch color face wood main open seem together next white children begin walk example ease paper group always music those both mark often letter until mile river feet care second enough plain girl usual young ready above ever list though feel talk bird soon body family direct pose leave song measure door product black short numeral class wind question happen complete ship area half rock order fire south problem piece told knew pass since whole king street inch multiply nothing course stay wheel full force blue object decide surface deep moon island foot system busy test record boat common gold possible plane stead wonder laugh thousand check game shape equate miss brought heat snow tire bring distant fill east paint language among unit power town fine certain fall lead dark machine note wait plan figure star noun field rest correct able pound done beauty drive stood contain front teach week final gave green quick develop ocean warm free minute strong special mind behind clear tail produce fact space heard best hour better true during hundred five remember step early hold west ground interest reach fast verb sing listen table travel less morning simple several vowel toward against pattern slow center love person money serve appear road rain rule govern pull cold notice voice energy hunt probable brother ride cell believe perhaps pick sudden count square reason length represent subject region size vary settle speak weight general matter circle pair include divide syllable felt grand ball wave drop present heavy dance engine position wide sail material fraction forest race window store summer train sleep prove lone exercise wall catch mount wish board winter written wild instrument kept glass grass edge sign visit past soft bright weather month million bear finish happy hope flower clothe strange gone trade melody trip office receive mouth exact symbol least trouble shout except wrote seed tone join suggest clean break lady yard rise blow blood touch grew cent team wire cost lost brown wear garden equal sent choose fell flow fair bank collect save control decimal else quite broke case middle kill lake moment scale loud spring observe child straight consonant nation dictionary milk speed method organ section dress cloud surprise quiet stone tiny climb cool design poor experiment bottom iron single stick flat twenty skin smile crease hole jump baby eight village meet root raise solve metal whether push seven paragraph third shall held hair describe cook floor either result burn hill safe century consider type coast copy phrase silent tall sand soil roll temperature finger industry value fight beat excite natural view sense capital won’t chair danger fruit rich thick soldier process operate practice separate difficult doctor please protect noon crop modern element student corner party supply whose locate ring character insect caught period indicate radio spoke atom human history effect electric expect bone rail imagine provide agree thus gentle woman captain guess necessary sharp wing create neighbor wash rather crowd corn compare poem string bell depend meat tube famous dollar stream fear sight thin triangle planet hurry chief colony clock mine enter major fresh search send yellow allow print dead spot desert suit current lift rose arrive master track parent shore division sheet substance favor connect post spend chord glad original share station bread charge proper offer segment slave duck instant market degree populate chick dear enemy reply drink occur support speech nature range steam motion path liquid meant quotient teeth shell neck oxygen sugar death pretty skill women season solution magnet silver thank branch match suffix especially afraid huge sister steel discuss forward similar guide experience score apple bought pitch coat mass card band rope slip dream evening condition feed tool total basic smell valley double seat continue block chart sell success company subtract event particular deal swim term opposite wife shoe shoulder spread arrange camp invent cotton born determine quart nine truck noise level chance gather shop stretch throw shine property column molecule select wrong gray repeat require broad prepare salt nose plural anger claim continent","Data":{"Id":1,"Title":"I","Children":[]}},"data":{"id":0,"title":"A","label":"no","definition":"yes","enabled":true,"disabled":false,"count":2,"children":[{"count":2},{}],"types":[true,false,null],"type":null}}
--------------------------------------------------------------------------------
/dict/dict2.txt:
--------------------------------------------------------------------------------
1 | a ability able about above accept according account across act action activity actually add address administration admit adult affect after again against age agency agent ago agree agreement ahead air all allow almost alone along already also although always American among amount analysis and animal another answer any anyone anything appear apply approach area argue arm around arrive art article artist as ask assume at attack attention attorney audience author authority available avoid away baby back bad bag ball bank bar base be beat beautiful because become bed before begin behavior behind believe benefit best better between beyond big bill billion bit black blood blue board body book born both box boy break bring brother budget build building business but buy by call camera campaign can cancer candidate capital car card care career carry case catch cause cell center central century certain certainly chair challenge chance change character charge check child choice choose church citizen city civil claim class clear clearly close coach cold collection college color come commercial common community company compare computer concern condition conference Congress consider consumer contain continue control cost could country couple course court cover create crime cultural culture cup current customer cut dark data daughter day dead deal death debate decade decide decision deep defense degree Democrat democratic describe design despite detail determine develop development die difference different difficult dinner direction director discover discuss discussion disease do doctor dog door down draw dream drive drop drug during each early east easy eat economic economy edge education effect effort eight either election else employee end energy enjoy enough enter entire environment environmental especially establish even evening event ever every everybody everyone everything evidence exactly example executive exist expect experience expert explain eye face fact factor fail fall family far fast father fear federal feel feeling few field fight figure fill film final finally financial find fine finger finish fire firm first fish five floor fly focus follow food foot for force foreign forget form former forward four free friend from front full fund future game garden gas general generation get girl give glass go goal good government great green ground group grow growth guess gun guy hair half hand hang happen happy hard have he head health hear heart heat heavy help her here herself high him himself his history hit hold home hope hospital hot hotel hour house how however huge human hundred husband I idea identify if image imagine impact important improve in include including increase indeed indicate individual industry information inside instead institution interest interesting international interview into investment involve issue it item its itself job join just keep key kid kill kind kitchen know knowledge land language large last late later laugh law lawyer lay lead leader learn least leave left leg legal less let letter level lie life light like likely line list listen little live local long look lose loss lot love low machine magazine main maintain major majority make man manage management manager many market marriage material matter may maybe me mean measure media medical meet meeting member memory mention message method middle might military million mind minute miss mission model modern moment money month more morning most mother mouth move movement movie Mr Mrs much music must my myself name nation national natural nature near nearly necessary need network never new news newspaper next nice night no none nor north not note nothing notice now n't number occur of off offer office officer official often oh oil ok old on once one only onto open operation opportunity option or order organization other others our out outside over own owner page pain painting paper parent part participant particular particularly partner party pass past patient pattern pay peace people per perform performance perhaps period person personal phone physical pick picture piece place plan plant play player PM point police policy political politics poor popular population position positive possible power practice prepare present president pressure pretty prevent price private probably problem process produce product production professional professor program project property protect prove provide public pull purpose push put quality question quickly quite race radio raise range rate rather reach read ready real reality realize really reason receive recent recently recognize record red reduce reflect region relate relationship religious remain remember remove report represent Republican require research resource respond response responsibility rest result return reveal rich right rise risk road rock role room rule run safe same save say scene school science scientist score sea season seat second section security see seek seem sell send senior sense series serious serve service set seven several sex sexual shake share she shoot short shot should shoulder show side sign significant similar simple simply since sing single sister sit site situation six size skill skin small smile so social society soldier some somebody someone something sometimes son song soon sort sound source south southern space speak special specific speech spend sport spring staff stage stand standard star start state statement station stay step still stock stop store story strategy street strong structure student study stuff style subject success successful such suddenly suffer suggest summer support sure surface system table take talk task tax teach teacher team technology television tell ten tend term test than thank that the their them themselves then theory there these they thing think third this those though thought thousand threat three through throughout throw thus time to today together tonight too top total tough toward town trade traditional training travel treat treatment tree trial trip trouble true truth try turn TV two type under understand unit until up upon us use usually value various very victim view violence visit voice vote wait walk wall want war watch water way we weapon wear week weight well west western what whatever when where whether which while white who whole whom whose why wide wife will win wind window wish with within without woman wonder word work worker world worry would write writer wrong yard yeah year yes yet you young your yourself
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | import { EventEmitter } from 'events';
2 | import { setExternals, setNativeFunctions, Dbi, version } from './native.js';
3 | import { arch, tmpdir, platform, endianness } from 'os';
4 | import fs from 'fs';
5 | import { Encoder as MsgpackrEncoder } from 'msgpackr';
6 | import { WeakLRUCache } from 'weak-lru-cache';
7 | import * as orderedBinary from 'ordered-binary';
8 |
9 |
10 | orderedBinary.enableNullTermination();
11 | setExternals({
12 | arch, fs, tmpdir, MsgpackrEncoder, WeakLRUCache, orderedBinary,
13 | EventEmitter, os: platform(), onExit(callback) {
14 | if (process.getMaxListeners() < process.listenerCount('exit') + 8)
15 | process.setMaxListeners(process.listenerCount('exit') + 8);
16 | process.on('exit', callback);
17 | }, isLittleEndian: endianness() == 'LE'
18 | });
19 | export { toBufferKey as keyValueToBuffer, compareKeys, compareKeys as compareKey, fromBufferKey as bufferToKeyValue } from 'ordered-binary';
20 | export { ABORT, IF_EXISTS, asBinary } from './write.js';
21 | import { ABORT, IF_EXISTS, asBinary } from './write.js';
22 | export { levelup } from './level.js';
23 | export { SKIP } from './util/RangeIterable.js';
24 | import { levelup } from './level.js';
25 | export { clearKeptObjects, version } from './native.js';
26 | import { nativeAddon } from './native.js';
27 | export let { noop } = nativeAddon;
28 | export const TIMESTAMP_PLACEHOLDER = (() => {
29 | if (endianness() == 'BE') {
30 | return new Uint8Array([0,0,0,0,1,1,1,1]);
31 | } else {
32 | return new Uint8Array([1,1,1,1,0,0,0,0]);
33 | }
34 | })();
35 | export const DIRECT_WRITE_PLACEHOLDER = (() => {
36 | if (endianness() == 'BE') {
37 | return new Uint8Array([0,0,0,0,2,1,1,1]);
38 | } else {
39 | return new Uint8Array([1,1,1,2,0,0,0,0]);
40 | }
41 | })();
42 | export function setSpecialWriteValue(destArray, placeholder, uint32Value) {
43 | destArray.set(placeholder);
44 | let uint32 = new Uint32Array(destArray.buffer, 0, 2);
45 | endianness() == 'BE' ? uint32[0] = uint32Value : uint32[1] = uint32Value;
46 | }
47 | export { open, openAsClass, getLastVersion, allDbs, getLastTxnId } from './open.js';
48 | import { toBufferKey as keyValueToBuffer, compareKeys as compareKey, fromBufferKey as bufferToKeyValue } from 'ordered-binary';
49 | import { open, openAsClass, getLastVersion } from './open.js';
50 | export const TransactionFlags = {
51 | ABORTABLE: 1,
52 | SYNCHRONOUS_COMMIT: 2,
53 |
54 | NO_SYNC_FLUSH: 0x10000,
55 | };
56 | export default {
57 | open, openAsClass, getLastVersion, compareKey, keyValueToBuffer, bufferToKeyValue, ABORT, IF_EXISTS, asBinary, levelup, TransactionFlags, version
58 | };
59 |
--------------------------------------------------------------------------------
/keys.js:
--------------------------------------------------------------------------------
1 | import { getAddress, orderedBinary, isLittleEndian } from './native.js';
2 |
3 | const REUSE_BUFFER_MODE = 512;
4 | const writeUint32Key = (key, target, start) => {
5 | (target.dataView || (target.dataView = new DataView(target.buffer, 0, target.length))).setUint32(start, key, isLittleEndian);
6 | return start + 4;
7 | };
8 | const readUint32Key = (target, start) => {
9 | return (target.dataView || (target.dataView = new DataView(target.buffer, 0, target.length))).getUint32(start, isLittleEndian);
10 | };
11 | const writeBufferKey = (key, target, start) => {
12 | target.set(key, start);
13 | return key.length + start;
14 | };
15 | const Uint8ArraySlice = Uint8Array.prototype.slice;
16 | const readBufferKey = (target, start, end) => {
17 | return Uint8ArraySlice.call(target, start, end);
18 | };
19 |
20 | let lastEncodedValue, bytes;
21 | export function applyKeyHandling(store) {
22 | if (store.encoding == 'ordered-binary') {
23 | store.encoder = store.decoder = {
24 | writeKey: orderedBinary.writeKey,
25 | readKey: orderedBinary.readKey,
26 | };
27 | }
28 | if (store.encoder && store.encoder.writeKey && !store.encoder.encode) {
29 | store.encoder.encode = function(value, mode) {
30 | if (typeof value !== 'object' && value && value === lastEncodedValue) {
31 | // reuse the last serialized bytes
32 | // NOTE that it is very important that nothing else calls saveKey with saveTo: false
33 | } else {
34 | lastEncodedValue = value;
35 | bytes = saveKey(value, this.writeKey, false, store.maxKeySize);
36 | }
37 | if (bytes.end > 0 && !(REUSE_BUFFER_MODE & mode)) {
38 | return bytes.subarray(bytes.start, bytes.end);
39 | }
40 | return bytes;
41 | };
42 | store.encoder.copyBuffers = true; // just an indicator for the buffer reuse in write.js
43 | }
44 | if (store.decoder && store.decoder.readKey && !store.decoder.decode) {
45 | store.decoder.decode = function(buffer) { return this.readKey(buffer, 0, buffer.length); };
46 | store.decoderCopies = true;
47 | }
48 | if (store.keyIsUint32 || store.keyEncoding == 'uint32') {
49 | store.writeKey = writeUint32Key;
50 | store.readKey = readUint32Key;
51 | } else if (store.keyIsBuffer || store.keyEncoding == 'binary') {
52 | store.writeKey = writeBufferKey;
53 | store.readKey = readBufferKey;
54 | } else if (store.keyEncoder) {
55 | store.writeKey = store.keyEncoder.writeKey;
56 | store.readKey = store.keyEncoder.readKey;
57 | } else {
58 | store.writeKey = orderedBinary.writeKey;
59 | store.readKey = orderedBinary.readKey;
60 | }
61 | }
62 |
63 | let saveBuffer, uint32, saveDataView = { setFloat64() {}, setUint32() {} }, saveDataAddress;
64 | let savePosition = 8000;
65 | let DYNAMIC_KEY_BUFFER_SIZE = 8192;
66 | function allocateSaveBuffer() {
67 | saveBuffer = typeof Buffer != 'undefined' ? Buffer.alloc(DYNAMIC_KEY_BUFFER_SIZE) : new Uint8Array(DYNAMIC_KEY_BUFFER_SIZE);
68 | uint32 = null;
69 | saveBuffer.buffer.address = getAddress(saveBuffer.buffer);
70 | saveDataAddress = saveBuffer.buffer.address;
71 | // TODO: Conditionally only do this for key sequences?
72 | saveDataView.setUint32(savePosition, 0xffffffff);
73 | saveDataView.setFloat64(savePosition + 4, saveDataAddress, isLittleEndian); // save a pointer from the old buffer to the new address for the sake of the prefetch sequences
74 | saveDataView = saveBuffer.dataView || (saveBuffer.dataView = new DataView(saveBuffer.buffer, saveBuffer.byteOffset, saveBuffer.byteLength));
75 | savePosition = 0;
76 | }
77 | export function saveKey(key, writeKey, saveTo, maxKeySize, flags) {
78 | if (savePosition > 7800) {
79 | allocateSaveBuffer();
80 | }
81 | let start = savePosition;
82 | try {
83 | savePosition = key === undefined ? start + 4 :
84 | writeKey(key, saveBuffer, start + 4);
85 | } catch (error) {
86 | saveBuffer.fill(0, start + 4); // restore zeros
87 | if (error.name == 'RangeError') {
88 | if (8180 - start < maxKeySize) {
89 | allocateSaveBuffer(); // try again:
90 | return saveKey(key, writeKey, saveTo, maxKeySize);
91 | }
92 | throw new Error('Key was too large, max key size is ' + maxKeySize);
93 | } else
94 | throw error;
95 | }
96 | let length = savePosition - start - 4;
97 | if (length > maxKeySize) {
98 | throw new Error('Key of size ' + length + ' was too large, max key size is ' + maxKeySize);
99 | }
100 | if (savePosition >= 8160) { // need to reserve enough room at the end for pointers
101 | savePosition = start // reset position
102 | allocateSaveBuffer(); // try again:
103 | return saveKey(key, writeKey, saveTo, maxKeySize);
104 | }
105 | if (saveTo) {
106 | saveDataView.setUint32(start, flags ? length | flags : length, isLittleEndian); // save the length
107 | saveTo.saveBuffer = saveBuffer;
108 | savePosition = (savePosition + 12) & 0xfffffc;
109 | return start + saveDataAddress;
110 | } else {
111 | saveBuffer.start = start + 4;
112 | saveBuffer.end = savePosition;
113 | savePosition = (savePosition + 7) & 0xfffff8; // full 64-bit word alignment since these are usually copied
114 | return saveBuffer;
115 | }
116 | }
--------------------------------------------------------------------------------
/level.js:
--------------------------------------------------------------------------------
1 | export function levelup(store) {
2 | return Object.assign(Object.create(store), {
3 | get(key, options, callback) {
4 | let result = store.get(key);
5 | if (typeof options == 'function')
6 | callback = options;
7 | if (callback) {
8 | if (result === undefined)
9 | callback(new NotFoundError());
10 | else
11 | callback(null, result);
12 | } else {
13 | if (result === undefined)
14 | return Promise.reject(new NotFoundError());
15 | else
16 | return Promise.resolve(result);
17 | }
18 | },
19 | });
20 | }
21 | class NotFoundError extends Error {
22 | constructor(message) {
23 | super(message);
24 | this.name = 'NotFoundError';
25 | this.notFound = true;
26 | }
27 | }
--------------------------------------------------------------------------------
/native.js:
--------------------------------------------------------------------------------
1 | import { dirname, join, default as pathModule } from 'path';
2 | import { fileURLToPath } from 'url';
3 | import loadNAPI from 'node-gyp-build-optional-packages';
4 | export let Env,
5 | Txn,
6 | Dbi,
7 | Compression,
8 | Cursor,
9 | getAddress,
10 | getBufferAddress,
11 | createBufferForAddress,
12 | clearKeptObjects,
13 | globalBuffer,
14 | setGlobalBuffer,
15 | arch,
16 | fs,
17 | os,
18 | onExit,
19 | isLittleEndian,
20 | tmpdir,
21 | lmdbError,
22 | path,
23 | EventEmitter,
24 | orderedBinary,
25 | MsgpackrEncoder,
26 | WeakLRUCache,
27 | setEnvMap,
28 | getEnvMap,
29 | getByBinary,
30 | detachBuffer,
31 | startRead,
32 | setReadCallback,
33 | write,
34 | position,
35 | iterate,
36 | prefetch,
37 | resetTxn,
38 | getCurrentValue,
39 | getCurrentShared,
40 | getStringByBinary,
41 | getSharedByBinary,
42 | getSharedBuffer,
43 | compress,
44 | directWrite,
45 | getUserSharedBuffer,
46 | notifyUserCallbacks,
47 | attemptLock,
48 | unlock,
49 | version;
50 | path = pathModule;
51 | let dirName = dirname(fileURLToPath(import.meta.url)).replace(/dist$/, '');
52 | export let nativeAddon = loadNAPI(dirName);
53 |
54 | if (process.isBun && false) {
55 | const { linkSymbols, FFIType } = require('bun:ffi');
56 | let lmdbLib = linkSymbols({
57 | getByBinary: {
58 | args: [FFIType.f64, FFIType.u32],
59 | returns: FFIType.u32,
60 | ptr: nativeAddon.getByBinaryPtr,
61 | },
62 | iterate: {
63 | args: [FFIType.f64],
64 | returns: FFIType.i32,
65 | ptr: nativeAddon.iteratePtr,
66 | },
67 | position: {
68 | args: [FFIType.f64, FFIType.u32, FFIType.u32, FFIType.u32, FFIType.f64],
69 | returns: FFIType.i32,
70 | ptr: nativeAddon.positionPtr,
71 | },
72 | write: {
73 | args: [FFIType.f64, FFIType.f64],
74 | returns: FFIType.i32,
75 | ptr: nativeAddon.writePtr,
76 | },
77 | resetTxn: {
78 | args: [FFIType.f64],
79 | returns: FFIType.void,
80 | ptr: nativeAddon.resetTxnPtr,
81 | },
82 | });
83 | for (let key in lmdbLib.symbols) {
84 | nativeAddon[key] = lmdbLib.symbols[key].native;
85 | }
86 | }
87 | setNativeFunctions(nativeAddon);
88 |
89 | export function setNativeFunctions(externals) {
90 | Env = externals.Env;
91 | Txn = externals.Txn;
92 | Dbi = externals.Dbi;
93 | Compression = externals.Compression;
94 | getAddress = externals.getAddress;
95 | getBufferAddress = externals.getBufferAddress;
96 | createBufferForAddress = externals.createBufferForAddress;
97 | clearKeptObjects = externals.clearKeptObjects || function () {};
98 | getByBinary = externals.getByBinary;
99 | detachBuffer = externals.detachBuffer;
100 | startRead = externals.startRead;
101 | setReadCallback = externals.setReadCallback;
102 | setGlobalBuffer = externals.setGlobalBuffer;
103 | globalBuffer = externals.globalBuffer;
104 | getSharedBuffer = externals.getSharedBuffer;
105 | prefetch = externals.prefetch;
106 | iterate = externals.iterate;
107 | position = externals.position;
108 | resetTxn = externals.resetTxn;
109 | directWrite = externals.directWrite;
110 | getUserSharedBuffer = externals.getUserSharedBuffer;
111 | notifyUserCallbacks = externals.notifyUserCallbacks;
112 | attemptLock = externals.attemptLock;
113 | unlock = externals.unlock;
114 | getCurrentValue = externals.getCurrentValue;
115 | getCurrentShared = externals.getCurrentShared;
116 | getStringByBinary = externals.getStringByBinary;
117 | getSharedByBinary = externals.getSharedByBinary;
118 | write = externals.write;
119 | compress = externals.compress;
120 | Cursor = externals.Cursor;
121 | lmdbError = externals.lmdbError;
122 | version = externals.version;
123 | if (externals.tmpdir) tmpdir = externals.tmpdir;
124 | }
125 | export function setExternals(externals) {
126 | arch = externals.arch;
127 | fs = externals.fs;
128 | EventEmitter = externals.EventEmitter;
129 | orderedBinary = externals.orderedBinary;
130 | MsgpackrEncoder = externals.MsgpackrEncoder;
131 | WeakLRUCache = externals.WeakLRUCache;
132 | tmpdir = externals.tmpdir;
133 | os = externals.os;
134 | onExit = externals.onExit;
135 | isLittleEndian = externals.isLittleEndian;
136 | }
137 |
--------------------------------------------------------------------------------
/node-index.js:
--------------------------------------------------------------------------------
1 | import { createRequire } from 'module';
2 | import { setRequire } from './open.js';
3 | import { nativeAddon, setNativeFunctions } from './native.js';
4 | export { nativeAddon } from './native.js';
5 | let require = createRequire(import.meta.url);
6 | setRequire(require);
7 | export let v8AccelerationEnabled = false;
8 |
9 | let versions = process.versions;
10 | if (!versions.deno && !process.isBun) {
11 | let [majorVersion, minorVersion] = versions.node.split('.');
12 | if (versions.v8 && +majorVersion == nativeAddon.version.nodeCompiledVersion) {
13 | let v8Funcs = {};
14 | let fastApiCalls =
15 | (majorVersion == 17 ||
16 | majorVersion == 18 ||
17 | (majorVersion == 16 && minorVersion > 8)) &&
18 | !process.env.DISABLE_TURBO_CALLS;
19 | if (fastApiCalls) {
20 | require('v8').setFlagsFromString('--turbo-fast-api-calls');
21 | }
22 | nativeAddon.enableDirectV8(v8Funcs, fastApiCalls);
23 | Object.assign(nativeAddon, v8Funcs);
24 | v8AccelerationEnabled = true;
25 | } else if (majorVersion == 14) {
26 | // node v14 only has ABI compatibility with node v16 for zero-arg clearKeptObjects
27 | let v8Funcs = {};
28 | nativeAddon.enableDirectV8(v8Funcs, false);
29 | nativeAddon.clearKeptObjects = v8Funcs.clearKeptObjects;
30 | }
31 | }
32 | nativeAddon.enableThreadSafeCalls();
33 | setNativeFunctions(nativeAddon);
34 |
35 | export * from './index.js';
36 | export { default } from './index.js';
37 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "lmdb",
3 | "author": "Kris Zyp",
4 | "version": "3.4.0",
5 | "description": "Simple, efficient, scalable, high-performance LMDB interface",
6 | "license": "MIT",
7 | "repository": {
8 | "type": "git",
9 | "url": "git+ssh://git@github.com/kriszyp/lmdb-js.git"
10 | },
11 | "keywords": [
12 | "lmdb",
13 | "database",
14 | "mdb",
15 | "lightning",
16 | "key-value store",
17 | "storage",
18 | "adapter",
19 | "performance"
20 | ],
21 | "type": "module",
22 | "main": "dist/index.cjs",
23 | "module": "index.js",
24 | "exports": {
25 | ".": {
26 | "types": {
27 | "require": "./index.d.cts",
28 | "import": "./index.d.ts"
29 | },
30 | "node": {
31 | "require": "./dist/index.cjs",
32 | "import": "./node-index.js"
33 | },
34 | "default": "./index.js"
35 | }
36 | },
37 | "files": [
38 | "/dist",
39 | "/util",
40 | "/dict",
41 | "/dependencies",
42 | "/src",
43 | "*.md",
44 | "/*.js",
45 | "index.d.ts",
46 | "index.d.cts",
47 | "/*.ts",
48 | "/*.gyp",
49 | "/bin"
50 | ],
51 | "types": "./index.d.ts",
52 | "tsd": {
53 | "directory": "test/types"
54 | },
55 | "bin": {
56 | "download-lmdb-prebuilds": "./bin/download-prebuilds.js"
57 | },
58 | "scripts": {
59 | "install": "node-gyp-build-optional-packages",
60 | "build": "node-gyp --debug configure && node-gyp --debug build && rollup -c",
61 | "rebuild": "node-gyp build && rollup -c && cpy index.d.ts . --rename=index.d.cts",
62 | "build-js": "rollup -c",
63 | "prepare": "rollup -c",
64 | "before-publish": "rollup -c && cpy index.d.ts . --rename=index.d.cts && prebuildify-ci download && node util/set-optional-deps.cjs && npm run test",
65 | "prebuild-libc-musl": "ENABLE_V8_FUNCTIONS=false prebuildify-platform-packages --debug --tag-libc --napi --platform-packages --target 22.11.0",
66 | "prebuild-libc": "prebuildify-platform-packages --debug --tag-libc --target 20.18.0 || true && prebuildify-platform-packages --debug --platform-packages --tag-libc --target 22.11.0 && ENABLE_V8_FUNCTIONS=false prebuildify-platform-packages --debug --napi --platform-packages --tag-libc --target 22.11.0",
67 | "prebuild-macos": "ENABLE_V8_FUNCTIONS=false prebuildify-platform-packages --debug --napi --platform-packages --target 18.17.1",
68 | "prebuild-win32": "set ENABLE_V8_FUNCTIONS=false&& prebuildify-platform-packages --debug --napi --platform-packages --target 20.18.0",
69 | "prebuild-libc-arm7": "ENABLE_V8_FUNCTIONS=false prebuildify-platform-packages --debug --napi --platform-packages --tag-libc --target 22.11.0",
70 | "prebuildify": "prebuildify-platform-packages --debug --napi --target 22.11.0",
71 | "full-publish": "cd prebuilds/win32-x64 && npm publish --access public && cd ../win32-arm64 && npm publish --access public && cd ../darwin-x64 && npm publish --access public && cd ../darwin-arm64 && npm publish --access public && cd ../linux-x64 && npm publish --access public && cd ../linux-arm64 && npm publish --access public && cd ../linux-arm && npm publish --access public && cd ../.. && npm publish && node util/remove-optional-deps.cjs",
72 | "recompile": "node-gyp clean && node-gyp configure && node-gyp build",
73 | "recompile-v1": "node-gyp clean && set LMDB_DATA_V1=true&& node-gyp configure && set LMDB_DATA_V1=true&& node-gyp build",
74 | "test": "mocha test/**.test.js --expose-gc --recursive",
75 | "deno-test": "deno run --allow-ffi --allow-write --allow-read --allow-env --allow-net --unstable test/deno.ts",
76 | "test2": "mocha test/performance.js -u tdd",
77 | "test:types": "tsd",
78 | "benchmark": "node ./benchmark/index.js"
79 | },
80 | "gypfile": true,
81 | "dependencies": {
82 | "msgpackr": "^1.11.2",
83 | "node-addon-api": "^6.1.0",
84 | "node-gyp-build-optional-packages": "5.2.2",
85 | "ordered-binary": "^1.5.3",
86 | "weak-lru-cache": "^1.2.2"
87 | },
88 | "devDependencies": {
89 | "@types/node": "^16.7.10",
90 | "benchmark": "^2.1.4",
91 | "chai": "^4.3.4",
92 | "cpy-cli": "^4.1.0",
93 | "fs-extra": "^9.0.1",
94 | "mocha": "^10.1.0",
95 | "prebuildify-ci": "^1.0.5",
96 | "prebuildify-platform-packages": "5.0.5",
97 | "prettier": "^3.0.2",
98 | "rimraf": "^3.0.2",
99 | "rollup": "^2.61.1",
100 | "tsd": "^0.14.0"
101 | },
102 | "bugs": {
103 | "url": "https://github.com/kriszyp/lmdb-js/issues"
104 | },
105 | "homepage": "https://github.com/kriszyp/lmdb-js#readme",
106 | "directories": {
107 | "test": "tests"
108 | },
109 | "prettier": {
110 | "useTabs": true,
111 | "singleQuote": true
112 | },
113 | "optionalDependencies": {}
114 | }
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | export default [
2 | {
3 | input: "node-index.js",
4 | output: [
5 | {
6 | file: "dist/index.cjs",
7 | format: "cjs",
8 | sourcemap: true
9 | }
10 | ]
11 | }
12 | ];
13 |
--------------------------------------------------------------------------------
/src/.npmignore:
--------------------------------------------------------------------------------
1 | .vs
--------------------------------------------------------------------------------
/src/lmdb-js.cpp:
--------------------------------------------------------------------------------
1 | #include "lmdb-js.h"
2 |
3 | using namespace Napi;
4 |
5 | int Logging::initLogging() {
6 | char* logging = getenv("LMDB_JS_LOGGING");
7 | if (logging)
8 | fprintf(stderr, "Start logging for lmdb-js\n");
9 | return !!logging;
10 | }
11 | int Logging::debugLogging = Logging::initLogging();
12 |
13 | Object InitAll(Napi::Env env, Object exports) {
14 | if (Logging::debugLogging)
15 | fprintf(stderr, "Start initialization\n");
16 | // Initializes the module
17 | // Export Env as constructor for EnvWrap
18 | EnvWrap::setupExports(env, exports);
19 |
20 | // Export Cursor as constructor for CursorWrap
21 | CursorWrap::setupExports(env, exports);
22 | TxnWrap::setupExports(env, exports);
23 | DbiWrap::setupExports(env, exports);
24 | CursorWrap::setupExports(env, exports);
25 | Compression::setupExports(env, exports);
26 |
27 | // Export misc things
28 | setupExportMisc(env, exports);
29 | if (Logging::debugLogging)
30 | fprintf(stderr, "Finished initialization\n");
31 | return exports;
32 | }
33 | NAPI_MODULE_INIT() {
34 | Value exp = Value::From(env, exports);
35 | return InitAll(env, exp.As