Uploaded image for project: 'Code Tools'
  1. Code Tools
  2. CODETOOLS-7903878

jextract should derive struct field offsets from struct layouts

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • None
    • None
    • tools

      When extracting a C struct - e.g.

      ```
      struct Point {
         int x;
         int y;
      }
      ```

      Jextract emits hardwired offsets:

      ```
      class Point {
         ...
         private static final long x$OFFSET = 0;
         ...
         private static final long y$OFFSET = 4;
      }
      ```

      While this is good for startup, it makes it difficult to alter the layout of a struct after the fact - e.g. by adding platform-dependent padding -- which will make all the offsets incorrect.

      It would be better/more robust if the generated code looked like this:

      ```
      class Point {
         private static final long x$OFFSET = LAYOUT.byteOffset(groupLayout("x"));
      ...
         private static final long y$OFFSET = LAYOUT.byteOffset(groupLayout("y"));
      ...
      }
      ```

            nbenalla Nizar Benalla
            mcimadamore Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: