[foreign-preview] RFR: 8280460: MemorySegment::allocateNative should be tolerant of zero-sized allocation requests
    Maurizio Cimadamore 
    mcimadamore at openjdk.java.net
       
    Tue Feb 22 13:11:27 UTC 2022
    
    
  
This patch addresses the issues discussed here:
https://mail.openjdk.java.net/pipermail/panama-dev/2022-January/016071.html
And makes `MemorySegment::allocateNative` tolerand of zero-sized allocation requests. After evaluating a number of alternatives, I have decided to do what `ByteBuffer` also does, that is, always compute the size of the allocation as `max(size, 1L)`.
This means that we always perform some allocation - which works better with alignment constraints (e.g. the address you get back is aligned as per request; this is a corner case, but makes the API more consistent).
I've tweaked the javadoc to reflect that (and also added some javadoc to `SegmentAllocator` as well), and added a test for various kinds of native segments, created both safely and unsafely.
-------------
Commit messages:
 - Initial push
Changes: https://git.openjdk.java.net/panama-foreign/pull/650/files
 Webrev: https://webrevs.openjdk.java.net/?repo=panama-foreign&pr=650&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8280460
  Stats: 37 lines in 6 files changed: 27 ins; 1 del; 9 mod
  Patch: https://git.openjdk.java.net/panama-foreign/pull/650.diff
  Fetch: git fetch https://git.openjdk.java.net/panama-foreign pull/650/head:pull/650
PR: https://git.openjdk.java.net/panama-foreign/pull/650
    
    
More information about the panama-dev
mailing list