Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8244959: Jextract's VarargsInvoker fails to link functions when passing integer types other than long #164

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -165,10 +165,20 @@ public class RuntimeHelper {
}
}

private Class<?> promote(Class<?> c) {
if (c == byte.class || c == char.class || c == short.class || c == int.class) {
return long.class;
} else if (c == float.class) {
return double.class;
} else {
return c;
}
}

private Class<?> normalize(Class<?> c) {
c = unboxIfNeeded(c);
if (c.isPrimitive()) {
return c;
return promote(c);
}
if (MemoryAddress.class.isAssignableFrom(c)) {
return MemoryAddress.class;
Expand All @@ -180,11 +190,9 @@ public class RuntimeHelper {
}

private MemoryLayout variadicLayout(Class<?> c) {
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.
if (c == long.class) {
return C_LONGLONG;
} else if (c == float.class || c == double.class) {
} else if (c == double.class) {
return C_DOUBLE;
} else if (MemoryAddress.class.isAssignableFrom(c)) {
return C_POINTER;
Expand Down
50 changes: 50 additions & 0 deletions test/jdk/tools/jextract/test8244959/Test8244959.java
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

import org.testng.annotations.Test;

import jdk.incubator.foreign.MemorySegment;

import static org.testng.Assert.assertEquals;
import static test.jextract.printf.Cstring.*;
import static test.jextract.printf.printf_h.*;

/*
* @test
* @library ..
* @modules jdk.incubator.jextract
* @run driver JtregJextract -t test.jextract.printf -- printf.h
* @run testng/othervm -Dforeign.restricted=permit Test8244959
*/
public class Test8244959 {
@Test
public void testsPrintf() {
try (MemorySegment s = MemorySegment.allocateNative(1024)) {
sprintf(s.baseAddress(),
toCString("%hhd %c %.2f %.2f %ld %ld %d %hd %d %d %lld %c").baseAddress(),
(byte) 1, 'b', -1.25f, 5.5d, -200l, Long.MAX_VALUE, (byte) -2, (short) 2, 3, (short) -4, 5l, 'a');
String str = toJavaString(s.baseAddress());
assertEquals(str, "1 b -1.25 5.50 -200 " + Long.MAX_VALUE + " -2 2 3 -4 5 a");
}
}
}
1 change: 1 addition & 0 deletions test/jdk/tools/jextract/test8244959/printf.h
@@ -0,0 +1 @@
int sprintf(char *buf, const char *fmt, ...);