diff --git a/core/src/fr/hammons/slinc/Mem.scala b/core/src/fr/hammons/slinc/Mem.scala index b2da4e9..94e436c 100644 --- a/core/src/fr/hammons/slinc/Mem.scala +++ b/core/src/fr/hammons/slinc/Mem.scala @@ -7,6 +7,7 @@ trait Mem: def asBase: Object def asAddress: Object def asVarArgs: VarArgs + def copyFrom(other: Mem): Unit def writeFloat(v: Float, offset: Bytes): Unit def writeLong(v: Long, offset: Bytes): Unit diff --git a/core/src/fr/hammons/slinc/TypeDescriptor.scala b/core/src/fr/hammons/slinc/TypeDescriptor.scala index d6630a6..ce1d46d 100644 --- a/core/src/fr/hammons/slinc/TypeDescriptor.scala +++ b/core/src/fr/hammons/slinc/TypeDescriptor.scala @@ -201,11 +201,12 @@ case class CUnionDescriptor(possibleTypes: Set[TypeDescriptor]) type Inner = CUnion[? <: NonEmptyTuple] override val reader: (ReadWriteModule, DescriptorModule) ?=> Reader[Inner] = - ??? + summon[ReadWriteModule].unionReader(this) override val returnTransition : (TransitionModule, ReadWriteModule) ?=> ReturnTransition[Inner] = obj => - summon[TransitionModule].cUnionReturn(this, obj).asInstanceOf[Inner] + summon[ReadWriteModule] + .unionReader(this)(summon[TransitionModule].memReturn(obj), Bytes(0)) override val argumentTransition : (TransitionModule, ReadWriteModule, Allocator) ?=> ArgumentTransition[ @@ -213,4 +214,4 @@ case class CUnionDescriptor(possibleTypes: Set[TypeDescriptor]) ] = (i: Inner) => i.mem.asBase override val writer: (ReadWriteModule, DescriptorModule) ?=> Writer[Inner] = - ??? + summon[ReadWriteModule].unionWriter(this) diff --git a/core/src/fr/hammons/slinc/modules/ReadWriteModule.scala b/core/src/fr/hammons/slinc/modules/ReadWriteModule.scala index 7f08445..c232b36 100644 --- a/core/src/fr/hammons/slinc/modules/ReadWriteModule.scala +++ b/core/src/fr/hammons/slinc/modules/ReadWriteModule.scala @@ -3,6 +3,7 @@ package fr.hammons.slinc.modules import fr.hammons.slinc.* import java.lang.invoke.MethodHandle import scala.reflect.ClassTag +import scala.NonEmptyTuple type Reader[A] = (Mem, Bytes) => A type Writer[A] = (Mem, Bytes, A) => Unit @@ -27,6 +28,8 @@ trait ReadWriteModule: val memReader: Reader[Mem] val memWriter: Writer[Mem] + def unionReader(td: TypeDescriptor): Reader[CUnion[? <: NonEmptyTuple]] + def unionWriter(td: TypeDescriptor): Writer[CUnion[? <: NonEmptyTuple]] def write( memory: Mem, diff --git a/core/src/fr/hammons/slinc/modules/TransitionModule.scala b/core/src/fr/hammons/slinc/modules/TransitionModule.scala index 21545a1..20c488b 100644 --- a/core/src/fr/hammons/slinc/modules/TransitionModule.scala +++ b/core/src/fr/hammons/slinc/modules/TransitionModule.scala @@ -44,8 +44,6 @@ trait TransitionModule: def memReturn(value: Object): Mem - def cUnionReturn(td: TypeDescriptor, value: Object): CUnion[?] - def functionArgument[A](td: TypeDescriptor, value: Object): A = methodReturn[A](td, value) diff --git a/core/test/resources/native/test.c b/core/test/resources/native/test.c index 191cadc..9721d26 100644 --- a/core/test/resources/native/test.c +++ b/core/test/resources/native/test.c @@ -123,4 +123,19 @@ EXPORTED union_b_issue_176 i176_test(union_a_issue_176 a, char is_left) { } return b; -} \ No newline at end of file +} + +typedef struct { + union { + long x; + double y; + } my_union; +} struct_issue_175; +EXPORTED struct_issue_175 i175_test(struct_issue_175 a, char left) { + if(left) { + a.my_union.x = a.my_union.x * 2; + } else { + a.my_union.y = a.my_union.y / 2; + } + return a; +} diff --git a/core/test/src/fr/hammons/slinc/BindingSpec.scala b/core/test/src/fr/hammons/slinc/BindingSpec.scala index 0092ea5..ef8a049 100644 --- a/core/test/src/fr/hammons/slinc/BindingSpec.scala +++ b/core/test/src/fr/hammons/slinc/BindingSpec.scala @@ -22,6 +22,7 @@ trait BindingSpec(val slinc: Slinc) extends ScalaCheckSuite: case class I36Outer(inner: Ptr[I36Inner]) derives Struct case class I30Struct(list: Ptr[VarArgs]) derives Struct + case class I175_Struct(union: CUnion[(CInt, CDouble)]) derives Struct @NeedsResource("test") trait TestLib derives FSet: @@ -53,6 +54,11 @@ trait BindingSpec(val slinc: Slinc) extends ScalaCheckSuite: is_left: CChar ): CUnion[(CLong, CDouble)] + def i175_test( + input: I175_Struct, + left: CChar + ): I175_Struct + test("int_identity") { val test = FSet.instance[TestLib] @@ -162,3 +168,21 @@ trait BindingSpec(val slinc: Slinc) extends ScalaCheckSuite: union.set(int) val res = test.i176_test(union, 0).get[CLong] assertEquals(res, CLong(int)) + + property( + "issue 175 - can send and receive structs with union types to C functions" + ): + val test = FSet.instance[TestLib] + forAll: (int: CInt, double: CDouble, left: Boolean) => + val union = CUnion[(CInt, CDouble)] + if left then + union.set(int) + val res = test.i175_test(I175_Struct(union), 1) + assertEquals( + res.union.get[CInt], + int * 2 + ) + else + union.set(double) + val res = test.i175_test(I175_Struct(union), 0) + assertEquals(res.union.get[CDouble], double / 2) diff --git a/core/test/src/fr/hammons/slinc/TransferSpec.scala b/core/test/src/fr/hammons/slinc/TransferSpec.scala index 40f2d8f..5f6d4af 100644 --- a/core/test/src/fr/hammons/slinc/TransferSpec.scala +++ b/core/test/src/fr/hammons/slinc/TransferSpec.scala @@ -26,6 +26,8 @@ trait TransferSpec[ThreadException <: Throwable](val slinc: Slinc)(using case class E(list: VarArgs) derives Struct + case class F(u: CUnion[(CInt, CFloat)]) derives Struct + test("can read and write jvm ints") { Scope.global { val mem = Ptr.blank[Int] @@ -331,3 +333,23 @@ trait TransferSpec[ThreadException <: Throwable](val slinc: Slinc)(using assertEquals(deallocated, false) assertEquals(union.get[CInt], 0) + + property("can create F ptrs"): + val union = CUnion[(CInt, CFloat)] + forAll: (a: CInt, b: CFloat, left: Boolean) => + if left then + union.set(a) + val fReturn = Scope.confined { + val f = Ptr.copy(F(union)) + !f + } + + assertEquals(fReturn.u.get[CInt], union.get[CInt]) + else + union.set(b) + val fReturn = Scope.confined { + val f = Ptr.copy(F(union)) + !f + } + + assertEquals(fReturn.u.get[CFloat], union.get[CFloat]) diff --git a/j17/src/fr/hammons/slinc/Allocator17.scala b/j17/src/fr/hammons/slinc/Allocator17.scala index e68eafb..9d93faa 100644 --- a/j17/src/fr/hammons/slinc/Allocator17.scala +++ b/j17/src/fr/hammons/slinc/Allocator17.scala @@ -11,7 +11,6 @@ import jdk.incubator.foreign.{ }, CLinker.{C_POINTER, C_INT, C_LONG_LONG, C_DOUBLE, VaList} import fr.hammons.slinc.modules.{descriptorModule17, transitionModule17} import fr.hammons.slinc.modules.LinkageModule17 -import java.lang.ref.Cleaner class Allocator17( segmentAllocator: SegmentAllocator, diff --git a/j17/src/fr/hammons/slinc/Mem17.scala b/j17/src/fr/hammons/slinc/Mem17.scala index 4ba6403..7149630 100644 --- a/j17/src/fr/hammons/slinc/Mem17.scala +++ b/j17/src/fr/hammons/slinc/Mem17.scala @@ -18,6 +18,10 @@ class Mem17(private[slinc] val mem: MemorySegment) extends Mem: VaList.ofAddress(mem.address().nn).nn ) + override def copyFrom(other: Mem): Unit = + other match + case oMem: Mem17 => mem.copyFrom(oMem.mem) + override def readLong(offset: Bytes): Long = MemoryAccess.getLongAtOffset(mem, offset.toLong) diff --git a/j17/src/fr/hammons/slinc/Scope17.scala b/j17/src/fr/hammons/slinc/Scope17.scala index 8c9d5fe..8c134f3 100644 --- a/j17/src/fr/hammons/slinc/Scope17.scala +++ b/j17/src/fr/hammons/slinc/Scope17.scala @@ -1,11 +1,10 @@ package fr.hammons.slinc -import jdk.incubator.foreign.CLinker import jdk.incubator.foreign.ResourceScope import jdk.incubator.foreign.SegmentAllocator import jdk.incubator.foreign.MemoryAddress -class Scope17(linker: CLinker) extends ScopeI.PlatformSpecific: +object Scope17 extends ScopeI.PlatformSpecific: private val baseNull = Ptr[Nothing]( Mem17(MemoryAddress.NULL.nn.asSegment(1, ResourceScope.globalScope).nn), Bytes(0) @@ -17,14 +16,14 @@ class Scope17(linker: CLinker) extends ScopeI.PlatformSpecific: def apply[A](fn: (Allocator) ?=> A): A = val rs = ResourceScope.globalScope().nn given Allocator = - Allocator17(SegmentAllocator.arenaAllocator(rs).nn, rs, linker) + Allocator17(SegmentAllocator.arenaAllocator(rs).nn, rs, Slinc17.linker) fn def createConfinedScope: ConfinedScope = new ConfinedScope: def apply[A](fn: Allocator ?=> A): A = val rs = ResourceScope.newConfinedScope().nn given Allocator = - Allocator17(SegmentAllocator.arenaAllocator(rs).nn, rs, linker) + Allocator17(SegmentAllocator.arenaAllocator(rs).nn, rs, Slinc17.linker) val res = fn rs.close() res @@ -33,7 +32,7 @@ class Scope17(linker: CLinker) extends ScopeI.PlatformSpecific: def apply[A](fn: Allocator ?=> A): A = val rs = ResourceScope.newSharedScope().nn given Allocator = - Allocator17(SegmentAllocator.arenaAllocator(rs).nn, rs, linker) + Allocator17(SegmentAllocator.arenaAllocator(rs).nn, rs, Slinc17.linker) val res = fn rs.close() res @@ -46,7 +45,7 @@ class Scope17(linker: CLinker) extends ScopeI.PlatformSpecific: given Allocator = Allocator17( segmentAllocator, ResourceScope.globalScope().nn, - linker + Slinc17.linker ) val res = fn allocator.reset() @@ -55,5 +54,5 @@ class Scope17(linker: CLinker) extends ScopeI.PlatformSpecific: def createInferredScope: InferredScope = new InferredScope: def apply[A](fn: Allocator ?=> A): A = val scope = ResourceScope.newSharedScope().nn - given Allocator = InferredAllocator17(scope, linker) + given Allocator = InferredAllocator17(scope, Slinc17.linker) fn diff --git a/j17/src/fr/hammons/slinc/Slinc17.scala b/j17/src/fr/hammons/slinc/Slinc17.scala index 37da9c0..83ac9b1 100644 --- a/j17/src/fr/hammons/slinc/Slinc17.scala +++ b/j17/src/fr/hammons/slinc/Slinc17.scala @@ -9,7 +9,7 @@ import fr.hammons.slinc.modules.{ } import fr.hammons.slinc.modules.given -class Slinc17(_jitManager: JitManager, linker: CLinker)(using +class Slinc17(_jitManager: JitManager)(using val dm: DescriptorModule, val tm: TransitionModule, val rwm: ReadWriteModule, @@ -17,13 +17,13 @@ class Slinc17(_jitManager: JitManager, linker: CLinker)(using ) extends Slinc: val version: Int = 17 protected def jitManager = _jitManager - protected def scopePlatformSpecific = Scope17(linker) + protected def scopePlatformSpecific = Scope17 @SlincImpl(17) object Slinc17: - private val compiler = + private lazy val compiler = scala.quoted.staging.Compiler.make(getClass().getClassLoader().nn) - private[slinc] val linker = CLinker.getInstance().nn - val default = Slinc17(JitManagerImpl(compiler), linker) - val noJit = Slinc17(NoJitManager, linker) - val immediateJit = Slinc17(InstantJitManager(compiler), linker) + private[slinc] lazy val linker = CLinker.getInstance().nn + val default = Slinc17(JitManagerImpl(compiler)) + val noJit = Slinc17(NoJitManager) + val immediateJit = Slinc17(InstantJitManager(compiler)) diff --git a/j17/src/fr/hammons/slinc/modules/LinkageModule17.scala b/j17/src/fr/hammons/slinc/modules/LinkageModule17.scala index a873693..dc524cf 100644 --- a/j17/src/fr/hammons/slinc/modules/LinkageModule17.scala +++ b/j17/src/fr/hammons/slinc/modules/LinkageModule17.scala @@ -9,10 +9,8 @@ import java.lang.invoke.MethodType object LinkageModule17 extends LinkageModule: import descriptorModule17.* override type CSymbol = Addressable - private val linker = CLinker.getInstance().nn private val lookup = CLinker.systemLookup().nn private val lookupLoader = SymbolLookup.loaderLookup().nn - private val ts = Scope17(linker) override def defaultLookup(name: String): Option[CSymbol] = lookup.lookup(name).nn.toScala @@ -59,7 +57,7 @@ object LinkageModule17 extends LinkageModule: .toSeq ) - linker.downcallHandle(mt, fd).nn + Slinc17.linker.downcallHandle(mt, fd).nn end getDowncall - lazy val tempScope: Scope = ts.createTempScope + lazy val tempScope: Scope = Scope17.createTempScope diff --git a/j17/src/fr/hammons/slinc/modules/ReadWriteModule17.scala b/j17/src/fr/hammons/slinc/modules/ReadWriteModule17.scala index 094ca86..127d93f 100644 --- a/j17/src/fr/hammons/slinc/modules/ReadWriteModule17.scala +++ b/j17/src/fr/hammons/slinc/modules/ReadWriteModule17.scala @@ -41,6 +41,22 @@ given readWriteModule17: ReadWriteModule with val memReader = (mem, offset) => mem.readAddress(offset) + def unionReader( + typeDescriptor: TypeDescriptor + ): Reader[CUnion[? <: NonEmptyTuple]] = + val size = descriptorModule17.sizeOf(typeDescriptor) + (mem, offset) => + Scope17.createInferredScope(alloc ?=> + val newMem = alloc.allocate(typeDescriptor, 1) + newMem.copyFrom(mem.offset(offset).resize(size)) + + new CUnion(newMem) + ) + + def unionWriter(td: TypeDescriptor): Writer[CUnion[? <: NonEmptyTuple]] = + val size = descriptorModule17.sizeOf(td) + (mem, offset, value) => mem.offset(offset).resize(size).copyFrom(value.mem) + arrayWriterCache .addOne( ByteDescriptor, diff --git a/j17/src/fr/hammons/slinc/modules/TransitionModule17.scala b/j17/src/fr/hammons/slinc/modules/TransitionModule17.scala index 227a8fe..c061e9a 100644 --- a/j17/src/fr/hammons/slinc/modules/TransitionModule17.scala +++ b/j17/src/fr/hammons/slinc/modules/TransitionModule17.scala @@ -5,12 +5,7 @@ import fr.hammons.slinc.TypeDescriptor import scala.collection.concurrent.TrieMap import fr.hammons.slinc.* -import jdk.incubator.foreign.{ - MemoryAddress, - MemorySegment, - ResourceScope, - SegmentAllocator -} +import jdk.incubator.foreign.{MemoryAddress, MemorySegment} given transitionModule17: TransitionModule with @@ -18,13 +13,6 @@ given transitionModule17: TransitionModule with value.asInstanceOf[MemorySegment] ) - override def cUnionReturn(td: TypeDescriptor, value: Object): CUnion[?] = - val scope = ResourceScope.newImplicitScope().nn - val alloc = SegmentAllocator.arenaAllocator(scope).nn - val segment = alloc.allocate(descriptorModule17.toMemoryLayout(td)).nn - segment.copyFrom(value.asInstanceOf[MemorySegment]) - new CUnion(Mem17(segment)) - override def addressReturn(value: Object): Mem = Mem17( MemorySegment .globalNativeSegment() diff --git a/j19/src/fr/hammons/slinc/Mem19.scala b/j19/src/fr/hammons/slinc/Mem19.scala index 9df4249..6093d71 100644 --- a/j19/src/fr/hammons/slinc/Mem19.scala +++ b/j19/src/fr/hammons/slinc/Mem19.scala @@ -19,6 +19,9 @@ object Mem19: class Mem19(private[slinc] val mem: MemorySegment) extends Mem: import Mem19.* + override def copyFrom(other: Mem): Unit = other match + case oMem: Mem19 => mem.copyFrom(oMem.mem).nn + override def writeByteArray(v: Array[Byte], offset: Bytes): Unit = mem.asSlice(offset.toLong).nn.copyFrom(MemorySegment.ofArray(v)) diff --git a/j19/src/fr/hammons/slinc/Scope19.scala b/j19/src/fr/hammons/slinc/Scope19.scala index 6069b86..02fec03 100644 --- a/j19/src/fr/hammons/slinc/Scope19.scala +++ b/j19/src/fr/hammons/slinc/Scope19.scala @@ -1,12 +1,11 @@ package fr.hammons.slinc -import java.lang.foreign.Linker import java.lang.foreign.MemorySession import java.lang.foreign.SegmentAllocator import java.lang.foreign.MemorySegment import java.lang.foreign.MemoryAddress -class Scope19(linker: Linker) extends ScopeI.PlatformSpecific: +object Scope19 extends ScopeI.PlatformSpecific: val baseNull: Ptr[Any] = Ptr( Mem19( @@ -20,7 +19,7 @@ class Scope19(linker: Linker) extends ScopeI.PlatformSpecific: given Allocator = Allocator19( TempAllocator19.localAllocator, MemorySession.global().nn, - linker + Slinc19.linker ) def apply[A](fn: Allocator ?=> A): A = val res = fn @@ -31,14 +30,14 @@ class Scope19(linker: Linker) extends ScopeI.PlatformSpecific: def apply[A](fn: Allocator ?=> A): A = val rs = MemorySession.global().nn given Allocator = - Allocator19(SegmentAllocator.newNativeArena(rs).nn, rs, linker) + Allocator19(SegmentAllocator.newNativeArena(rs).nn, rs, Slinc19.linker) fn override def createConfinedScope: ConfinedScope = new ConfinedScope: def apply[A](fn: Allocator ?=> A): A = val rs = MemorySession.openConfined().nn given Allocator = - Allocator19(SegmentAllocator.newNativeArena(rs).nn, rs, linker) + Allocator19(SegmentAllocator.newNativeArena(rs).nn, rs, Slinc19.linker) val res = fn rs.close() res @@ -47,7 +46,7 @@ class Scope19(linker: Linker) extends ScopeI.PlatformSpecific: def apply[A](fn: Allocator ?=> A): A = val rs = MemorySession.openShared().nn given Allocator = - Allocator19(SegmentAllocator.newNativeArena(rs).nn, rs, linker) + Allocator19(SegmentAllocator.newNativeArena(rs).nn, rs, Slinc19.linker) val res = fn rs.close() res @@ -57,5 +56,5 @@ class Scope19(linker: Linker) extends ScopeI.PlatformSpecific: val rs = MemorySession.openImplicit().nn given Allocator = - Allocator19(SegmentAllocator.newNativeArena(rs).nn, rs, linker) + Allocator19(SegmentAllocator.newNativeArena(rs).nn, rs, Slinc19.linker) fn diff --git a/j19/src/fr/hammons/slinc/Slinc19.scala b/j19/src/fr/hammons/slinc/Slinc19.scala index 4a1aec0..79e2b62 100644 --- a/j19/src/fr/hammons/slinc/Slinc19.scala +++ b/j19/src/fr/hammons/slinc/Slinc19.scala @@ -3,7 +3,7 @@ package fr.hammons.slinc import java.lang.foreign.Linker import fr.hammons.slinc.modules.{*, given} -class Slinc19(_jitManager: JitManager, linker: Linker)(using +class Slinc19(_jitManager: JitManager)(using val dm: DescriptorModule, val tm: TransitionModule, val rwm: ReadWriteModule, @@ -13,13 +13,13 @@ class Slinc19(_jitManager: JitManager, linker: Linker)(using protected def jitManager: JitManager = _jitManager protected def scopePlatformSpecific: ScopeI.PlatformSpecific = - Scope19(linker) + Scope19 @SlincImpl(19) object Slinc19: private val compiler = scala.quoted.staging.Compiler.make(getClass().getClassLoader().nn) - private[slinc] val linker = Linker.nativeLinker().nn - val default = Slinc19(JitManagerImpl(compiler), linker) - val noJit = Slinc19(NoJitManager, linker) - val immediateJit = Slinc19(InstantJitManager(compiler), linker) + private[slinc] lazy val linker = Linker.nativeLinker().nn + val default = Slinc19(JitManagerImpl(compiler)) + val noJit = Slinc19(NoJitManager) + val immediateJit = Slinc19(InstantJitManager(compiler)) diff --git a/j19/src/fr/hammons/slinc/modules/LinkageModule19.scala b/j19/src/fr/hammons/slinc/modules/LinkageModule19.scala index a256080..4c6d335 100644 --- a/j19/src/fr/hammons/slinc/modules/LinkageModule19.scala +++ b/j19/src/fr/hammons/slinc/modules/LinkageModule19.scala @@ -1,7 +1,6 @@ package fr.hammons.slinc.modules import java.lang.invoke.MethodHandle -import java.lang.foreign.Linker import java.lang.foreign.{FunctionDescriptor as JFunctionDescriptor} import scala.jdk.OptionConverters.* import java.lang.foreign.MemorySegment @@ -12,10 +11,8 @@ import java.lang.foreign.SymbolLookup object LinkageModule19 extends LinkageModule: import descriptorModule19.* override type CSymbol = MemorySegment - private val linker = Linker.nativeLinker().nn - private val lookup = linker.defaultLookup().nn + private val lookup = Slinc19.linker.defaultLookup().nn private val loaderLookup = SymbolLookup.loaderLookup().nn - private val ts = Scope19(linker) override def defaultLookup(name: String): Option[CSymbol] = lookup.lookup(name).nn.toScala @@ -57,7 +54,7 @@ object LinkageModule19 extends LinkageModule: .toList ) - linker.downcallHandle(fd).nn + Slinc19.linker.downcallHandle(fd).nn end getDowncall - lazy val tempScope: Scope = ts.createTempScope + lazy val tempScope: Scope = Scope19.createTempScope diff --git a/j19/src/fr/hammons/slinc/modules/ReadWriteModule19.scala b/j19/src/fr/hammons/slinc/modules/ReadWriteModule19.scala index 5071b14..f0dd6b6 100644 --- a/j19/src/fr/hammons/slinc/modules/ReadWriteModule19.scala +++ b/j19/src/fr/hammons/slinc/modules/ReadWriteModule19.scala @@ -6,6 +6,24 @@ import java.lang.invoke.MethodHandle import scala.reflect.ClassTag private[slinc] given readWriteModule19: ReadWriteModule with + + override def unionWriter( + td: TypeDescriptor + ): Writer[CUnion[? <: NonEmptyTuple]] = + val size = descriptorModule19.sizeOf(td) + (mem, offset, value) => mem.offset(offset).resize(size).copyFrom(value.mem) + + override def unionReader( + td: TypeDescriptor + ): Reader[CUnion[? <: NonEmptyTuple]] = + val size = descriptorModule19.sizeOf(td) + (mem, offset) => + Scope19.createInferredScope(alloc ?=> + val newMem = alloc.allocate(td, 1) + newMem.copyFrom(mem.offset(offset).resize(size)) + new CUnion(newMem) + ) + val writerCache = DependentTrieMap[Writer] val arrayWriterCache = DependentTrieMap[[I] =>> Writer[Array[I]]] diff --git a/j19/src/fr/hammons/slinc/modules/TransitionModule19.scala b/j19/src/fr/hammons/slinc/modules/TransitionModule19.scala index 42956d3..29b04df 100644 --- a/j19/src/fr/hammons/slinc/modules/TransitionModule19.scala +++ b/j19/src/fr/hammons/slinc/modules/TransitionModule19.scala @@ -5,7 +5,6 @@ import scala.collection.concurrent.TrieMap import java.lang.foreign.MemorySegment import java.lang.foreign.MemorySession import java.lang.foreign.MemoryAddress -import java.lang.foreign.SegmentAllocator given transitionModule19: TransitionModule with @@ -44,14 +43,3 @@ given transitionModule19: TransitionModule with override def memReturn(value: Object): Mem = Mem19( value.asInstanceOf[MemorySegment] ) - - override def cUnionReturn(td: TypeDescriptor, value: Object): CUnion[?] = - val session = MemorySession.openImplicit().nn - val segmentAlloc = SegmentAllocator.newNativeArena(session).nn - val segment = - segmentAlloc.allocate(descriptorModule19.toMemoryLayout(td)).nn - new CUnion( - Mem19( - segment.copyFrom(value.asInstanceOf[MemorySegment]).nn - ) - )