[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
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Wed Mar 18 18:02:48 UTC 2020
On Wed, 18 Mar 2020 16:54:13 GMT, Athijegannathan Sundararajan <sundar at openjdk.org> wrote:
> Adding utility methods to ForeignUnsafe class.
Looks good - some minor comments on naming and test.
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?
test/jdk/java/foreign/StdLibTest.java line 455:
> 454: static MemorySegment makeNativeString(String value) {
> 455: return ForeignUnsafe.makeNativeString(value);
> 456: }
thx for updating these
test/jdk/java/foreign/Test8241148.java line 81:
> 80: assertEquals(pathStr.length(), len);
> 81: System.out.println("PATH = " + pathStr);
> 82: }
Should we compare it with System.getEnv?
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/System.html#getenv()
Perhaps we could strengthen the test that way by ensuring that the naive getenv returns same values for all the keys in
the System.getEnv Map.
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/55
More information about the panama-dev
mailing list