Skip to content

Commit

Permalink
Merge pull request #16628 from ChengJin01/ffi_test_remove_struct_padd…
Browse files Browse the repository at this point in the history
…ing_win_zlinux

[Test/FFI] Remove the struct padding on Windows & zLinux
  • Loading branch information
tajila authored Jan 31, 2023
2 parents df96e90 + 19d8dd3 commit e57d584
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 196 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2022 IBM Corp. and others
* Copyright (c) 2021, 2023 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -271,9 +271,10 @@ public void test_addBoolAndBoolsFromNestedStructWithXor_reverseOrderByUpcallMH()

@Test
public void test_addBoolAndBoolsFromStructWithNestedBoolArrayByUpcallMH() throws Throwable {
SequenceLayout intArray = MemoryLayout.sequenceLayout(2, C_CHAR);
GroupLayout structLayout = MemoryLayout.structLayout(intArray.withName("array_elem1"),
C_CHAR.withName("elem2"), MemoryLayout.paddingLayout(16));
SequenceLayout boolArray = MemoryLayout.sequenceLayout(2, C_CHAR);
GroupLayout structLayout = isStructPaddingNotRequired ? MemoryLayout.structLayout(boolArray.withName("array_elem1"),
C_CHAR.withName("elem2")): MemoryLayout.structLayout(boolArray.withName("array_elem1"),
C_CHAR.withName("elem2"), MemoryLayout.paddingLayout(8));
MethodType mt = MethodType.methodType(boolean.class, boolean.class, MemorySegment.class, MemoryAddress.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_CHAR, C_CHAR, structLayout, C_POINTER);
Addressable functionSymbol = nativeLibLookup.lookup("addBoolAndBoolsFromStructWithNestedBoolArrayByUpcallMH").get();
Expand All @@ -295,9 +296,10 @@ public void test_addBoolAndBoolsFromStructWithNestedBoolArrayByUpcallMH() throws

@Test
public void test_addBoolAndBoolsFromStructWithNestedBoolArray_reverseOrderByUpcallMH() throws Throwable {
SequenceLayout intArray = MemoryLayout.sequenceLayout(2, C_CHAR);
GroupLayout structLayout = MemoryLayout.structLayout(C_CHAR.withName("elem1"),
intArray.withName("array_elem2"), MemoryLayout.paddingLayout(16));
SequenceLayout boolArray = MemoryLayout.sequenceLayout(2, C_CHAR);
GroupLayout structLayout = isStructPaddingNotRequired ? MemoryLayout.structLayout(C_CHAR.withName("elem1"),
boolArray.withName("array_elem2")): MemoryLayout.structLayout(C_CHAR.withName("elem1"),
boolArray.withName("array_elem2"), MemoryLayout.paddingLayout(8));
MethodType mt = MethodType.methodType(boolean.class, boolean.class, MemorySegment.class, MemoryAddress.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_CHAR, C_CHAR, structLayout, C_POINTER);
Addressable functionSymbol = nativeLibLookup.lookup("addBoolAndBoolsFromStructWithNestedBoolArray_reverseOrderByUpcallMH").get();
Expand All @@ -319,8 +321,8 @@ public void test_addBoolAndBoolsFromStructWithNestedBoolArray_reverseOrderByUpca

@Test
public void test_addBoolAndBoolsFromStructWithNestedStructArrayByUpcallMH() throws Throwable {
GroupLayout intStruct = MemoryLayout.structLayout(C_CHAR.withName("elem1"), C_CHAR.withName("elem2"));
SequenceLayout structArray = MemoryLayout.sequenceLayout(2, intStruct);
GroupLayout boolStruct = MemoryLayout.structLayout(C_CHAR.withName("elem1"), C_CHAR.withName("elem2"));
SequenceLayout structArray = MemoryLayout.sequenceLayout(2, boolStruct);
GroupLayout structLayout = isStructPaddingNotRequired ? MemoryLayout.structLayout(structArray.withName("struct_array_elem1"),
C_CHAR.withName("elem2")) : MemoryLayout.structLayout(structArray.withName("struct_array_elem1"),
C_CHAR.withName("elem2"), MemoryLayout.paddingLayout(C_CHAR.bitSize() * 3));
Expand All @@ -347,8 +349,8 @@ public void test_addBoolAndBoolsFromStructWithNestedStructArrayByUpcallMH() thro

@Test
public void test_addBoolAndBoolsFromStructWithNestedStructArray_reverseOrderByUpcallMH() throws Throwable {
GroupLayout intStruct = MemoryLayout.structLayout(C_CHAR.withName("elem1"), C_CHAR.withName("elem2"));
SequenceLayout structArray = MemoryLayout.sequenceLayout(2, intStruct);
GroupLayout boolStruct = MemoryLayout.structLayout(C_CHAR.withName("elem1"), C_CHAR.withName("elem2"));
SequenceLayout structArray = MemoryLayout.sequenceLayout(2, boolStruct);
GroupLayout structLayout = isStructPaddingNotRequired ? MemoryLayout.structLayout(C_CHAR.withName("elem1"),
structArray.withName("struct_array_elem2")) : MemoryLayout.structLayout(C_CHAR.withName("elem1"),
structArray.withName("struct_array_elem2"), MemoryLayout.paddingLayout(C_CHAR.bitSize() * 3));
Expand Down
Loading

0 comments on commit e57d584

Please sign in to comment.