Skip to content

Commit 6266289

Browse files
authored
[ffigen] Fix opaque struct in arr (#2545)
1 parent 8ccc543 commit 6266289

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

pkgs/ffigen/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
object may change, but the underlying ObjC object will still be the same.
1515
In any case, you should be using `Foo.isInstance(x)` instead of `x is Foo`
1616
to check the runtime type of an ObjC object.
17+
- Fix for opaque dependencies for struct/union const arrays.
1718

1819
## 19.1.0
1920

pkgs/ffigen/lib/src/visitor/opaque_compounds.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class FindByValueCompoundsVisitation extends Visitation {
2121

2222
@override
2323
void visitPointerType(PointerType node) {
24-
if (node.child.typealiasType is Compound) {
24+
if (node.child.typealiasType is Compound && node is! ConstantArray) {
2525
// Don't visit compounds through pointers. We're only interested in
2626
// compounds that are referred to by value.
2727
} else {

pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_opaque_dependencies_bindings.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,20 @@ final class D extends ffi.Struct {
5959
external ffi.Pointer<NoDefinitionStructInD> nds;
6060
}
6161

62+
final class DArray extends ffi.Struct {
63+
@ffi.Int()
64+
external int a;
65+
66+
external ffi.Pointer<NoDefinitionStructInD> nds;
67+
}
68+
6269
final class E extends ffi.Struct {
6370
external ffi.Pointer<C> c;
6471

6572
external D d;
73+
74+
@ffi.Array.multi([10])
75+
external ffi.Array<DArray> dArray;
6676
}
6777

6878
final class UA extends ffi.Opaque {}
@@ -76,8 +86,16 @@ final class UD extends ffi.Union {
7686
external int a;
7787
}
7888

89+
final class UDArray extends ffi.Union {
90+
@ffi.Int()
91+
external int a;
92+
}
93+
7994
final class UE extends ffi.Union {
8095
external ffi.Pointer<UC> c;
8196

8297
external UD d;
98+
99+
@ffi.Array.multi([10])
100+
external ffi.Array<UDArray> dArray;
83101
}

pkgs/ffigen/test/header_parser_tests/opaque_dependencies.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,19 @@ struct D
3030
struct NoDefinitionStructInD* nds;
3131
};
3232

33+
// Full (excluded, but used by value in an array).
34+
struct DArray
35+
{
36+
int a;
37+
struct NoDefinitionStructInD* nds;
38+
};
39+
3340
// Full (included)
3441
struct E
3542
{
3643
struct C *c;
3744
struct D d;
45+
struct DArray dArray[10];
3846
};
3947

4048
// Opaque.
@@ -63,9 +71,16 @@ union UD
6371
int a;
6472
};
6573

74+
// Full (excluded, but used by value in array).
75+
union UDArray
76+
{
77+
int a;
78+
};
79+
6680
// Full (included)
6781
union UE
6882
{
6983
union UC *c;
7084
union UD d;
85+
union UDArray dArray[10];
7186
};

0 commit comments

Comments
 (0)