Remove memcpy wrap stuff to support old, broken systems... memcpy is never used here, only libusb uses it and there they don't support it in any particular way, so I don't believe there should be a workaround for this that forces memcpy to be slower on all x86_64 linux systems.

Enable silent building and C99 support.
Enable lots of warnings and don't enable Werror, as there are warnings in libusb.h.
Fix all warnings. Add const to exceptions.
Make it possible to pass null to setDevHandle and setBuffer in Transfer now.
This commit is contained in:
Luca Longinotti 2013-06-13 12:59:42 +02:00
parent b3e261f050
commit 95ee591d46
16 changed files with 111 additions and 112 deletions

View File

@ -9,9 +9,8 @@ set -e
OS="linux"
ARCH="x86_64"
HOST="$ARCH-$OS-gnu"
CFLAGS="-m64 -Wl,--wrap=memcpy"
CFLAGS="-m64"
LIBUSB_CONFIG="--disable-shared"
USB4JAVA_LIBS="-lrt"
USB4JAVA_CFLAGS="-DWRAP_MEMCPY"
build

View File

@ -1,12 +1,14 @@
AC_PREREQ([2.61])
AC_INIT([libusb4java], [1.0.0], [k@ailis.de])
AM_INIT_AUTOMAKE([foreign -Wall -Werror -Wno-extra-portability])
AM_SILENT_RULES(yes)
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_SRCDIR([src/usb4java.h])
AC_LANG_C
AC_PROG_CC
AC_PROG_CC_STDC
AM_PROG_LIBTOOL
AC_CHECK_JAVA
AC_CHECK_SIZEOF([void *])

View File

@ -35,7 +35,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(ConfigDescriptor, bLength)
struct libusb_config_descriptor *config = unwrapConfigDescriptor(env, this);
if (!config) return 0;
return config->bLength;
return (jbyte) config->bLength;
}
/**
@ -49,7 +49,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(ConfigDescriptor, bDescriptorType)
struct libusb_config_descriptor *config = unwrapConfigDescriptor(env, this);
if (!config) return 0;
return config->bDescriptorType;
return (jbyte) config->bDescriptorType;
}
/**
@ -63,7 +63,7 @@ JNIEXPORT jshort JNICALL METHOD_NAME(ConfigDescriptor, wTotalLength)
struct libusb_config_descriptor *config = unwrapConfigDescriptor(env, this);
if (!config) return 0;
return config->wTotalLength;
return (jshort) config->wTotalLength;
}
/**
@ -77,7 +77,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(ConfigDescriptor, bNumInterfaces)
struct libusb_config_descriptor *config = unwrapConfigDescriptor(env, this);
if (!config) return 0;
return config->bNumInterfaces;
return (jbyte) config->bNumInterfaces;
}
/**
@ -91,7 +91,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(ConfigDescriptor, bConfigurationValue)
struct libusb_config_descriptor *config = unwrapConfigDescriptor(env, this);
if (!config) return 0;
return config->bConfigurationValue;
return (jbyte) config->bConfigurationValue;
}
/**
@ -105,7 +105,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(ConfigDescriptor, iConfiguration)
struct libusb_config_descriptor *config = unwrapConfigDescriptor(env, this);
if (!config) return 0;
return config->iConfiguration;
return (jbyte) config->iConfiguration;
}
/**
@ -119,7 +119,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(ConfigDescriptor, bmAttributes)
struct libusb_config_descriptor *config = unwrapConfigDescriptor(env, this);
if (!config) return 0;
return config->bmAttributes;
return (jbyte) config->bmAttributes;
}
/**
@ -133,7 +133,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(ConfigDescriptor, bMaxPower)
struct libusb_config_descriptor *config = unwrapConfigDescriptor(env, this);
if (!config) return 0;
return config->MaxPower;
return (jbyte) config->MaxPower;
}
/**

View File

@ -34,7 +34,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(DeviceDescriptor, bLength)
struct libusb_device_descriptor *device = unwrapDeviceDescriptor(env, this);
if (!device) return 0;
return device->bLength;
return (jbyte) device->bLength;
}
/**
@ -48,7 +48,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(DeviceDescriptor, bDescriptorType)
struct libusb_device_descriptor *device = unwrapDeviceDescriptor(env, this);
if (!device) return 0;
return device->bDescriptorType;
return (jbyte) device->bDescriptorType;
}
/**
@ -62,7 +62,7 @@ JNIEXPORT jshort JNICALL METHOD_NAME(DeviceDescriptor, bcdUSB)
struct libusb_device_descriptor *device = unwrapDeviceDescriptor(env, this);
if (!device) return 0;
return device->bcdUSB;
return (jshort) device->bcdUSB;
}
/**
@ -76,7 +76,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(DeviceDescriptor, bDeviceClass)
struct libusb_device_descriptor *device = unwrapDeviceDescriptor(env, this);
if (!device) return 0;
return device->bDeviceClass;
return (jbyte) device->bDeviceClass;
}
/**
@ -90,7 +90,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(DeviceDescriptor, bDeviceSubClass)
struct libusb_device_descriptor *device = unwrapDeviceDescriptor(env, this);
if (!device) return 0;
return device->bDeviceSubClass;
return (jbyte) device->bDeviceSubClass;
}
/**
@ -104,7 +104,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(DeviceDescriptor, bDeviceProtocol)
struct libusb_device_descriptor *device = unwrapDeviceDescriptor(env, this);
if (!device) return 0;
return device->bDeviceProtocol;
return (jbyte) device->bDeviceProtocol;
}
/**
@ -118,7 +118,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(DeviceDescriptor, bMaxPacketSize0)
struct libusb_device_descriptor *device = unwrapDeviceDescriptor(env, this);
if (!device) return 0;
return device->bMaxPacketSize0;
return (jbyte) device->bMaxPacketSize0;
}
/**
@ -132,7 +132,7 @@ JNIEXPORT jshort JNICALL METHOD_NAME(DeviceDescriptor, idVendor)
struct libusb_device_descriptor *device = unwrapDeviceDescriptor(env, this);
if (!device) return 0;
return device->idVendor;
return (jshort) device->idVendor;
}
/**
@ -146,7 +146,7 @@ JNIEXPORT jshort JNICALL METHOD_NAME(DeviceDescriptor, idProduct)
struct libusb_device_descriptor *device = unwrapDeviceDescriptor(env, this);
if (!device) return 0;
return device->idProduct;
return (jshort) device->idProduct;
}
/**
@ -160,7 +160,7 @@ JNIEXPORT jshort JNICALL METHOD_NAME(DeviceDescriptor, bcdDevice)
struct libusb_device_descriptor *device = unwrapDeviceDescriptor(env, this);
if (!device) return 0;
return device->bcdDevice;
return (jshort) device->bcdDevice;
}
@ -175,7 +175,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(DeviceDescriptor, iManufacturer)
struct libusb_device_descriptor *device = unwrapDeviceDescriptor(env, this);
if (!device) return 0;
return device->iManufacturer;
return (jbyte) device->iManufacturer;
}
/**
@ -189,7 +189,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(DeviceDescriptor, iProduct)
struct libusb_device_descriptor *device = unwrapDeviceDescriptor(env, this);
if (!device) return 0;
return device->iProduct;
return (jbyte) device->iProduct;
}
/**
@ -201,7 +201,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(DeviceDescriptor, iSerialNumber)
struct libusb_device_descriptor *device = unwrapDeviceDescriptor(env, this);
if (!device) return 0;
return device->iSerialNumber;
return (jbyte) device->iSerialNumber;
}
/**
@ -215,5 +215,5 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(DeviceDescriptor, bNumConfigurations)
struct libusb_device_descriptor *device = unwrapDeviceDescriptor(env, this);
if (!device) return 0;
return device->bNumConfigurations;
return (jbyte) device->bNumConfigurations;
}

View File

@ -6,7 +6,7 @@
#include "DeviceList.h"
#include "Device.h"
void setDeviceList(JNIEnv* env, libusb_device* const * list, int size, jobject object)
void setDeviceList(JNIEnv* env, libusb_device* const * list, jint size, jobject object)
{
SET_POINTER(env, list, object, "deviceListPointer");

View File

@ -8,7 +8,7 @@
#include "usb4java.h"
void setDeviceList(JNIEnv*, libusb_device* const *, int, jobject);
void setDeviceList(JNIEnv*, libusb_device* const *, jint, jobject);
libusb_device** unwrapDeviceList(JNIEnv*, jobject);
void resetDeviceList(JNIEnv*, jobject);

View File

@ -44,7 +44,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(EndpointDescriptor, bLength)
struct libusb_endpoint_descriptor *ep = unwrapEndpointDescriptor(env, this);
if (!ep) return 0;
return ep->bLength;
return (jbyte) ep->bLength;
}
/**
@ -58,7 +58,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(EndpointDescriptor, bDescriptorType)
struct libusb_endpoint_descriptor *ep = unwrapEndpointDescriptor(env, this);
if (!ep) return 0;
return ep->bDescriptorType;
return (jbyte) ep->bDescriptorType;
}
/**
@ -72,7 +72,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(EndpointDescriptor, bEndpointAddress)
struct libusb_endpoint_descriptor *ep = unwrapEndpointDescriptor(env, this);
if (!ep) return 0;
return ep->bEndpointAddress;
return (jbyte) ep->bEndpointAddress;
}
/**
@ -86,7 +86,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(EndpointDescriptor, bmAttributes)
struct libusb_endpoint_descriptor *ep = unwrapEndpointDescriptor(env, this);
if (!ep) return 0;
return ep->bmAttributes;
return (jbyte) ep->bmAttributes;
}
/**
@ -100,7 +100,7 @@ JNIEXPORT jshort JNICALL METHOD_NAME(EndpointDescriptor, wMaxPacketSize)
struct libusb_endpoint_descriptor *ep = unwrapEndpointDescriptor(env, this);
if (!ep) return 0;
return ep->wMaxPacketSize;
return (jshort) ep->wMaxPacketSize;
}
/**
@ -114,7 +114,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(EndpointDescriptor, bInterval)
struct libusb_endpoint_descriptor *ep = unwrapEndpointDescriptor(env, this);
if (!ep) return 0;
return ep->bInterval;
return (jbyte) ep->bInterval;
}
/**
@ -128,7 +128,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(EndpointDescriptor, bRefresh)
struct libusb_endpoint_descriptor *ep = unwrapEndpointDescriptor(env, this);
if (!ep) return 0;
return ep->bRefresh;
return (jbyte) ep->bRefresh;
}
/**
@ -142,7 +142,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(EndpointDescriptor, bSynchAddress)
struct libusb_endpoint_descriptor *ep = unwrapEndpointDescriptor(env, this);
if (!ep) return 0;
return ep->bSynchAddress;
return (jbyte) ep->bSynchAddress;
}
/**

View File

@ -47,7 +47,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bLength)
unwrapInterfaceDescriptor(env, this);
if (!interface) return 0;
return interface->bLength;
return (jbyte) interface->bLength;
}
/**
@ -62,7 +62,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bDescriptorType)
unwrapInterfaceDescriptor(env, this);
if (!interface) return 0;
return interface->bDescriptorType;
return (jbyte) interface->bDescriptorType;
}
/**
@ -77,7 +77,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bInterfaceNumber)
unwrapInterfaceDescriptor(env, this);
if (!interface) return 0;
return interface->bInterfaceNumber;
return (jbyte) interface->bInterfaceNumber;
}
/**
@ -92,7 +92,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bAlternateSetting)
unwrapInterfaceDescriptor(env, this);
if (!interface) return 0;
return interface->bAlternateSetting;
return (jbyte) interface->bAlternateSetting;
}
/**
@ -107,7 +107,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bNumEndpoints)
unwrapInterfaceDescriptor(env, this);
if (!interface) return 0;
return interface->bNumEndpoints;
return (jbyte) interface->bNumEndpoints;
}
/**
@ -122,7 +122,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bInterfaceClass)
unwrapInterfaceDescriptor(env, this);
if (!interface) return 0;
return interface->bInterfaceClass;
return (jbyte) interface->bInterfaceClass;
}
/**
@ -137,7 +137,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bInterfaceSubClass)
unwrapInterfaceDescriptor(env, this);
if (!interface) return 0;
return interface->bInterfaceSubClass;
return (jbyte) interface->bInterfaceSubClass;
}
/**
@ -152,7 +152,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, bInterfaceProtocol)
unwrapInterfaceDescriptor(env, this);
if (!interface) return 0;
return interface->bInterfaceProtocol;
return (jbyte) interface->bInterfaceProtocol;
}
/**
@ -167,7 +167,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(InterfaceDescriptor, iInterface)
unwrapInterfaceDescriptor(env, this);
if (!interface) return 0;
return interface->iInterface;
return (jbyte) interface->iInterface;
}
/**

View File

@ -40,7 +40,7 @@ JNIEXPORT jint JNICALL METHOD_NAME(IsoPacketDescriptor, length)
unwrapIsoPacketDescriptor(env, this);
if (!isopacket) return 0;
return isopacket->length;
return (jint) isopacket->length;
}
/**
@ -55,7 +55,7 @@ JNIEXPORT void JNICALL METHOD_NAME(IsoPacketDescriptor, setLength)
unwrapIsoPacketDescriptor(env, this);
if (!isopacket) return;
isopacket->length = length;
isopacket->length = (unsigned int) length;
}
/**
@ -70,7 +70,7 @@ JNIEXPORT jint JNICALL METHOD_NAME(IsoPacketDescriptor, actualLength)
unwrapIsoPacketDescriptor(env, this);
if (!isopacket) return 0;
return isopacket->actual_length;
return (jint) isopacket->actual_length;
}
/**

View File

@ -120,8 +120,8 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getDeviceList)
libusb_device **list;
ssize_t result = libusb_get_device_list(ctx, &list);
if (result >= 0) setDeviceList(env, list, result, deviceList);
return result;
if (result >= 0) setDeviceList(env, list, (jint) result, deviceList);
return (jint) result;
}
/**
@ -193,7 +193,7 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getPortPath)
#if defined(LIBUSBX_API_VERSION)
jlong path_size = (*env)->GetDirectBufferCapacity(env, path);
return libusb_get_port_path(ctx, dev, path_ptr, path_size);
return libusb_get_port_path(ctx, dev, path_ptr, (uint8_t) path_size);
#else
return 0;
#endif
@ -260,7 +260,7 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getMaxPacketSize)
libusb_device *dev = unwrapDevice(env, device);
if (!dev) return 0;
return libusb_get_max_packet_size(dev, endpoint);
return libusb_get_max_packet_size(dev, (unsigned char) endpoint);
}
/**
@ -275,7 +275,7 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getMaxIsoPacketSize)
libusb_device *dev = unwrapDevice(env, device);
if (!dev) return 0;
return libusb_get_max_iso_packet_size(dev, endpoint);
return libusb_get_max_iso_packet_size(dev, (unsigned char) endpoint);
}
/**
@ -342,7 +342,7 @@ JNIEXPORT jobject JNICALL METHOD_NAME(LibUsb, openDeviceWithVidPid)
if (!ctx && context) return NULL;
return wrapDeviceHandle(env, libusb_open_device_with_vid_pid(
ctx, vendorId, productId));
ctx, (uint16_t) vendorId, (uint16_t) productId));
}
/**
@ -472,7 +472,7 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, clearHalt)
libusb_device_handle *dev_handle = unwrapDeviceHandle(env, handle);
if (!dev_handle) return 0;
return libusb_clear_halt(dev_handle, endpoint);
return libusb_clear_halt(dev_handle, (unsigned char) endpoint);
}
/**
@ -543,7 +543,7 @@ JNIEXPORT jboolean JNICALL METHOD_NAME(LibUsb, hasCapability)
JNIEnv *env, jclass class, jint capability
)
{
return libusb_has_capability(capability);
return (jboolean) libusb_has_capability((uint32_t) capability);
}
/**
@ -565,7 +565,7 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, le16ToCpu)
JNIEnv *env, jclass class, jint x
)
{
return libusb_le16_to_cpu(x);
return libusb_le16_to_cpu((uint16_t) x);
}
/**
@ -576,7 +576,7 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, cpuToLe16)
JNIEnv *env, jclass class, jint x
)
{
return libusb_cpu_to_le16(x);
return libusb_cpu_to_le16((uint16_t) x);
}
/**
@ -642,7 +642,7 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getStringDescriptorAscii)
// and then +1 for the terminating NUL byte for C strings (the descriptor itself doesn't necessarily have one!).
unsigned char buffer[127 + 1];
int result = libusb_get_string_descriptor_ascii(
dev_handle, index, buffer, 127);
dev_handle, (uint8_t) index, buffer, 127);
if (result >= 0)
{
buffer[result] = 0x00;
@ -689,7 +689,7 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getConfigDescriptor)
if (!dev) return 0;
struct libusb_config_descriptor *config;
int result = libusb_get_config_descriptor(dev, index, &config);
int result = libusb_get_config_descriptor(dev, (uint8_t) index, &config);
if (result == LIBUSB_SUCCESS) setConfigDescriptor(env, config, descriptor);
return result;
}
@ -710,7 +710,7 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, getConfigDescriptorByValue)
struct libusb_config_descriptor *config;
int result = libusb_get_config_descriptor_by_value(
dev, index, &config);
dev, (uint8_t) index, &config);
if (result == LIBUSB_SUCCESS) setConfigDescriptor(env, config, descriptor);
return result;
}
@ -748,8 +748,9 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, controlTransfer)
if (!dev_handle) return 0;
jlong data_size = (*env)->GetDirectBufferCapacity(env, data);
return libusb_control_transfer(dev_handle, bmRequestType, bRequest,
wValue, wIndex, data_ptr, data_size, timeout);
return libusb_control_transfer(dev_handle, (uint8_t) bmRequestType,
(uint8_t) bRequest, (uint16_t) wValue, (uint16_t) wIndex, data_ptr,
(uint16_t) data_size, (unsigned int) timeout);
}
/**
@ -770,8 +771,8 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, bulkTransfer)
int sent;
jlong data_size = (*env)->GetDirectBufferCapacity(env, data);
int result = libusb_bulk_transfer(dev_handle, endpoint, data_ptr, data_size, &sent,
timeout);
int result = libusb_bulk_transfer(dev_handle, (unsigned char) endpoint,
data_ptr, (int) data_size, &sent, (unsigned int) timeout);
if (result == LIBUSB_SUCCESS)
{
jclass cls = (*env)->GetObjectClass(env, transferred);
@ -800,8 +801,8 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, interruptTransfer)
int sent;
jlong data_size = (*env)->GetDirectBufferCapacity(env, data);
int result = libusb_interrupt_transfer(dev_handle, endpoint, data_ptr, data_size,
&sent, timeout);
int result = libusb_interrupt_transfer(dev_handle, (unsigned char) endpoint,
data_ptr, (int) data_size, &sent, (unsigned int) timeout);
if (result == LIBUSB_SUCCESS)
{
jclass cls = (*env)->GetObjectClass(env, transferred);
@ -922,8 +923,8 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, waitForEvent)
if (!ctx && context) return 0;
struct timeval tv;
tv.tv_sec = timeout / 1000000;
tv.tv_usec = timeout % 1000000;
tv.tv_sec = (long int) timeout / 1000000;
tv.tv_usec = (long int) timeout % 1000000;
return libusb_wait_for_event(ctx, &tv);
}
@ -938,7 +939,8 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, handleEventsTimeoutCompleted)
)
{
int *complete = NULL;
if (completed) {
if (completed)
{
DIRECT_BUFFER(env, completed, complete_tmp, return 0);
complete = (int *) complete_tmp;
}
@ -947,8 +949,8 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, handleEventsTimeoutCompleted)
if (!ctx && context) return 0;
struct timeval tv;
tv.tv_sec = timeout / 1000000;
tv.tv_usec = timeout % 1000000;
tv.tv_sec = (long int) timeout / 1000000;
tv.tv_usec = (long int) timeout % 1000000;
return libusb_handle_events_timeout_completed(ctx, &tv, complete);
}
@ -965,8 +967,8 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, handleEventsTimeout)
if (!ctx && context) return 0;
struct timeval tv;
tv.tv_sec = timeout / 1000000;
tv.tv_usec = timeout % 1000000;
tv.tv_sec = (long int) timeout / 1000000;
tv.tv_usec = (long int) timeout % 1000000;
return libusb_handle_events_timeout(ctx, &tv);
}
@ -994,7 +996,8 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, handleEventsCompleted)
)
{
int *complete = NULL;
if (completed) {
if (completed)
{
DIRECT_BUFFER(env, completed, complete_tmp, return 0);
complete = (int *) complete_tmp;
}
@ -1017,8 +1020,8 @@ JNIEXPORT jint JNICALL METHOD_NAME(LibUsb, handleEventsLocked)
if (!ctx && context) return 0;
struct timeval tv;
tv.tv_sec = timeout / 1000000;
tv.tv_usec = timeout % 1000000;
tv.tv_sec = (long int) timeout / 1000000;
tv.tv_usec = (long int) timeout % 1000000;
return libusb_handle_events_locked(ctx, &tv);
}
@ -1145,7 +1148,7 @@ JNIEXPORT jobject JNICALL METHOD_NAME(LibUsb, allocTransfer)
}
transfer->user_data = transferData;
transferData->maxNumIsoPackets = isoPackets;
transferData->maxNumIsoPackets = (size_t) isoPackets;
jobject transferObject = wrapTransfer(env, transfer);

View File

@ -1,10 +1,9 @@
lib_LTLIBRARIES = libusb4java.la
libusb4java_la_CFLAGS = -Wall -Werror $(LIBUSB_CFLAGS)
libusb4java_la_CFLAGS = -pedantic -Wall -Wextra -Wformat=2 -Winit-self -Wunused -Wno-unused-parameter -Wuninitialized -Wundef -Wshadow -Wbad-function-cast -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wlogical-op -Wstrict-prototypes -Wredundant-decls -Wnested-externs $(LIBUSB_CFLAGS)
libusb4java_la_LIBADD = $(LIBUSB_LIBS)
libusb4java_la_LDFLAGS = -version-info 1:0:0 -no-undefined
EXTRA_DIST = *.h
libusb4java_la_SOURCES = \
wrappers.c \
usb4java.c \
LibUsb.c \
Version.c \

View File

@ -40,9 +40,8 @@ JNIEXPORT void JNICALL METHOD_NAME(Transfer, setDevHandle)
JNIEnv *env, jobject this, jobject handle
)
{
NOT_NULL(env, handle, return);
libusb_device_handle *dev_handle = unwrapDeviceHandle(env, handle);
if (!dev_handle) return;
if (!dev_handle && handle) return;
struct libusb_transfer *transfer = unwrapTransfer(env, this);
if (!transfer) return;
@ -74,7 +73,7 @@ JNIEXPORT void JNICALL METHOD_NAME(Transfer, setFlags)
struct libusb_transfer *transfer = unwrapTransfer(env, this);
if (!transfer) return;
transfer->flags = flags;
transfer->flags = (uint8_t) flags;
}
/**
@ -88,7 +87,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(Transfer, flags)
struct libusb_transfer *transfer = unwrapTransfer(env, this);
if (!transfer) return 0;
return transfer->flags;
return (jbyte) transfer->flags;
}
/**
@ -102,7 +101,7 @@ JNIEXPORT void JNICALL METHOD_NAME(Transfer, setEndpoint)
struct libusb_transfer *transfer = unwrapTransfer(env, this);
if (!transfer) return;
transfer->endpoint = endpoint;
transfer->endpoint = (unsigned char) endpoint;
}
/**
@ -116,7 +115,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(Transfer, endpoint)
struct libusb_transfer *transfer = unwrapTransfer(env, this);
if (!transfer) return 0;
return transfer->endpoint;
return (jbyte) transfer->endpoint;
}
/**
@ -130,7 +129,7 @@ JNIEXPORT void JNICALL METHOD_NAME(Transfer, setType)
struct libusb_transfer *transfer = unwrapTransfer(env, this);
if (!transfer) return;
transfer->type = type;
transfer->type = (unsigned char) type;
}
/**
@ -144,7 +143,7 @@ JNIEXPORT jbyte JNICALL METHOD_NAME(Transfer, type)
struct libusb_transfer *transfer = unwrapTransfer(env, this);
if (!transfer) return 0;
return transfer->type;
return (jbyte) transfer->type;
}
/**
@ -158,7 +157,7 @@ JNIEXPORT void JNICALL METHOD_NAME(Transfer, setTimeout)
struct libusb_transfer *transfer = unwrapTransfer(env, this);
if (!transfer) return;
transfer->timeout = timeout;
transfer->timeout = (unsigned int) timeout;
}
/**
@ -172,7 +171,7 @@ JNIEXPORT jint JNICALL METHOD_NAME(Transfer, timeout)
struct libusb_transfer *transfer = unwrapTransfer(env, this);
if (!transfer) return 0;
return transfer->timeout;
return (jint) transfer->timeout;
}
/**
@ -430,8 +429,13 @@ JNIEXPORT void JNICALL METHOD_NAME(Transfer, setBufferNative)
JNIEnv *env, jobject this, jobject buffer
)
{
NOT_NULL(env, buffer, return);
DIRECT_BUFFER(env, buffer, buffer_ptr, return);
unsigned char *buffer_ptr = NULL;
if (buffer)
{
DIRECT_BUFFER(env, buffer, buffer_tmp, return);
buffer_ptr = buffer_tmp;
}
struct libusb_transfer *transfer = unwrapTransfer(env, this);
if (!transfer) return;
@ -452,7 +456,7 @@ JNIEXPORT void JNICALL METHOD_NAME(Transfer, setNumIsoPackets)
// Check that calls to setNumIsoPackets() never set a number exceeding
// the maximum, which was originally set at allocTransfer() time.
if (((struct transfer_data *) transfer->user_data)->maxNumIsoPackets
< numIsoPackets)
< (size_t) numIsoPackets)
{
illegalArgument(env,
"numIsoPackets exceeds maximum allowed number set with allocTransfer()");

View File

@ -7,13 +7,13 @@
JavaVM *jvm = NULL;
jint illegalArgument(JNIEnv *env, char *message)
jint illegalArgument(JNIEnv *env, const char *message)
{
jclass cls = (*env)->FindClass(env, "java/lang/IllegalArgumentException");
return (*env)->ThrowNew(env, cls, message);
}
jint illegalState(JNIEnv *env, char *message)
jint illegalState(JNIEnv *env, const char *message)
{
jclass cls = (*env)->FindClass(env, "java/lang/IllegalStateException");
return (*env)->ThrowNew(env, cls, message);

View File

@ -86,7 +86,7 @@
extern JavaVM *jvm;
jint illegalArgument(JNIEnv *env, char *message);
jint illegalState(JNIEnv *env, char *message);
jint illegalArgument(JNIEnv *env, const char *message);
jint illegalState(JNIEnv *env, const char *message);
#endif

View File

@ -1,15 +0,0 @@
/*
* Copyright (C) 2013 Klaus Reimer (k@ailis.de)
* See COPYING file for copying conditions
*/
#include <string.h>
// Enforce usage of older memcpy to be compatible with older libc versions
#if 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

View File

@ -248,8 +248,15 @@ public final class Transfer
// Native call.
setBufferNative(buffer);
// Set new length. The native call above ensures that buffer isn't null.
setLengthNative(buffer.capacity());
if (buffer != null)
{
// Set new length based on buffer's capacity.
setLengthNative(buffer.capacity());
}
else
{
setLengthNative(0);
}
// Once we know the native calls have gone through, update the
// reference.