[foreign-jextract] [Rev 04] RFR: 8239128: Macro defines constant pointers can crash VM via jextract API

Maurizio Cimadamore mcimadamore at openjdk.java.net
Fri Feb 21 21:28:52 UTC 2020


On Fri, 21 Feb 2020 03:17:02 GMT, Henry Jen <henryjen at openjdk.org> wrote:

>> src/jdk.incubator.jextract/share/classes/jdk/incubator/jextract/Type.java line 426:
>> 
>>> 425:      */
>>> 426:     static Type.Function function(boolean varargs, Type returnType, Type... arguments) {
>>> 427:         return new TypeImpl.FunctionImpl(varargs, Stream.of(arguments).collect(Collectors.toList()), returnType);
>> 
>> This shouldn't be removed! It's the only way for a client to create mutually referring pointer types.
> 
> This change is what I meant at beginning to make this an implementation detail.
> 
> I have trouble to figure out how to use this API without an API providing something like the TypeReference, which I can implement as a Type that is a transparent delegate.
> 
> Imagine Type.declare(Declareation.struct(pos, "foo", Type.pointer(<what can I do to provide this struct type>)).

The problem is always with cases like:

struct A {
  struct B *b;
};

struct B {
  struct A *a;
};

If you have a supplier-accepting constructor, you can imagine an approach where you store the pointers in different fields, and then you set up the lambdas to retrieve the field values - that will work in such pathological cases.

-------------

PR: https://git.openjdk.java.net/panama-foreign/pull/21


More information about the panama-dev mailing list