Skip to content

Commit

Permalink
Added annotation Custom and FixedSize
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Dec 3, 2023
1 parent 30c6088 commit 5f859a5
Show file tree
Hide file tree
Showing 6 changed files with 382 additions and 253 deletions.
6 changes: 4 additions & 2 deletions demo/src/main/java/overrun/marshal/test/CMarshalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public interface CMarshalTest {

MemorySegment testWithArgAndReturnValue(MemorySegment segment);

MemorySegment testWithCustomBody();

@Native(scope = MarshalScope.PRIVATE)
int testWithPrivate(int i);

Expand All @@ -59,10 +61,10 @@ public interface CMarshalTest {
@Overload
void testWithArray(int[] arr);

void testWithRefArray(MemorySegment arr0, MemorySegment arr1, MemorySegment arr2, MemorySegment arr3, MemorySegment arr4);
void testWithRefArray(MemorySegment arr0, MemorySegment arr1, MemorySegment arr2, MemorySegment arr3, MemorySegment arr4, MemorySegment arr5);

@Overload
void testWithRefArray(int[] arr0, @Ref int[] arr1, @Ref(nullable = true) int[] arr2, boolean[] arr3, @Ref boolean[] arr4);
void testWithRefArray(int[] arr0, @Ref int[] arr1, @Ref(nullable = true) int[] arr2, boolean[] arr3, @Ref boolean[] arr4, int[] arr5);

void testWithString(MemorySegment str);

Expand Down
29 changes: 0 additions & 29 deletions demo/src/main/java/overrun/marshal/test/MarshalTestOverload.java

This file was deleted.

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ orgUrl=https://over-run.github.io/

# JDK Options
jdkVersion=22
jdkEnablePreview=true
jdkEnablePreview=false
# javadoc link of JDK early access build
# https://download.java.net/java/early_access/$jdkEarlyAccessDoc/docs/api/
# Uncomment it if you need to use EA build of JDK.
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/overrun/marshal/BoolHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
* @since 0.1.0
*/
public final class BoolHelper {
private BoolHelper() {
//no instance
}

public static MemorySegment of(SegmentAllocator allocator, boolean[] arr) {
final MemorySegment segment = allocator.allocate(ValueLayout.JAVA_BOOLEAN, arr.length);
for (int i = 0; i < arr.length; i++) {
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/overrun/marshal/Checks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* MIT License
*
* Copyright (c) 2023 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
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*/

package overrun.marshal;

import java.util.function.Supplier;

/**
* @author squid233
* @since 0.1.0
*/
public final class Checks {
public static final Entry<Boolean> CHECK_ARRAY_SIZE = new Entry<>(() -> true);

private Checks() {
//no instance
}

public static void checkArraySize(int expected, int got) {
if (CHECK_ARRAY_SIZE.get() && expected != got) {
throw new IllegalArgumentException("Expected array of size " + expected + ", got " + got);
}
}

/**
* @author squid233
* @since 0.1.0
*/
public static final class Entry<T> {
private final Supplier<T> supplier;
private T value;

public Entry(Supplier<T> supplier) {
this.supplier = supplier;
}

public T get() {
if (value == null) {
value = supplier.get();
}
return value;
}
}
}
Loading

0 comments on commit 5f859a5

Please sign in to comment.