Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Feb 16, 2024
1 parent abd1628 commit 2e6069a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 47 deletions.
4 changes: 2 additions & 2 deletions dependencies/lmdb-data-v1/libraries/liblmdb/midl.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ MDB_IDL mdb_midl_alloc(int num)

void mdb_midl_free(MDB_IDL ids)
{
if (ids)
free(ids-1);
// if (ids)
// free(ids-1);
}

void mdb_midl_shrink( MDB_IDL *idp )
Expand Down
5 changes: 3 additions & 2 deletions dependencies/lmdb/libraries/liblmdb/mdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -4173,6 +4173,7 @@ mdb_freelist_save(MDB_txn *txn)
MDB_val key, data;

/* Protect DB env from any (buggy) freelist use when saving mop */
MDB_IDL pghead = env->me_pghead;
env->me_pghead = NULL;
txn->mt_dirty_room = 0;

Expand All @@ -4199,9 +4200,9 @@ mdb_freelist_save(MDB_txn *txn)
if (rc || !mop_len)
break;
}
mdb_midl_free(mop);
//mdb_midl_free(mop);

//env->me_pghead = mop - mop_len;
env->me_pghead = pghead;
}

/* Restore this so we can check vs. dirty_list after mdb_page_flush() */
Expand Down
43 changes: 21 additions & 22 deletions dependencies/lmdb/libraries/liblmdb/midl.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,30 @@ unsigned mdb_midl_search( MDB_IDL ids, MDB_ID id )
if (++x > end) { // reached the end, go to lower half
n = pivot;
val = 0;
end -= pivot;
end = cursor;
goto binary_search;
}
}
val = CMP( ids[cursor], id );
val = CMP( ids[x], id );

if( val < 0 ) {
n = pivot;
end -= pivot;
end = x;
} else if ( val > 0 ) {
base = cursor;
n -= pivot + 1;
} else {
return cursor;
}
}
if( val > 0 ) {
unsigned next = ++cursor;
end = ids[0];
// skip past empty and block length entries
while(((ssize_t)ids[cursor]) <= 0) {
if (++cursor > end) { // reached the end
return next; // go back to the one after the last value in this case
}
unsigned next;
if( val > 0 ) ++cursor;
unsigned x = cursor;
end = ids[0];
// skip past empty and block length entries
while(((ssize_t)ids[cursor]) <= 0) {
if (++cursor > end) { // reached the end
return x; // go back to the one after the last value in this case
}
}
return cursor;
Expand Down Expand Up @@ -157,14 +157,12 @@ int mdb_midl_insert( MDB_IDL* ids_ref, MDB_ID id )
} else {
if (x > ids[0]) return -3; // at the end
ssize_t next_id = ids[x];
unsigned next_count = 1;
if (next_id < 0) {
next_count = -next_id;
next_id = ids[x + 1];
}
ssize_t next_count = ids[x - 1];
if (next_count < 0) next_count = -next_count;
else next_count = 1;
unsigned before = x; // this will end up pointing to an entry or zero right before a block of empty space
while (!ids[--before] && before > 0) {
// move past empty entries
while ((ssize_t)ids[--before] <= 0 && before > 0) {
// move past empty entries (and the length entry)
}
if (id - next_count == next_id && next_id > 0) {
// connected to next entry
Expand All @@ -190,7 +188,7 @@ int mdb_midl_insert( MDB_IDL* ids_ref, MDB_ID id )
}
}
if (next_count > 1) {
ids[x] = -count; // update the count
ids[x - 1] = -count; // update the count
} else if (ids[x - 1] == 0) {
ids[x - 1] = -2;
} else {
Expand Down Expand Up @@ -221,7 +219,7 @@ int mdb_midl_insert( MDB_IDL* ids_ref, MDB_ID id )
ids[2] = id;
return 0;
}
if (before + 1 < x) {
if (!ids[before + 1]) {
// there is an empty slot we can use, find a place in the middle
ids[before + 3 < x ? (before + 2) : (before + 1)] = id;
i = 0;
Expand All @@ -231,6 +229,7 @@ int mdb_midl_insert( MDB_IDL* ids_ref, MDB_ID id )
// move items to try to make room
ssize_t last_id = id;
i = x;
if ((ssize_t)ids[i - 1] < 0) i--;
do {
next_id = ids[i];
ids[i++] = last_id;
Expand Down Expand Up @@ -259,8 +258,8 @@ MDB_IDL mdb_midl_alloc(int num)

void mdb_midl_free(MDB_IDL ids)
{
if (ids)
free(ids-1);
//if (ids)
// free(ids-1);
}

void mdb_midl_shrink( MDB_IDL *idp )
Expand Down
41 changes: 20 additions & 21 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
import chai from 'chai';
import path, { dirname } from 'path';
import path, {dirname} from 'path';
import rimraf from 'rimraf';

let should = chai.should();
let expect = chai.expect;
import { spawn } from 'child_process';
import { unlinkSync } from 'fs'
import { fileURLToPath } from 'url'
import { Worker } from 'worker_threads';
import { encoder as orderedBinaryEncoder } from 'ordered-binary/index.js'
import inspector from 'inspector'
//inspector.open(9229, null, true); debugger
let nativeMethods,
dirName = dirname(fileURLToPath(import.meta.url));

import { createRequire } from 'module';
import { createBufferForAddress, fs } from '../native.js';
import {spawn} from 'child_process';
import {unlinkSync} from 'fs'
import {fileURLToPath} from 'url'
import {Worker} from 'worker_threads';
import {encoder as orderedBinaryEncoder} from 'ordered-binary/index.js'
import {createRequire} from 'module';
import {createBufferForAddress} from '../native.js';
import {
ABORT,
IF_EXISTS,
asBinary,
bufferToKeyValue,
DIRECT_WRITE_PLACEHOLDER,
IF_EXISTS,
keyValueToBuffer,
levelup,
open,
TIMESTAMP_PLACEHOLDER,
DIRECT_WRITE_PLACEHOLDER
TIMESTAMP_PLACEHOLDER
} from '../node-index.js';
import { openAsClass } from '../open.js';
import { RangeIterable } from '../util/RangeIterable.js';
import {openAsClass} from '../open.js';
import {RangeIterable} from '../util/RangeIterable.js';

let should = chai.should();
let expect = chai.expect;
//inspector.open(9229, null, true); debugger
let nativeMethods,
dirName = dirname(fileURLToPath(import.meta.url));

const require = createRequire(import.meta.url);
// we don't always test CJS because it messes up debugging in webstorm (and I am not about to give the awesomeness
// that is webstorm debugging)
Expand Down

0 comments on commit 2e6069a

Please sign in to comment.