Skip to content

Commit

Permalink
Fix bug in codegen for kotlin arrays of unsigned numeric primitives (#…
Browse files Browse the repository at this point in the history
…685)

Co-authored-by: Ellen Arteca <[email protected]>
  • Loading branch information
emarteca and Ellen Arteca authored Sep 11, 2024
1 parent e92e497 commit cd9fb53
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
8 changes: 4 additions & 4 deletions tool/src/kotlin/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ impl<'tcx> KotlinFormatter<'tcx> {
PrimitiveType::Int(IntType::I16) => "Short",
PrimitiveType::Int(IntType::I32) => "Int",
PrimitiveType::Int(IntType::I64) => "Long",
PrimitiveType::Int(IntType::U8) => "Byte",
PrimitiveType::Int(IntType::U16) => "Short",
PrimitiveType::Int(IntType::U32) => "Int",
PrimitiveType::Int(IntType::U64) => "Long",
PrimitiveType::Int(IntType::U8) => "UByte",
PrimitiveType::Int(IntType::U16) => "UShort",
PrimitiveType::Int(IntType::U32) => "UInt",
PrimitiveType::Int(IntType::U64) => "ULong",
PrimitiveType::Byte => "Byte",
PrimitiveType::IntSize(IntSizeType::Isize) => "Long",
PrimitiveType::IntSize(IntSizeType::Usize) => "Long",
Expand Down
5 changes: 4 additions & 1 deletion tool/src/kotlin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,10 @@ mod test {
pub fn test_multi_arg_callback(f: impl Fn(i32) -> i32, x: i32) -> i32 {
f(10 + x)
}

pub fn get_u_byte_slice<'a>() -> &'a [u8] {
todo!()
}
}
}
};
Expand Down Expand Up @@ -1902,7 +1906,6 @@ mod test {
pub fn string_stuff_2<'a, 'c>(&'a self, some_str: &'c DiplomatStr) -> &'a MyOpaqueStruct<'b> {
self.0.as_ref()
}

}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: tool/src/kotlin/mod.rs
assertion_line: 1823
assertion_line: 1828
expression: struct_code
---
package dev.gigapixel.somelib
Expand All @@ -14,6 +14,7 @@ import com.sun.jna.Structure
internal interface MyNativeStructLib: Library {
fun MyNativeStruct_new(): MyNativeStructNative
fun MyNativeStruct_test_multi_arg_callback(f: DiplomatCallback_MyNativeStruct_test_multi_arg_callback_diplomatCallback_f_Native, x: Int): Int
fun MyNativeStruct_get_u_byte_slice(): Slice
}

internal class MyNativeStructNative: Structure(), Structure.ByValue {
Expand Down Expand Up @@ -140,6 +141,12 @@ class MyNativeStruct internal constructor (
val returnVal = lib.MyNativeStruct_test_multi_arg_callback(DiplomatCallback_MyNativeStruct_test_multi_arg_callback_diplomatCallback_f.fromCallback(f).nativeStruct, x);
return returnVal
}

fun getUByteSlice(): UByteArray {

val returnVal = lib.MyNativeStruct_get_u_byte_slice();
return PrimitiveArrayTools.getUByteArray(returnVal)
}
}

}

0 comments on commit cd9fb53

Please sign in to comment.