--- old/src/jdk.incubator.jextract/share/classes/jdk/incubator/jextract/tool/HandleSourceFactory.java 2020-01-27 14:36:52.000000000 +0530 +++ new/src/jdk.incubator.jextract/share/classes/jdk/incubator/jextract/tool/HandleSourceFactory.java 2020-01-27 14:36:52.000000000 +0530 @@ -78,6 +78,24 @@ this.pkgName = pkgName; } + private static String getCLangConstantsHolder() { + String prefix = "jdk.incubator.foreign.MemoryLayouts."; + String arch = System.getProperty("os.arch"); + String os = System.getProperty("os.name"); + if (arch.equals("amd64") || arch.equals("x86_64")) { + if (os.startsWith("Windows")) { + return prefix + "WinABI"; + } else { + return prefix + "SysV"; + } + } else if (arch.equals("aarch64")) { + return prefix + "AArch64ABI"; + } + throw new UnsupportedOperationException("Unsupported os or arch: " + os + ", " + arch); + } + + private static final String C_LANG_CONSTANTS_HOLDER = getCLangConstantsHolder(); + public JavaFileObject[] generate(Declaration.Scoped decl) { builder.addPackagePrefix(pkgName); builder.classBegin(clsName); @@ -99,7 +117,7 @@ fileFromString(pkgName, clsName, src), fileFromString(pkgName,"RuntimeHelper", (pkgName.isEmpty()? "" : "package " + pkgName + ";\n") + Files.readAllLines(Paths.get(runtimeHelper.toURI())) - .stream().collect(Collectors.joining("\n"))) + .stream().collect(Collectors.joining("\n")).replace("${C_LANG}", C_LANG_CONSTANTS_HOLDER)) }; } catch (IOException ex) { throw new UncheckedIOException(ex); --- old/src/jdk.incubator.jextract/share/classes/jdk/incubator/jextract/tool/resources/RuntimeHelper.template 2020-01-27 14:36:55.000000000 +0530 +++ new/src/jdk.incubator.jextract/share/classes/jdk/incubator/jextract/tool/resources/RuntimeHelper.template 2020-01-27 14:36:54.000000000 +0530 @@ -16,7 +16,7 @@ import java.util.Arrays; import java.util.Optional; -import static jdk.incubator.foreign.MemoryLayouts.*; +import static ${C_LANG}.*; public class RuntimeHelper { @@ -195,7 +195,7 @@ if (c == char.class || c == byte.class || c == short.class || c == int.class || c == long.class) { //it is ok to approximate with a machine word here; numerics arguments in a prototype-less //function call are always rounded up to a register size anyway. - return C_LONG; + return C_LONGLONG; } else if (c == float.class || c == double.class) { return C_DOUBLE; } else if (MemoryAddress.class.isAssignableFrom(c)) {