diff --git a/src/main/c/build/linux-x86_64.sh b/src/main/c/build/linux-x86_64.sh index 9d14f94..9d25cb8 100755 --- a/src/main/c/build/linux-x86_64.sh +++ b/src/main/c/build/linux-x86_64.sh @@ -9,8 +9,9 @@ set -e OS="linux" ARCH="x86_64" HOST="$ARCH-$OS-gnu" -CFLAGS="-m64" +CFLAGS="-m64 -Wl,--wrap=memcpy" LIBUSB_CONFIG="--disable-shared --disable-udev" USB4JAVA_LIBS="-lrt" +USB4JAVA_CFLAGS="-DWRAP_MEMCPY" build diff --git a/src/main/c/src/BosDescriptor.c b/src/main/c/src/BosDescriptor.c index 12aadc5..4a65a2d 100644 --- a/src/main/c/src/BosDescriptor.c +++ b/src/main/c/src/BosDescriptor.c @@ -7,7 +7,7 @@ #include "BosDevCapabilityDescriptor.h" void setBosDescriptor(JNIEnv* env, - struct libusb_bos_descriptor* descriptor, jobject object) + const struct libusb_bos_descriptor* descriptor, jobject object) { SET_POINTER(env, descriptor, object, "bosDescriptorPointer"); } @@ -35,7 +35,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(BosDescriptor, bLength) struct libusb_bos_descriptor *descriptor = unwrapBosDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bLength; + return (jbyte) descriptor->bLength; } /** @@ -49,7 +49,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(BosDescriptor, bDescriptorType) struct libusb_bos_descriptor *descriptor = unwrapBosDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bDescriptorType; + return (jbyte) descriptor->bDescriptorType; } /** @@ -63,7 +63,7 @@ JNIEXPORT jshort JNICALL METHOD_NAME(BosDescriptor, wTotalLength) struct libusb_bos_descriptor *descriptor = unwrapBosDescriptor(env, this); if (!descriptor) return 0; - return descriptor->wTotalLength; + return (jshort) descriptor->wTotalLength; } /** @@ -77,7 +77,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(BosDescriptor, bNumDeviceCaps) struct libusb_bos_descriptor *descriptor = unwrapBosDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bNumDeviceCaps; + return (jbyte) descriptor->bNumDeviceCaps; } /** diff --git a/src/main/c/src/BosDescriptor.h b/src/main/c/src/BosDescriptor.h index c7e0fd4..13166eb 100644 --- a/src/main/c/src/BosDescriptor.h +++ b/src/main/c/src/BosDescriptor.h @@ -8,7 +8,7 @@ #include "usb4java.h" -void setBosDescriptor(JNIEnv*, struct libusb_bos_descriptor*, jobject); +void setBosDescriptor(JNIEnv*, const struct libusb_bos_descriptor*, jobject); struct libusb_bos_descriptor* unwrapBosDescriptor(JNIEnv*, jobject); void resetBosDescriptor(JNIEnv*, jobject); diff --git a/src/main/c/src/BosDevCapabilityDescriptor.c b/src/main/c/src/BosDevCapabilityDescriptor.c index eed2fb9..6bf0cc6 100644 --- a/src/main/c/src/BosDevCapabilityDescriptor.c +++ b/src/main/c/src/BosDevCapabilityDescriptor.c @@ -13,21 +13,21 @@ jobject wrapBosDevCapabilityDescriptor(JNIEnv *env, } jobjectArray wrapBosDevCapabilityDescriptors(JNIEnv *env, int count, - struct libusb_bos_dev_capability_descriptor **descriptors) + struct libusb_bos_dev_capability_descriptor * const *descriptors) { - int i; - jobjectArray array = (jobjectArray) (*env)->NewObjectArray(env, count, (*env)->FindClass(env, PACKAGE_DIR"/BosDevCapabilityDescriptor"), NULL); - for (i = 0; i < count; i++) + + for (int i = 0; i < count; i++) (*env)->SetObjectArrayElement(env, array, i, wrapBosDevCapabilityDescriptor(env, descriptors[i])); + return array; } -struct libusb_bos_dev_capability_descriptor - *unwrapBosDevCapabilityDescriptor(JNIEnv *env, jobject obj) +struct libusb_bos_dev_capability_descriptor* + unwrapBosDevCapabilityDescriptor(JNIEnv *env, jobject obj) { UNWRAP_POINTER(env, obj, struct libusb_bos_dev_capability_descriptor*, "bosDevCapabilityDescriptorPointer"); @@ -44,7 +44,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(BosDevCapabilityDescriptor, bLength) struct libusb_bos_dev_capability_descriptor* descriptor = unwrapBosDevCapabilityDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bLength; + return (jbyte) descriptor->bLength; } /** @@ -59,7 +59,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(BosDevCapabilityDescriptor, struct libusb_bos_dev_capability_descriptor* descriptor = unwrapBosDevCapabilityDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bDescriptorType; + return (jbyte) descriptor->bDescriptorType; } /** @@ -74,7 +74,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(BosDevCapabilityDescriptor, struct libusb_bos_dev_capability_descriptor* descriptor = unwrapBosDevCapabilityDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bDevCapabilityType; + return (jbyte) descriptor->bDevCapabilityType; } /** @@ -89,6 +89,5 @@ JNIEXPORT jobject JNICALL METHOD_NAME(BosDevCapabilityDescriptor, struct libusb_bos_dev_capability_descriptor *descriptor = unwrapBosDevCapabilityDescriptor(env, this); if (!descriptor) return NULL; - return (*env)->NewDirectByteBuffer(env, (void *) - descriptor->dev_capability_data, descriptor->bLength - 3); + return NewDirectReadOnlyByteBuffer(env, descriptor->dev_capability_data, descriptor->bLength - 3); } diff --git a/src/main/c/src/BosDevCapabilityDescriptor.h b/src/main/c/src/BosDevCapabilityDescriptor.h index 82d553c..2cd376c 100644 --- a/src/main/c/src/BosDevCapabilityDescriptor.h +++ b/src/main/c/src/BosDevCapabilityDescriptor.h @@ -8,9 +8,11 @@ #include "usb4java.h" +jobject wrapBosDevCapabilityDescriptor(JNIEnv *, + const struct libusb_bos_dev_capability_descriptor *); jobjectArray wrapBosDevCapabilityDescriptors(JNIEnv*, int, - struct libusb_bos_dev_capability_descriptor**); -struct libusb_bos_dev_capability_descriptor - *unwrapBosDevCapabilityDescriptor(JNIEnv *, jobject); + struct libusb_bos_dev_capability_descriptor * const *); +struct libusb_bos_dev_capability_descriptor* + unwrapBosDevCapabilityDescriptor(JNIEnv *, jobject); #endif diff --git a/src/main/c/src/ContainerIdDescriptor.c b/src/main/c/src/ContainerIdDescriptor.c index e40e65e..d72625b 100644 --- a/src/main/c/src/ContainerIdDescriptor.c +++ b/src/main/c/src/ContainerIdDescriptor.c @@ -6,7 +6,7 @@ #include "ContainerIdDescriptor.h" void setContainerIdDescriptor(JNIEnv* env, - struct libusb_container_id_descriptor* descriptor, jobject object) + const struct libusb_container_id_descriptor* descriptor, jobject object) { SET_POINTER(env, descriptor, object, "containerIdDescriptorPointer"); } @@ -35,7 +35,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(ContainerIdDescriptor, bLength) struct libusb_container_id_descriptor *descriptor = unwrapContainerIdDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bLength; + return (jbyte) descriptor->bLength; } /** @@ -49,7 +49,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(ContainerIdDescriptor, bDescriptorType) struct libusb_container_id_descriptor *descriptor = unwrapContainerIdDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bDescriptorType; + return (jbyte) descriptor->bDescriptorType; } /** @@ -63,7 +63,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(ContainerIdDescriptor, bDevCapabilityType) struct libusb_container_id_descriptor *descriptor = unwrapContainerIdDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bDevCapabilityType; + return (jbyte) descriptor->bDevCapabilityType; } /** @@ -77,7 +77,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(ContainerIdDescriptor, bReserved) struct libusb_container_id_descriptor *descriptor = unwrapContainerIdDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bReserved; + return (jbyte) descriptor->bReserved; } /** @@ -91,6 +91,5 @@ JNIEXPORT jobject JNICALL METHOD_NAME(ContainerIdDescriptor, containerId) struct libusb_container_id_descriptor *descriptor = unwrapContainerIdDescriptor(env, this); if (!descriptor) return NULL; - return (*env)->NewDirectByteBuffer(env, (void *) descriptor->ContainerID, - 16); + return NewDirectReadOnlyByteBuffer(env, descriptor->ContainerID, 16); } diff --git a/src/main/c/src/ContainerIdDescriptor.h b/src/main/c/src/ContainerIdDescriptor.h index 0114aa8..698c8c8 100644 --- a/src/main/c/src/ContainerIdDescriptor.h +++ b/src/main/c/src/ContainerIdDescriptor.h @@ -9,7 +9,7 @@ #include "usb4java.h" void setContainerIdDescriptor(JNIEnv*, - struct libusb_container_id_descriptor*, jobject); + const struct libusb_container_id_descriptor*, jobject); struct libusb_container_id_descriptor* unwrapContainerIdDescriptor(JNIEnv*, jobject); void resetContainerIdDescriptor(JNIEnv*, jobject); diff --git a/src/main/c/src/DeviceDescriptor.c b/src/main/c/src/DeviceDescriptor.c index 3472897..7ecfbc6 100644 --- a/src/main/c/src/DeviceDescriptor.c +++ b/src/main/c/src/DeviceDescriptor.c @@ -11,10 +11,10 @@ void setDeviceDescriptor(JNIEnv* env, SET_POINTER(env, descriptor, object, "deviceDescriptorPointer"); } -struct libusb_device_descriptor* unwrapDeviceDescriptor(JNIEnv *env, - jobject obj) +struct libusb_device_descriptor* unwrapDeviceDescriptor(JNIEnv* env, + jobject descriptor) { - UNWRAP_POINTER(env, obj, struct libusb_device_descriptor*, + UNWRAP_POINTER(env, descriptor, struct libusb_device_descriptor*, "deviceDescriptorPointer"); } diff --git a/src/main/c/src/DeviceHandle.c b/src/main/c/src/DeviceHandle.c index 2d06da0..0f21888 100644 --- a/src/main/c/src/DeviceHandle.c +++ b/src/main/c/src/DeviceHandle.c @@ -18,8 +18,7 @@ jobject wrapDeviceHandle(JNIEnv* env, const libusb_device_handle* deviceHandle) libusb_device_handle* unwrapDeviceHandle(JNIEnv* env, jobject deviceHandle) { - UNWRAP_POINTER(env, deviceHandle, libusb_device_handle*, - "deviceHandlePointer"); + UNWRAP_POINTER(env, deviceHandle, libusb_device_handle*, "deviceHandlePointer"); } void resetDeviceHandle(JNIEnv* env, jobject object) diff --git a/src/main/c/src/DeviceList.c b/src/main/c/src/DeviceList.c index cdbfe56..292be4f 100644 --- a/src/main/c/src/DeviceList.c +++ b/src/main/c/src/DeviceList.c @@ -6,7 +6,7 @@ #include "DeviceList.h" #include "Device.h" -void setDeviceList(JNIEnv* env, libusb_device* const * list, jint size, jobject object) +void setDeviceList(JNIEnv* env, libusb_device* const *list, jint size, jobject object) { SET_POINTER(env, list, object, "deviceListPointer"); @@ -38,7 +38,7 @@ JNIEXPORT jobject JNICALL METHOD_NAME(DeviceList, get) JNIEnv *env, jobject this, jint index ) { - libusb_device **list = unwrapDeviceList(env, this); + libusb_device* const *list = unwrapDeviceList(env, this); if (!list) return NULL; jclass cls = (*env)->GetObjectClass(env, this); diff --git a/src/main/c/src/LibUsb.c b/src/main/c/src/LibUsb.c index 387b752..3a5f326 100644 --- a/src/main/c/src/LibUsb.c +++ b/src/main/c/src/LibUsb.c @@ -198,7 +198,7 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getPortNumbers) libusb_device *dev = unwrapDevice(env, device); if (!dev) return 0; jlong path_size = (*env)->GetDirectBufferCapacity(env, path); - return libusb_get_port_numbers(dev, path_ptr, path_size); + return libusb_get_port_numbers(dev, path_ptr, (int) path_size); } /** @@ -254,7 +254,6 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getMaxPacketSize) NOT_NULL(env, device, return 0); libusb_device *dev = unwrapDevice(env, device); if (!dev) return 0; - return libusb_get_max_packet_size(dev, (unsigned char) endpoint); } @@ -269,7 +268,6 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getMaxIsoPacketSize) NOT_NULL(env, device, return 0); libusb_device *dev = unwrapDevice(env, device); if (!dev) return 0; - return libusb_get_max_iso_packet_size(dev, (unsigned char) endpoint); } @@ -284,7 +282,6 @@ JNIEXPORT jobject JNICALL METHOD_NAME(LibUsb, refDevice) NOT_NULL(env, device, return NULL); libusb_device *dev = unwrapDevice(env, device); if (!dev) return NULL; - return wrapDevice(env, libusb_ref_device(dev)); } @@ -456,7 +453,6 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, clearHalt) NOT_NULL(env, handle, return 0); libusb_device_handle *dev_handle = unwrapDeviceHandle(env, handle); if (!dev_handle) return 0; - return libusb_clear_halt(dev_handle, (unsigned char) endpoint); } @@ -624,6 +620,7 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getDeviceDescriptor) } else { + // Free memory again on error. free(dev_desc); } return result; @@ -761,7 +758,7 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getSsEndpointCompanionDescriptor) if (!ctx && context) return 0; NOT_NULL(env, endpointDescriptor, return 0); NOT_NULL(env, companionDescriptor, return 0); - NOT_SET(env, companionDescriptor, "ssEndpointCompanionDescriptor", return 0); + NOT_SET(env, companionDescriptor, "ssEndpointCompanionDescriptorPointer", return 0); struct libusb_endpoint_descriptor *endpoint_descriptor = unwrapEndpointDescriptor(env, endpointDescriptor); diff --git a/src/main/c/src/SsEndpointCompanionDescriptor.c b/src/main/c/src/SsEndpointCompanionDescriptor.c index eeb329c..3f39d8e 100644 --- a/src/main/c/src/SsEndpointCompanionDescriptor.c +++ b/src/main/c/src/SsEndpointCompanionDescriptor.c @@ -7,9 +7,9 @@ #include "Interface.h" void setSsEndpointCompanionDescriptor(JNIEnv* env, - struct libusb_ss_endpoint_companion_descriptor* descriptor, jobject object) + const struct libusb_ss_endpoint_companion_descriptor* descriptor, jobject object) { - SET_POINTER(env, descriptor, object, "ssEndpointCompanionDescriptor"); + SET_POINTER(env, descriptor, object, "ssEndpointCompanionDescriptorPointer"); } struct libusb_ss_endpoint_companion_descriptor* @@ -17,12 +17,12 @@ struct libusb_ss_endpoint_companion_descriptor* { UNWRAP_POINTER(env, descriptor, struct libusb_ss_endpoint_companion_descriptor*, - "ssEndpointCompanionDescriptor"); + "ssEndpointCompanionDescriptorPointer"); } void resetSsEndpointCompanionDescriptor(JNIEnv* env, jobject obj) { - RESET_POINTER(env, obj, "ssEndpointCompanionDescriptor"); + RESET_POINTER(env, obj, "ssEndpointCompanionDescriptorPointer"); } /** @@ -36,7 +36,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(SsEndpointCompanionDescriptor, bLength) struct libusb_ss_endpoint_companion_descriptor *descriptor = unwrapSsEndpointCompanionDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bLength; + return (jbyte) descriptor->bLength; } /** @@ -51,7 +51,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(SsEndpointCompanionDescriptor, struct libusb_ss_endpoint_companion_descriptor *descriptor = unwrapSsEndpointCompanionDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bDescriptorType; + return (jbyte) descriptor->bDescriptorType; } /** @@ -65,7 +65,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(SsEndpointCompanionDescriptor, bMaxBurst) struct libusb_ss_endpoint_companion_descriptor *descriptor = unwrapSsEndpointCompanionDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bMaxBurst; + return (jbyte) descriptor->bMaxBurst; } /** @@ -79,7 +79,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(SsEndpointCompanionDescriptor, bmAttributes) struct libusb_ss_endpoint_companion_descriptor *descriptor = unwrapSsEndpointCompanionDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bmAttributes; + return (jbyte) descriptor->bmAttributes; } /** @@ -93,5 +93,5 @@ JNIEXPORT jshort JNICALL METHOD_NAME(SsEndpointCompanionDescriptor, wBytesPerInt struct libusb_ss_endpoint_companion_descriptor *descriptor = unwrapSsEndpointCompanionDescriptor(env, this); if (!descriptor) return 0; - return descriptor->wBytesPerInterval; + return (jshort) descriptor->wBytesPerInterval; } diff --git a/src/main/c/src/SsEndpointCompanionDescriptor.h b/src/main/c/src/SsEndpointCompanionDescriptor.h index e05d2be..3febd7d 100644 --- a/src/main/c/src/SsEndpointCompanionDescriptor.h +++ b/src/main/c/src/SsEndpointCompanionDescriptor.h @@ -9,7 +9,7 @@ #include "usb4java.h" void setSsEndpointCompanionDescriptor(JNIEnv*, - struct libusb_ss_endpoint_companion_descriptor*, jobject); + const struct libusb_ss_endpoint_companion_descriptor*, jobject); struct libusb_ss_endpoint_companion_descriptor* unwrapSsEndpointCompanionDescriptor(JNIEnv*, jobject); void resetSsEndpointCompanionDescriptor(JNIEnv*, jobject); diff --git a/src/main/c/src/SsUsbDeviceCapabilityDescriptor.c b/src/main/c/src/SsUsbDeviceCapabilityDescriptor.c index 26dc131..03e8aa4 100644 --- a/src/main/c/src/SsUsbDeviceCapabilityDescriptor.c +++ b/src/main/c/src/SsUsbDeviceCapabilityDescriptor.c @@ -6,7 +6,7 @@ #include "SsUsbDeviceCapabilityDescriptor.h" void setSsUsbDeviceCapabilityDescriptor(JNIEnv* env, - struct libusb_ss_usb_device_capability_descriptor* descriptor, jobject object) + const struct libusb_ss_usb_device_capability_descriptor* descriptor, jobject object) { SET_POINTER(env, descriptor, object, "ssUsbDeviceCapabilityDescriptorPointer"); } @@ -35,7 +35,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(SsUsbDeviceCapabilityDescriptor, bLength) struct libusb_ss_usb_device_capability_descriptor *descriptor = unwrapSsUsbDeviceCapabilityDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bLength; + return (jbyte) descriptor->bLength; } /** @@ -49,7 +49,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(SsUsbDeviceCapabilityDescriptor, bDescriptor struct libusb_ss_usb_device_capability_descriptor *descriptor = unwrapSsUsbDeviceCapabilityDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bDescriptorType; + return (jbyte) descriptor->bDescriptorType; } /** @@ -64,11 +64,11 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(SsUsbDeviceCapabilityDescriptor, struct libusb_ss_usb_device_capability_descriptor *descriptor = unwrapSsUsbDeviceCapabilityDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bDevCapabilityType; + return (jbyte) descriptor->bDevCapabilityType; } /** - * int bmAttributes() + * byte bmAttributes() */ JNIEXPORT jbyte JNICALL METHOD_NAME(SsUsbDeviceCapabilityDescriptor, bmAttributes) @@ -79,7 +79,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(SsUsbDeviceCapabilityDescriptor, struct libusb_ss_usb_device_capability_descriptor *descriptor = unwrapSsUsbDeviceCapabilityDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bmAttributes; + return (jbyte) descriptor->bmAttributes; } /** @@ -94,7 +94,7 @@ JNIEXPORT jshort JNICALL METHOD_NAME(SsUsbDeviceCapabilityDescriptor, struct libusb_ss_usb_device_capability_descriptor *descriptor = unwrapSsUsbDeviceCapabilityDescriptor(env, this); if (!descriptor) return 0; - return descriptor->wSpeedSupported; + return (jshort) descriptor->wSpeedSupported; } /** @@ -109,7 +109,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(SsUsbDeviceCapabilityDescriptor, struct libusb_ss_usb_device_capability_descriptor *descriptor = unwrapSsUsbDeviceCapabilityDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bFunctionalitySupport; + return (jbyte) descriptor->bFunctionalitySupport; } /** @@ -124,7 +124,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(SsUsbDeviceCapabilityDescriptor, struct libusb_ss_usb_device_capability_descriptor *descriptor = unwrapSsUsbDeviceCapabilityDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bU1DevExitLat; + return (jbyte) descriptor->bU1DevExitLat; } /** @@ -139,5 +139,5 @@ JNIEXPORT jshort JNICALL METHOD_NAME(SsUsbDeviceCapabilityDescriptor, struct libusb_ss_usb_device_capability_descriptor *descriptor = unwrapSsUsbDeviceCapabilityDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bU2DevExitLat; + return (jshort) descriptor->bU2DevExitLat; } diff --git a/src/main/c/src/SsUsbDeviceCapabilityDescriptor.h b/src/main/c/src/SsUsbDeviceCapabilityDescriptor.h index bbeddbb..bd35734 100644 --- a/src/main/c/src/SsUsbDeviceCapabilityDescriptor.h +++ b/src/main/c/src/SsUsbDeviceCapabilityDescriptor.h @@ -9,7 +9,7 @@ #include "usb4java.h" void setSsUsbDeviceCapabilityDescriptor(JNIEnv*, - struct libusb_ss_usb_device_capability_descriptor*, jobject); + const struct libusb_ss_usb_device_capability_descriptor*, jobject); struct libusb_ss_usb_device_capability_descriptor* unwrapSsUsbDeviceCapabilityDescriptor(JNIEnv*, jobject); void resetSsUsbDeviceCapabilityDescriptor(JNIEnv*, jobject); diff --git a/src/main/c/src/Usb20ExtensionDescriptor.c b/src/main/c/src/Usb20ExtensionDescriptor.c index 553b62b..e201d48 100644 --- a/src/main/c/src/Usb20ExtensionDescriptor.c +++ b/src/main/c/src/Usb20ExtensionDescriptor.c @@ -6,7 +6,7 @@ #include "Usb20ExtensionDescriptor.h" void setUsb20ExtensionDescriptor(JNIEnv* env, - struct libusb_usb_2_0_extension_descriptor* descriptor, jobject object) + const struct libusb_usb_2_0_extension_descriptor* descriptor, jobject object) { SET_POINTER(env, descriptor, object, "usb20ExtensionDescriptorPointer"); } @@ -35,7 +35,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(Usb20ExtensionDescriptor, bLength) struct libusb_usb_2_0_extension_descriptor *descriptor = unwrapUsb20ExtensionDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bLength; + return (jbyte) descriptor->bLength; } /** @@ -49,7 +49,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(Usb20ExtensionDescriptor, bDescriptorType) struct libusb_usb_2_0_extension_descriptor *descriptor = unwrapUsb20ExtensionDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bDescriptorType; + return (jbyte) descriptor->bDescriptorType; } /** @@ -64,7 +64,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(Usb20ExtensionDescriptor, struct libusb_usb_2_0_extension_descriptor *descriptor = unwrapUsb20ExtensionDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bDevCapabilityType; + return (jbyte) descriptor->bDevCapabilityType; } /** @@ -79,5 +79,5 @@ JNIEXPORT jint JNICALL METHOD_NAME(Usb20ExtensionDescriptor, struct libusb_usb_2_0_extension_descriptor *descriptor = unwrapUsb20ExtensionDescriptor(env, this); if (!descriptor) return 0; - return descriptor->bmAttributes; + return (jint) descriptor->bmAttributes; } diff --git a/src/main/c/src/Usb20ExtensionDescriptor.h b/src/main/c/src/Usb20ExtensionDescriptor.h index d076ec4..ec57bc9 100644 --- a/src/main/c/src/Usb20ExtensionDescriptor.h +++ b/src/main/c/src/Usb20ExtensionDescriptor.h @@ -9,7 +9,7 @@ #include "usb4java.h" void setUsb20ExtensionDescriptor(JNIEnv*, - struct libusb_usb_2_0_extension_descriptor*, jobject); + const struct libusb_usb_2_0_extension_descriptor*, jobject); struct libusb_usb_2_0_extension_descriptor* unwrapUsb20ExtensionDescriptor(JNIEnv*, jobject); void resetUsb20ExtensionDescriptor(JNIEnv*, jobject); diff --git a/src/main/c/src/usb4java.h b/src/main/c/src/usb4java.h index 5f29849..f9bb518 100644 --- a/src/main/c/src/usb4java.h +++ b/src/main/c/src/usb4java.h @@ -51,11 +51,11 @@ // GetDirectBufferAddress returns NULL if called on a non-direct buffer. #define DIRECT_BUFFER(ENV, VAR, BUFFER, ACTION) \ unsigned char *BUFFER = (*ENV)->GetDirectBufferAddress(ENV, VAR); \ - if (!BUFFER) \ - { \ - illegalArgument(ENV, #VAR" must be a direct buffer"); \ - ACTION; \ - } + if (!BUFFER) \ + { \ + illegalArgument(ENV, #VAR" must be a direct buffer"); \ + ACTION; \ + } #define NOT_NULL(ENV, VAR, ACTION) \ if (!VAR) \ diff --git a/src/main/c/src/wrappers.c b/src/main/c/src/wrappers.c new file mode 100644 index 0000000..f11f829 --- /dev/null +++ b/src/main/c/src/wrappers.c @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2013 Klaus Reimer (k@ailis.de) + * See COPYING file for copying conditions + */ + +#include + +// Enforce usage of older memcpy to be compatible with older libc versions +#ifdef WRAP_MEMCPY +asm (".symver memcpy, memcpy@GLIBC_2.2.5"); +void *__wrap_memcpy(void *dest, const void *src, size_t n) +{ + return memcpy(dest, src, n); +} +#endif diff --git a/src/main/java/de/ailis/usb4java/libusb/SsEndpointCompanionDescriptor.java b/src/main/java/de/ailis/usb4java/libusb/SsEndpointCompanionDescriptor.java index 1f7e6da..eb726b7 100644 --- a/src/main/java/de/ailis/usb4java/libusb/SsEndpointCompanionDescriptor.java +++ b/src/main/java/de/ailis/usb4java/libusb/SsEndpointCompanionDescriptor.java @@ -32,7 +32,7 @@ import org.apache.commons.lang3.builder.HashCodeBuilder; public final class SsEndpointCompanionDescriptor { /** The native pointer to the descriptor structure. */ - private long ssEndpointCompanionDescriptor; + private long ssEndpointCompanionDescriptorPointer; /** * Constructs a new descriptor which can be passed to the @@ -52,7 +52,7 @@ public final class SsEndpointCompanionDescriptor */ public long getPointer() { - return this.ssEndpointCompanionDescriptor; + return this.ssEndpointCompanionDescriptorPointer; } /**