From 87606ccdcc6395848704aa4ad2363d2a987ed586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Mon, 26 Sep 2016 21:26:44 +0200 Subject: [PATCH 1/2] Make warnings treated as errors for dispatch.c and protect.c This follows an advise given by David Keller, to replace a unittest to ensure correct version of strerror_r is used. Quote: I'm afraid the strerror(EBADF) can also produce Bad file number depending on the libc (e.g. Android libc vs Glibc). If I were you, I'd remove the strerror_r() unit test as the new code will trigger a warning if the wrong strerror_r() is picked (invalid conversion from int to char*: warning: initialization makes pointer from integer without a cast) and treat warnings as errors with -Werror. --- native/Makefile | 8 +- native/dispatch.c | 86 ++++++++++---------- native/dispatch.h | 3 + native/testlib.c | 2 +- test/com/sun/jna/unix/XsiComplianceTest.java | 42 ---------- 5 files changed, 52 insertions(+), 89 deletions(-) delete mode 100644 test/com/sun/jna/unix/XsiComplianceTest.java diff --git a/native/Makefile b/native/Makefile index 1cda1ece47..8c41035acf 100644 --- a/native/Makefile +++ b/native/Makefile @@ -84,6 +84,8 @@ JNISFX=$(LIBSFX) CC=gcc LD=$(CC) LIBS= +# CC_OPTS only applied to objects build for jnidispatch, not for libffi +LOC_CC_OPTS=-Wno-unknown-warning-option -Werror -Wno-clobbered # Default to Sun recommendations for JNI compilation COPT=-O2 -fno-omit-frame-pointer -fno-strict-aliasing CASM=-S @@ -402,13 +404,13 @@ endif $(BUILD)/%.o : %.c dispatch.h protect.h $(FFI_LIB) @mkdir -p $(BUILD) ifneq ($(SDKROOT),) - $(CC) -arch $(ARCH) $(CFLAGS) -c $< -o $@.$(ARCH) + $(CC) $(LOC_CC_OPTS) -arch $(ARCH) $(CFLAGS) -c $< -o $@.$(ARCH) for arch in $(ALT_ARCHS); do \ - $(CC) -arch $$arch -I$(BUILD)/libffi.$$arch/include $(CFLAGS) -c $< -o $@.$$arch; \ + $(CC) $(LOC_CC_OPTS) -arch $$arch -I$(BUILD)/libffi.$$arch/include $(CFLAGS) -c $< -o $@.$$arch; \ done lipo -create -output $@ $@.* else - $(CC) $(CFLAGS) -c $< $(COUT) + $(CC) $(CFLAGS) $(LOC_CC_OPTS) -c $< $(COUT) endif all: $(LIBRARY) $(TESTLIB) $(TESTLIB2) $(TESTLIB_JAR) $(TESTLIB_PATH) $(TESTLIB_TRUNC) diff --git a/native/dispatch.c b/native/dispatch.c index 141faf7e54..549f057c57 100644 --- a/native/dispatch.c +++ b/native/dispatch.c @@ -2032,7 +2032,7 @@ closure_handler(ffi_cif* cif, void* resp, void** argp, void *cdata) */ JNIEXPORT jlong JNICALL Java_com_sun_jna_Native_invokePointer (JNIEnv *env, jclass UNUSED(cls), - jobject function, jlong fp, + jobject UNUSED(function), jlong fp, jint callconv, jobjectArray arr) { jvalue result; @@ -2048,7 +2048,7 @@ Java_com_sun_jna_Native_invokePointer (JNIEnv *env, jclass UNUSED(cls), */ JNIEXPORT jobject JNICALL Java_com_sun_jna_Native_invokeObject(JNIEnv *env, jclass UNUSED(cls), - jobject function, jlong fp, + jobject UNUSED(function), jlong fp, jint callconv, jobjectArray arr) { jvalue result; @@ -2064,7 +2064,7 @@ JNICALL Java_com_sun_jna_Native_invokeObject(JNIEnv *env, jclass UNUSED(cls), */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_invokeStructure(JNIEnv *env, jclass UNUSED(cls), - jobject function, jlong fp, + jobject UNUSED(function), jlong fp, jint callconv, jobjectArray arr, jlong memory, jlong type_info) { @@ -2084,7 +2084,7 @@ Java_com_sun_jna_Native_invokeStructure(JNIEnv *env, jclass UNUSED(cls), */ JNIEXPORT jdouble JNICALL Java_com_sun_jna_Native_invokeDouble(JNIEnv *env, jclass UNUSED(cls), - jobject function, jlong fp, + jobject UNUSED(function), jlong fp, jint callconv, jobjectArray arr) { jvalue result; @@ -2099,7 +2099,7 @@ Java_com_sun_jna_Native_invokeDouble(JNIEnv *env, jclass UNUSED(cls), */ JNIEXPORT jfloat JNICALL Java_com_sun_jna_Native_invokeFloat(JNIEnv *env, jclass UNUSED(cls), - jobject function, jlong fp, + jobject UNUSED(function), jlong fp, jint callconv, jobjectArray arr) { jvalue result; @@ -2114,7 +2114,7 @@ Java_com_sun_jna_Native_invokeFloat(JNIEnv *env, jclass UNUSED(cls), */ JNIEXPORT jint JNICALL Java_com_sun_jna_Native_invokeInt(JNIEnv *env, jclass UNUSED(cls), - jobject function, jlong fp, jint callconv, + jobject UNUSED(function), jlong fp, jint callconv, jobjectArray arr) { ffi_arg result; @@ -2129,7 +2129,7 @@ Java_com_sun_jna_Native_invokeInt(JNIEnv *env, jclass UNUSED(cls), */ JNIEXPORT jlong JNICALL Java_com_sun_jna_Native_invokeLong(JNIEnv *env, jclass UNUSED(cls), - jobject function, jlong fp, jint callconv, + jobject UNUSED(function), jlong fp, jint callconv, jobjectArray arr) { jvalue result; @@ -2144,7 +2144,7 @@ Java_com_sun_jna_Native_invokeLong(JNIEnv *env, jclass UNUSED(cls), */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_invokeVoid(JNIEnv *env, jclass UNUSED(cls), - jobject function, jlong fp, jint callconv, + jobject UNUSED(function), jlong fp, jint callconv, jobjectArray arr) { jvalue result; @@ -2262,7 +2262,7 @@ Java_com_sun_jna_Native_findSymbol(JNIEnv *env, jclass UNUSED(cls), * Signature: (Lcom/sun/jna/Pointer;JJ[BII)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3BII -(JNIEnv *env, jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jbyteArray arr, jint off, jint n) +(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jbyteArray arr, jint off, jint n) { PSTART(); (*env)->GetByteArrayRegion(env, arr, off, n, L2A(addr + offset)); @@ -2275,7 +2275,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3 * Signature: (Lcom/sun/jna/Pointer;JJ[CII)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3CII -(JNIEnv *env, jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jcharArray arr, jint off, jint n) +(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jcharArray arr, jint off, jint n) { getChars(env, (wchar_t*)L2A(addr + offset), arr, off, n); } @@ -2286,7 +2286,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3 * Signature: (Lcom/sun/jna/Pointer;JJ[DII)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3DII -(JNIEnv *env, jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jdoubleArray arr, jint off, jint n) +(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jdoubleArray arr, jint off, jint n) { PSTART(); (*env)->GetDoubleArrayRegion(env, arr, off, n, (jdouble*)L2A(addr + offset)); @@ -2299,7 +2299,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3 * Signature: (Lcom/sun/jna/Pointer;JJ[FII)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3FII -(JNIEnv *env, jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jfloatArray arr, jint off, jint n) +(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jfloatArray arr, jint off, jint n) { PSTART(); (*env)->GetFloatArrayRegion(env, arr, off, n, (jfloat*)L2A(addr + offset)); @@ -2312,7 +2312,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3 * Signature: (Lcom/sun/jna/Pointer;JJ[III)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3III -(JNIEnv *env, jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jintArray arr, jint off, jint n) +(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jintArray arr, jint off, jint n) { PSTART(); (*env)->GetIntArrayRegion(env, arr, off, n, (jint*)L2A(addr + offset)); @@ -2325,7 +2325,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3 * Signature: (Lcom/sun/jna/Pointer;JJ[JII)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3JII -(JNIEnv *env, jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jlongArray arr, jint off, jint n) +(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jlongArray arr, jint off, jint n) { PSTART(); (*env)->GetLongArrayRegion(env, arr, off, n, (jlong*)L2A(addr + offset)); @@ -2338,7 +2338,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3 * Signature: (Lcom/sun/jna/Pointer;JJ[SII)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3SII -(JNIEnv *env, jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jshortArray arr, jint off, jint n) +(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jshortArray arr, jint off, jint n) { PSTART(); (*env)->GetShortArrayRegion(env, arr, off, n, (jshort*)L2A(addr + offset)); @@ -2351,7 +2351,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_write__Lcom_sun_jna_Pointer_2JJ_3 * Signature: (Lcom/sun/jna/Pointer;JJB)J */ JNIEXPORT jlong JNICALL Java_com_sun_jna_Native_indexOf -(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jbyte value) +(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jbyte value) { jbyte *peer = (jbyte *)L2A(addr + offset); volatile jlong i = 0; @@ -2373,7 +2373,7 @@ JNIEXPORT jlong JNICALL Java_com_sun_jna_Native_indexOf * Signature: (Lcom/sun/jna/Pointer;JJ[BII)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3BII -(JNIEnv *env, jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jbyteArray arr, jint off, jint n) +(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jbyteArray arr, jint off, jint n) { PSTART(); (*env)->SetByteArrayRegion(env, arr, off, n, L2A(addr + offset)); @@ -2386,7 +2386,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3B * Signature: (Lcom/sun/jna/Pointer;JJ[CII)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3CII - (JNIEnv *env, jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jcharArray arr, jint off, jint n) + (JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jcharArray arr, jint off, jint n) { setChars(env, (wchar_t*)L2A(addr + offset), arr, off, n); } @@ -2397,7 +2397,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3C * Signature: (Lcom/sun/jna/Pointer;JJ[DII)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3DII - (JNIEnv *env, jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jdoubleArray arr, jint off, jint n) + (JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jdoubleArray arr, jint off, jint n) { PSTART(); (*env)->SetDoubleArrayRegion(env, arr, off, n, (jdouble*)L2A(addr + offset)); @@ -2410,7 +2410,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3D * Signature: (Lcom/sun/jna/Pointer;JJ[FII)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3FII - (JNIEnv *env, jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jfloatArray arr, jint off, jint n) + (JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jfloatArray arr, jint off, jint n) { PSTART(); (*env)->SetFloatArrayRegion(env, arr, off, n, (jfloat*)L2A(addr + offset)); @@ -2423,7 +2423,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3F * Signature: (Lcom/sun/jna/Pointer;JJ[III)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3III - (JNIEnv *env, jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jintArray arr, jint off, jint n) + (JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jintArray arr, jint off, jint n) { PSTART(); (*env)->SetIntArrayRegion(env, arr, off, n, (jint*)L2A(addr + offset)); @@ -2436,7 +2436,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3I * Signature: (Lcom/sun/jna/Pointer;JJ[JII)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3JII - (JNIEnv *env, jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jlongArray arr, jint off, jint n) + (JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jlongArray arr, jint off, jint n) { PSTART(); (*env)->SetLongArrayRegion(env, arr, off, n, (jlong*)L2A(addr + offset)); @@ -2449,7 +2449,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3J * Signature: (Lcom/sun/jna/Pointer;JJ[SII)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3SII - (JNIEnv *env, jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jshortArray arr, jint off, jint n) + (JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jshortArray arr, jint off, jint n) { PSTART(); (*env)->SetShortArrayRegion(env, arr, off, n, (jshort*)L2A(addr + offset)); @@ -2462,7 +2462,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_read__Lcom_sun_jna_Pointer_2JJ_3S * Signature: (Lcom/sun/jna/Pointer;JJ)B */ JNIEXPORT jbyte JNICALL Java_com_sun_jna_Native_getByte -(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset) +(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset) { jbyte res = 0; MEMCPY(env, &res, L2A(addr + offset), sizeof(res)); @@ -2475,7 +2475,7 @@ JNIEXPORT jbyte JNICALL Java_com_sun_jna_Native_getByte * Signature: (Lcom/sun/jna/Pointer;JJ)C */ JNIEXPORT jchar JNICALL Java_com_sun_jna_Native_getChar -(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset) +(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset) { wchar_t res = 0; MEMCPY(env, &res, L2A(addr + offset), sizeof(res)); @@ -2516,7 +2516,7 @@ JNIEXPORT jobject JNICALL Java_com_sun_jna_Native_getDirectByteBuffer__JJ * Signature: (Lcom/sun/jna/Pointer;JJJ)Ljava/nio/ByteBuffer; */ JNIEXPORT jobject JNICALL Java_com_sun_jna_Native_getDirectByteBuffer__Lcom_sun_jna_Pointer_2JJJ - (JNIEnv *env, jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jlong length) + (JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jlong length) { #ifdef NO_NIO_BUFFERS return NULL; @@ -2531,7 +2531,7 @@ JNIEXPORT jobject JNICALL Java_com_sun_jna_Native_getDirectByteBuffer__Lcom_sun_ * Signature: (Lcom/sun/jna/Pointer;JJ)D */ JNIEXPORT jdouble JNICALL Java_com_sun_jna_Native_getDouble -(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset) +(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset) { jdouble res = 0; MEMCPY(env, &res, L2A(addr + offset), sizeof(res)); @@ -2544,7 +2544,7 @@ JNIEXPORT jdouble JNICALL Java_com_sun_jna_Native_getDouble * Signature: (Lcom/sun/jna/Pointer;JJ)F */ JNIEXPORT jfloat JNICALL Java_com_sun_jna_Native_getFloat -(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset) +(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset) { jfloat res = 0; MEMCPY(env, &res, L2A(addr + offset), sizeof(res)); @@ -2557,7 +2557,7 @@ JNIEXPORT jfloat JNICALL Java_com_sun_jna_Native_getFloat * Signature: (Lcom/sun/jna/Pointer;JJ)I */ JNIEXPORT jint JNICALL Java_com_sun_jna_Native_getInt -(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset) +(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset) { jint res = 0; MEMCPY(env, &res, L2A(addr + offset), sizeof(res)); @@ -2570,7 +2570,7 @@ JNIEXPORT jint JNICALL Java_com_sun_jna_Native_getInt * Signature: (Lcom/sun/jna/Pointer;JJ)J */ JNIEXPORT jlong JNICALL Java_com_sun_jna_Native_getLong -(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset) +(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset) { jlong res = 0; MEMCPY(env, &res, L2A(addr + offset), sizeof(res)); @@ -2583,7 +2583,7 @@ JNIEXPORT jlong JNICALL Java_com_sun_jna_Native_getLong * Signature: (Lcom/sun/jna/Pointer;JJ)S */ JNIEXPORT jshort JNICALL Java_com_sun_jna_Native_getShort -(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset) +(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset) { jshort res = 0; MEMCPY(env, &res, L2A(addr + offset), sizeof(res)); @@ -2596,7 +2596,7 @@ JNIEXPORT jshort JNICALL Java_com_sun_jna_Native_getShort * Signature: (Lcom/sun/jna/Pointer;JJ)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_com_sun_jna_Native_getWideString -(JNIEnv *env, jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset) +(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset) { return newJavaString(env, L2A(addr + offset), NULL); } @@ -2607,7 +2607,7 @@ JNIEXPORT jstring JNICALL Java_com_sun_jna_Native_getWideString * Signature: (Lcom/sun/jna/Pointer;JJ)[B */ JNIEXPORT jbyteArray JNICALL Java_com_sun_jna_Native_getStringBytes -(JNIEnv *env, jclass UNUSED(cls), jobject pointer, jlong baseaddr, jlong offset) +(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong baseaddr, jlong offset) { volatile jbyteArray bytes = 0; PSTART(); @@ -2632,7 +2632,7 @@ JNIEXPORT jbyteArray JNICALL Java_com_sun_jna_Native_getStringBytes * Signature: (Lcom/sun/jna/Pointer;JJJB)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_setMemory -(JNIEnv *UNUSED_ENV(env), jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jlong count, jbyte value) +(JNIEnv *UNUSED_ENV(env), jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jlong count, jbyte value) { MEMSET(env, L2A(addr + offset), (int)value, (size_t)count); } @@ -2643,7 +2643,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_setMemory * Signature: (Lcom/sun/jna/Pointer;JJB)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_setByte -(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jbyte value) +(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jbyte value) { MEMCPY(env, L2A(addr + offset), &value, sizeof(value)); } @@ -2654,7 +2654,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_setByte * Signature: (Lcom/sun/jna/Pointer;JJC)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_setChar -(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jchar value) +(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jchar value) { wchar_t ch = value; MEMCPY(env, L2A(addr + offset), &ch, sizeof(ch)); @@ -2666,7 +2666,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_setChar * Signature: (Lcom/sun/jna/Pointer;JJJ)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_setPointer -(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jlong value) +(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jlong value) { void *ptr = L2A(value); MEMCPY(env, L2A(addr + offset), &ptr, sizeof(void *)); @@ -2678,7 +2678,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_setPointer * Signature: (Lcom/sun/jna/Pointer;JJD)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_setDouble -(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jdouble value) +(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jdouble value) { MEMCPY(env, L2A(addr + offset), &value, sizeof(value)); } @@ -2689,7 +2689,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_setDouble * Signature: (Lcom/sun/jna/Pointer;JJF)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_setFloat -(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jfloat value) +(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jfloat value) { MEMCPY(env, L2A(addr + offset), &value, sizeof(value)); } @@ -2700,7 +2700,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_setFloat * Signature: (Lcom/sun/jna/Pointer;JJI)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_setInt -(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jint value) +(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jint value) { MEMCPY(env, L2A(addr + offset), &value, sizeof(value)); } @@ -2711,7 +2711,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_setInt * Signature: (Lcom/sun/jna/Pointer;JJJ)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_setLong -(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jlong value) +(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jlong value) { MEMCPY(env, L2A(addr + offset), &value, sizeof(value)); } @@ -2722,7 +2722,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_setLong * Signature: (Lcom/sun/jna/Pointer;JJS)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_setShort -(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jshort value) +(JNIEnv * UNUSED_ENV(env), jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jshort value) { MEMCPY(env, L2A(addr + offset), &value, sizeof(value)); } @@ -2733,7 +2733,7 @@ JNIEXPORT void JNICALL Java_com_sun_jna_Native_setShort * Signature: (Lcom/sun/jna/Pointer;JJLjava/lang/String;)V */ JNIEXPORT void JNICALL Java_com_sun_jna_Native_setWideString -(JNIEnv *env, jclass UNUSED(cls), jobject pointer, jlong addr, jlong offset, jstring value) +(JNIEnv *env, jclass UNUSED(cls), jobject UNUSED(pointer), jlong addr, jlong offset, jstring value) { int len = (*env)->GetStringLength(env, value); const void* volatile str; diff --git a/native/dispatch.h b/native/dispatch.h index 4e144cf083..5fdfa9c4c0 100644 --- a/native/dispatch.h +++ b/native/dispatch.h @@ -30,6 +30,7 @@ #pragma warning( disable : 4204 ) /* structure initializer */ #pragma warning( disable : 4710 ) /* swprintf not inlined */ #pragma warning( disable : 4201 ) /* nameless struct/union (jni_md.h) */ +#pragma warning( disable : 4996 ) /* deprecated functions (strdup) */ #else #include #endif /* _MSC_VER */ @@ -152,6 +153,8 @@ typedef struct _callback { #define L2A(X) ((void *)(unsigned long)(X)) #define A2L(X) ((jlong)(unsigned long)(X)) #endif +#else +#include #endif /* Convenience macros */ diff --git a/native/testlib.c b/native/testlib.c index 6aafac259a..5e640c0092 100644 --- a/native/testlib.c +++ b/native/testlib.c @@ -876,7 +876,7 @@ addVarArgs(const char *fmt, ...) { break; case 'f': // float (promoted to ‘double’ when passed through ‘...’) case 'g': // double - sum += va_arg(ap, double); + sum += (int) va_arg(ap, double); break; default: break; diff --git a/test/com/sun/jna/unix/XsiComplianceTest.java b/test/com/sun/jna/unix/XsiComplianceTest.java deleted file mode 100644 index 342e2f21f2..0000000000 --- a/test/com/sun/jna/unix/XsiComplianceTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.sun.jna.unix; - -import com.sun.jna.LastErrorException; -import com.sun.jna.Library; -import com.sun.jna.Memory; -import com.sun.jna.Native; -import com.sun.jna.Pointer; -import junit.framework.TestCase; - -public final class XsiComplianceTest extends TestCase { - - public static void main(String[] args) { - junit.textui.TestRunner.run(XsiComplianceTest.class); - } - - /** - * Regression test for https://github.com/java-native-access/jna/issues/392 - * - * Depending on the toolchain on GCC/GLIBC the wrong definition of - * strerror_r was included. - * - * This leads to broken messages. - */ - public void testErrorReporting() { - boolean exceptionWasCaught = false; - try { - INSTANCE.read(Integer.MAX_VALUE, new Memory(1024), 1024); - } catch (LastErrorException ex) { - exceptionWasCaught = true; - assertEquals("[9] Bad file descriptor", ex.getMessage()); - assertEquals(9, ex.getErrorCode()); - } - assertEquals(true, exceptionWasCaught); - } - - static POSIX INSTANCE = (POSIX) Native.loadLibrary(POSIX.class); - - interface POSIX extends Library { - - long read(int fildes, Pointer buf, long nbyte) throws LastErrorException; - } -} \ No newline at end of file From c07db9a243fcb8198a9eaed13d8c4875483e9642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Wed, 5 Oct 2016 20:24:35 +0200 Subject: [PATCH 2/2] Document warning configuration and fix strdup (#define based on compiler) --- native/Makefile | 8 ++++++++ native/dispatch.c | 2 +- native/dispatch.h | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/native/Makefile b/native/Makefile index 8c41035acf..0e7da41c37 100644 --- a/native/Makefile +++ b/native/Makefile @@ -85,6 +85,14 @@ CC=gcc LD=$(CC) LIBS= # CC_OPTS only applied to objects build for jnidispatch, not for libffi +# -Wno-unknown-warning-option +# => Suppress warning for unknown warnings +# -Werror => Treat warnings as errors +# -Wno-clobbered => Silence GCC warning about clobbered automatic variables. +# The "longjmp" case only happens in protect.h in the logic +# that implements "protected" mode. In that case an exception +# is raised and the value of the potentially clobbered +# variables is ignored. LOC_CC_OPTS=-Wno-unknown-warning-option -Werror -Wno-clobbered # Default to Sun recommendations for JNI compilation COPT=-O2 -fno-omit-frame-pointer -fno-strict-aliasing diff --git a/native/dispatch.c b/native/dispatch.c index 549f057c57..f87edaba62 100644 --- a/native/dispatch.c +++ b/native/dispatch.c @@ -1116,7 +1116,7 @@ initializeThread(callback* cb, AttachOptions* args) { if (args->name != NULL) { // Make a copy, since the Java Structure which owns this native memory // will go out of scope and be available for GC - args->name = strdup(args->name); + args->name = STRDUP(args->name); } } } diff --git a/native/dispatch.h b/native/dispatch.h index 5fdfa9c4c0..2ce7485e8f 100644 --- a/native/dispatch.h +++ b/native/dispatch.h @@ -30,7 +30,6 @@ #pragma warning( disable : 4204 ) /* structure initializer */ #pragma warning( disable : 4710 ) /* swprintf not inlined */ #pragma warning( disable : 4201 ) /* nameless struct/union (jni_md.h) */ -#pragma warning( disable : 4996 ) /* deprecated functions (strdup) */ #else #include #endif /* _MSC_VER */ @@ -145,7 +144,7 @@ typedef struct _callback { #if defined(_MSC_VER) #include "snprintf.h" -#define strdup _strdup +#define STRDUP _strdup #if defined(_WIN64) #define L2A(X) ((void *)(X)) #define A2L(X) ((jlong)(X)) @@ -155,6 +154,7 @@ typedef struct _callback { #endif #else #include +#define STRDUP strdup #endif /* Convenience macros */