Pass all non-primitive types by (immutable) reference
This commit is contained in:
parent
8cb0bf9c5e
commit
9e8bccdafd
@ -57,13 +57,13 @@ hello :: ByteString -> IO ()
|
||||
hello s = useAsCString s $ Raw.hello . unsafeFromPtr
|
||||
|
||||
helloStruct :: T -> IO ()
|
||||
helloStruct = Raw.hello_struct . convertT
|
||||
helloStruct = flip with (Raw.hello_struct . unsafeFromPtr) . convertT
|
||||
|
||||
helloShape :: Shape -> IO ()
|
||||
helloShape = Raw.hello_shape . convertShape
|
||||
helloShape = flip with (Raw.hello_shape . unsafeFromPtr) . convertShape
|
||||
|
||||
add :: Int64 -> Int64 -> Int64
|
||||
add = Raw.add
|
||||
|
||||
sumTree :: BTree Int64 -> Int64
|
||||
sumTree = unsafePerformIO . flip withBTree Raw.sum_tree
|
||||
sumTree = unsafePerformIO . flip withBTree (flip with $ Raw.sum_tree . unsafeFromPtr)
|
||||
|
||||
@ -22,7 +22,7 @@ struct T {
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn hello_struct(t: T) -> () {
|
||||
extern "C" fn hello_struct(t: &T) -> () {
|
||||
say_hello(&format!("{:?}", t))
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ enum Shape {
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn hello_shape(s: Shape) -> () {
|
||||
extern "C" fn hello_shape(s: &Shape) -> () {
|
||||
say_hello(&format!("{:?}", s))
|
||||
}
|
||||
|
||||
@ -78,6 +78,6 @@ enum BTreeC {
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn sum_tree(t: BTreeC) -> i64 {
|
||||
(unsafe { std::mem::transmute::<_, &BTree<i64>>(&t) }).sum()
|
||||
extern "C" fn sum_tree(t: &BTreeC) -> i64 {
|
||||
(unsafe { std::mem::transmute::<_, &BTree<i64>>(t) }).sum()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user