JMOD ?= $(JAVA_HOME)/bin/jmod
GCCPLUGINDIR:=$(shell gcc -print-file-name=plugin)
-JAVACFLAGS += --enable-preview --source 20
+JAVACFLAGS +=
# Linux options
linux-amd64_CPPFLAGS = \
build.xml.data.CRC32=d287ed4e
build.xml.script.CRC32=b55362bc
-build.xml.stylesheet.CRC32=32069288@1.6.1
+build.xml.stylesheet.CRC32=32069288@1.30
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=d287ed4e
-nbproject/build-impl.xml.script.CRC32=727ac37b
-nbproject/build-impl.xml.stylesheet.CRC32=d1ebcf0f@1.14
+nbproject/build-impl.xml.data.CRC32=508a6882
+nbproject/build-impl.xml.script.CRC32=cd15f7cb
+nbproject/build-impl.xml.stylesheet.CRC32=d1ebcf0f@1.30
-annotation.processing.enabled=true
+annotation.processing.enabled=false
annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
jar.compress=false
javac.classpath=
# Space-separated list of extra javac options
-javac.compilerargs=-Xlint:unchecked --enable-preview
-javac.deprecation=false
+javac.compilerargs=-Xlint:unchecked
+javac.deprecation=true
javac.external.vm=false
javac.modulepath=
javac.processormodulepath=
javac.processorpath=\
${javac.classpath}
-javac.source=19
-javac.target=19
+javac.source=24
+javac.target=24
javac.test.classpath=\
${javac.classpath}
javac.test.modulepath=\
jlink.additionalparam=
jlink.launcher=true
jlink.launcher.name=notzed.nativez
+main.class=au.notzed.nativez.tools.Generator
platform.active=default_platform
project.license=gpl3-notzed
run.classpath=
# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
-run.jvmargs=-Djava.library.path=bin/notzed.nativez/linux-amd64/lib
+run.jvmargs=-ea -Djava.library.path=bin/notzed.nativez/linux-amd64/lib --enable-native-access=notzed.nativez
run.modulepath=\
${javac.modulepath}:\
${build.modules.dir}
'gcc',
"-fplugin=$FindBin::Bin/../lib/libexport.so",
"-fplugin-arg-libexport-output=$var->{workdir}/$apibase.pm",
+# "-fplugin-arg-libexport-debug=5",
# "-fplugin-arg-libexport-verbose=$var->{verbose}",
'-O0',
'-o', "$var->{workdir}/$apibase.pch",
return new ByteArray(segment);
}
- public static ByteArray create(MemorySegment address, long length, SegmentScope scope) {
- return create(MemorySegment.ofAddress(address.address(), length, scope));
+ public static ByteArray create(MemorySegment address, long length, Arena scope) {
+ return create(MemorySegment.ofAddress(address.address()).reinterpret(length * Memory.BYTE.byteSize(), scope, null));
}
- public static ByteArray create(MemorySegment address, SegmentScope scope) {
- return create(MemorySegment.ofAddress(address.address(), Long.MAX_VALUE, scope));
+ public static ByteArray create(MemorySegment address, Arena scope) {
+ return create(MemorySegment.ofAddress(address.address()).reinterpret(Long.MAX_VALUE, scope, null));
}
public static ByteArray create(long length, SegmentAllocator alloc) {
- return create(alloc.allocateArray(Memory.BYTE, length));
+ return create(alloc.allocate(Memory.BYTE, length));
}
public static ByteArray create(SegmentAllocator alloc, String value) {
- return create(alloc.allocateUtf8String(value));
+ return create(alloc.allocateFrom(value));
}
- //public static ByteArray create(SegmentScope scope, String value) {
- // return create(scope.allocateUtf8String(value));
- //}
-
@Override
public final MemorySegment address() {
return segment;
}
@Override
- public final SegmentScope scope() {
+ public final MemorySegment.Scope scope() {
return segment.scope();
}
}
public String toUtf8String() {
- return segment.getUtf8String(0L);
+ return segment.getString(0L);
}
}
return new DoubleArray(segment);
}
- public static DoubleArray create(MemorySegment address, long length, SegmentScope scope) {
- return create(MemorySegment.ofAddress(address.address(), length * Memory.DOUBLE.byteSize(), scope));
+ public static DoubleArray create(MemorySegment address, long length, Arena scope) {
+ return create(MemorySegment.ofAddress(address.address()).reinterpret(length * Memory.DOUBLE.byteSize(), scope, null));
}
- public static DoubleArray create(MemorySegment address, SegmentScope scope) {
- return create(MemorySegment.ofAddress(address.address(), Long.MAX_VALUE, scope));
+ public static DoubleArray create(MemorySegment address, Arena scope) {
+ return create(MemorySegment.ofAddress(address.address()).reinterpret(Long.MAX_VALUE, scope, null));
}
public static DoubleArray create(long length, SegmentAllocator alloc) {
- return create(alloc.allocateArray(Memory.DOUBLE, length));
+ return create(alloc.allocate(Memory.DOUBLE, length));
}
public static DoubleArray create(SegmentAllocator alloc, double... values) {
- return create(alloc.allocateArray(Memory.DOUBLE, values));
+ return create(alloc.allocateFrom(Memory.DOUBLE, values));
}
@Override
}
@Override
- public final SegmentScope scope() {
+ public final MemorySegment.Scope scope() {
return segment.scope();
}
return new FloatArray(segment);
}
- public static FloatArray create(MemorySegment address, long length, SegmentScope scope) {
- return create(MemorySegment.ofAddress(address.address(), length * Memory.FLOAT.byteSize(), scope));
+ public static FloatArray create(MemorySegment address, long length, Arena scope) {
+ return create(MemorySegment.ofAddress(address.address()).reinterpret(length * Memory.FLOAT.byteSize(), scope, null));
}
- public static FloatArray create(MemorySegment address, SegmentScope scope) {
- return create(MemorySegment.ofAddress(address.address(), Long.MAX_VALUE, scope));
+ public static FloatArray create(MemorySegment address, Arena scope) {
+ return create(address, Long.MAX_VALUE, scope);
}
public static FloatArray create(SegmentAllocator alloc, int length) {
- return create(alloc.allocateArray(Memory.FLOAT, length));
+ return create(alloc.allocate(Memory.FLOAT, length));
}
public static FloatArray create(SegmentAllocator alloc, float... values) {
- return create(alloc.allocateArray(Memory.FLOAT, values));
+ return create(alloc.allocateFrom(Memory.FLOAT, values));
}
@Override
}
@Override
- public final SegmentScope scope() {
+ public final MemorySegment.Scope scope() {
return segment.scope();
}
package au.notzed.nativez;
import java.lang.foreign.*;
-import static java.lang.foreign.ValueLayout.OfAddress;
/**
- * This is a per-thread stack-based allocator.
- * <pre>
- * try (Frame f = Memory.createFrame()) {
- * MemorySegment a = f.allocate(size);
- * }
- * </pre>
- * Any memory allocated is freed when the frame is closed.
+ * Local allocator.
* <p>
- * This is quite a bit faster than using an arena allocator ... but it also
- * removes most scope guarantees.
+ * This was a helper for a pre-release version of java.lang.foreign.
+ * Just use an Arena.
*/
+@Deprecated
public class Frame implements AutoCloseable, SegmentAllocator {
private final Arena alloc;
Frame() {
- this.alloc = Arena.openConfined();
+ this.alloc = Arena.ofConfined();
}
public static Frame frame() {
return new Frame();
}
- public SegmentScope scope() {
+ public MemorySegment.Scope scope() {
return alloc.scope();
}
}
public MemorySegment allocateLong(int count) {
- return allocateArray(Memory.LONG, count);
+ return allocate(Memory.LONG, count);
}
public MemorySegment allocatePointer() {
}
public MemorySegment allocatePointer(int count) {
- return allocateArray(Memory.POINTER, count);
+ return allocate(Memory.POINTER, count);
}
- public MemorySegment allocateArray(OfAddress type, MemorySegment[] value) {
- MemorySegment m = allocateArray(type, value.length);
- for (int i=0;i<value.length;i++)
+ public MemorySegment allocateArray(AddressLayout type, MemorySegment[] value) {
+ MemorySegment m = allocate(type, value.length);
+ for (int i = 0; i < value.length; i++)
m.setAtIndex(type, i, value[i]);
return m;
}
+ @Deprecated
public MemorySegment copy(byte value) {
return allocate(Memory.BYTE, value);
}
+ @Deprecated
public MemorySegment copy(short value) {
return allocate(Memory.SHORT, value);
}
+ @Deprecated
public MemorySegment copy(int value) {
return allocate(Memory.INT, value);
}
+ @Deprecated
public MemorySegment copy(long value) {
return allocate(Memory.LONG, value);
}
+ @Deprecated
public MemorySegment copy(float value) {
- return allocate(Memory.FLOAT, value);
+ return allocateFrom(Memory.FLOAT, value);
}
+ @Deprecated
public MemorySegment copy(double value) {
- return allocate(Memory.DOUBLE, value);
+ return allocateFrom(Memory.DOUBLE, value);
}
+ @Deprecated
public MemorySegment copy(byte[] value) {
- return allocateArray(Memory.BYTE, value);
+ return allocateFrom(Memory.BYTE, value);
}
+ @Deprecated
public MemorySegment copy(int[] value) {
- return allocateArray(Memory.INT, value);
+ return allocateFrom(Memory.INT, value);
}
+ @Deprecated
public MemorySegment copy(long[] value) {
- return allocateArray(Memory.LONG, value);
+ return allocateFrom(Memory.LONG, value);
}
+ @Deprecated
public MemorySegment copy(float[] value) {
- return allocateArray(Memory.FLOAT, value);
+ return allocateFrom(Memory.FLOAT, value);
}
+ @Deprecated
public MemorySegment copy(String value) {
- return allocateUtf8String(value);
+ return allocateFrom(value);
}
/*
}
return list;
} else {
- return Memory.NULL;
+ return MemorySegment.NULL;
}
}
*/
public class HandleArray<T extends Pointer> extends AbstractList<T> implements Pointer {
public final MemorySegment segment;
- final SegmentScope scope;
- BiFunction<MemorySegment,SegmentScope,T> create;
+ final Arena scope;
+ BiFunction<MemorySegment,Arena,T> create;
- private HandleArray(MemorySegment segment, BiFunction<MemorySegment,SegmentScope,T> create, SegmentScope scope) {
+ private HandleArray(MemorySegment segment, BiFunction<MemorySegment,Arena,T> create, Arena scope) {
this.segment = segment;
this.create = create;
this.scope = scope;
}
- public static <T extends Pointer> HandleArray<T> create(MemorySegment segment, BiFunction<MemorySegment,SegmentScope,T> create) {
- return new HandleArray<>(segment, create, segment.scope());
+ public static <T extends Pointer> HandleArray<T> create(MemorySegment segment, BiFunction<MemorySegment,Arena,T> create) {
+ return new HandleArray<>(segment, create, null);
}
- public static <T extends Pointer> HandleArray<T> create(MemorySegment segment, BiFunction<MemorySegment,SegmentScope,T> create, SegmentScope scope) {
+ public static <T extends Pointer> HandleArray<T> create(MemorySegment segment, BiFunction<MemorySegment,Arena,T> create, Arena scope) {
return new HandleArray<>(segment, create, scope);
}
- public static <T extends Pointer> HandleArray<T> create(long size, BiFunction<MemorySegment,SegmentScope,T> create, SegmentAllocator alloc) {
- return create(alloc.allocateArray(Memory.POINTER, size), create);
+ public static <T extends Pointer> HandleArray<T> create(long size, BiFunction<MemorySegment,Arena,T> create, SegmentAllocator alloc) {
+ return create(alloc.allocate(Memory.POINTER, size), create);
}
- public static <T extends Pointer> HandleArray<T> create(long size, BiFunction<MemorySegment,SegmentScope,T> create, SegmentAllocator alloc, SegmentScope scope) {
- return create(alloc.allocateArray(Memory.POINTER, size), create, scope);
+ public static <T extends Pointer> HandleArray<T> create(long size, BiFunction<MemorySegment,Arena,T> create, SegmentAllocator alloc, Arena scope) {
+ return create(alloc.allocate(Memory.POINTER, size), create, scope);
}
- public static <T extends Pointer> HandleArray<T> create(MemorySegment address, long size, BiFunction<MemorySegment,SegmentScope,T> create, SegmentScope scope) {
- return create(MemorySegment.ofAddress(address.address(), size * Memory.POINTER.byteSize(), scope), create);
+ public static <T extends Pointer> HandleArray<T> create(MemorySegment address, long size, BiFunction<MemorySegment,Arena,T> create, Arena scope) {
+ return create(MemorySegment.ofAddress(address.address()).reinterpret(size * Memory.POINTER.byteSize(), scope, null), create);
}
- public static <T extends Pointer> HandleArray<T> create(BiFunction<MemorySegment,SegmentScope,T> create, SegmentAllocator alloc, T... values) {
- HandleArray<T> array = create(alloc.allocateArray(Memory.POINTER, values.length), create);
+ public static <T extends Pointer> HandleArray<T> create(BiFunction<MemorySegment,Arena,T> create, SegmentAllocator alloc, T... values) {
+ HandleArray<T> array = create(alloc.allocate(Memory.POINTER, values.length), create);
for (int i=0;i<values.length;i++)
array.setAtIndex(i, values[i]);
return array;
}
@Override
- public final SegmentScope scope() {
+ public final MemorySegment.Scope scope() {
return segment.scope();
}
return new IntArray(segment);
}
- public static IntArray create(MemorySegment address, long length, SegmentScope scope) {
- return create(MemorySegment.ofAddress(address.address(), length * Memory.INT.byteSize(), scope));
+ public static IntArray create(MemorySegment address, long length, Arena scope) {
+ return create(MemorySegment.ofAddress(address.address()).reinterpret(length * Memory.INT.byteSize(), scope, null));
}
- public static IntArray create(MemorySegment address, SegmentScope scope) {
- return create(MemorySegment.ofAddress(address.address(), Long.MAX_VALUE, scope));
+ public static IntArray create(MemorySegment address, Arena scope) {
+ return create(MemorySegment.ofAddress(address.address()).reinterpret(Long.MAX_VALUE, scope, null));
}
public static IntArray create(long length, SegmentAllocator alloc) {
- return create(alloc.allocateArray(Memory.INT, length));
+ return create(alloc.allocate(Memory.INT, length));
}
public static IntArray create(SegmentAllocator alloc, int... values) {
- return create(alloc.allocateArray(Memory.INT, values));
+ return create(alloc.allocateFrom(Memory.INT, values));
}
public IntArray asSlice(long offset) {
}
@Override
- public final SegmentScope scope() {
+ public final MemorySegment.Scope scope() {
return segment.scope();
}
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
package au.notzed.nativez;
import java.lang.foreign.*;
return new LongArray(segment);
}
- public static LongArray create(MemorySegment address, long length, SegmentScope scope) {
- return create(MemorySegment.ofAddress(address.address(), length * Memory.LONG.byteSize(), scope));
+ public static LongArray create(MemorySegment address, long length, Arena scope) {
+ return create(MemorySegment.ofAddress(address.address()).reinterpret(length * Memory.LONG.byteSize(), scope, null));
+ }
+
+ public static LongArray create(MemorySegment address, Arena scope) {
+ return create(MemorySegment.ofAddress(address.address()).reinterpret(Long.MAX_VALUE, scope, null));
}
public static LongArray create(long length, SegmentAllocator alloc) {
- return create(alloc.allocateArray(Memory.LONG, length));
+ return create(alloc.allocate(Memory.LONG, length));
}
public static LongArray create(SegmentAllocator alloc, long... values) {
- return create(alloc.allocateArray(Memory.LONG, values));
+ return create(alloc.allocateFrom(Memory.LONG, values));
}
@Override
}
@Override
- public final SegmentScope scope() {
+ public final MemorySegment.Scope scope() {
return segment.scope();
}
// probably should be INT8 INT16, etc
public static final OfByte BYTE = JAVA_BYTE;
- public static final OfShort SHORT = JAVA_SHORT.withBitAlignment(16);
- public static final OfInt INT = JAVA_INT.withBitAlignment(32);
- public static final OfLong LONG = JAVA_LONG.withBitAlignment(64);
- public static final OfFloat FLOAT = JAVA_FLOAT.withBitAlignment(32);
- public static final OfDouble DOUBLE = JAVA_DOUBLE.withBitAlignment(64);
- public static final OfAddress POINTER = ADDRESS.withBitAlignment(64);
-
- static final SegmentScope sharedScope = SegmentScope.auto(); // cleaner?
- // Note: currently can't create zero-length segments
- @Deprecated
- static final MemorySegment NULL = MemorySegment.NULL;
-
- public static SegmentScope sharedScope() {
+ public static final OfShort SHORT = JAVA_SHORT.withByteAlignment(2);
+ public static final OfInt INT = JAVA_INT.withByteAlignment(4);
+ public static final OfLong LONG = JAVA_LONG.withByteAlignment(8);
+ public static final OfFloat FLOAT = JAVA_FLOAT.withByteAlignment(4);
+ public static final OfDouble DOUBLE = JAVA_DOUBLE.withByteAlignment(8);
+ public static final AddressLayout POINTER = ADDRESS.withByteAlignment(8);
+
+ static final Arena sharedScope = Arena.ofAuto(); // cleaner?
+
+ public static Arena sharedScope() {
return sharedScope;
}
return Linker.nativeLinker().downcallHandle(desc);
}
+ public static MethodHandle downcall(SymbolLookup lookup, String name, FunctionDescriptor desc) {
+ return lookup.find(name)
+ .map(sym -> Linker.nativeLinker().downcallHandle(sym, desc))
+ .orElse(null);
+ }
+
public static MethodHandle downcall(String name, FunctionDescriptor desc) {
return SymbolLookup.loaderLookup().find(name)
.map(sym -> Linker.nativeLinker().downcallHandle(sym, desc))
public static MethodHandle downcall(MemorySegment sym, FunctionDescriptor desc) {
return Linker.nativeLinker().downcallHandle(sym, desc);
}
-/*
+ /*
public static MethodHandle downcall(MemorySegment sym, FunctionDescriptor desc, SegmentScope scope) {
return sym != MemorySegment.NULL
? Linker.nativeLinker().downcallHandle(MemorySegment.ofAddress(sym, 0, scope), desc)
? Linker.nativeLinker().downcallHandle(MemorySegment.ofAddress(sym, 0, scope), desc)
: null;
}
-*/
+ */
static final MethodHandles.Lookup lookup = MethodHandles.lookup();
- public static MemorySegment upcall(Object instance, FunctionDescriptor desc, SegmentScope scope) {
+ public static MemorySegment upcall(Object instance, FunctionDescriptor desc, Arena scope) {
try {
java.lang.reflect.Method m = instance.getClass().getMethods()[0];
MethodHandle handle = lookup.findVirtual(instance.getClass(), "call", MethodType.methodType(m.getReturnType(), m.getParameterTypes()))
}
}
- public static MemorySegment upcall(MethodHandles.Lookup lookup, Object instance, String signature, FunctionDescriptor desc, SegmentScope scope) {
+ public static MemorySegment upcall(MethodHandles.Lookup lookup, Object instance, String signature, FunctionDescriptor desc, Arena scope) {
try {
java.lang.reflect.Method m = instance.getClass().getMethods()[0];
MethodHandle handle = lookup.findVirtual(instance.getClass(), m.getName(), MethodType.fromMethodDescriptorString(signature, Memory.class.getClassLoader()))
}
}
- public static MemorySegment upcall(MethodHandles.Lookup lookup, Object instance, String method, String signature, FunctionDescriptor desc, SegmentScope scope) {
+ public static MemorySegment upcall(MethodHandles.Lookup lookup, Object instance, String method, String signature, FunctionDescriptor desc, Arena scope) {
try {
MethodHandle handle = lookup.findVirtual(instance.getClass(), method, MethodType.fromMethodDescriptorString(signature, Memory.class.getClassLoader()))
.bindTo(instance);
public static <T> MemorySegment address(FunctionPointer<T> v) {
return v.symbol();
}
- */
+ */
public static MemorySegment address(MemorySegment v) {
return v != null ? v : MemorySegment.NULL;
}
}
public static MemorySegment slice(MemorySegment segment, MethodHandle sliceHandle) {
- try {
- return (MemorySegment)sliceHandle.invokeExact(segment);
- } catch (Throwable ex) {
- throw new RuntimeException(ex);
- }
+ try {
+ return (MemorySegment)sliceHandle.invokeExact(segment);
+ } catch (Throwable ex) {
+ throw new RuntimeException(ex);
+ }
}
public static String copyString(MemorySegment string) {
- return string != MemorySegment.NULL ? string.getUtf8String(0) : null;
+ return string != MemorySegment.NULL ? string.getString(0) : null;
}
public static MemorySegment copyString(String string, SegmentAllocator alloc) {
- return (string != null) ? alloc.allocateUtf8String(string) : Memory.NULL;
+ return (string != null) ? alloc.allocateFrom(string) : MemorySegment.NULL;
}
public static String[] copyStringArray(MemorySegment list, long len) {
String[] array = new String[(int)len];
for (int i = 0; i < array.length; i++) {
MemorySegment fu = list.getAtIndex(Memory.POINTER, i);
- array[i] = fu != MemorySegment.NULL ? fu.getUtf8String(0) : null;
+ array[i] = fu != MemorySegment.NULL ? fu.getString(0) : null;
}
return array;
} else {
public static MemorySegment copyStringArray(String[] array, SegmentAllocator alloc) {
if (array != null) {
- MemorySegment list = alloc.allocateArray(Memory.POINTER, array.length);
+ MemorySegment list = alloc.allocate(Memory.POINTER, array.length);
for (int i = 0; i < array.length; i++) {
- list.setAtIndex(Memory.POINTER, i, array[i] != null ? alloc.allocateUtf8String(array[i]) : MemorySegment.NULL);
+ list.setAtIndex(Memory.POINTER, i, array[i] != null ? alloc.allocateFrom(array[i]) : MemorySegment.NULL);
}
return list;
} else {
- return Memory.NULL;
+ return MemorySegment.NULL;
}
}
}
@Override
- public SegmentScope scope() {
+ public MemorySegment.Scope scope() {
return p.scope();
}
*/
public interface Pointer {
MemorySegment address();
- default SegmentScope scope() {
- return SegmentScope.global();
+ default MemorySegment.Scope scope() {
+ return Arena.global().scope();
}
}
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
package au.notzed.nativez;
import java.lang.foreign.*;
return new PointerArray(segment);
}
- public static PointerArray create(MemorySegment address, long length, SegmentScope scope) {
- return create(MemorySegment.ofAddress(address.address(), length, scope));
+ public static PointerArray create(MemorySegment address, long length, Arena scope) {
+ return create(MemorySegment.ofAddress(address.address()).reinterpret(length, scope, null));
+ }
+
+ public static PointerArray create(MemorySegment address, Arena scope) {
+ return create(address, Long.MAX_VALUE, scope);
}
public static PointerArray create(long length, SegmentAllocator alloc) {
- return create(alloc.allocateArray(Memory.POINTER, length));
+ return create(alloc.allocate(Memory.POINTER, length));
}
public static PointerArray create(SegmentAllocator alloc, MemorySegment... values) {
- MemorySegment m = alloc.allocateArray(Memory.POINTER, values.length);
- for (int i=0;i<values.length;i++)
+ MemorySegment m = alloc.allocate(Memory.POINTER, values.length);
+ for (int i = 0; i < values.length; i++)
m.setAtIndex(Memory.POINTER, i, values[i]);
return create(m);
}
}
@Override
- public final SegmentScope scope() {
+ public final MemorySegment.Scope scope() {
return segment.scope();
}
return new ShortArray(segment);
}
- public static ShortArray create(MemorySegment address, long length, SegmentScope scope) {
- return create(MemorySegment.ofAddress(address.address(), length * Memory.SHORT.byteSize(), scope));
+ public static ShortArray create(MemorySegment address, long length, Arena scope) {
+ return create(MemorySegment.ofAddress(address.address()).reinterpret(length * Memory.SHORT.byteSize(), scope, null));
}
- public static ShortArray create(MemorySegment address, SegmentScope scope) {
- return create(MemorySegment.ofAddress(address.address(), Long.MAX_VALUE, scope));
+ public static ShortArray create(MemorySegment address, Arena scope) {
+ return create(MemorySegment.ofAddress(address.address()).reinterpret(Long.MAX_VALUE, scope, null));
}
+ @Deprecated
public static ShortArray create(long length, SegmentAllocator alloc) {
- return create(alloc.allocateArray(Memory.SHORT, length));
+ return create(alloc.allocate(Memory.SHORT, length));
}
+ @Deprecated
public static ShortArray create(SegmentAllocator alloc, short... values) {
- return create(alloc.allocateArray(Memory.SHORT, values));
+ return create(alloc.allocateFrom(Memory.SHORT, values));
}
@Override
}
@Override
- public final SegmentScope scope() {
+ public final MemorySegment.Scope scope() {
return segment.scope();
}
# callback function/types
downcall {{
- public static FunctionPointer<{rename}> downcall(MemorySegment addr$, SegmentScope scope$) {
+ public static FunctionPointer<{rename}> downcall(MemorySegment addr$, Arena scope$) {
MemorySegment symbol$ = MemorySegment.ofAddress(addr$.address(), 0, scope$);
MethodHandle {rename}$FH = Memory.downcall(symbol$, descriptor());
return new FunctionPointer<{rename}>(
}}
upcall {{
- public static FunctionPointer<{rename}> upcall({rename} target$, SegmentScope scope$) {
+ public static FunctionPointer<{rename}> upcall({rename} target$, Arena scope$) {
interface Trampoline {
{java-result} call({native-arguments});
}
{imports}
public class {name} {
- {name}(Function<String,MemorySegment> resolve, SegmentScope scope) {
+ {name}(Function<String,MemorySegment> resolve, Arena scope) {
{init}
}
- public static {name} create(Function<String,MemorySegment> resolve, SegmentScope scope) {
+ public static {name} create(Function<String,MemorySegment> resolve, Arena scope) {
return new {name}(resolve, scope);
}
{defines}
{init}
}
+
+
public static {rename} create(MemorySegment segment) {
return new {rename}(segment);
}
- public static {rename} create(MemorySegment address, SegmentScope scope) {
- return MemorySegment.NULL != address ? create(MemorySegment.ofAddress(address.address(), LAYOUT.byteSize(), scope)) : null;
+ public static {rename} create(MemorySegment address, Arena scope) {
+ return MemorySegment.NULL != address ? create(MemorySegment.ofAddress(address.address()).reinterpret(LAYOUT.byteSize(), scope, null)) : null;
}
public static {rename} create(SegmentAllocator frame) {
}
@Override
- public final SegmentScope scope() {
+ public final MemorySegment.Scope scope() {
return segment.scope();
}
return new {rename}(segment);
}
- public static {rename} create(MemorySegment address, SegmentScope scope) {
+ public static {rename} create(MemorySegment address, Arena scope) {
return MemorySegment.NULL != address ? create(MemorySegment.ofAddress(address.address(), LAYOUT.byteSize(), scope)) : null;
}
return create(frame.allocate(LAYOUT));
}
- public static {rename} createArray(MemorySegment address, SegmentScope scope) {
+ public static {rename} createArray(MemorySegment address, Arena scope) {
return MemorySegment.NULL != address ? create(MemorySegment.ofAddress(address.address(), Long.MAX_VALUE, scope)) : null;
}
- public static {rename} createArray(MemorySegment address, long length, SegmentScope scope) {
+ public static {rename} createArray(MemorySegment address, long length, Arena scope) {
return MemorySegment.NULL != address ? create(MemorySegment.ofAddress(address.address(), LAYOUT.byteSize() * length, scope)) : null;
}
}
@Override
- public final SegmentScope scope() {
+ public final MemorySegment.Scope scope() {
return segment.scope();
}
public class {rename} implements Pointer {
MemorySegment address;
- SegmentScope scope;
+ Arena scope;
- private {rename}(MemorySegment address, SegmentScope scope) {
+ private {rename}(MemorySegment address, Arena scope) {
this.address = address;
this.scope = scope;
{init}
}
- public static {rename} create(MemorySegment address, SegmentScope scope) {
+ public static {rename} create(MemorySegment address, Arena scope) {
return MemorySegment.NULL != address ? new {rename}(address, scope) : null;
}
}
@Override
- public SegmentScope scope() {
+ public Arena scope() {
return scope;
}
$layout .= 'MemoryLayout.paddingLayout('.($s->{size} - $lastOffset).')';
}
- $layout .= "\n\t).withBitAlignment($maxSize);\n";
+ $layout .= "\n\t).withByteAlignment(".($maxSize/8).");\n";
$layout;
}
type /^u64:\$\{(\w+)\}$/ select=array-size copy=<pointer> {
type {{ "$data->{$m->{type}}->{rename}" }}
length {{ 'get'.($m->{'array-size'}->{rename}).'()' }}
- tojava {{ "$data->{$m->{type}}->{rename}.create({value}, {length}, {scope})" }}
+ tojava {{ "$data->{$m->{type}}->{rename}.createArray({value}, {length}, {scope})" }}
}
# *type struct? handle?