Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
8254983: jextract fails to hande layout paths nested structs/union
Reviewed-by: jvernee, sundar
- Loading branch information
Showing
with
130 additions
and 16 deletions.
- +3 −2 src/jdk.incubator.jextract/share/classes/jdk/internal/jextract/impl/JavaSourceBuilder.java
- +1 −1 src/jdk.incubator.jextract/share/classes/jdk/internal/jextract/impl/NestedClassBuilder.java
- +3 −5 src/jdk.incubator.jextract/share/classes/jdk/internal/jextract/impl/OutputFactory.java
- +24 −8 src/jdk.incubator.jextract/share/classes/jdk/internal/jextract/impl/StructBuilder.java
- +64 −0 test/jdk/tools/jextract/test8254983/LibTest8254983Test.java
- +35 −0 test/jdk/tools/jextract/test8254983/test8254983.h
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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 jdk.incubator.foreign.GroupLayout; | ||
import jdk.incubator.foreign.MemorySegment; | ||
import org.testng.annotations.Test; | ||
import static org.testng.Assert.assertEquals; | ||
import static test.jextract.test8254983.test8254983_h.*; | ||
|
||
/* | ||
* @test id=classes | ||
* @library .. | ||
* @modules jdk.incubator.jextract | ||
* @bug 8254983 | ||
* @summary jextract fails to hande layout paths nested structs/union | ||
* @run driver JtregJextract -t test.jextract.test8254983 -- test8254983.h | ||
* @run testng/othervm -Dforeign.restricted=permit LibTest8254983Test | ||
*/ | ||
/* | ||
* @test id=sources | ||
* @library .. | ||
* @modules jdk.incubator.jextract | ||
* @bug 8254983 | ||
* @summary jextract fails to hande layout paths nested structs/union | ||
* @run driver JtregJextractSources -t test.jextract.test8254983 -- test8254983.h | ||
* @run testng/othervm -Dforeign.restricted=permit LibTest8254983Test | ||
*/ | ||
public class LibTest8254983Test { | ||
@Test | ||
public void testOuterStruct() { | ||
assertEquals(((GroupLayout)Foo._struct.$LAYOUT()).memberLayouts().size(), 1); | ||
MemorySegment str = Foo._struct.allocate(); | ||
Foo._struct.x$set(str, 42); | ||
assertEquals(Foo._struct.x$get(str), 42); | ||
} | ||
|
||
@Test | ||
public void testInnerStruct() { | ||
assertEquals(((GroupLayout)Foo._union._struct.$LAYOUT()).memberLayouts().size(), 2); | ||
MemorySegment str = Foo._union._struct.allocate(); | ||
Foo._union._struct.x$set(str, 42); | ||
assertEquals(Foo._union._struct.x$get(str), 42); | ||
} | ||
} |
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
struct Foo { | ||
struct { | ||
int x; | ||
} _struct; | ||
|
||
union { | ||
struct { | ||
int u; | ||
int x; | ||
} _struct; | ||
} _union; | ||
}; |