Skip to content

Commit 379a010

Browse files
authored
Merge pull request #181 from scala-native/test-reuse-of-union-bindings
Test reuse of union bindings
2 parents c1eca2f + 8a54baf commit 379a010

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

tests/samples/CustomNames.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ object CustomNames {
1414
type EnumWithTypedef = enum_enumWithTypedef
1515
type page = native.CStruct2[native.CString, native.Ptr[Byte]]
1616
type book = native.CStruct1[native.Ptr[page]]
17+
type weight = native.CArray[Byte, native.Nat._4]
1718
type MY_INT = native.CInt
1819
}

tests/samples/ReuseBindings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ typedef struct bigStruct aliasForBigStruct;
1111

1212
struct usesImportedEnum {
1313
enum pointIndex index;
14+
union weight weight;
1415
};
1516

1617
void readBook(struct book *book);
18+
void getWeight(union weight *weight);
1719

1820
myInt getMyInt();
1921
enumWithTypedef getEnum();

tests/samples/ReuseBindings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"names": {
66
"struct book": "book",
77
"struct page": "page",
8+
"union weight": "weight",
89
"myInt": "MY_INT",
910
"enumWithTypedef": "EnumWithTypedef"
1011
}

tests/samples/ReuseBindings.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,31 @@ import scala.scalanative.native._
77
@native.extern
88
object ReuseBindings {
99
type aliasForBigStruct = org.scalanative.bindgen.samples.Struct.struct_bigStruct
10-
type struct_usesImportedEnum = native.CStruct1[org.scalanative.bindgen.samples.Struct.enum_pointIndex]
10+
type struct_usesImportedEnum = native.CStruct2[org.scalanative.bindgen.samples.Struct.enum_pointIndex, org.scalanative.bindgen.samples.CustomNames.weight]
1111
def useStruct(p0: native.Ptr[org.scalanative.bindgen.samples.Struct.struct_point]): Unit = native.extern
1212
def returnTypedef_point_s(): native.Ptr[org.scalanative.bindgen.samples.Struct.struct_point] = native.extern
1313
def returnTypedef_point(): native.Ptr[org.scalanative.bindgen.samples.Struct.point] = native.extern
1414
def readBook(book: native.Ptr[org.scalanative.bindgen.samples.CustomNames.book]): Unit = native.extern
15+
def getWeight(weight: native.Ptr[org.scalanative.bindgen.samples.CustomNames.weight]): Unit = native.extern
1516
def getMyInt(): org.scalanative.bindgen.samples.CustomNames.MY_INT = native.extern
1617
def getEnum(): org.scalanative.bindgen.samples.CustomNames.EnumWithTypedef = native.extern
1718

1819
object implicits {
1920
implicit class struct_usesImportedEnum_ops(val p: native.Ptr[struct_usesImportedEnum]) extends AnyVal {
2021
def index: org.scalanative.bindgen.samples.Struct.enum_pointIndex = !p._1
2122
def index_=(value: org.scalanative.bindgen.samples.Struct.enum_pointIndex): Unit = !p._1 = value
23+
def weight: native.Ptr[org.scalanative.bindgen.samples.CustomNames.weight] = p._2
24+
def weight_=(value: native.Ptr[org.scalanative.bindgen.samples.CustomNames.weight]): Unit = !p._2 = !value
2225
}
2326
}
2427

2528
object struct_usesImportedEnum {
2629
import implicits._
2730
def apply()(implicit z: native.Zone): native.Ptr[struct_usesImportedEnum] = native.alloc[struct_usesImportedEnum]
28-
def apply(index: org.scalanative.bindgen.samples.Struct.enum_pointIndex)(implicit z: native.Zone): native.Ptr[struct_usesImportedEnum] = {
31+
def apply(index: org.scalanative.bindgen.samples.Struct.enum_pointIndex, weight: native.Ptr[org.scalanative.bindgen.samples.CustomNames.weight])(implicit z: native.Zone): native.Ptr[struct_usesImportedEnum] = {
2932
val ptr = native.alloc[struct_usesImportedEnum]
3033
ptr.index = index
34+
ptr.weight = weight
3135
ptr
3236
}
3337
}

tests/samples/include/CustomNames.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,10 @@ struct book {
77
struct page *firstPage;
88
};
99

10+
union weight {
11+
int kilos;
12+
float grams;
13+
};
14+
1015
typedef int myInt;
1116
typedef enum { CONST } enumWithTypedef;

0 commit comments

Comments
 (0)