Skip to content

Commit

Permalink
Apply old master changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauri Wiljami Ahonen committed Jan 22, 2025
1 parent 02bf7cc commit 2cbff3a
Show file tree
Hide file tree
Showing 13 changed files with 426 additions and 46 deletions.
10 changes: 10 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/win32/OaIdl.java
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,16 @@ public static class SAFEARRAY extends Structure implements Closeable {

public static class ByReference extends SAFEARRAY implements
Structure.ByReference {

public ByReference() {
super();
}

public ByReference(Pointer pointer) {
super(pointer);
this.read();
}

}

public USHORT cDims;
Expand Down
5 changes: 5 additions & 0 deletions pom-jna-jpms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<version>TEMPLATE</version>
<packaging>jar</packaging>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>

<name>Java Native Access</name>
<description>Java Native Access</description>
<url>https://github.com/java-native-access/jna</url>
Expand Down
6 changes: 6 additions & 0 deletions pom-jna-platform-jpms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
<description>Java Native Access Platform</description>
<url>https://github.com/java-native-access/jna</url>


<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>

<licenses>
<license>
<name>LGPL-2.1-or-later</name>
Expand Down
5 changes: 5 additions & 0 deletions pom-jna-platform.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
<description>Java Native Access Platform</description>
<url>https://github.com/java-native-access/jna</url>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>

<licenses>
<license>
<name>LGPL-2.1-or-later</name>
Expand Down
5 changes: 5 additions & 0 deletions pom-jna.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
<description>Java Native Access</description>
<url>https://github.com/java-native-access/jna</url>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>

<licenses>
<license>
<name>LGPL-2.1-or-later</name>
Expand Down
2 changes: 1 addition & 1 deletion src/com/sun/jna/ELFAnalyser.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public ELFSectionHeaders(boolean _64bit, boolean bigEndian, ByteBuffer headerDat
raf.getChannel().read(data, shoff);

for(int i = 0; i < shnum; i++) {
data.position(i * shentsize);
((Buffer)data).position(i * shentsize);
ByteBuffer header = data.slice();
header.order(data.order());
header.limit(shentsize);
Expand Down
41 changes: 41 additions & 0 deletions src/com/sun/jna/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
package com.sun.jna;

import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Map;
Expand Down Expand Up @@ -49,6 +50,8 @@
* @see Pointer
*/
public class Function extends Pointer {
public static TypeMapper globalFallbackMapper=null;

/** Any argument which implements this interface will have the
* {@link #read} method called immediately after function invocation.
*/
Expand Down Expand Up @@ -621,11 +624,49 @@ private Object convertArgument(Object[] args, int index,
return ss[0].getPointer();
}
} else if (argClass.isArray()){
if(globalFallbackMapper != null) {
Pointer[] pointers=new Pointer[Array.getLength(arg)];
for (int i=0; i < pointers.length; i++) {
Object item=Array.get(arg, i);
Class<?> type=item.getClass();
ToNativeConverter converter=globalFallbackMapper.getToNativeConverter(type);
if (converter != null) {
ToNativeContext context;
if (invokingMethod != null) {
context=new MethodParameterContext(this, args, index, invokingMethod);
} else {
context=new FunctionParameterContext(this, args, index);
}
item=converter.toNative(item, context);
pointers[i]=(Pointer) item;
}
else {
throw new IllegalArgumentException("Unsupported array element type: "
+ item.getClass());
}
}
return new PointerArray(pointers);
}
throw new IllegalArgumentException("Unsupported array argument type: "
+ argClass.getComponentType());
} else if (allowObjects) {
return arg;
} else if (!Native.isSupportedNativeType(arg.getClass())) {
if(globalFallbackMapper != null) {
Class<?> type=arg.getClass();
ToNativeConverter converter=globalFallbackMapper.getToNativeConverter(type);
if (converter != null) {
ToNativeContext context;
if (invokingMethod != null) {
context=new MethodParameterContext(this, args, index, invokingMethod);
} else {
context=new FunctionParameterContext(this, args, index);
}
arg=converter.toNative(arg, context);
return arg;
}
}

throw new IllegalArgumentException("Unsupported argument type "
+ arg.getClass().getName()
+ " at parameter " + index
Expand Down
18 changes: 16 additions & 2 deletions src/com/sun/jna/IntegerType.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,22 @@ public double doubleValue() {

@Override
public boolean equals(Object rhs) {
return rhs instanceof IntegerType
&& number.equals(((IntegerType)rhs).number);
if(rhs instanceof IntegerType)
return number.equals(((IntegerType)rhs).number);

if(rhs instanceof Integer)
return rhs.equals(number.intValue());
if(rhs instanceof Long)
return rhs.equals(number.longValue());
if(rhs instanceof Float)
return rhs.equals(number.floatValue());
if(rhs instanceof Double)
return rhs.equals(number.doubleValue());
if(rhs instanceof Byte)
return rhs.equals(number.byteValue());
if(rhs instanceof Short)
return rhs.equals(number.shortValue());
return false;
}

@Override
Expand Down
Loading

0 comments on commit 2cbff3a

Please sign in to comment.