diff --git a/modules/overrungl.core/src/main/java/overrungl/FunctionDescriptors.java b/modules/overrungl.core/src/main/java/overrungl/FunctionDescriptors.java index 8b5ccb38..7287b1be 100644 --- a/modules/overrungl.core/src/main/java/overrungl/FunctionDescriptors.java +++ b/modules/overrungl.core/src/main/java/overrungl/FunctionDescriptors.java @@ -17,7 +17,7 @@ package overrungl; import overrungl.internal.Exceptions; -import overrungl.util.CStdio; +import overrungl.util.CStdlib; import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.ValueLayout; @@ -38,7 +38,7 @@ * case 'F' -> JAVA_FLOAT; * case 'D' -> JAVA_DOUBLE; * case 'P' -> ADDRESS; - * case 'p' -> CStdio.ADDRESS_UNBOUNDED; + * case 'p' -> CStdlib.ADDRESS_UNBOUNDED; * default -> throw new IllegalArgumentException(); * }} * @@ -123,7 +123,7 @@ public static ValueLayout ofValue(char c) throws IllegalArgumentException { case 'F' -> JAVA_FLOAT; case 'D' -> JAVA_DOUBLE; case 'P' -> ADDRESS; - case 'p' -> CStdio.ADDRESS_UNBOUNDED; + case 'p' -> CStdlib.ADDRESS_UNBOUNDED; default -> throw Exceptions.IAE. "Invalid argument c: expected one of B, S, I, J, C, Z, F, D, P or p; got '\{ c }'" ; }; diff --git a/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java b/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java index fe876479..eae0bdbd 100644 --- a/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java +++ b/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java @@ -20,7 +20,7 @@ import overrungl.FunctionDescriptors; import overrungl.os.Architecture; import overrungl.os.Platform; -import overrungl.util.CStdio; +import overrungl.util.CStdlib; import java.io.File; import java.lang.foreign.*; @@ -50,7 +50,7 @@ public final class RuntimeHelper { /** * An unbounded address layout. */ - public static final AddressLayout ADDRESS_UNBOUNDED = CStdio.ADDRESS_UNBOUNDED; + public static final AddressLayout ADDRESS_UNBOUNDED = CStdlib.ADDRESS_UNBOUNDED; private static final StackWalker STACK_WALKER = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE); /** @@ -194,7 +194,7 @@ public static SymbolLookup load(String module, String basename, String version) * @param segment the segment. */ public static boolean isNullptr(@Nullable MemorySegment segment) { - return CStdio.isNullptr(segment); + return CStdlib.isNullptr(segment); } /** diff --git a/modules/overrungl.core/src/main/java/overrungl/util/CStdio.java b/modules/overrungl.core/src/main/java/overrungl/util/CStdlib.java similarity index 99% rename from modules/overrungl.core/src/main/java/overrungl/util/CStdio.java rename to modules/overrungl.core/src/main/java/overrungl/util/CStdlib.java index cb2eb9ce..1e780730 100644 --- a/modules/overrungl.core/src/main/java/overrungl/util/CStdio.java +++ b/modules/overrungl.core/src/main/java/overrungl/util/CStdlib.java @@ -33,7 +33,7 @@ * @author squid233 * @since 0.1.0 */ -public final class CStdio { +public final class CStdlib { /** * An unbounded address layout. */ @@ -57,7 +57,7 @@ private static MethodHandle downcall(String name, FunctionDescriptors function) return RuntimeHelper.downcallThrow(LOOKUP.find(name), function); } - private CStdio() { + private CStdlib() { throw new IllegalStateException("Do not construct instance"); } diff --git a/modules/overrungl.core/src/main/java/overrungl/util/CheckUtil.java b/modules/overrungl.core/src/main/java/overrungl/util/CheckUtil.java index ab0793c0..7b694e62 100644 --- a/modules/overrungl.core/src/main/java/overrungl/util/CheckUtil.java +++ b/modules/overrungl.core/src/main/java/overrungl/util/CheckUtil.java @@ -92,7 +92,7 @@ public static void checkNotNullptr(MemorySegment segment) throws IllegalStateExc * @see #checkNotNullptr(MemorySegment, String) */ public static void checkNotNullptr(MemorySegment segment, Supplier messageSupplier) throws IllegalStateException { - if (CStdio.isNullptr(segment)) throw new IllegalStateException(messageSupplier.get()); + if (CStdlib.isNullptr(segment)) throw new IllegalStateException(messageSupplier.get()); } /** @@ -105,6 +105,6 @@ public static void checkNotNullptr(MemorySegment segment, Supplier messa * @see #checkNotNullptr(MemorySegment, Supplier) */ public static void checkNotNullptr(MemorySegment segment, String message) throws IllegalStateException { - if (CStdio.isNullptr(segment)) throw new IllegalStateException(message); + if (CStdlib.isNullptr(segment)) throw new IllegalStateException(message); } } diff --git a/modules/overrungl.core/src/main/java/overrungl/util/DebugAllocator.java b/modules/overrungl.core/src/main/java/overrungl/util/DebugAllocator.java index b0d4fd96..7b0e05d8 100644 --- a/modules/overrungl.core/src/main/java/overrungl/util/DebugAllocator.java +++ b/modules/overrungl.core/src/main/java/overrungl/util/DebugAllocator.java @@ -74,7 +74,7 @@ private DebugAllocator() { } static long track(long address, long size) { - if (CStdio.isNullptr(address)) { + if (CStdlib.isNullptr(address)) { Thread t = Thread.currentThread(); THREADS.putIfAbsent(t.threadId(), t.getName()); @@ -122,7 +122,7 @@ private static void trackAbortPrint(Allocation allocation, String name, String a } static long untrack(long address) { - if (CStdio.isNullptr(address)) { + if (CStdlib.isNullptr(address)) { return 0L; } diff --git a/modules/overrungl.core/src/main/java/overrungl/util/MemoryStack.java b/modules/overrungl.core/src/main/java/overrungl/util/MemoryStack.java index d42d7c88..a6f25b7c 100644 --- a/modules/overrungl.core/src/main/java/overrungl/util/MemoryStack.java +++ b/modules/overrungl.core/src/main/java/overrungl/util/MemoryStack.java @@ -312,7 +312,7 @@ private void checkPointer(long pointer) { */ public MemorySegment malloc(long alignment, long size) { if (DEBUG) { - CStdio.checkAlignment(alignment); + CStdlib.checkAlignment(alignment); } // Align address to the specified alignment @@ -338,7 +338,7 @@ public MemorySegment malloc(long alignment, long size) { */ public MemorySegment ncalloc(long alignment, long num, long size) { if (DEBUG) { - CStdio.checkAlignment(alignment); + CStdlib.checkAlignment(alignment); } long bytes = num * size; @@ -559,8 +559,8 @@ public MemorySegment callocPointer() { @Override public MemorySegment allocate(long byteSize, long byteAlignment) throws IllegalArgumentException { - CStdio.checkByteSize(byteSize); - CStdio.checkAlignment(byteAlignment); + CStdlib.checkByteSize(byteSize); + CStdlib.checkAlignment(byteAlignment); return calloc(byteAlignment, byteSize); } diff --git a/modules/overrungl.core/src/main/java/overrungl/util/StackWalkUtil.java b/modules/overrungl.core/src/main/java/overrungl/util/StackWalkUtil.java index ddf7fdd9..667a7d98 100644 --- a/modules/overrungl.core/src/main/java/overrungl/util/StackWalkUtil.java +++ b/modules/overrungl.core/src/main/java/overrungl/util/StackWalkUtil.java @@ -109,7 +109,7 @@ static Object[] stackWalkGetTrace() { .skip(2) .dropWhile(f -> { String name = f.getClassName(); - return name.equals(CStdio.class.getName()) || name.equals(DebugAllocator.class.getName()); + return name.equals(CStdlib.class.getName()) || name.equals(DebugAllocator.class.getName()); }) .toArray(StackWalker.StackFrame[]::new) ); diff --git a/modules/overrungl.joml/src/main/java/overrungl/joml/Matrixn.java b/modules/overrungl.joml/src/main/java/overrungl/joml/Matrixn.java index 9d454021..34d4bb71 100644 --- a/modules/overrungl.joml/src/main/java/overrungl/joml/Matrixn.java +++ b/modules/overrungl.joml/src/main/java/overrungl/joml/Matrixn.java @@ -18,7 +18,7 @@ import org.joml.*; import overrungl.util.MemoryStack; -import overrungl.util.CStdio; +import overrungl.util.CStdlib; import java.lang.foreign.MemoryLayout; import java.lang.foreign.MemorySegment; @@ -197,7 +197,7 @@ public static MemorySegment allocate(SegmentAllocator allocator, Matrix4dc mat) * @return the memory address */ public static MemorySegment malloc(Matrix2fc mat) { - return put(mat, CStdio.malloc(MAT2F)); + return put(mat, CStdlib.malloc(MAT2F)); } /** @@ -207,7 +207,7 @@ public static MemorySegment malloc(Matrix2fc mat) { * @return the memory address */ public static MemorySegment malloc(Matrix2dc mat) { - return put(mat, CStdio.malloc(MAT2D)); + return put(mat, CStdlib.malloc(MAT2D)); } /** @@ -217,7 +217,7 @@ public static MemorySegment malloc(Matrix2dc mat) { * @return the memory address */ public static MemorySegment malloc(Matrix3x2fc mat) { - return put(mat, CStdio.malloc(MAT3X2F)); + return put(mat, CStdlib.malloc(MAT3X2F)); } /** @@ -227,7 +227,7 @@ public static MemorySegment malloc(Matrix3x2fc mat) { * @return the memory address */ public static MemorySegment malloc(Matrix3x2dc mat) { - return put(mat, CStdio.malloc(MAT3X2D)); + return put(mat, CStdlib.malloc(MAT3X2D)); } /** @@ -237,7 +237,7 @@ public static MemorySegment malloc(Matrix3x2dc mat) { * @return the memory address */ public static MemorySegment malloc(Matrix3fc mat) { - return put(mat, CStdio.malloc(MAT3F)); + return put(mat, CStdlib.malloc(MAT3F)); } /** @@ -247,7 +247,7 @@ public static MemorySegment malloc(Matrix3fc mat) { * @return the memory address */ public static MemorySegment malloc(Matrix3dc mat) { - return put(mat, CStdio.malloc(MAT3D)); + return put(mat, CStdlib.malloc(MAT3D)); } /** @@ -257,7 +257,7 @@ public static MemorySegment malloc(Matrix3dc mat) { * @return the memory address */ public static MemorySegment malloc(Matrix4x3fc mat) { - return put(mat, CStdio.malloc(MAT4X3F)); + return put(mat, CStdlib.malloc(MAT4X3F)); } /** @@ -267,7 +267,7 @@ public static MemorySegment malloc(Matrix4x3fc mat) { * @return the memory address */ public static MemorySegment malloc(Matrix4x3dc mat) { - return put(mat, CStdio.malloc(MAT4X3D)); + return put(mat, CStdlib.malloc(MAT4X3D)); } /** @@ -277,7 +277,7 @@ public static MemorySegment malloc(Matrix4x3dc mat) { * @return the memory address */ public static MemorySegment malloc(Matrix4fc mat) { - return put(mat, CStdio.malloc(MAT4F)); + return put(mat, CStdlib.malloc(MAT4F)); } /** @@ -287,7 +287,7 @@ public static MemorySegment malloc(Matrix4fc mat) { * @return the memory address */ public static MemorySegment malloc(Matrix4dc mat) { - return put(mat, CStdio.malloc(MAT4D)); + return put(mat, CStdlib.malloc(MAT4D)); } /** diff --git a/modules/overrungl.joml/src/main/java/overrungl/joml/Vectorn.java b/modules/overrungl.joml/src/main/java/overrungl/joml/Vectorn.java index f3806b91..53f597fe 100644 --- a/modules/overrungl.joml/src/main/java/overrungl/joml/Vectorn.java +++ b/modules/overrungl.joml/src/main/java/overrungl/joml/Vectorn.java @@ -18,7 +18,7 @@ import org.joml.*; import overrungl.util.MemoryStack; -import overrungl.util.CStdio; +import overrungl.util.CStdlib; import java.lang.foreign.MemoryLayout; import java.lang.foreign.MemorySegment; @@ -181,7 +181,7 @@ public static MemorySegment allocate(SegmentAllocator allocator, Vector4dc vec) * @return the memory address */ public static MemorySegment malloc(Vector2ic vec) { - return put(vec, CStdio.malloc(VEC2I)); + return put(vec, CStdlib.malloc(VEC2I)); } /** @@ -191,7 +191,7 @@ public static MemorySegment malloc(Vector2ic vec) { * @return the memory address */ public static MemorySegment malloc(Vector2fc vec) { - return put(vec, CStdio.malloc(VEC2F)); + return put(vec, CStdlib.malloc(VEC2F)); } /** @@ -201,7 +201,7 @@ public static MemorySegment malloc(Vector2fc vec) { * @return the memory address */ public static MemorySegment malloc(Vector2dc vec) { - return put(vec, CStdio.malloc(VEC2D)); + return put(vec, CStdlib.malloc(VEC2D)); } /** @@ -211,7 +211,7 @@ public static MemorySegment malloc(Vector2dc vec) { * @return the memory address */ public static MemorySegment malloc(Vector3ic vec) { - return put(vec, CStdio.malloc(VEC3I)); + return put(vec, CStdlib.malloc(VEC3I)); } /** @@ -221,7 +221,7 @@ public static MemorySegment malloc(Vector3ic vec) { * @return the memory address */ public static MemorySegment malloc(Vector3fc vec) { - return put(vec, CStdio.malloc(VEC3F)); + return put(vec, CStdlib.malloc(VEC3F)); } /** @@ -231,7 +231,7 @@ public static MemorySegment malloc(Vector3fc vec) { * @return the memory address */ public static MemorySegment malloc(Vector3dc vec) { - return put(vec, CStdio.malloc(VEC3D)); + return put(vec, CStdlib.malloc(VEC3D)); } /** @@ -241,7 +241,7 @@ public static MemorySegment malloc(Vector3dc vec) { * @return the memory address */ public static MemorySegment malloc(Vector4ic vec) { - return put(vec, CStdio.malloc(VEC4I)); + return put(vec, CStdlib.malloc(VEC4I)); } /** @@ -251,7 +251,7 @@ public static MemorySegment malloc(Vector4ic vec) { * @return the memory address */ public static MemorySegment malloc(Vector4fc vec) { - return put(vec, CStdio.malloc(VEC4F)); + return put(vec, CStdlib.malloc(VEC4F)); } /** @@ -261,7 +261,7 @@ public static MemorySegment malloc(Vector4fc vec) { * @return the memory address */ public static MemorySegment malloc(Vector4dc vec) { - return put(vec, CStdio.malloc(VEC4D)); + return put(vec, CStdlib.malloc(VEC4D)); } /** diff --git a/modules/samples/src/jmh/java/overrungl/demo/mem/MemoryUtilTest.java b/modules/samples/src/jmh/java/overrungl/demo/mem/MemoryUtilTest.java index 68a238c3..a6ea1303 100644 --- a/modules/samples/src/jmh/java/overrungl/demo/mem/MemoryUtilTest.java +++ b/modules/samples/src/jmh/java/overrungl/demo/mem/MemoryUtilTest.java @@ -25,7 +25,7 @@ import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.OptionsBuilder; -import overrungl.util.CStdio; +import overrungl.util.CStdlib; /** * Tests memory util @@ -66,10 +66,10 @@ public MemorySegment testArenaOutside() { public MemorySegment memoryUtilMalloc() { MemorySegment seg = null; try { - seg = CStdio.malloc(size); + seg = CStdlib.malloc(size); return seg; } finally { - CStdio.free(seg); + CStdlib.free(seg); } } @@ -77,10 +77,10 @@ public MemorySegment memoryUtilMalloc() { public MemorySegment memoryUtilCalloc() { MemorySegment seg = null; try { - seg = CStdio.calloc(1, size); + seg = CStdlib.calloc(1, size); return seg; } finally { - CStdio.free(seg); + CStdlib.free(seg); } }