RFR: 7903239: ofAddress factory of function pointer type is wrong for struct returns

Maurizio Cimadamore mcimadamore at openjdk.org
Mon Aug 1 21:17:08 UTC 2022


On Fri, 29 Jul 2022 04:47:22 GMT, Marko <duke at openjdk.org> wrote:

> When generating the lambda inside the `ofAddress` factory, it is missing the `SegmentAllocator` needed when the function returns a struct. This is [implemented for regular functions](https://github.com/openjdk/jextract/blob/0582eaf1b4cdba95f0ee8c2480767433bb647d0d/src/main/java/org/openjdk/jextract/impl/HeaderFileBuilder.java#L122-L127), but not for function pointers.

test/testng/org/openjdk/jextract/test/toolprovider/Test7903239.java line 34:

> 32: public class Test7903239 extends JextractToolRunner {
> 33:     @Test
> 34:     public void testFunctionPointerReturningStruct() {

While this test in itself is good, I feel it's perhaps the wrong kind of test, in the sense that it only checks that jextract completes normally. Maybe a test that uses the jextract jtreg extension would be better? For inspiration look here:

https://github.com/openjdk/jextract/blob/master/test/jtreg/generator/funcPointerInvokers/TestFuncPointerInvokers.java

You can basically run jextract as part of a jtreg test action, as here:

https://github.com/openjdk/jextract/blob/master/test/jtreg/generator/funcPointerInvokers/TestFuncPointerInvokers.java#L39

Then you can actually compile (against the jextracted bits) and even run:

https://github.com/openjdk/jextract/blob/master/test/jtreg/generator/funcPointerInvokers/TestFuncPointerInvokers.java#L40

So you can check that the generated code actually behaves as expected at runtime.

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

PR: https://git.openjdk.org/jextract/pull/58


More information about the jextract-dev mailing list