[foreign-abi] RFR: 8241148: need a way to create MemorySegment with contents from java String and a way to read a C char* as java String

Athijegannathan Sundararajan sundar at openjdk.java.net
Thu Mar 19 04:07:56 UTC 2020


On Wed, 18 Mar 2020 19:11:41 GMT, Henry Jen <henryjen at openjdk.org> wrote:

>> src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/unsafe/ForeignUnsafe.java line 102:
>> 
>>> 101:
>>> 102:     private static MemorySegment makeNativeString(String str, int length) {
>>> 103:         MemoryLayout strLayout = MemoryLayout.ofSequence(length, C_CHAR);
>> 
>> name bikeshed: makeNativeString or toCString to make it more symmetric with the other method you added?
>
> We also need a function to make a byte array into native string.
> 
> Although I think makeNativeString(new String(byte[])) should be good enough, but I think
> makeNativeString(string.getBytes()) is more accurate on keeping byte array encoding.

Current feature is only about conversion to/from C and Java Strings. Array conversions - not just byte[] - could be
another feature.

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

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


More information about the panama-dev mailing list