Skip to content
Permalink
Browse files
8261511: jextract fails to handle name clashes between unrelated cons…
…tants

Reviewed-by: mcimadamore
  • Loading branch information
sundararajana committed Mar 10, 2021
1 parent 7532916 commit a11bb7d2606543d43ddbda835ca7c4020b5abc8c
@@ -86,6 +86,11 @@ public List<JavaFileObject> toFiles() {

@Override
protected void emitWithConstantClass(String javaName, Consumer<ConstantBuilder> constantConsumer) {
enclosing.emitWithConstantClass(javaName, constantConsumer);
if (this instanceof ConstantBuilder cb) {
// use this class to emit constants
constantConsumer.accept(cb);
} else {
enclosing.emitWithConstantClass(javaName, constantConsumer);
}
}
}
@@ -36,6 +36,7 @@

public class PrettyPrinter implements Declaration.Visitor<Void, Void> {

private static String SPACES = " ".repeat(92);
int align = 0;

void incr() {
@@ -47,7 +48,7 @@ void decr() {
}

void indent() {
builder.append(" ".substring(0, align));
builder.append(SPACES.substring(0, align));
}

StringBuilder builder = new StringBuilder();
@@ -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);
}
}
@@ -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
@@ -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

0 comments on commit a11bb7d

Please sign in to comment.