Skip to content

Commit 1cc982b

Browse files
committed
7903715: Jextract generates duplicate allocator parameters
Reviewed-by: jvernee
1 parent cde2665 commit 1cc982b

File tree

3 files changed

+71
-4
lines changed

3 files changed

+71
-4
lines changed

src/main/java/org/openjdk/jextract/impl/HeaderFileBuilder.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ public void addConstant(Declaration.Constant constantTree) {
116116
private static List<String> finalizeParameterNames(List<String> parameterNames, boolean needsAllocator, boolean isVarArg) {
117117
List<String> result = new ArrayList<>();
118118

119-
if (needsAllocator) {
120-
result.add("allocator");
121-
}
122-
123119
int i = 0;
124120
for (; i < parameterNames.size(); i++) {
125121
String name = parameterNames.get(i);
@@ -133,6 +129,14 @@ private static List<String> finalizeParameterNames(List<String> parameterNames,
133129
result.add("x" + i);
134130
}
135131

132+
if (needsAllocator) {
133+
String allocatorName = "allocator";
134+
while (result.contains(allocatorName)) {
135+
allocatorName = "_" + allocatorName;
136+
}
137+
result.add(0, allocatorName);
138+
}
139+
136140
return result;
137141
}
138142

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @library /lib
27+
* @build testlib.TestUtils
28+
* @run main/othervm JtregJextract -t test.jextract.mangle.params parameter_names.h
29+
*/
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
#ifdef _WIN64
25+
#define EXPORT __declspec(dllexport)
26+
#else
27+
#define EXPORT
28+
#endif
29+
30+
struct A { int x; };
31+
32+
EXPORT struct A foo1(int a);
33+
EXPORT struct A foo2(int allocator);
34+
EXPORT struct A foo3(int allocator, int _allocator);

0 commit comments

Comments
 (0)