Skip to content

Commit 71b55ed

Browse files
author
Ivan Dlugos
committed
switch manual C-API bindings definition to generated code (ffigen)
1 parent 58edb7c commit 71b55ed

21 files changed

+10251
-1145
lines changed

lib/integration_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
library integration_test;
22

33
import 'package:objectbox/objectbox.dart';
4-
import './src/bindings/constants.dart';
54
import './src/bindings/helpers.dart';
65
import './src/bindings/bindings.dart';
76

lib/src/bindings/bindings.dart

Lines changed: 25 additions & 651 deletions
Large diffs are not rendered by default.

lib/src/bindings/constants.dart

Lines changed: 0 additions & 138 deletions
This file was deleted.

lib/src/bindings/data_visitor.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import 'dart:ffi';
2-
import 'signatures.dart';
32
import 'package:ffi/ffi.dart' show allocate, free;
43

4+
import 'bindings.dart';
5+
56
/// This file implements C call forwarding using a trampoline approach.
67
///
78
/// When you want to pass a dart callback to a C function you cannot use lambdas and instead the callback must be
@@ -28,21 +29,22 @@ int _lastId = 0;
2829
final _callbacks = <int, bool Function(Pointer<Uint8> dataPtr, int length)>{};
2930

3031
// called from C, forwards calls to the actual callback registered at the given ID
31-
int _forwarder(Pointer<Void> callbackId, Pointer<Uint8> dataPtr, int size) {
32+
int _forwarder(Pointer<Void> callbackId, Pointer<Void> dataPtr, int size) {
3233
if (callbackId == null || callbackId.address == 0) {
3334
throw Exception(
3435
'Data-visitor callback issued with NULL user_data (callback ID)');
3536
}
3637

37-
return _callbacks[callbackId.cast<Int64>().value](dataPtr, size) ? 1 : 0;
38+
final callback = _callbacks[callbackId.cast<Int64>().value];
39+
return callback(dataPtr.cast<Uint8>(), size) ? 1 : 0;
3840
}
3941

4042
/// A data visitor wrapper/forwarder to be used where obx_data_visitor is expected.
4143
class DataVisitor {
4244
int _id;
4345
Pointer<Int64> _idPtr;
4446

45-
Pointer<NativeFunction<obx_data_visitor_native_t>> get fn =>
47+
Pointer<NativeFunction<obx_data_visitor>> get fn =>
4648
Pointer.fromFunction(_forwarder, 0);
4749

4850
Pointer<Void> get userData => _idPtr.cast<Void>();

lib/src/bindings/flatbuffers.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import 'dart:ffi';
22
import 'dart:typed_data' show Uint8List;
3+
34
import 'package:flat_buffers/flat_buffers.dart' as fb;
45

5-
import 'constants.dart';
6+
import 'bindings.dart';
67
import 'structs.dart';
78
import '../modelinfo/index.dart';
89

lib/src/bindings/helpers.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ import 'dart:ffi';
22
import 'package:ffi/ffi.dart';
33

44
import 'bindings.dart';
5-
import 'constants.dart';
65
import '../common.dart';
76

87
void checkObx(int code) {
9-
if (code != OBXError.OBX_SUCCESS) {
8+
if (code != OBX_SUCCESS) {
109
throw latestNativeError(codeIfMissing: code);
1110
}
1211
}
1312

1413
bool checkObxSuccess(int code) {
15-
if (code == OBXError.OBX_NO_SUCCESS) return false;
14+
if (code == OBX_NO_SUCCESS) return false;
1615
checkObx(code);
1716
return true;
1817
}
@@ -39,11 +38,11 @@ ObjectBoxException latestNativeError({String dartMsg, int codeIfMissing}) {
3938
dartMsg: dartMsg, nativeCode: code, nativeMsg: text);
4039
}
4140

42-
String cString(Pointer<Utf8> charPtr) {
41+
String cString(Pointer<Int8> charPtr) {
4342
// Utf8.fromUtf8 segfaults when called on nullptr
4443
if (charPtr.address == 0) {
4544
return '';
4645
}
4746

48-
return Utf8.fromUtf8(charPtr);
47+
return Utf8.fromUtf8(charPtr.cast<Utf8>());
4948
}

0 commit comments

Comments
 (0)