Skip to content

Commit

Permalink
Fix NullPointerException
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Sep 1, 2024
1 parent ff0c3af commit 357e09f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Import as a Gradle dependency:

```groovy
dependencies {
implementation("io.github.over-run:marshal:0.1.0-alpha.31-jdk23")
implementation("io.github.over-run:marshal:0.1.0-alpha.32-jdk23")
}
```

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ projGroupId=io.github.over-run
projArtifactId=marshal
# The project name should only contain lowercase letters, numbers and hyphen.
projName=marshal
projVersion=0.1.0-alpha.31-jdk23
projVersion=0.1.0-alpha.32-jdk23
projDesc=Marshaler of native libraries
# Uncomment them if you want to publish to maven repository.
projUrl=https://github.com/Over-Run/marshal
Expand Down
42 changes: 22 additions & 20 deletions src/main/java/overrun/marshal/Downcall.java
Original file line number Diff line number Diff line change
Expand Up @@ -647,29 +647,31 @@ private static DowncallData generateData(
}
descriptorMap1.put(entrypoint, descriptor);

final Optional<MemorySegment> optional = lookup.find(entrypoint);
MethodHandle handle;
if (optional.isPresent()) {
// linker options
final Linker.Option[] options;
final Critical critical = method.getDeclaredAnnotation(Critical.class);
if (critical != null) {
options = critical.allowHeapAccess() ? OPTION_CRITICAL_TRUE : OPTION_CRITICAL_FALSE;
} else {
options = NO_OPTION;
}
if (descriptor != null) {
final Optional<MemorySegment> optional = lookup.find(entrypoint);
MethodHandle handle;
if (optional.isPresent()) {
// linker options
final Linker.Option[] options;
final Critical critical = method.getDeclaredAnnotation(Critical.class);
if (critical != null) {
options = critical.allowHeapAccess() ? OPTION_CRITICAL_TRUE : OPTION_CRITICAL_FALSE;
} else {
options = NO_OPTION;
}

handle = transform.apply(LINKER.downcallHandle(optional.get(), descriptor, options));
} else {
MethodHandle apply = transform.apply(null);
if (apply != null || method.isDefault()) {
handle = apply;
handle = transform.apply(LINKER.downcallHandle(optional.get(), descriptor, options));
} else {
throw new NoSuchElementException("Symbol not found: " + entrypoint + " (" + descriptor + "): " + methodData.signatureString());
MethodHandle apply = transform.apply(null);
if (apply != null || method.isDefault()) {
handle = apply;
} else {
throw new NoSuchElementException("Symbol not found: " + entrypoint + " (" + descriptor + "): " + methodData.signatureString());
}
}
if (!map.containsKey(entrypoint) || map.get(entrypoint) == null) {
map.putIfAbsent(entrypoint, handle);
}
}
if (!map.containsKey(entrypoint) || map.get(entrypoint) == null) {
map.put(entrypoint, handle);
}
}
return new DowncallData(Collections.unmodifiableMap(descriptorMap1),
Expand Down
5 changes: 1 addition & 4 deletions src/test/java/overrun/marshal/test/downcall/IDowncall.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@
* @since 0.1.0
*/
public interface IDowncall {
Map<String, FunctionDescriptor> MAP = Map.of(
"testDefault", FunctionDescriptor.of(ValueLayout.JAVA_INT),
"testReturnInt", FunctionDescriptor.of(ValueLayout.JAVA_INT)
);
Map<String, FunctionDescriptor> MAP = Map.of("testDefault", FunctionDescriptor.of(ValueLayout.JAVA_INT));

static IDowncall getInstance(boolean testDefaultNull) {
ProcessorTypes.registerStruct(Vector3.class, Vector3.OF);
Expand Down

0 comments on commit 357e09f

Please sign in to comment.