[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

Henry Jen henryjen at openjdk.java.net
Wed Mar 18 19:13:59 UTC 2020


On Wed, 18 Mar 2020 17:56:03 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Adding utility methods to ForeignUnsafe class.
>
> 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.

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

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


More information about the panama-dev mailing list