Skip to content

Commit 9b45662

Browse files
committed
Return value from callable to work around VM issue
Due to dart-lang/sdk#56064, Dart stable 3.4 reports an exception on native calls involving `NativeCallable`s returning `null` (which they do for `void`). This exception is not critical as it only occurs when a debugger is attached, but it's still annoying and easy to work around by returning a bogus value then dropped. Closes simolus3#242
1 parent db5077b commit 9b45662

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

sqlite3/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.4.4
2+
3+
- Add a temporary workaround for [a Dart bug](https://github.com/dart-lang/sdk/issues/56064)
4+
causing spurious exceptions when databases are closed and a debugger is attached.
5+
16
## 2.4.3
27

38
- Migrate away from legacy web APIs: `dart:html`, `dart:js`, `dart:indexeddb`

sqlite3/lib/src/ffi/bindings.dart

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,13 @@ final class FfiDatabase extends RawSqliteDatabase {
299299

300300
static Pointer<NativeFunction<Void Function(Pointer<Void>)>> _xDestroy(
301301
List<NativeCallable> callables) {
302-
void destroy(Pointer<Void> _) {
302+
int destroy(Pointer<Void> _) {
303303
for (final callable in callables) {
304304
callable.close();
305305
}
306+
307+
// TODO: Remove and change to void after Dart 3.5 or https://github.com/dart-lang/sdk/issues/56064
308+
return 0;
306309
}
307310

308311
final callable =
@@ -711,7 +714,9 @@ extension on RawXFunc {
711714
NativeCallable<_XFunc> toNative(Bindings bindings) {
712715
return NativeCallable.isolateLocal((Pointer<sqlite3_context> ctx, int nArgs,
713716
Pointer<Pointer<sqlite3_value>> args) {
714-
return this(FfiContext(bindings, ctx), _ValueList(nArgs, args, bindings));
717+
this(FfiContext(bindings, ctx), _ValueList(nArgs, args, bindings));
718+
// TODO: Remove and change to void after Dart 3.5 or https://github.com/dart-lang/sdk/issues/56064
719+
return 0;
715720
})
716721
..keepIsolateAlive = false;
717722
}
@@ -721,9 +726,10 @@ extension on RawXFinal {
721726
NativeCallable<_XFinal> toNative(Bindings bindings, bool clean) {
722727
return NativeCallable.isolateLocal((Pointer<sqlite3_context> ctx) {
723728
final context = FfiContext(bindings, ctx);
724-
final res = this(context);
729+
this(context);
725730
if (clean) context.freeContext();
726-
return res;
731+
// TODO: Remove and change to void after Dart 3.5 or https://github.com/dart-lang/sdk/issues/56064
732+
return 0;
727733
})
728734
..keepIsolateAlive = false;
729735
}
@@ -757,12 +763,9 @@ extension on RawUpdateHook {
757763
final tableName = table.readString();
758764
this(kind, tableName, rowid);
759765

760-
// This closure needs to return `void` exactly to make the FFI analyzer
761-
// happy.
762-
return _returnsVoid();
766+
// TODO: Remove and change to void after Dart 3.5 or https://github.com/dart-lang/sdk/issues/56064
767+
return 0;
763768
},
764769
)..keepIsolateAlive = false;
765770
}
766-
767-
static void _returnsVoid() {}
768771
}

sqlite3/pubspec.yaml

Lines changed: 1 addition & 1 deletion
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.3
3+
version: 2.4.4
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)