Skip to content

Commit 5307ea1

Browse files
author
Ivan Dlugos
committed
generated C-API binding - fixes
1 parent 3c07f27 commit 5307ea1

File tree

9 files changed

+480
-1189
lines changed

9 files changed

+480
-1189
lines changed

generator/integration-tests/basics/1.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'lib/objectbox.g.dart';
44
import 'package:test/test.dart';
55
import '../test_env.dart';
66
import '../common.dart';
7-
import 'package:objectbox/src/bindings/constants.dart';
7+
import 'package:objectbox/src/bindings/bindings.dart';
88

99
void main() {
1010
TestEnv<A> env;
@@ -32,7 +32,7 @@ void main() {
3232
expect(entity(model, 'A').flags, equals(0));
3333
expect(entity(jsonModel, 'A').flags, equals(0));
3434

35-
expect(entity(model, 'D').flags, equals(OBXEntityFlag.SYNC_ENABLED));
36-
expect(entity(jsonModel, 'D').flags, equals(OBXEntityFlag.SYNC_ENABLED));
35+
expect(entity(model, 'D').flags, equals(OBXEntityFlags.SYNC_ENABLED));
36+
expect(entity(jsonModel, 'D').flags, equals(OBXEntityFlags.SYNC_ENABLED));
3737
});
3838
}

generator/lib/src/code_chunks.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "dart:convert";
22
import "package:objectbox/src/modelinfo/index.dart";
3-
import "package:objectbox/src/bindings/constants.dart" show OBXPropertyType;
3+
import "package:objectbox/src/bindings/bindings.dart" show OBXPropertyType;
44
import "package:source_gen/source_gen.dart" show InvalidGenerationSourceError;
55

66
class CodeChunks {

generator/lib/src/entity_resolver.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'dart:convert';
44
import 'package:analyzer/dart/element/element.dart';
55
import 'package:build/build.dart';
66
import 'package:objectbox/objectbox.dart' as obx;
7-
import 'package:objectbox/src/bindings/constants.dart';
7+
import 'package:objectbox/src/bindings/bindings.dart';
88
import 'package:objectbox/src/modelinfo/index.dart';
99
import 'package:source_gen/source_gen.dart';
1010

@@ -61,11 +61,11 @@ class EntityResolver extends Builder {
6161
}
6262

6363
if (_syncChecker.hasAnnotationOfExact(element)) {
64-
entity.flags |= OBXEntityFlag.SYNC_ENABLED;
64+
entity.flags |= OBXEntityFlags.SYNC_ENABLED;
6565
}
6666

6767
log.info('entity ${entity.name}(${entity.id}), sync=' +
68-
(entity.hasFlag(OBXEntityFlag.SYNC_ENABLED) ? 'ON' : 'OFF'));
68+
(entity.hasFlag(OBXEntityFlags.SYNC_ENABLED) ? 'ON' : 'OFF'));
6969

7070
// getters, ... (anything else?)
7171
final readOnlyFields = <String, bool>{};
@@ -104,7 +104,7 @@ class EntityResolver extends Builder {
104104
hasIdProperty = true;
105105

106106
fieldType = OBXPropertyType.Long;
107-
flags |= OBXPropertyFlag.ID;
107+
flags |= OBXPropertyFlags.ID;
108108

109109
final _idAnnotation = _idChecker.firstAnnotationOfExact(f);
110110
propUid = _idAnnotation.getField('uid').toIntValue();

install.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
set -eu
33

44
# https://github.com/objectbox/objectbox-c/releases
5-
# Warning: ensure C lib signature changes are reflected in lib/src/bindings/signatures.dart
6-
# Dart won't error if they do not match, it may lead to obscure memory bugs.
5+
# It's important that the generated dart bindings and the c-api library version match. Dart won't error on C function
6+
# signature mismatch, leading to obscure memory bugs.
7+
# After upgrading to a different C-API version:
8+
# * update lib/src/bindings/objectbox.h
9+
# * execute pub run ffigen
10+
# * have a look at the changed files to see if some call sites need to be updated
711
cLibVersion=0.10.0
812
os=$(uname)
913

lib/src/bindings/helpers.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,7 @@ String cString(Pointer<Int8> charPtr) {
4646

4747
return Utf8.fromUtf8(charPtr.cast<Utf8>());
4848
}
49+
50+
// ffigen currently uses Pointer<Int32> for bool* so we need to clear the whole
51+
// allocated memory before C call, to make sure the result looks is as expected.
52+
Pointer<Int32> cBool() => allocate<Int32>()..value = 0;

0 commit comments

Comments
 (0)