Win32 / OLE issues
Duncan Gittins
duncan.gittins at gmail.com
Mon Sep 27 15:45:53 UTC 2021
The jextract parameters which generate the broken Windows OLE API code I
outlined below is:
jextract -source -lole32 -t duncan.win.ole -d source\duncan.win\java
headers\Ole32.h
where headers\Ole32.h contains:
#include <objbase.h>
A temporary workaround for this jextract issue is to edit
FunctionalInterfaceBuilder.java / emitFunctionalFactoryForPointer() to
insert the (Addressable) casts for MemoryAddress parameters:
---
a/src/jdk.incubator.jextract/share/classes/jdk/internal/jextract/impl/FunctionalInterfaceBuilder.java
+++
b/src/jdk.incubator.jextract/share/classes/jdk/internal/jextract/impl/FunctionalInterfaceBuilder.java
@@ -123,7 +123,7 @@ public class FunctionalInterfaceBuilder extends
ClassSourceBuilder {
append(mhConstant.accessExpression() +
".invokeExact((Addressable)addr");
if (fiType.parameterCount() > 0) {
String params = IntStream.range(0, fiType.parameterCount())
- .mapToObj(i -> "x" + i)
+ .mapToObj(i ->
(fiType.parameterType(i).getName().endsWith(".MemoryAddress") ?
"(Addressable)":"")+"x" + i)
.collect(Collectors.joining(", "));
append(", " + params);
}
this fixes the ofAddress callbacks, for example see IPersistFileVtbl.java:
public interface Load {
....
static Load ofAddress(MemoryAddress addr) {
return (jdk.incubator.foreign.MemoryAddress x0,
jdk.incubator.foreign.MemoryAddress x1, int x2) -> {
try {
// WAS: return
(int)IPersistFileVtbl.Load$MH.invokeExact((Addressable)addr, x0, x1, x2);
return
(int)IPersistFileVtbl.Load$MH.invokeExact((Addressable)addr,
(Addressable)x0, (Addressable)x1, x2);
} catch (Throwable ex$) {
throw new AssertionError("should not reach here", ex$);
}
};
}
Kind regards
Duncan
On Fri, 24 Sept 2021 at 16:36, Duncan Gittins <duncan.gittins at gmail.com>
wrote:
> I've pulled latest panama-foreign which has the changes outlined in
>
> https://inside.java/2021/09/16/finalizing-the-foreign-apis/
>
> I've a few problems to resolve to match up, one is related to jextract
> which generates interfaces for Windows OLE APIs. The invokeExact params
> are missing some (Addressable) casts (I think?) eg this is IUnknown Release:
>
> public interface Release {
>
> int apply(jdk.incubator.foreign.MemoryAddress x0);
> static CLinker.UpcallStub allocate(Release fi) {
> return RuntimeHelper.upcallStub(Release.class, fi,
> IUnknownVtbl.Release$FUNC, "(Ljdk/incubator/foreign/MemoryAddress;)I");
> }
> static CLinker.UpcallStub allocate(Release fi, ResourceScope
> scope) {
> return RuntimeHelper.upcallStub(Release.class, fi,
> IUnknownVtbl.Release$FUNC, "(Ljdk/incubator/foreign/MemoryAddress;)I",
> scope);
> }
> static Release ofAddress(MemoryAddress addr) {
> return (jdk.incubator.foreign.MemoryAddress x0) -> {
> try {
> return
> (int)IUnknownVtbl.Release$MH.invokeExact((Addressable)addr, x0);
> } catch (Throwable ex$) {
> throw new AssertionError("should not reach here", ex$);
> }
> };
> }
> }
>
> Stack traces show
>
> Caused by: java.lang.invoke.WrongMethodTypeException: expected
> (Addressable,Addressable)int but found (Addressable,MemoryAddress)int
>
> Kind regards
>
> Duncan
>
>
>
More information about the panama-dev
mailing list