Skip to content

Commit ebb23f2

Browse files
authored
Merge pull request #6 from powersync-ja/chore/update-sqlite3-upstream
Update sqlite3 upstream
2 parents d35a6f0 + b4397f9 commit ebb23f2

File tree

6 files changed

+46
-17
lines changed

6 files changed

+46
-17
lines changed

sqlite3/CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 2.4.6
2+
3+
- Fix selecting large integers (being represented as a `BigInt` in Dart)
4+
not working when compiled with dartdevc.
5+
6+
## 2.4.5
7+
8+
- Fix a bug in the OPFS-locks implementation causing a deadlock when the `xSleep`
9+
VFS call is issued.
10+
111
## 2.4.4
212

313
- Add a temporary workaround for [a Dart bug](https://github.com/dart-lang/sdk/issues/56064)

sqlite3/lib/src/wasm/js_interop/core.dart

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ external JSBigInt _bigInt(JSAny? s);
88
@JS('Number')
99
external JSNumber _number(JSAny? obj);
1010

11-
@JS('Object')
12-
extension type WrappedJSObject._(JSObject _) implements JSObject {
13-
external WrappedJSObject(JSBigInt _);
14-
11+
extension type WrappedJSAny._(JSAny _) implements JSAny {
1512
external static JSArray<JSAny?> keys(JSObject o);
1613

1714
@JS('toString')
1815
external JSString _toString();
1916
}
2017

18+
@JS('Object')
19+
extension type WrappedJSObject._(JSObject _) implements JSObject {
20+
external static JSArray<JSAny?> keys(JSObject o);
21+
}
22+
2123
extension type JsBigInt(JSBigInt _jsBigInt) implements JSBigInt {
2224
factory JsBigInt.parse(String s) => JsBigInt(_bigInt(s.toJS));
2325
factory JsBigInt.fromInt(int i) => JsBigInt(_bigInt(i.toJS));
@@ -42,7 +44,7 @@ extension type JsBigInt(JSBigInt _jsBigInt) implements JSBigInt {
4244
}
4345

4446
String jsToString() {
45-
return (WrappedJSObject(_jsBigInt))._toString().toDart;
47+
return (_jsBigInt as WrappedJSAny)._toString().toDart;
4648
}
4749
}
4850

sqlite3/lib/src/wasm/vfs/async_opfs/client.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ final class WasmVfs extends BaseVirtualFileSystem {
9191

9292
static WorkerOptions createOptions({String root = 'pkg_sqlite3_db/'}) {
9393
return WorkerOptions(
94-
synchronizationBuffer:
95-
SharedArrayBuffer(RequestResponseSynchronizer.byteLength),
94+
synchronizationBuffer: RequestResponseSynchronizer.createBuffer(),
9695
communicationBuffer: SharedArrayBuffer(MessageSerializer.totalSize),
9796
root: root,
9897
);

sqlite3/lib/src/wasm/vfs/async_opfs/sync_channel.dart

+22-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class RequestResponseSynchronizer {
1313
static const _responseIndex = 1;
1414

1515
// 2 32-bit slots for the int32 array
16-
static const byteLength = 2 * 4;
16+
static const _byteLength = 2 * 4;
1717

1818
/// The shared array buffer used with atomics for synchronization.
1919
///
@@ -26,17 +26,32 @@ class RequestResponseSynchronizer {
2626
RequestResponseSynchronizer._(this.buffer) : int32View = buffer.asInt32List();
2727

2828
factory RequestResponseSynchronizer([SharedArrayBuffer? buffer]) {
29-
if (buffer != null && buffer.byteLength != byteLength) {
30-
throw ArgumentError('Must be $byteLength in length');
29+
if (buffer != null && buffer.byteLength != _byteLength) {
30+
throw ArgumentError('Must be $_byteLength in length');
3131
}
3232

3333
return RequestResponseSynchronizer._(
34-
buffer ?? SharedArrayBuffer(byteLength));
34+
buffer ?? SharedArrayBuffer(_byteLength));
35+
}
36+
37+
/// Creates a shared buffer and fills it with the initial state suitable for
38+
/// a request synchronization channel.
39+
static SharedArrayBuffer createBuffer() {
40+
final buffer = SharedArrayBuffer(_byteLength);
41+
final view = buffer.asInt32List();
42+
43+
// The server will wait for the request index to not be -1 to wait for a
44+
// request. The initial value when allocating shared buffers is 0, which is
45+
// also a valid opcode.
46+
Atomics.store(view, _requestIndex, -1);
47+
48+
return buffer;
3549
}
3650

3751
/// Send a request with the given [opcode], wait for the remote worker to
3852
/// process it and returns the response code.
3953
int requestAndWaitForResponse(int opcode) {
54+
assert(opcode >= 0);
4055
Atomics.store(int32View, _responseIndex, -1);
4156
Atomics.store(int32View, _requestIndex, opcode);
4257
Atomics.notify(int32View, _requestIndex);
@@ -49,16 +64,17 @@ class RequestResponseSynchronizer {
4964

5065
String waitForRequest() {
5166
return Atomics.waitWithTimeout(
52-
int32View, _requestIndex, 0, asyncIdleWaitTimeMs);
67+
int32View, _requestIndex, -1, asyncIdleWaitTimeMs);
5368
}
5469

5570
int takeOpcode() {
5671
final opcode = Atomics.load(int32View, _requestIndex);
57-
Atomics.store(int32View, _requestIndex, 0);
72+
Atomics.store(int32View, _requestIndex, -1);
5873
return opcode;
5974
}
6075

6176
void respond(int rc) {
77+
assert(rc != -1);
6278
Atomics.store(int32View, _responseIndex, rc);
6379
Atomics.notify(int32View, _responseIndex);
6480
}

sqlite3/lib/src/wasm/vfs/async_opfs/worker.dart

+5-3
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,16 @@ class VfsWorker {
293293
continue;
294294
}
295295

296-
final opcode = WorkerOperation.values[synchronizer.takeOpcode()];
297-
Object? request;
298296
int rc;
297+
WorkerOperation? opcode;
298+
Object? request;
299299

300300
try {
301-
Message response;
301+
opcode = WorkerOperation.values[synchronizer.takeOpcode()];
302302
request = opcode.readRequest(messages);
303303

304+
Message response;
305+
304306
switch (opcode) {
305307
case WorkerOperation.xSleep:
306308
_releaseImplicitLocks();

sqlite3/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: sqlite3
22
description: Provides lightweight yet convenient bindings to SQLite by using dart:ffi
3-
version: 2.4.4
3+
version: 2.4.6
44
homepage: https://github.com/simolus3/sqlite3.dart/tree/main/sqlite3
55
issue_tracker: https://github.com/simolus3/sqlite3.dart/issues
66

0 commit comments

Comments
 (0)