Skip to content

Commit

Permalink
Merge pull request #17 from Over-Run/fix
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 authored Sep 1, 2024
2 parents e835671 + cc3d53d commit ff0c3af
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 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.30-jdk23")
implementation("io.github.over-run:marshal:0.1.0-alpha.31-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.30-jdk23
projVersion=0.1.0-alpha.31-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
20 changes: 13 additions & 7 deletions src/main/java/overrun/marshal/Downcall.java
Original file line number Diff line number Diff line change
Expand Up @@ -635,12 +635,16 @@ private static DowncallData generateData(

// function descriptor
final FunctionDescriptor get = descriptorMap.get(entrypoint);
final FunctionDescriptor descriptor = get != null ?
get :
DescriptorTransformer.getInstance().process(new DescriptorTransformer.Context(method,
methodData.descriptorSkipFirstParameter(),
methodData.parameters()));

final FunctionDescriptor descriptor;
if (method.getReturnType() == MethodHandle.class) {
descriptor = get;
} else {
descriptor = get != null ?
get :
DescriptorTransformer.getInstance().process(new DescriptorTransformer.Context(method,
methodData.descriptorSkipFirstParameter(),
methodData.parameters()));
}
descriptorMap1.put(entrypoint, descriptor);

final Optional<MemorySegment> optional = lookup.find(entrypoint);
Expand All @@ -664,7 +668,9 @@ private static DowncallData generateData(
throw new NoSuchElementException("Symbol not found: " + entrypoint + " (" + descriptor + "): " + methodData.signatureString());
}
}
map.putIfAbsent(entrypoint, handle);
if (!map.containsKey(entrypoint) || map.get(entrypoint) == null) {
map.put(entrypoint, handle);
}
}
return new DowncallData(Collections.unmodifiableMap(descriptorMap1),
Collections.unmodifiableMap(map),
Expand Down
8 changes: 7 additions & 1 deletion src/test/java/overrun/marshal/test/downcall/IDowncall.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,20 @@
* @since 0.1.0
*/
public interface IDowncall {
Map<String, FunctionDescriptor> MAP = Map.of("testDefault", FunctionDescriptor.of(ValueLayout.JAVA_INT));
Map<String, FunctionDescriptor> MAP = Map.of(
"testDefault", FunctionDescriptor.of(ValueLayout.JAVA_INT),
"testReturnInt", FunctionDescriptor.of(ValueLayout.JAVA_INT)
);

static IDowncall getInstance(boolean testDefaultNull) {
ProcessorTypes.registerStruct(Vector3.class, Vector3.OF);
ProcessorTypes.registerUpcall(SimpleUpcall.class, stub -> i -> SimpleUpcall.invoke(stub, i));
return Downcall.load(MethodHandles.lookup(), DowncallProvider.lookup(testDefaultNull), DowncallOption.descriptors(MAP));
}

@Entrypoint("testReturnInt")
MethodHandle mh_testReturnInt();

void test();

@Entrypoint("test")
Expand Down

0 comments on commit ff0c3af

Please sign in to comment.