Skip to content

Commit

Permalink
Merge pull request #43 from Over-Run/glfw
Browse files Browse the repository at this point in the history
[GLFW] Rewrite GLFW
  • Loading branch information
squid233 authored Jan 30, 2024
2 parents 06cfc42 + 443dd7f commit b106663
Show file tree
Hide file tree
Showing 51 changed files with 1,592 additions and 2,997 deletions.
4 changes: 1 addition & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@ jdkEnablePreview=true
jdkEarlyAccessDoc=jdk22
kotlinTargetJdkVersion=21

overrunMarshalVersion=0.1.0-alpha.9-jdk22
overrunMarshalVersion=0.1.0-alpha.10-jdk22
overrunPlatformVersion=1.0.0

cLibraryVersion=0.1.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* @author squid233
* @since 0.1.0
*/
@Deprecated(since = "0.1.0")
@FunctionalInterface
public interface Addressable {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* @author squid233
* @since 0.1.0
*/
@Deprecated(since = "0.1.0")
public interface ArrayPointer extends Addressable {
/**
* {@return the count of the elements in this array}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* @author squid233
* @since 0.1.0
*/
@Deprecated(since = "0.1.0")
public interface Callback {
/**
* Gets the address with the given arena.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @author squid233
* @since 0.1.0
*/
@Deprecated(since = "0.1.0")
public class Pointer implements Addressable {
/**
* The pointer address.
Expand Down
1 change: 1 addition & 0 deletions modules/overrungl.core/src/main/java/overrungl/Struct.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @author squid233
* @since 0.1.0
*/
@Deprecated(since = "0.1.0")
public class Struct extends Pointer {
/**
* The memory layout of this struct.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2023 Overrun Organization
* Copyright (c) 2023-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -22,6 +22,7 @@
* @author squid233
* @since 0.1.0
*/
@Deprecated(since = "0.1.0")
public final class Exceptions {
/**
* {@link IllegalStateException}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public final class RuntimeHelper {
public static final boolean CHECKS = Configurations.CHECKS.get();
private static final StackWalker STACK_WALKER = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
private static final Map<String, MemoryLayout> CANONICAL_LAYOUTS = LINKER.canonicalLayouts();
/**
* Some canonical layouts
*/
public static final MemoryLayout LONG = CANONICAL_LAYOUTS.get("long"),
SIZE_T = CANONICAL_LAYOUTS.get("size_t"),
WCHAR_T = CANONICAL_LAYOUTS.get("wchar_t");
Expand All @@ -71,42 +74,24 @@ 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);
}

/**
* Converts the segment into a string.
*
* @param segment the segment
* @return the string
*/
public static String getString(MemorySegment segment) {
return segment.reinterpret(MemoryUtil.strlen(segment) + 1).getString(0);
}

/**
* Generates a string for unknown token.
*
Expand Down Expand Up @@ -187,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 @@ -200,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 @@ -212,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 @@ -225,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 @@ -237,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 @@ -250,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 @@ -265,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 @@ -276,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 @@ -290,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 @@ -304,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 @@ -316,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 @@ -328,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 @@ -340,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 @@ -352,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 @@ -364,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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.jetbrains.annotations.Nullable;
import overrungl.Configurations;
import overrungl.OverrunGL;
import overrungl.internal.Exceptions;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand Down Expand Up @@ -99,7 +98,7 @@ private static void trackAbort(long address, Allocation allocationOld, Allocatio
trackAbortPrint(allocationOld, "Old", addressHex);
trackAbortPrint(allocationNew, "New", addressHex);

throw Exceptions.ISE."The memory address specified is already being tracked: 0x\{addressHex}";
throw new IllegalStateException(STR."The memory address specified is already being tracked: 0x\{addressHex}");
}

private static void trackAbortPrint(Allocation allocation, String name, String address) {
Expand Down Expand Up @@ -138,7 +137,7 @@ static long untrack(long address) {
private static void untrackAbort(long address) {
String addressHex = Long.toHexString(address).toUpperCase();

throw Exceptions.ISE."The memory address specified is not being tracked: 0x\{addressHex}";
throw new IllegalStateException(STR."The memory address specified is not being tracked: 0x\{addressHex}");
}

private record Allocation(long address, long size, long threadId, @Nullable Object[] stacktrace) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2022-2023 Overrun Organization
* Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -39,6 +39,7 @@
* @see Configurations#DEBUG_STACK
* @since 0.1.0
*/
@Deprecated(since = "0.1.0")
public sealed class MemoryStack extends Pointer implements Arena {
private static final boolean DEBUG = Configurations.DEBUG.get();
private static final boolean DEBUG_STACK = Configurations.DEBUG_STACK.get();
Expand Down
Loading

0 comments on commit b106663

Please sign in to comment.