some thoughts on panama/jextract

Michael Zucchi notzed at gmail.com
Thu Jan 9 07:53:39 UTC 2020


On 9/1/20 12:40 pm, Michael Zucchi wrote:
>
> So what you call "not so rosy" to me is "fundamental and basic c". 
> That really should have first-class support and not be hidden by any 
> complexity that will make it harder to use and thus more prone to 
> mistakes.
>
> I don't really see the justification of having 
> MemoryAddress::ofLong(p, size) not being available, or the 
> MemoryAddress varhandle .get method not taking a length parameter (i 
> think better than being able to change the MemoryAddress size as this 
> keeps the size immutable).  Particularly if there's some 
> less-convenient work-around to get the same functionality anyway. 

Ok so the varhandle thing wont work it seems (sorry i didn't know the 
details until i looked), but the patch below isn't much to make the low 
level api significantly more practical from my perspective.  Obviously 
the code is there for a reason so not exposing it seems either an 
oversight or unjustified.

Again, this in the context that i haven't managed to work out the 
mechanism you referred to previously, it's just a timezone thing and i 
was bored today.

diff -r 6ff1ae33576a src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryAddress.java
--- a/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryAddress.java  Wed Jan 08 23:57:27 2020 +0000
+++ b/src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryAddress.java  Thu Jan 09 17:54:24 2020 +1030
@@ -138,4 +138,24 @@
      static MemoryAddress ofLong(long value) {
          return MemorySegmentImpl.NOTHING.baseAddress().add(value);
      }
+
+    /**
+     * Obtain a new memory address instance from a long address that can dereference the given range.
+     * @param value the long address.
+     * @param byteSize the memory size in bytes.
+     * @return the new memory address instance.
+     */
+    static MemoryAddress ofLong(long value, long byteSize) {
+        return MemoryAddressImpl.ofLongUnchecked(value, byteSize);
+    }
+
+    /**
+     * Apply a size to a native memory address.
+     * @param value a native memory address.
+     * @param byteSize the size in bytes.
+     * @return the new memory address instance.
+     */
+    static MemoryAddress ofAddress(MemoryAddress value, long byteSize) {
+        return MemoryAddressImpl.ofAddressUnchecked(value, byteSize);
+    }
  }
diff -r 6ff1ae33576a src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/MemoryAddressImpl.java
--- a/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/MemoryAddressImpl.java       Wed Jan 08 23:57:27 2020 +0000
+++ b/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/MemoryAddressImpl.java       Thu Jan 09 17:54:24 2020 +1030
@@ -146,4 +146,8 @@
      public static MemoryAddress ofLongUnchecked(long value, long byteSize) {
          return new MemoryAddressImpl((MemorySegmentImpl)Utils.makeNativeSegmentUnchecked(value, byteSize), 0);
      }
+
+    public static MemoryAddress ofAddressUnchecked(MemoryAddress base, long byteSize) {
+        return new MemoryAddressImpl((MemorySegmentImpl)Utils.makeNativeSegmentUnchecked(base, byteSize), 0);
+    }
  }



More information about the panama-dev mailing list