[foreign-preview] Integrated: 8280460: MemorySegment::allocateNative should be tolerant of zero-sized allocation requests

Maurizio Cimadamore mcimadamore at openjdk.java.net
Tue Feb 22 14:45:11 UTC 2022


On Tue, 22 Feb 2022 13:05:57 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> 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.

This pull request has now been integrated.

Changeset: 8403a4df
Author:    Maurizio Cimadamore <mcimadamore at openjdk.org>
URL:       https://git.openjdk.java.net/panama-foreign/commit/8403a4dfdf3ef0c838edfea5ae36849e77465045
Stats:     37 lines in 6 files changed: 27 ins; 1 del; 9 mod

8280460: MemorySegment::allocateNative should be tolerant of zero-sized allocation requests

Reviewed-by: jvernee

-------------

PR: https://git.openjdk.java.net/panama-foreign/pull/650


More information about the panama-dev mailing list