Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
8261511: jextract fails to handle name clashes between unrelated cons…
…tants Reviewed-by: mcimadamore
- Loading branch information
Showing
with
152 additions
and 2 deletions.
- +6 −1 src/jdk.incubator.jextract/share/classes/jdk/internal/jextract/impl/NestedClassBuilder.java
- +2 −1 src/jdk.incubator.jextract/share/classes/jdk/internal/jextract/impl/PrettyPrinter.java
- +55 −0 test/jdk/tools/jextract/test8261511/Test8261511.java
- +46 −0 test/jdk/tools/jextract/test8261511/libTest8261511.c
- +43 −0 test/jdk/tools/jextract/test8261511/test8261511.h
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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 test.jextract.test8261511.*; | ||
import static org.testng.Assert.assertEquals; | ||
import static test.jextract.test8261511.test8261511_h.*; | ||
|
||
/* | ||
* @test id=classes | ||
* @bug 8261511 | ||
* @summary jextract does not generate accessor for MemorySegement typed values | ||
* @library .. | ||
* @modules jdk.incubator.jextract | ||
* @run driver JtregJextract -l Test8261511 -t test.jextract.test8261511 -- test8261511.h | ||
* @run testng/othervm -Dforeign.restricted=permit Test8261511 | ||
*/ | ||
/* | ||
* @test id=sources | ||
* @bug 8261511 | ||
* @summary jextract does not generate accessor for MemorySegement typed values | ||
* @library .. | ||
* @modules jdk.incubator.jextract | ||
* @run driver JtregJextractSources -l Test8261511 -t test.jextract.test8261511 -- test8261511.h | ||
* @run testng/othervm -Dforeign.restricted=permit Test8261511 | ||
*/ | ||
public class Test8261511 { | ||
@Test | ||
public void test() { | ||
var funcPtr = Foo.sum$get(get_foo()); | ||
var sumIface = Foo.sum.ofAddressRestricted(funcPtr); | ||
assertEquals(sumIface.apply(15,20), 35); | ||
assertEquals(sum(1.2, 4.5), 5.7, 0.001); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2021, 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 "test8261511.h" | ||
#include <stdio.h> | ||
|
||
struct Foo theFoo; | ||
|
||
int foo_sum(int x, int y) { | ||
printf("foo_sum called\n"); | ||
return x + y; | ||
} | ||
|
||
EXPORT struct Foo get_foo() { | ||
theFoo.sum = foo_sum; | ||
return theFoo; | ||
} | ||
|
||
EXPORT double sum(double x, double y) { | ||
printf("sum called\n"); | ||
return x + y; | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif // __cplusplus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2021, 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 __cplusplus | ||
extern "C" { | ||
#endif // __cplusplus | ||
|
||
#ifdef _WIN64 | ||
#define EXPORT __declspec(dllexport) | ||
#else | ||
#define EXPORT | ||
#endif | ||
|
||
struct Foo { | ||
int (*sum)(int x, int y); | ||
}; | ||
|
||
EXPORT struct Foo get_foo(); | ||
EXPORT double sum(double x, double y); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif // __cplusplus |