Skip to content

Commit

Permalink
fix alignment on osx/ppc
Browse files Browse the repository at this point in the history
  • Loading branch information
twall committed Jun 7, 2013
1 parent acf06d7 commit 2d7971a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/com/sun/jna/Native.java
Expand Up @@ -124,6 +124,7 @@ public void uncaughtException(Callback c, Throwable e) {
private static final int TYPE_WCHAR_T = 2;
private static final int TYPE_SIZE_T = 3;

static final int MAX_ALIGNMENT;
static final int MAX_PADDING;

static {
Expand Down Expand Up @@ -153,10 +154,12 @@ public void uncaughtException(Callback c, Throwable e) {
+ " - set jna.boot.library.path to include the path to the version of the " + LS
+ " jnidispatch library included with the JNA jar file you are using" + LS);
}
MAX_PADDING = Platform.isSPARC() || Platform.isWindows() || Platform.isARM()
|| Platform.isAIX() || Platform.isAndroid()
|| Platform.isPPC()
MAX_ALIGNMENT = Platform.isSPARC() || Platform.isWindows()
|| (Platform.isLinux() && (Platform.isARM() || Platform.isPPC()))
|| Platform.isAIX()
|| Platform.isAndroid()
? 8 : LONG_SIZE;
MAX_PADDING = (Platform.isMac() && Platform.isPPC()) ? 8 : MAX_ALIGNMENT;
}

/** Force a dispose when this class is GC'd. */
Expand Down
2 changes: 1 addition & 1 deletion src/com/sun/jna/Structure.java
Expand Up @@ -1301,7 +1301,7 @@ else if (actualAlignType == ALIGN_GNUC) {
// NOTE this is published ABI for 32-bit gcc/linux/x86, osx/x86,
// and osx/ppc. osx/ppc special-cases the first element
if (!isFirstElement || !(Platform.isMac() && Platform.isPPC())) {
alignment = Math.min(Native.MAX_PADDING, alignment);
alignment = Math.min(Native.MAX_ALIGNMENT, alignment);
}
if (!isFirstElement && Platform.isAIX() && (type == double.class || type == Double.class)) {
alignment = 4;
Expand Down
2 changes: 1 addition & 1 deletion test/com/sun/jna/StructureTest.java
Expand Up @@ -158,7 +158,7 @@ protected List getFieldOrder() {
}
Structure s = new TestStructure();
s.setAlignType(Structure.ALIGN_GNUC);
final int SIZE = Native.MAX_PADDING == 8 ? 32 : 28;
final int SIZE = Native.MAX_ALIGNMENT == 8 ? 32 : 28;
assertEquals("Wrong structure size", SIZE, s.size());
}

Expand Down

0 comments on commit 2d7971a

Please sign in to comment.