Skip to content

Commit

Permalink
panama-backend - fix kotlin test from merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist1 committed Sep 13, 2024
1 parent dfe88e3 commit 42d941b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 265 deletions.
263 changes: 0 additions & 263 deletions tool/src/kotlin/snapshots/diplomat_tool__kotlin__test__opaque_gen.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: tool/src/kotlin/mod.rs
assertion_line: 1995
expression: result
---
package dev.diplomattest.somelib
Expand Down Expand Up @@ -38,265 +37,3 @@ class OwndingStruct internal constructor (
}

}

=======================
package dev.diplomattest.somelib

import com.sun.jna.Callback
import com.sun.jna.Library
import com.sun.jna.Native
import com.sun.jna.Pointer
import com.sun.jna.Structure

internal interface OwnedStructLib: Library {
}

internal class OwnedStructNative: Structure(), Structure.ByValue {
@JvmField
internal var int: Int = 0;

// Define the fields of the struct
override fun getFieldOrder(): List<String> {
return listOf("int")
}
}

class OwnedStruct internal constructor (
internal val nativeStruct: OwnedStructNative) {
val int: Int = nativeStruct.int

companion object {
internal val libClass: Class<OwnedStructLib> = OwnedStructLib::class.java
internal val lib: OwnedStructLib = Native.load("somelib", libClass)
val NATIVESIZE: Long = Native.getNativeSize(OwnedStructNative::class.java).toLong()
}

}

=======================
package dev.diplomattest.somelib;
import com.sun.jna.Callback
import com.sun.jna.Library
import com.sun.jna.Native
import com.sun.jna.Pointer
import com.sun.jna.Structure


internal interface BorrowWrapperLib: Library {
fun BorrowWrapper_destroy(handle: Pointer)
}

class BorrowWrapper internal constructor (
internal val handle: Pointer,
// These ensure that anything that is borrowed is kept alive and not cleaned
// up by the garbage collector.
internal val selfEdges: List<Any>,
internal val aEdges: List<Any>,
internal val bEdges: List<Any>,
) {

internal class BorrowWrapperCleaner(val handle: Pointer, val lib: BorrowWrapperLib) : Runnable {
override fun run() {
lib.BorrowWrapper_destroy(handle)
}
}

companion object {
internal val libClass: Class<BorrowWrapperLib> = BorrowWrapperLib::class.java
internal val lib: BorrowWrapperLib = Native.load("somelib", libClass)
}

}

=======================
package dev.diplomattest.somelib;
import com.sun.jna.Callback
import com.sun.jna.Library
import com.sun.jna.Native
import com.sun.jna.Pointer
import com.sun.jna.Structure


internal interface InputStructLib: Library {
fun InputStruct_destroy(handle: Pointer)
}

class InputStruct internal constructor (
internal val handle: Pointer,
// These ensure that anything that is borrowed is kept alive and not cleaned
// up by the garbage collector.
internal val selfEdges: List<Any>
) {

internal class InputStructCleaner(val handle: Pointer, val lib: InputStructLib) : Runnable {
override fun run() {
lib.InputStruct_destroy(handle)
}
}

companion object {
internal val libClass: Class<InputStructLib> = InputStructLib::class.java
internal val lib: InputStructLib = Native.load("somelib", libClass)
}

}

=======================
package dev.diplomattest.somelib;
import com.sun.jna.Callback
import com.sun.jna.Library
import com.sun.jna.Native
import com.sun.jna.Pointer
import com.sun.jna.Structure


internal interface MyOpaqueStructLib: Library {
fun MyOpaqueStruct_destroy(handle: Pointer)
fun MyOpaqueStruct_get_byte(): Byte
fun MyOpaqueStruct_get_string_wrapper(in1: Int): Int
fun MyOpaqueStruct_copy(handle: Pointer, borrow: Pointer): Int
fun MyOpaqueStruct_borrow_other(inp1: Pointer, inp2: Pointer, borrow: Pointer): Pointer
fun MyOpaqueStruct_create(in1: Int): Pointer
fun MyOpaqueStruct_do_stuff(handle: Pointer, in1: Int): Double
fun MyOpaqueStruct_borrow(handle: Pointer): Pointer
fun MyOpaqueStruct_borrow2(handle: Pointer): Pointer
fun MyOpaqueStruct_borrow3(handle: Pointer, write: Pointer): Unit
fun MyOpaqueStruct_borrow(other: Pointer): Pointer
fun MyOpaqueStruct_string_stuff(handle: Pointer, someStr: Slice): Pointer
fun MyOpaqueStruct_string_stuff_2(handle: Pointer, someStr: Slice): Pointer
}

class MyOpaqueStruct internal constructor (
internal val handle: Pointer,
// These ensure that anything that is borrowed is kept alive and not cleaned
// up by the garbage collector.
internal val selfEdges: List<Any>,
internal val bEdges: List<Any>,
) {

internal class MyOpaqueStructCleaner(val handle: Pointer, val lib: MyOpaqueStructLib) : Runnable {
override fun run() {
lib.MyOpaqueStruct_destroy(handle)
}
}

companion object {
internal val libClass: Class<MyOpaqueStructLib> = MyOpaqueStructLib::class.java
internal val lib: MyOpaqueStructLib = Native.load("somelib", libClass)

fun getByte(): UByte {

val returnVal = lib.MyOpaqueStruct_get_byte();
return returnVal.toUByte()
}

fun getStringWrapper(in1: Int): Int {

val returnVal = lib.MyOpaqueStruct_get_string_wrapper(in1);
return returnVal
}

fun borrowOther(inp1: InputStruct, inp2: InputStruct, borrow: MyOpaqueStruct): MyOpaqueStruct {

val returnVal = lib.MyOpaqueStruct_borrow_other(inp1.handle, inp2.handle, borrow.handle);
val selfEdges: List<Any> = listOf(inp1) + listOf(inp2) + listOf(borrow)
val bEdges: List<Any> = listOf(borrow)
val handle = returnVal
val returnOpaque = MyOpaqueStruct(handle, selfEdges, bEdges)
return returnOpaque
}

fun create(in1: Int): MyOpaqueStruct {

val returnVal = lib.MyOpaqueStruct_create(in1);
val selfEdges: List<Any> = listOf()
val bEdges: List<Any> = listOf()
val handle = returnVal
val returnOpaque = MyOpaqueStruct(handle, selfEdges, bEdges)
CLEANER.register(returnOpaque, MyOpaqueStruct.MyOpaqueStructCleaner(handle, MyOpaqueStruct.lib));

return returnOpaque
}

fun borrow(other: MyOpaqueStruct): BorrowWrapper {

val returnVal = lib.MyOpaqueStruct_borrow(other.handle);
val selfEdges: List<Any> = listOf()
val bEdges: List<Any> = listOf(other)
val aEdges: List<Any> = listOf(other)
val handle = returnVal
val returnOpaque = BorrowWrapper(handle, selfEdges, bEdges, aEdges)
CLEANER.register(returnOpaque, BorrowWrapper.BorrowWrapperCleaner(handle, BorrowWrapper.lib));

return returnOpaque
}
}

fun copy(borrow: MyOpaqueStruct): Int {

val returnVal = lib.MyOpaqueStruct_copy(handle, borrow.handle);
return returnVal
}

fun doStuff(in1: Int): Double {

val returnVal = lib.MyOpaqueStruct_do_stuff(handle, in1);
return returnVal
}

fun borrow(): BorrowWrapper {

val returnVal = lib.MyOpaqueStruct_borrow(handle);
val selfEdges: List<Any> = listOf()
val bEdges: List<Any> = listOf(this)
val aEdges: List<Any> = listOf(this)
val handle = returnVal
val returnOpaque = BorrowWrapper(handle, selfEdges, bEdges, aEdges)
CLEANER.register(returnOpaque, BorrowWrapper.BorrowWrapperCleaner(handle, BorrowWrapper.lib));

return returnOpaque
}

fun borrow2(): MyOpaqueStruct {

val returnVal = lib.MyOpaqueStruct_borrow2(handle);
val selfEdges: List<Any> = listOf(this)
val bEdges: List<Any> = listOf(this)
val handle = returnVal
val returnOpaque = MyOpaqueStruct(handle, selfEdges, bEdges)
return returnOpaque
}

fun borrow3(): String {
val write = DW.lib.diplomat_buffer_write_create(0)
val returnVal = lib.MyOpaqueStruct_borrow3(handle, write);

val returnString = DW.writeToString(write)
return returnString
}

fun stringStuff(someStr: String): MyOpaqueStruct {
val (someStrMem, someStrSlice) = PrimitiveArrayTools.readUtf8(someStr)

val returnVal = lib.MyOpaqueStruct_string_stuff(handle, someStrSlice);
val selfEdges: List<Any> = listOf(this) + listOf(someStrMem)
val bEdges: List<Any> = listOf(this)
val handle = returnVal
val returnOpaque = MyOpaqueStruct(handle, selfEdges, bEdges)
return returnOpaque
}

fun stringStuff2(someStr: String): MyOpaqueStruct {
val (someStrMem, someStrSlice) = PrimitiveArrayTools.readUtf8(someStr)

val returnVal = lib.MyOpaqueStruct_string_stuff_2(handle, someStrSlice);
val selfEdges: List<Any> = listOf(this)
val bEdges: List<Any> = listOf(this)
val handle = returnVal
val returnOpaque = MyOpaqueStruct(handle, selfEdges, bEdges)someStrMem.close()
return returnOpaque
}

}

=======================
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
---
source: tool/src/kotlin/mod.rs
assertion_line: 2042
expression: result
---
package dev.gigapixel.somelib;
package dev.diplomattest.somelib;
import com.sun.jna.Callback
import com.sun.jna.Library
import com.sun.jna.Native
Expand Down

0 comments on commit 42d941b

Please sign in to comment.