21
21
* questions.
22
22
*/
23
23
24
+ /*
25
+ * ===========================================================================
26
+ * (c) Copyright IBM Corp. 2024, 2024 All Rights Reserved
27
+ * ===========================================================================
28
+ */
29
+
24
30
/*
25
31
* @test
26
32
* @run testng/othervm --enable-native-access=ALL-UNNAMED StdLibTest
29
35
import java .lang .invoke .MethodHandle ;
30
36
import java .lang .invoke .MethodHandles ;
31
37
import java .lang .invoke .MethodType ;
38
+ import java .nio .charset .Charset ;
32
39
import java .time .Instant ;
33
40
import java .time .LocalDateTime ;
34
41
import java .time .ZoneOffset ;
@@ -53,6 +60,8 @@ public class StdLibTest extends NativeTestHelper {
53
60
54
61
final static Linker abi = Linker .nativeLinker ();
55
62
63
+ final static Charset charSetNative = Charset .forName (System .getProperty ("native.encoding" ));
64
+
56
65
private StdLibHelper stdLibHelper = new StdLibHelper ();
57
66
58
67
@ Test (dataProvider = "stringPairs" )
@@ -306,7 +315,7 @@ int rand() throws Throwable {
306
315
307
316
int printf (String format , List <PrintfArg > args ) throws Throwable {
308
317
try (var arena = Arena .ofConfined ()) {
309
- MemorySegment formatStr = arena .allocateFrom (format );
318
+ MemorySegment formatStr = arena .allocateFrom (format , charSetNative );
310
319
return (int )specializedPrintf (args ).invokeExact (formatStr ,
311
320
args .stream ().map (a -> a .nativeValue (arena )).toArray ());
312
321
}
@@ -387,7 +396,7 @@ enum PrintfArg {
387
396
INT (int .class , C_INT , "%d" , "%d" , arena -> 42 , 42 ),
388
397
LONG (long .class , C_LONG_LONG , "%lld" , "%d" , arena -> 84L , 84L ),
389
398
DOUBLE (double .class , C_DOUBLE , "%.4f" , "%.4f" , arena -> 1.2345d , 1.2345d ),
390
- STRING (MemorySegment .class , C_POINTER , "%s" , "%s" , arena -> arena .allocateFrom ("str" ), "str" );
399
+ STRING (MemorySegment .class , C_POINTER , "%s" , "%s" , arena -> arena .allocateFrom ("str" , charSetNative ), "str" );
391
400
392
401
final Class <?> carrier ;
393
402
final ValueLayout layout ;
0 commit comments