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

ofAddress factory of function pointer type is wrong for struct returns

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • None
    • None
    • tools
    • None

    Description

      For the following:

          typedef struct { int x; } (*CB)(void);

      Jextract generates this:

          static CB ofAddress(MemoryAddress addr, MemorySession session) {
              MemorySegment symbol = MemorySegment.ofAddress(addr, 0, session);
              return () -> {
                  try {
                      return (java.lang.foreign.MemorySegment)constants$0.CB$MH.invokeExact((Addressable)symbol);
                  } catch (Throwable ex$) {
                      throw new AssertionError("should not reach here", ex$);
                  }
              };
          }

      Which is incorrect, since it doesn't take the leading SegmentAllocator paramert into account.

      Invoking apply will result in WrongMethodTypeException:

          CB.ofAddress(MemoryAddress.NULL, MemorySession.openImplicit()).apply();


      | Exception java.lang.AssertionError: should not reach here
      | at CB.lambda$ofAddress$0 (CB.java:22)
      | at (#5:1)
      | Caused by: java.lang.invoke.WrongMethodTypeException: expected (Addressable,SegmentAllocator)MemorySegment but found (Addressable)MemorySegment
      | at Invokers.newWrongMethodTypeException (Invokers.java:523)
      | at Invokers.checkExactType (Invokers.java:532)
      | at CB.lambda$ofAddress$0 (CB.java:20)
      | ...

      Attachments

        Issue Links

          Activity

            People

              jvernee Jorn Vernee
              jvernee Jorn Vernee
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: