Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AIX stability improvements #1445

Merged
merged 2 commits into from Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions contrib/platform/test/com/sun/jna/platform/unix/LibCTest.java
Expand Up @@ -24,6 +24,7 @@
package com.sun.jna.platform.unix;

import com.sun.jna.Native;
import com.sun.jna.Platform;
import java.sql.Date;
import java.util.Map;

Expand Down Expand Up @@ -64,6 +65,10 @@ public void testSetenv() {

@Test
public void testGetLoadAvg() {
if (Platform.isAIX()) {
System.out.println("Skip testGetLoadAvg - getloadavg is not implemented on AIX");
return;
}
double[] loadavg = new double[3];
int retval = LibC.INSTANCE.getloadavg(loadavg, 3);
assertEquals(retval, 3);
Expand All @@ -79,10 +84,10 @@ public void testGethostnameGetdomainname() {
LibC.INSTANCE.gethostname(buffer, buffer.length);
String hostname = Native.toString(buffer);
System.out.println("Hostname: " + hostname);
assertTrue(hostname.length() > 0);
assertNotNull(hostname);
LibC.INSTANCE.getdomainname(buffer, buffer.length);
String domainname = Native.toString(buffer);
System.out.println("Domainname: " + domainname);
assertTrue(domainname.length() > 0);
assertNotNull(domainname);
}
}
10 changes: 8 additions & 2 deletions src/com/sun/jna/NativeLibrary.java
Expand Up @@ -781,7 +781,8 @@ else if (Platform.isLinux() || Platform.isFreeBSD()) {
}
}
else if (Platform.isAIX()) { // can be libx.a, libx.a(shr.o), libx.so
if (libName.startsWith("lib")) {
if (isVersionedName(libName) || libName.endsWith(".so") || libName.startsWith("lib") || libName.endsWith(".a")) {
dbwiddis marked this conversation as resolved.
Show resolved Hide resolved
// A specific version was requested - use as is for search
return libName;
}
}
Expand All @@ -791,7 +792,12 @@ else if (Platform.isWindows()) {
}
}

return System.mapLibraryName(libName);
String mappedName = System.mapLibraryName(libName);
if(Platform.isAIX() && mappedName.endsWith(".so")) {
return mappedName.replaceAll(".so$", ".a");
} else {
return mappedName;
}
}

private static boolean isVersionedName(String name) {
Expand Down
5 changes: 5 additions & 0 deletions test/com/sun/jna/DirectTest.java
Expand Up @@ -137,6 +137,11 @@ protected Class<?> findClass(String name) throws ClassNotFoundException {
}

public void testRegisterMethods() throws Exception {
if (Platform.isAIX()) {
// https://stackoverflow.com/questions/8961441/java-system-loadlibrarym-fails-on-aix-6-1
System.out.println("Skip " + getName() + " - libm can't be dynamically linked on AIX");
return;
}
assertEquals("Math library call failed", 1., MathLibrary.cos(0), .01);
assertTrue("Library not registered",
Native.registered(MathLibrary.class));
Expand Down
3 changes: 3 additions & 0 deletions test/com/sun/jna/JNALoadTest.java
Expand Up @@ -79,6 +79,9 @@ protected void assertJarExists() {
protected void assertLibraryExists() {
String osPrefix = Platform.getNativeLibraryResourcePrefix();
String name = System.mapLibraryName("jnidispatch").replace(".dylib", ".jnilib");
if(Platform.isAIX()) {
name = name.replaceAll(".so$", ".a");
}
File lib = new File(CLASSES + "/com/sun/jna/" + osPrefix + "/" + name);
if (!lib.exists()) {
throw new Error("Expected JNA library at " + lib + " is missing");
Expand Down