File tree Expand file tree Collapse file tree 4 files changed +24
-18
lines changed
src/test/scala/org/scalanative/bindgen/samples Expand file tree Collapse file tree 4 files changed +24
-18
lines changed Original file line number Diff line number Diff line change 11#include "Union.h"
22#include <stdlib.h>
33
4- union values * getValues () {
5- union values * myValues = malloc (sizeof (union values ));
6- myValues -> a = 10 ;
7- return myValues ;
8- }
4+ void setIntValue (union values * v ) { v -> i = 10 ; }
5+
6+ void setLongValue (union values * v ) { v -> l = 10000000000 ; }
Original file line number Diff line number Diff line change 11union values {
2- long a ;
3- int b ;
4- long long c ;
2+ long l ;
3+ int i ;
4+ long long ll ;
55};
66
7- union values * getValues ();
7+ void setIntValue (union values * v );
8+
9+ void setLongValue (union values * v );
Original file line number Diff line number Diff line change @@ -7,19 +7,20 @@ import scala.scalanative.native._
77@ native.extern
88object Union {
99 type union_values = native.CArray [Byte , native.Nat ._8]
10- def getValues (): native.Ptr [union_values] = native.extern
10+ def setIntValue (v : native.Ptr [union_values]): Unit = native.extern
11+ def setLongValue (v : native.Ptr [union_values]): Unit = native.extern
1112}
1213
1314import Union ._
1415
1516object UnionHelpers {
1617
1718 implicit class union_values_pos (val p : native.Ptr [union_values]) extends AnyVal {
18- def a : native.Ptr [native.CLong ] = p.cast[native.Ptr [native.CLong ]]
19- def a_ = (value : native.CLong ): Unit = ! p.cast[native.Ptr [native.CLong ]] = value
20- def b : native.Ptr [native.CInt ] = p.cast[native.Ptr [native.CInt ]]
21- def b_ = (value : native.CInt ): Unit = ! p.cast[native.Ptr [native.CInt ]] = value
22- def c : native.Ptr [native.CLongLong ] = p.cast[native.Ptr [native.CLongLong ]]
23- def c_ = (value : native.CLongLong ): Unit = ! p.cast[native.Ptr [native.CLongLong ]] = value
19+ def l : native.Ptr [native.CLong ] = p.cast[native.Ptr [native.CLong ]]
20+ def l_ = (value : native.CLong ): Unit = ! p.cast[native.Ptr [native.CLong ]] = value
21+ def i : native.Ptr [native.CInt ] = p.cast[native.Ptr [native.CInt ]]
22+ def i_ = (value : native.CInt ): Unit = ! p.cast[native.Ptr [native.CInt ]] = value
23+ def ll : native.Ptr [native.CLongLong ] = p.cast[native.Ptr [native.CLongLong ]]
24+ def ll_ = (value : native.CLongLong ): Unit = ! p.cast[native.Ptr [native.CLongLong ]] = value
2425 }
2526}
Original file line number Diff line number Diff line change @@ -7,8 +7,13 @@ import org.scalanative.bindgen.samples.UnionHelpers._
77object UnionTests extends TestSuite {
88 val tests = Tests {
99 ' getValues - {
10- val point = Union .getValues()
11- assert(point.a == 10 )
10+ Zone {implicit zone =>
11+ val structPtr = alloc[Union .union_values]
12+ Union .setIntValue(structPtr)
13+ assert(! structPtr.i == 10 )
14+ Union .setLongValue(structPtr)
15+ assert(! structPtr.l == 10000000000L )
16+ }
1217 }
1318 }
1419}
You can’t perform that action at this time.
0 commit comments