Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8252701

jextract should add helpers for accessing struct fields inside an array of structs

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Not an Issue
    • P4
    • None
    • repo-panama
    • tools

    Description

      It is common to allocate an array of struct, and then set various fields in all the elements of the struct array.

      Currently, jextract generates static getter/setters which work great when operating on a single struct - but fail to scale in the array case - example:

      MemorySegment add_inputs = s.allocateArray(TF_Output.$LAYOUT(), 2);
      TF_Output.oper$set(add_inputs, one);
      TF_Output.index$set(add_inputs, 0);
      MemorySegment snd = add_inputs.asSlice(TF_Output.$LAYOUT().byteSize());
      TF_Output.oper$set(snd, two);
      TF_Output.index$set(snd, 0);

      Since the getter/setters take only a memory segment, we have no other way to do the above, other than slicing the segment and get a segment for the second element.

      If jextract added also array accessors, the above could be greatly simplified as:

      TF_Output.oper$setArray(add_inputs, 0, one);
      TF_Output.index$setArray(add_inputs, 0, 0);
      TF_Output.oper$setArray(add_inputs, 1, two);
      TF_Output.index$setArray(add_inputs, 1, 0);

      Now, the new getter/setter also take an additional parameter - the index of the struct element to be set/get.

      Attachments

        Activity

          People

            sundar Sundararajan Athijegannathan
            mcimadamore Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: