Skip to content

Commit

Permalink
[GLFW] Rewrite GLFW.java
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Jan 30, 2024
1 parent 12b5a6d commit 443dd7f
Show file tree
Hide file tree
Showing 13 changed files with 699 additions and 1,494 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,20 @@ private RuntimeHelper() {
throw new IllegalStateException("Do not construct instance");
}

@Deprecated(since = "0.1.0")
private static MemorySegment reinterpreting(MemorySegment pointerToPointer, int index, ToLongFunction<MemorySegment> size) {
final MemorySegment seg = pointerToPointer.getAtIndex(ADDRESS, index);
return seg.reinterpret(size.applyAsLong(seg));
}

/**
* Gets a UTF-8 string from the given pointer of a string.
*
* @param segment the memory segment.
* @return the string.
*/
public static String unboundPointerString(MemorySegment segment) {
return unboundPointerString(segment, 0);
}

/**
* Gets a UTF-8 string from the given pointer of a string at the given index.
*
* @param segment the memory segment.
* @param index the index.
* @return the string.
*/
@Deprecated(since = "0.1.0")
public static String unboundPointerString(MemorySegment segment, int index) {
return reinterpreting(segment, index, str -> MemoryUtil.strlen(str) + 1).getString(0);
}
Expand Down Expand Up @@ -180,6 +172,7 @@ public static SymbolLookup load(String module, String basename, String version)
*
* @param segment the segment.
*/
@Deprecated(since = "0.1.0")
public static boolean isNullptr(@Nullable MemorySegment segment) {
return segment == null || segment.equals(MemorySegment.NULL);
}
Expand All @@ -193,6 +186,7 @@ public static boolean isNullptr(@Nullable MemorySegment segment) {
* @return a downcall method handle. or {@code null} if the symbol {@link MemorySegment#NULL}
*/
@Nullable
@Deprecated(since = "0.1.0")
public static MethodHandle downcallSafe(@Nullable MemorySegment symbol, FunctionDescriptor function, Linker.Option... options) {
return isNullptr(symbol) ? null : LINKER.downcallHandle(symbol, function, options);
}
Expand All @@ -205,6 +199,7 @@ public static MethodHandle downcallSafe(@Nullable MemorySegment symbol, Function
* @param options the linker options associated with this linkage request.
* @return a downcall method handle.
*/
@Deprecated(since = "0.1.0")
public static MethodHandle downcallThrow(Optional<MemorySegment> optional, FunctionDescriptor function, Linker.Option... options) {
return LINKER.downcallHandle(optional.orElseThrow(), function, options);
}
Expand All @@ -218,6 +213,7 @@ public static MethodHandle downcallThrow(Optional<MemorySegment> optional, Funct
* @return a downcall method handle. or {@code null} if the symbol {@link MemorySegment#NULL}
*/
@Nullable
@Deprecated(since = "0.1.0")
public static MethodHandle downcallSafe(@Nullable MemorySegment symbol, FunctionDescriptors function, Linker.Option... options) {
return downcallSafe(symbol, function.descriptor(), options);
}
Expand All @@ -230,6 +226,7 @@ public static MethodHandle downcallSafe(@Nullable MemorySegment symbol, Function
* @param options the linker options associated with this linkage request.
* @return a downcall method handle.
*/
@Deprecated(since = "0.1.0")
public static MethodHandle downcallThrow(Optional<MemorySegment> optional, FunctionDescriptors function, Linker.Option... options) {
return downcallThrow(optional, function.descriptor(), options);
}
Expand All @@ -243,6 +240,7 @@ public static MethodHandle downcallThrow(Optional<MemorySegment> optional, Funct
* @param generator the generator, from a zero-length address to the array type
* @return arr
*/
@Deprecated(since = "0.1.0")
public static <T> T[] toArray(MemorySegment seg, T[] arr,
Function<MemorySegment, T> generator) {
for (int i = 0; i < arr.length; i++) {
Expand All @@ -258,6 +256,7 @@ public static <T> T[] toArray(MemorySegment seg, T[] arr,
* @param arr the array to hold the result
* @return an array of the zero-length addresses.
*/
@Deprecated(since = "0.1.0")
public static MemorySegment[] toArray(MemorySegment seg, MemorySegment[] arr) {
return toArray(seg, arr, Function.identity());
}
Expand All @@ -269,6 +268,7 @@ public static MemorySegment[] toArray(MemorySegment seg, MemorySegment[] arr) {
* @param arr the array to hold the result
* @return arr
*/
@Deprecated(since = "0.1.0")
public static String[] toUnboundedArray(@NativeType("char**") MemorySegment seg, String[] arr) {
for (int i = 0; i < arr.length; i++) {
arr[i] = unboundPointerString(seg, i);
Expand All @@ -283,6 +283,7 @@ public static String[] toUnboundedArray(@NativeType("char**") MemorySegment seg,
* @param arr the array to hold the result
* @return arr
*/
@Deprecated(since = "0.1.0")
public static boolean[] toArray(MemorySegment seg, boolean[] arr) {
for (int i = 0; i < arr.length; i++) {
arr[i] = seg.get(JAVA_BOOLEAN, i);
Expand All @@ -297,6 +298,7 @@ public static boolean[] toArray(MemorySegment seg, boolean[] arr) {
* @param arr the array to hold the result
* @return arr
*/
@Deprecated(since = "0.1.0")
public static byte[] toArray(MemorySegment seg, byte[] arr) {
MemorySegment.copy(seg, JAVA_BYTE, 0, arr, 0, arr.length);
return arr;
Expand All @@ -309,6 +311,7 @@ public static byte[] toArray(MemorySegment seg, byte[] arr) {
* @param arr the array to hold the result
* @return arr
*/
@Deprecated(since = "0.1.0")
public static short[] toArray(MemorySegment seg, short[] arr) {
MemorySegment.copy(seg, JAVA_SHORT, 0, arr, 0, arr.length);
return arr;
Expand All @@ -321,6 +324,7 @@ public static short[] toArray(MemorySegment seg, short[] arr) {
* @param arr the array to hold the result
* @return arr
*/
@Deprecated(since = "0.1.0")
public static int[] toArray(MemorySegment seg, int[] arr) {
MemorySegment.copy(seg, JAVA_INT, 0, arr, 0, arr.length);
return arr;
Expand All @@ -333,6 +337,7 @@ public static int[] toArray(MemorySegment seg, int[] arr) {
* @param arr the array to hold the result
* @return arr
*/
@Deprecated(since = "0.1.0")
public static long[] toArray(MemorySegment seg, long[] arr) {
MemorySegment.copy(seg, JAVA_LONG, 0, arr, 0, arr.length);
return arr;
Expand All @@ -345,6 +350,7 @@ public static long[] toArray(MemorySegment seg, long[] arr) {
* @param arr the array to hold the result
* @return arr
*/
@Deprecated(since = "0.1.0")
public static float[] toArray(MemorySegment seg, float[] arr) {
MemorySegment.copy(seg, JAVA_FLOAT, 0, arr, 0, arr.length);
return arr;
Expand All @@ -357,6 +363,7 @@ public static float[] toArray(MemorySegment seg, float[] arr) {
* @param arr the array to hold the result
* @return arr
*/
@Deprecated(since = "0.1.0")
public static double[] toArray(MemorySegment seg, double[] arr) {
MemorySegment.copy(seg, JAVA_DOUBLE, 0, arr, 0, arr.length);
return arr;
Expand Down
Loading

0 comments on commit 443dd7f

Please sign in to comment.