Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix detection of cycles that contain one struct #141

Merged
merged 1 commit into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bindgen/ir/Struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ Struct::shouldFieldBreakCycle(const std::shared_ptr<Field> &field) const {
* changed if this struct has the biggest name compared to other structs
* in cycle that have fields of non-value type.
*/
if (baseNode.cycleNodes.empty()) {
/* field references containing struct */
structTypesThatShouldBeReplaced.push_back(
shared_from_base<Struct>());
}
for (const auto &nextCycleNode : baseNode.cycleNodes) {
std::vector<std::string> namesInCycle;
if (hasBiggestName(nextCycleNode, namesInCycle)) {
Expand Down
5 changes: 5 additions & 0 deletions tests/samples/Cycles.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
struct node {
int value;
struct node *next;
};

struct b;
struct c;

Expand Down
10 changes: 10 additions & 0 deletions tests/samples/Cycles.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import scala.scalanative.native._
@native.link("bindgentests")
@native.extern
object Cycles {
type struct_node = native.CStruct2[native.CInt, native.Ptr[Byte]]
type struct_b = native.CStruct1[native.Ptr[native.Ptr[Byte]]]
type struct_a = native.CStruct1[native.Ptr[struct_b]]
type struct_c = native.CStruct1[struct_a]
Expand All @@ -27,6 +28,15 @@ import Cycles._

object CyclesHelpers {

implicit class struct_node_ops(val p: native.Ptr[struct_node]) extends AnyVal {
def value: native.CInt = !p._1
def value_=(value: native.CInt): Unit = !p._1 = value
def next: native.Ptr[struct_node] = (!p._2).cast[native.Ptr[struct_node]]
def next_=(value: native.Ptr[struct_node]): Unit = !p._2 = value.cast[native.Ptr[Byte]]
}

def struct_node()(implicit z: native.Zone): native.Ptr[struct_node] = native.alloc[struct_node]

implicit class struct_a_ops(val p: native.Ptr[struct_a]) extends AnyVal {
def bb: native.Ptr[struct_b] = !p._1
def bb_=(value: native.Ptr[struct_b]): Unit = !p._1 = value
Expand Down