Skip to content

Commit c9f062a

Browse files
Merge pull request #1504 from andrew-nowak/expand-max-fixedargs
Increase maximum supported fixed args on varargs calls from 3 to 255
2 parents 54fc662 + 767662a commit c9f062a

39 files changed

+61
-13
lines changed

CHANGES.md

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ Features
1111
Bug Fixes
1212
---------
1313
* [#1501](https://github.com/java-native-access/jna/pull/1501): `Library.OPTION_STRING_ENCODING` is ignore for string arguments function calls - [@matthiasblaesing](https://github.com/matthiasblaesing).
14+
* [#1504](https://github.com/java-native-access/jna/pull/1504): Increase maximum supported fixed args on varargs calls from 3 to 255 - [@andrew-nowak](https://github.com/andrew-nowak).
15+
16+
Important Changes
17+
-----------------
18+
* The interfaces between Java and native code have changed, so `libjnidispatch`
19+
must be rebuilt to be compatible with this release.
1420

1521
Release (5.13.0)
1622
================

build.xml

+10-4
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@
7575
<property name="jna.version" value="${jna.major}.${jna.minor}.${jna.revision}${version.suffix}"/>
7676
<property name="osgi.version" value="${jna.major}.${jna.minor}.${jna.revision}"/>
7777
<!-- jnidispatch library release version -->
78-
<property name="jni.major" value="6"/>
79-
<property name="jni.minor" value="1"/>
80-
<property name="jni.revision" value="6"/>
78+
<property name="jni.major" value="7"/>
79+
<property name="jni.minor" value="0"/>
80+
<property name="jni.revision" value="0"/>
8181
<property name="jni.build" value="0"/> <!--${build.number}-->
8282
<property name="jni.version" value="${jni.major}.${jni.minor}.${jni.revision}"/>
83-
<property name="jni.md5" value="147a998f0cbc89681a1ae6c0dd121629"/>
83+
<property name="jni.md5" value="5fb98531302accd485c534c452dd952a"/>
8484
<property name="spec.title" value="Java Native Access (JNA)"/>
8585
<property name="spec.vendor" value="${vendor}"/>
8686
<property name="spec.version" value="${jna.major}"/>
@@ -818,6 +818,12 @@ osname=macosx;processor=aarch64
818818
<arg value="JNIEXPORT"/>
819819
<fileset dir="${build.headers}" includes="*.h"/>
820820
</apply>
821+
<apply dir="${build.headers}" executable="${grep}" parallel="true"
822+
failonerror="${grep.required}" relative="true" output="${md5.file}"
823+
error="${md5.file}.error" append="true">
824+
<arg value="#define"/>
825+
<fileset dir="${build.headers}" includes="*.h"/>
826+
</apply>
821827
<!-- Clean up gcj javah output to match that of Sun's javah -->
822828
<fixcrlf file="${md5.file}" eol="unix"/>
823829
<replaceregexp match="^((.*\.h):JNIEXPORT[^(]+)( +\(.*)"

lib/native/aix-ppc.jar

-1 Bytes
Binary file not shown.

lib/native/aix-ppc64.jar

0 Bytes
Binary file not shown.

lib/native/android-aarch64.jar

-24 Bytes
Binary file not shown.

lib/native/android-arm.jar

-2 Bytes
Binary file not shown.

lib/native/android-armv7.jar

-2 Bytes
Binary file not shown.

lib/native/android-mips.jar

-3 Bytes
Binary file not shown.

lib/native/android-mips64.jar

-32 Bytes
Binary file not shown.

lib/native/android-x86-64.jar

-34 Bytes
Binary file not shown.

lib/native/android-x86.jar

-1 Bytes
Binary file not shown.

lib/native/darwin-aarch64.jar

-91 Bytes
Binary file not shown.

lib/native/darwin-x86-64.jar

-16 Bytes
Binary file not shown.

lib/native/freebsd-x86-64.jar

-1 Bytes
Binary file not shown.

lib/native/freebsd-x86.jar

0 Bytes
Binary file not shown.

lib/native/linux-aarch64.jar

-1 Bytes
Binary file not shown.

lib/native/linux-arm.jar

-2 Bytes
Binary file not shown.

lib/native/linux-armel.jar

-4 Bytes
Binary file not shown.

lib/native/linux-loongarch64.jar

17 Bytes
Binary file not shown.

lib/native/linux-mips64el.jar

0 Bytes
Binary file not shown.

lib/native/linux-ppc.jar

-4 Bytes
Binary file not shown.

lib/native/linux-ppc64le.jar

2 Bytes
Binary file not shown.

lib/native/linux-riscv64.jar

-1 Bytes
Binary file not shown.

lib/native/linux-s390x.jar

25 Bytes
Binary file not shown.

lib/native/linux-x86-64.jar

-12 Bytes
Binary file not shown.

lib/native/linux-x86.jar

14 Bytes
Binary file not shown.

lib/native/openbsd-x86-64.jar

-25 Bytes
Binary file not shown.

lib/native/openbsd-x86.jar

0 Bytes
Binary file not shown.

lib/native/sunos-sparc.jar

-7.51 KB
Binary file not shown.

lib/native/sunos-sparcv9.jar

1.12 KB
Binary file not shown.

lib/native/sunos-x86-64.jar

711 Bytes
Binary file not shown.

lib/native/sunos-x86.jar

4.45 KB
Binary file not shown.

lib/native/win32-aarch64.jar

1 Byte
Binary file not shown.

lib/native/win32-x86-64.jar

-3 Bytes
Binary file not shown.

lib/native/win32-x86.jar

-2 Bytes
Binary file not shown.

native/dispatch.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
#define DEFAULT_LOAD_OPTS (RTLD_LAZY|RTLD_GLOBAL)
7272
#define LOAD_LIBRARY(NAME,OPTS) dlopen(NAME, OPTS)
7373
static inline char * LOAD_ERROR() {
74-
char* message = dlerror();
74+
const char* message = dlerror();
7575
char* buf = (char*) malloc(strlen(message) + 1 /* null */);
7676
strcpy(buf, message);
7777
return buf;
@@ -144,9 +144,10 @@ extern "C" {
144144
PSTART(); memset(D,C,L); PEND(ENV); \
145145
} while(0)
146146

147-
#define MASK_CC com_sun_jna_Function_MASK_CC
148-
#define THROW_LAST_ERROR com_sun_jna_Function_THROW_LAST_ERROR
149-
#define USE_VARARGS com_sun_jna_Function_USE_VARARGS
147+
#define MASK_CC com_sun_jna_Function_MASK_CC
148+
#define THROW_LAST_ERROR com_sun_jna_Function_THROW_LAST_ERROR
149+
#define USE_VARARGS com_sun_jna_Function_USE_VARARGS
150+
#define USE_VARARGS_SHIFT com_sun_jna_Function_USE_VARARGS_SHIFT
150151

151152
/* Cached class, field and method IDs */
152153
static jclass classObject;
@@ -480,7 +481,7 @@ dispatch(JNIEnv *env, void* func, jint flags, jobjectArray args,
480481
callconv_t callconv = flags & MASK_CC;
481482
const char* volatile throw_type = NULL;
482483
const char* volatile throw_msg = NULL;
483-
int fixed_args = (flags & USE_VARARGS) >> 7;
484+
int fixed_args = (flags >> USE_VARARGS_SHIFT) & USE_VARARGS;
484485

485486
nargs = (*env)->GetArrayLength(env, args);
486487

native/testlib.c

+16-1
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,20 @@ addVarArgs(const char *fmt, ...) {
908908
return sum;
909909
}
910910

911+
EXPORT int32_t
912+
addSeveralFixedArgsAndVarArgs(int a, int b, int c, int d, int n_varargs, ...) {
913+
va_list ap;
914+
int i;
915+
int32_t sum = a + b + c + d;
916+
va_start(ap, n_varargs);
917+
918+
for (i = 0; i < n_varargs; i++) {
919+
sum += va_arg(ap, int32_t);
920+
}
921+
va_end(ap);
922+
return sum;
923+
}
924+
911925
EXPORT void
912926
modifyStructureVarArgs(const char* fmt, ...) {
913927
struct _ss {
@@ -1095,8 +1109,9 @@ EXPORT size_t copyString(char* input, char* output) {
10951109
* responsible to allocate a correctly sized buffer.
10961110
*/
10971111
EXPORT size_t copyStringArray(char** input, char* output) {
1112+
int i;
10981113
size_t len = 0;
1099-
for(int i = 0;; i++) {
1114+
for(i = 0;; i++) {
11001115
char* currInput = input[i];
11011116
if(currInput == NULL) {
11021117
break;

src/com/sun/jna/Function.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ public interface PostCallRead {
7676
/** Whether to throw an exception if last error is non-zero after call. */
7777
@java.lang.annotation.Native
7878
public static final int THROW_LAST_ERROR = 0x40;
79-
/** Mask for number of fixed args (1-3) for varargs calls. */
79+
/** Mask for number of fixed args (max 255) for varargs calls. */
8080
@java.lang.annotation.Native
81-
public static final int USE_VARARGS = 0x180;
81+
public static final int USE_VARARGS = 0xFF;
82+
/** Offset of USE_VARARGS in call flags */
83+
@java.lang.annotation.Native
84+
public static final int USE_VARARGS_SHIFT = 7;
8285

8386
static final Integer INTEGER_TRUE = Integer.valueOf(-1);
8487
static final Integer INTEGER_FALSE = Integer.valueOf(0);
@@ -410,7 +413,7 @@ Object invoke(Object[] args, Class<?> returnType, boolean allowObjects) {
410413
/* @see NativeLibrary#NativeLibrary(String,String,long,Map) implementation */
411414
Object invoke(Object[] args, Class<?> returnType, boolean allowObjects, int fixedArgs) {
412415
Object result = null;
413-
int callFlags = this.callFlags | ((fixedArgs & 0x3) << 7);
416+
int callFlags = this.callFlags | ((fixedArgs & USE_VARARGS) << USE_VARARGS_SHIFT);
414417
if (returnType == null || returnType==void.class || returnType==Void.class) {
415418
Native.invokeVoid(this, this.peer, callFlags, args);
416419
result = null;

test/com/sun/jna/VarArgsTest.java

+17
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ protected List<String> getFieldOrder() {
4141
}
4242
}
4343
public int addVarArgs(String fmt, Number... args);
44+
public int addSeveralFixedArgsAndVarArgs(int a, int b, int c, int d, int nArgs, Integer... args);
4445
public String returnStringVarArgs(String fmt, Object... args);
4546
public void modifyStructureVarArgs(String fmt, Object... args);
4647
public String returnStringVarArgs2(String fmt, String... args);
@@ -102,6 +103,22 @@ public void testStringVarArgsFull() {
102103
lib.returnStringVarArgs2("", "Test"));
103104
}
104105

106+
public void testSeveralFixedAndVarArgs() {
107+
int fixedarg1 = 1;
108+
int fixedarg2 = 2;
109+
int fixedarg3 = 3;
110+
int fixedarg4 = 4;
111+
int vararg1 = 100;
112+
int vararg2 = 200;
113+
114+
int expected = fixedarg1 + fixedarg2 + fixedarg3 + fixedarg4 + vararg1 + vararg2;
115+
int result = lib.addSeveralFixedArgsAndVarArgs(fixedarg1, fixedarg2, fixedarg3, fixedarg4,
116+
2, vararg1, vararg2);
117+
118+
assertEquals("varargs not passed correctly with multiple fixed args",
119+
expected, result);
120+
}
121+
105122
public void testAppendNullToVarargs() {
106123
Number[] args = new Number[] { Integer.valueOf(1) };
107124
assertEquals("No trailing NULL was appended to varargs list",

0 commit comments

Comments
 (0)