Skip to content

Commit

Permalink
[Core] Fix ExceptionInInitializerError
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Aug 1, 2023
1 parent a6f43dc commit 229c299
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package overrungl;

import overrungl.internal.RuntimeHelper;
import overrungl.util.MemoryUtil;

import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.ValueLayout;
Expand All @@ -25,7 +25,6 @@

/**
* The function descriptors.
*
* <h2>Mappings</h2>
* {@snippet lang = java:
* switch (c) {
Expand Down Expand Up @@ -123,7 +122,7 @@ public static ValueLayout ofValue(char c) throws IllegalArgumentException {
case 'F' -> JAVA_FLOAT;
case 'D' -> JAVA_DOUBLE;
case 'P' -> ADDRESS;
case 'p' -> RuntimeHelper.ADDRESS_UNBOUNDED;
case 'p' -> MemoryUtil.ADDRESS_UNBOUNDED;
default ->
throw new IllegalArgumentException(
STR."Invalid argument c: expected one of B, S, I, J, C, Z, F, D, P or p; got '\{c}'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
* @since 0.1.0
*/
public final class MemoryUtil {
/**
* An unbounded address layout.
*/
public static final AddressLayout ADDRESS_UNBOUNDED = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(ValueLayout.JAVA_BYTE));
private static final SymbolLookup LOOKUP = RuntimeHelper.LINKER.defaultLookup();
private static final MethodHandle
m_malloc = downcall("malloc", JP),
Expand All @@ -48,10 +52,6 @@ public final class MemoryUtil {
* The address of {@code NULL}.
*/
public static final long NULL = 0x0L;
/**
* An unbounded address layout.
*/
public static final AddressLayout ADDRESS_UNBOUNDED = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(ValueLayout.JAVA_BYTE));

private static MethodHandle downcall(String name, FunctionDescriptors function) {
return RuntimeHelper.downcallThrow(LOOKUP.find(name), function);
Expand Down

0 comments on commit 229c299

Please sign in to comment.