Skip to content

Commit 3a52cea

Browse files
authored
Merge pull request #141 from kornilova-l/fix-one-struct-cycle
Fix detection of cycles that contain one struct
2 parents 9146fd9 + 227373b commit 3a52cea

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

bindgen/ir/Struct.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,11 @@ Struct::shouldFieldBreakCycle(const std::shared_ptr<Field> &field) const {
325325
* changed if this struct has the biggest name compared to other structs
326326
* in cycle that have fields of non-value type.
327327
*/
328+
if (baseNode.cycleNodes.empty()) {
329+
/* field references containing struct */
330+
structTypesThatShouldBeReplaced.push_back(
331+
shared_from_base<Struct>());
332+
}
328333
for (const auto &nextCycleNode : baseNode.cycleNodes) {
329334
std::vector<std::string> namesInCycle;
330335
if (hasBiggestName(nextCycleNode, namesInCycle)) {

tests/samples/Cycles.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
struct node {
2+
int value;
3+
struct node *next;
4+
};
5+
16
struct b;
27
struct c;
38

tests/samples/Cycles.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import scala.scalanative.native._
66
@native.link("bindgentests")
77
@native.extern
88
object Cycles {
9+
type struct_node = native.CStruct2[native.CInt, native.Ptr[Byte]]
910
type struct_b = native.CStruct1[native.Ptr[native.Ptr[Byte]]]
1011
type struct_a = native.CStruct1[native.Ptr[struct_b]]
1112
type struct_c = native.CStruct1[struct_a]
@@ -27,6 +28,15 @@ import Cycles._
2728

2829
object CyclesHelpers {
2930

31+
implicit class struct_node_ops(val p: native.Ptr[struct_node]) extends AnyVal {
32+
def value: native.CInt = !p._1
33+
def value_=(value: native.CInt): Unit = !p._1 = value
34+
def next: native.Ptr[struct_node] = (!p._2).cast[native.Ptr[struct_node]]
35+
def next_=(value: native.Ptr[struct_node]): Unit = !p._2 = value.cast[native.Ptr[Byte]]
36+
}
37+
38+
def struct_node()(implicit z: native.Zone): native.Ptr[struct_node] = native.alloc[struct_node]
39+
3040
implicit class struct_a_ops(val p: native.Ptr[struct_a]) extends AnyVal {
3141
def bb: native.Ptr[struct_b] = !p._1
3242
def bb_=(value: native.Ptr[struct_b]): Unit = !p._1 = value

0 commit comments

Comments
 (0)