RFR: 8311630: [s390] Implementation of Foreign Function & Memory API (Preview) [v3]
Jorn Vernee
jvernee at openjdk.org
Fri Jul 21 17:24:45 UTC 2023
On Sat, 8 Jul 2023 10:48:15 GMT, sid8606 <duke at openjdk.org> wrote:
>> Implementation of "Foreign Function & Memory API" for s390x (Big Endian).
>
> sid8606 has updated the pull request incrementally with one additional commit since the last revision:
>
> Address suggestions from Jorn Vernee
FWIW, I found a bug in StdLibTest while working on something else: the format string for `LONG` is `%d` while it should be `%lld`. This might mess up some printf implementation I think.
This might fix your issue as well:
diff --git a/test/jdk/java/foreign/StdLibTest.java b/test/jdk/java/foreign/StdLibTest.java
index 0732f60525d9..c9ce60bfc09b 100644
--- a/test/jdk/java/foreign/StdLibTest.java
+++ b/test/jdk/java/foreign/StdLibTest.java
@@ -120,16 +119,20 @@ void test_rand() throws Throwable {
@Test(dataProvider = "printfArgs")
void test_printf(List<PrintfArg> args) throws Throwable {
- String formatArgs = args.stream()
- .map(a -> a.format)
+ String javaFormatArgs = args.stream()
+ .map(a -> a.javaFormat)
+ .collect(Collectors.joining(","));
+ String nativeFormatArgs = args.stream()
+ .map(a -> a.nativeFormat)
.collect(Collectors.joining(","));
- String formatString = "hello(" + formatArgs + ")\n";
+ String javaFormatString = "hello(" + javaFormatArgs + ")\n";
+ String nativeFormatString = "hello(" + nativeFormatArgs + ")\n";
- String expected = String.format(formatString, args.stream()
+ String expected = String.format(javaFormatString, args.stream()
.map(a -> a.javaValue).toArray());
- int found = stdLibHelper.printf(formatString, args);
+ int found = stdLibHelper.printf(nativeFormatString, args);
assertEquals(found, expected.length());
}
@@ -377,21 +385,24 @@ public static Object[][] printfArgs() {
}
enum PrintfArg {
- INT(int.class, C_INT, "%d", arena -> 42, 42),
- LONG(long.class, C_LONG_LONG, "%d", arena -> 84L, 84L),
- DOUBLE(double.class, C_DOUBLE, "%.4f", arena -> 1.2345d, 1.2345d),
- STRING(MemorySegment.class, C_POINTER, "%s", arena -> arena.allocateFrom("str"), "str");
+ INT(int.class, C_INT, "%d", "%d", arena -> 42, 42),
+ LONG(long.class, C_LONG_LONG, "%lld", "%d", arena -> 84L, 84L),
+ DOUBLE(double.class, C_DOUBLE, "%.4f", "%.4f", arena -> 1.2345d, 1.2345d),
+ STRING(MemorySegment.class, C_POINTER, "%s", "%s", arena -> arena.allocateFrom("str"), "str");
final Class<?> carrier;
final ValueLayout layout;
- final String format;
+ final String nativeFormat;
+ final String javaFormat;
final Function<Arena, ?> nativeValueFactory;
final Object javaValue;
- <Z, L extends ValueLayout> PrintfArg(Class<?> carrier, L layout, String format, Function<Arena, Z> nativeValueFactory, Object javaValue) {
+ <Z, L extends ValueLayout> PrintfArg(Class<?> carrier, L layout, String nativeFormat, String javaFormat,
+ Function<Arena, Z> nativeValueFactory, Object javaValue) {
this.carrier = carrier;
this.layout = layout;
- this.format = format;
+ this.nativeFormat = nativeFormat;
+ this.javaFormat = javaFormat;
this.nativeValueFactory = nativeValueFactory;
this.javaValue = javaValue;
}
-------------
PR Comment: https://git.openjdk.org/jdk/pull/14801#issuecomment-1646020324
More information about the core-libs-dev
mailing list