Skip to content

Commit

Permalink
Update downcall instance loading
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Aug 28, 2024
1 parent 20c82ed commit 6990cc2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 25 deletions.
11 changes: 5 additions & 6 deletions modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.nio.charset.StandardCharsets;

import static java.lang.foreign.ValueLayout.*;
import static overrungl.glfw.Handles.*;

/**
* The GLFW binding.
Expand All @@ -43,11 +42,6 @@
* @since 0.1.0
*/
public interface GLFW extends DirectAccess {
/**
* The instance of GLFW.
*/
GLFW INSTANCE = Downcall.load(MethodHandles.lookup(), lookup);

/**
* The major version number of the GLFW header.
* <p>
Expand Down Expand Up @@ -1110,6 +1104,11 @@ public interface GLFW extends DirectAccess {
*/
int DONT_CARE = -1;

/**
* The instance of GLFW.
*/
GLFW INSTANCE = Downcall.load(MethodHandles.lookup(), Handles.lookup);

/**
* Converts the given error code to a readable string.
* <p>
Expand Down
8 changes: 3 additions & 5 deletions modules/overrungl.nfd/src/main/java/overrungl/nfd/NFD.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

package overrungl.nfd;

import overrun.marshal.DirectAccess;
import overrun.marshal.Marshal;
import overrun.marshal.MemoryStack;
import overrun.marshal.Unmarshal;
import overrun.marshal.*;
import overrun.marshal.gen.Entrypoint;
import overrun.marshal.gen.SizedSeg;
import overrun.marshal.gen.Skip;
Expand All @@ -30,6 +27,7 @@
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;

import static java.lang.foreign.ValueLayout.*;

Expand Down Expand Up @@ -153,7 +151,7 @@ public interface NFD extends DirectAccess {
/**
* The instance of NFD.
*/
NFD INSTANCE = NFDInternal.instance;
NFD INSTANCE = Downcall.load(MethodHandles.lookup(), NFDInternal.LOOKUP);

/**
* {@return NFD_PathSet_GetPathN}
Expand Down
14 changes: 0 additions & 14 deletions modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDInternal.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,15 @@
package overrungl.nfd;

import io.github.overrun.platform.Platform;
import overrun.marshal.Downcall;
import overrun.marshal.DowncallOption;
import overrungl.Configurations;
import overrungl.OverrunGL;
import overrungl.internal.RuntimeHelper;

import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.SymbolLookup;
import java.lang.invoke.MethodHandles;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.function.Supplier;

import static java.lang.foreign.ValueLayout.ADDRESS;
import static java.lang.foreign.ValueLayout.JAVA_INT;
import static overrungl.nfd.NFD.PATH_SET_SIZE;

/**
* internal
*
Expand All @@ -43,16 +34,11 @@
*/
final class NFDInternal {
static final SymbolLookup LOOKUP;
static final NFD instance;

static {
final Supplier<SymbolLookup> lib = () -> RuntimeHelper.load("nfd", "nfd", OverrunGL.NFD_VERSION);
final var function = Configurations.NFD_SYMBOL_LOOKUP.get();
LOOKUP = function != null ? function.apply(lib) : lib.get();
instance = Downcall.load(MethodHandles.lookup(), NFDInternal.LOOKUP, DowncallOption.descriptors(Map.of(
"NFD_PathSet_GetPathN", FunctionDescriptor.of(JAVA_INT, ADDRESS, PATH_SET_SIZE, ADDRESS),
"NFD_PathSet_GetPathU8", FunctionDescriptor.of(JAVA_INT, ADDRESS, PATH_SET_SIZE, ADDRESS)
)));
}

static final Platform os = Platform.current();
Expand Down

0 comments on commit 6990cc2

Please sign in to comment.