Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this use finalParameterNames ? Note that finalParameterNames might contain additional parameters -- e.g. for the segment allocator.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that most of the time, they are the same.
finalParameterNames sometimes has the additional x0, x1 parameters but we can check for conflicts with those as well.

Copy link
Member Author

@nizarbenalla nizarbenalla Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed we can have conflicts for void foo_variadic(int x1, ...); too, I will update the PR to handle this

String holderName = nameConflict ? javaName + "$" : javaName;
String holderClass = newHolderClassName(holderName);
appendLines("""

private static class %1$s {
Expand Down
45 changes: 45 additions & 0 deletions test/jtreg/generator/nameConflict/TestNameConflict.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
36 changes: 36 additions & 0 deletions test/jtreg/generator/nameConflict/libnameconflict.c
Original file line number Diff line number Diff line change
@@ -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 ;
}
32 changes: 32 additions & 0 deletions test/jtreg/generator/nameConflict/nameconflict.h
Original file line number Diff line number Diff line change
@@ -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);