diff --git a/src/main/java/org/openjdk/jextract/impl/HeaderFileBuilder.java b/src/main/java/org/openjdk/jextract/impl/HeaderFileBuilder.java index 16159091..3ca2db3e 100644 --- a/src/main/java/org/openjdk/jextract/impl/HeaderFileBuilder.java +++ b/src/main/java/org/openjdk/jextract/impl/HeaderFileBuilder.java @@ -174,7 +174,10 @@ private void emitFunctionWrapper(String javaName, String nativeName, boolean nee String.format("\"%1$s\", %2$s", nativeName, paramList); incrAlign(); if (!isVarArg) { - String holderClass = newHolderClassName(javaName); + // function name may conflict with any of its parameter names. + boolean nameConflict = parameterNames.contains(javaName); + String holderName = nameConflict ? javaName + "$" : javaName; + String holderClass = newHolderClassName(holderName); appendLines(""" private static class %1$s { diff --git a/test/jtreg/generator/nameConflict/TestNameConflict.java b/test/jtreg/generator/nameConflict/TestNameConflict.java new file mode 100644 index 00000000..f308ff61 --- /dev/null +++ b/test/jtreg/generator/nameConflict/TestNameConflict.java @@ -0,0 +1,45 @@ +/* Copyright (c) 2025, 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 static org.testng.Assert.assertEquals; +import static test.jextract.nameconflict.nameconflict_h.*; + +/* + * @test + * @bug 7904089 + * @library /lib + * @build testlib.TestUtils + * @run main/othervm JtregJextract -l nameconflict --use-system-load-library -t test.jextract.nameconflict nameconflict.h + * @build TestNameConflict + * @run testng/othervm --enable-native-access=ALL-UNNAMED TestNameConflict + */ +public class TestNameConflict { + + @Test + public void testNameConflict() { + foo(5d); + assertEquals(add(9,1), 10); + assertEquals(increment(10), 11); + } +} diff --git a/test/jtreg/generator/nameConflict/libnameconflict.c b/test/jtreg/generator/nameConflict/libnameconflict.c new file mode 100644 index 00000000..cb89f632 --- /dev/null +++ b/test/jtreg/generator/nameConflict/libnameconflict.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025, 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. + */ + +#include "nameconflict.h" + +EXPORT int increment(int increment){ + return increment + 1; +} + +EXPORT int add(int add2, int add){ + return add + add2; +} + +EXPORT void foo(double foo){ + return ; +} diff --git a/test/jtreg/generator/nameConflict/nameconflict.h b/test/jtreg/generator/nameConflict/nameconflict.h new file mode 100644 index 00000000..87249b53 --- /dev/null +++ b/test/jtreg/generator/nameConflict/nameconflict.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025, 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. + */ + +#ifdef _WIN64 +#define EXPORT __declspec(dllexport) +#else +#define EXPORT +#endif + +EXPORT int increment(int increment); +EXPORT int add(int add2, int add); +EXPORT void foo(double foo);