pass by (immutable) reference for all non-primitive types

This commit is contained in:
George Thomas 2026-03-25 01:01:22 +00:00
parent 32de67723b
commit 9417c06574
2 changed files with 7 additions and 7 deletions

View File

@ -58,13 +58,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)

View File

@ -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()
}