Integrated: 7903616: Bad formatting of layout string for structs with nested anon structs/unions

Maurizio Cimadamore mcimadamore at openjdk.org
Wed Jan 10 14:19:50 UTC 2024


On Thu, 21 Dec 2023 16:06:42 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> This PR fixes an indentation issue when generating a struct layout string.
> 
> Example:
> 
> 
> struct Foo {
>     struct {
>         int x;
>         union {
>             int y;
>             int z;
>         };
>     };
> }; 
> 
> 
> For this, jextract generates:
> 
> 
>     private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
>         MemoryLayout.structLayout(
>         foo_h.C_INT.withName("x"),
>         MemoryLayout.unionLayout(
>         foo_h.C_INT.withName("y"),
>         foo_h.C_INT.withName("z")
>     ).withName("$anon$7:9")
>     ).withName("$anon$5:5")
>     ).withName("Foo");
> 
> 
> With the fix in this PR, the generated string is:
> 
> 
>     private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
>         MemoryLayout.structLayout(
>             foo_h.C_INT.withName("x"),
>             MemoryLayout.unionLayout(
>                 foo_h.C_INT.withName("y"),
>                 foo_h.C_INT.withName("z")
>             ).withName("$anon$7:9")
>         ).withName("$anon$5:5")
>     ).withName("Foo");
> 
> 
> The fix is to correctly track required indentation when descending into a scoped declaration.

This pull request has now been integrated.

Changeset: fbe46472
Author:    Maurizio Cimadamore <mcimadamore at openjdk.org>
URL:       https://git.openjdk.org/jextract/commit/fbe4647274549739034dcedab178177ed420e5c9
Stats:     18 lines in 3 files changed: 1 ins; 0 del; 17 mod

7903616: Bad formatting of layout string for structs with nested anon structs/unions

Reviewed-by: jvernee

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

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


More information about the jextract-dev mailing list