core: Convert internal macros to static inline functions
authorChris Dickens <christopher.a.dickens@gmail.com>
Sat, 25 Jan 2020 20:10:04 +0000 (12:10 -0800)
committerChris Dickens <christopher.a.dickens@gmail.com>
Sat, 25 Jan 2020 20:10:04 +0000 (12:10 -0800)
Older versions of the Visual Studio compiler are picky about macros
constructed with the 'do { ... } while (0)' construct. Convert these
internal ones to static inline functions. The result is functionally
equivalent but gets us type checking and a bit more readability.

Also address some compiler warnings due to some header files that are
being included in a different order than before.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
12 files changed:
libusb/core.c
libusb/hotplug.c
libusb/io.c
libusb/libusbi.h
libusb/os/poll_windows.c
libusb/os/poll_windows.h
libusb/os/threads_windows.c
libusb/os/threads_windows.h
libusb/os/windows_winusb.c
libusb/os/windows_winusb.h
libusb/version_nano.h
msvc/config.h

index 9ec9246..2282a38 100644 (file)
@@ -800,12 +800,14 @@ ssize_t API_EXPORTED libusb_get_device_list(libusb_context *ctx,
        struct libusb_device **ret;
        int r = 0;
        ssize_t i, len;
-       USBI_GET_CONTEXT(ctx);
+
        usbi_dbg(" ");
 
        if (!discdevs)
                return LIBUSB_ERROR_NO_MEM;
 
+       ctx = usbi_get_context(ctx);
+
        if (libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG)) {
                /* backend provides hotplug support */
                struct libusb_device *dev;
@@ -1254,9 +1256,10 @@ int API_EXPORTED libusb_wrap_sys_device(libusb_context *ctx, intptr_t sys_dev,
        struct libusb_device_handle *_dev_handle;
        size_t priv_size = usbi_backend.device_handle_priv_size;
        int r;
+
        usbi_dbg("wrap_sys_device %p", (void *)sys_dev);
 
-       USBI_GET_CONTEXT(ctx);
+       ctx = usbi_get_context(ctx);
 
        if (!usbi_backend.wrap_sys_device)
                return LIBUSB_ERROR_NOT_SUPPORTED;
@@ -2095,7 +2098,7 @@ int API_EXPORTED libusb_set_auto_detach_kernel_driver(
 void API_EXPORTED libusb_set_debug(libusb_context *ctx, int level)
 {
 #if defined(ENABLE_LOGGING) && !defined(ENABLE_DEBUG_LOGGING)
-       USBI_GET_CONTEXT(ctx);
+       ctx = usbi_get_context(ctx);
        if (!ctx->debug_fixed) {
                level = CLAMP(level, LIBUSB_LOG_LEVEL_NONE, LIBUSB_LOG_LEVEL_DEBUG);
                ctx->debug = (enum libusb_log_level)level;
@@ -2137,7 +2140,7 @@ void API_EXPORTED libusb_set_log_cb(libusb_context *ctx, libusb_log_cb cb,
 #endif
 #if !defined(ENABLE_DEBUG_LOGGING)
        if (mode & LIBUSB_LOG_CB_CONTEXT) {
-               USBI_GET_CONTEXT(ctx);
+               ctx = usbi_get_context(ctx);
                ctx->log_handler = cb;
        }
 #else
@@ -2175,7 +2178,7 @@ int API_EXPORTED libusb_set_option(libusb_context *ctx,
        int arg, r = LIBUSB_SUCCESS;
        va_list ap;
 
-       USBI_GET_CONTEXT(ctx);
+       ctx = usbi_get_context(ctx);
 
        va_start(ap, option);
        switch (option) {
@@ -2358,7 +2361,8 @@ void API_EXPORTED libusb_exit(struct libusb_context *ctx)
        int destroying_default_context = 0;
 
        usbi_dbg(" ");
-       USBI_GET_CONTEXT(ctx);
+
+       ctx = usbi_get_context(ctx);
 
        /* if working with default context, only actually do the deinitialization
         * if we're the last user */
@@ -2564,7 +2568,7 @@ void usbi_log_v(struct libusb_context *ctx, enum libusb_log_level level,
 #else
        enum libusb_log_level ctx_level = LIBUSB_LOG_LEVEL_NONE;
 
-       USBI_GET_CONTEXT(ctx);
+       ctx = usbi_get_context(ctx);
        if (ctx)
                ctx_level = ctx->debug;
        else
index 71ec3fb..85e161c 100644 (file)
@@ -243,7 +243,7 @@ int API_EXPORTED libusb_hotplug_register_callback(libusb_context *ctx,
                return LIBUSB_ERROR_NOT_SUPPORTED;
        }
 
-       USBI_GET_CONTEXT(ctx);
+       ctx = usbi_get_context(ctx);
 
        new_callback = calloc(1, sizeof(*new_callback));
        if (!new_callback) {
@@ -319,10 +319,10 @@ void API_EXPORTED libusb_hotplug_deregister_callback(struct libusb_context *ctx,
                return;
        }
 
-       USBI_GET_CONTEXT(ctx);
-
        usbi_dbg("deregister hotplug cb %d", callback_handle);
 
+       ctx = usbi_get_context(ctx);
+
        usbi_mutex_lock(&ctx->hotplug_cbs_lock);
        list_for_each_entry(hotplug_cb, &ctx->hotplug_cbs, list, struct libusb_hotplug_callback) {
                if (callback_handle == hotplug_cb->handle) {
@@ -357,10 +357,10 @@ void * LIBUSB_CALL libusb_hotplug_get_user_data(struct libusb_context *ctx,
                return NULL;
        }
 
-       USBI_GET_CONTEXT(ctx);
-
        usbi_dbg("get hotplug user data %d", callback_handle);
 
+       ctx = usbi_get_context(ctx);
+
        usbi_mutex_lock(&ctx->hotplug_cbs_lock);
        list_for_each_entry(hotplug_cb, &ctx->hotplug_cbs, list, struct libusb_hotplug_callback) {
                if (callback_handle == hotplug_cb->handle) {
index 4d0971b..883c4e1 100644 (file)
@@ -1752,7 +1752,8 @@ int API_EXPORTED libusb_try_lock_events(libusb_context *ctx)
 {
        int r;
        unsigned int ru;
-       USBI_GET_CONTEXT(ctx);
+
+       ctx = usbi_get_context(ctx);
 
        /* is someone else waiting to close a device? if so, don't let this thread
         * start event handling */
@@ -1792,7 +1793,7 @@ int API_EXPORTED libusb_try_lock_events(libusb_context *ctx)
  */
 void API_EXPORTED libusb_lock_events(libusb_context *ctx)
 {
-       USBI_GET_CONTEXT(ctx);
+       ctx = usbi_get_context(ctx);
        usbi_mutex_lock(&ctx->events_lock);
        ctx->event_handler_active = 1;
 }
@@ -1807,7 +1808,7 @@ void API_EXPORTED libusb_lock_events(libusb_context *ctx)
  */
 void API_EXPORTED libusb_unlock_events(libusb_context *ctx)
 {
-       USBI_GET_CONTEXT(ctx);
+       ctx = usbi_get_context(ctx);
        ctx->event_handler_active = 0;
        usbi_mutex_unlock(&ctx->events_lock);
 
@@ -1843,7 +1844,8 @@ void API_EXPORTED libusb_unlock_events(libusb_context *ctx)
 int API_EXPORTED libusb_event_handling_ok(libusb_context *ctx)
 {
        unsigned int r;
-       USBI_GET_CONTEXT(ctx);
+
+       ctx = usbi_get_context(ctx);
 
        /* is someone else waiting to close a device? if so, don't let this thread
         * continue event handling */
@@ -1871,7 +1873,8 @@ int API_EXPORTED libusb_event_handling_ok(libusb_context *ctx)
 int API_EXPORTED libusb_event_handler_active(libusb_context *ctx)
 {
        unsigned int r;
-       USBI_GET_CONTEXT(ctx);
+
+       ctx = usbi_get_context(ctx);
 
        /* is someone else waiting to close a device? if so, don't let this thread
         * start event handling -- indicate that event handling is happening */
@@ -1899,9 +1902,10 @@ int API_EXPORTED libusb_event_handler_active(libusb_context *ctx)
 void API_EXPORTED libusb_interrupt_event_handler(libusb_context *ctx)
 {
        int pending_events;
-       USBI_GET_CONTEXT(ctx);
 
        usbi_dbg(" ");
+
+       ctx = usbi_get_context(ctx);
        usbi_mutex_lock(&ctx->event_data_lock);
 
        pending_events = usbi_pending_events(ctx);
@@ -1933,7 +1937,7 @@ void API_EXPORTED libusb_interrupt_event_handler(libusb_context *ctx)
  */
 void API_EXPORTED libusb_lock_event_waiters(libusb_context *ctx)
 {
-       USBI_GET_CONTEXT(ctx);
+       ctx = usbi_get_context(ctx);
        usbi_mutex_lock(&ctx->event_waiters_lock);
 }
 
@@ -1944,7 +1948,7 @@ void API_EXPORTED libusb_lock_event_waiters(libusb_context *ctx)
  */
 void API_EXPORTED libusb_unlock_event_waiters(libusb_context *ctx)
 {
-       USBI_GET_CONTEXT(ctx);
+       ctx = usbi_get_context(ctx);
        usbi_mutex_unlock(&ctx->event_waiters_lock);
 }
 
@@ -1977,7 +1981,7 @@ int API_EXPORTED libusb_wait_for_event(libusb_context *ctx, struct timeval *tv)
 {
        int r;
 
-       USBI_GET_CONTEXT(ctx);
+       ctx = usbi_get_context(ctx);
        if (tv == NULL) {
                usbi_cond_wait(&ctx->event_waiters_cond, &ctx->event_waiters_lock);
                return 0;
@@ -2052,7 +2056,8 @@ static int handle_timeouts_locked(struct libusb_context *ctx)
 static int handle_timeouts(struct libusb_context *ctx)
 {
        int r;
-       USBI_GET_CONTEXT(ctx);
+
+       ctx = usbi_get_context(ctx);
        usbi_mutex_lock(&ctx->flying_transfers_lock);
        r = handle_timeouts_locked(ctx);
        usbi_mutex_unlock(&ctx->flying_transfers_lock);
@@ -2369,7 +2374,7 @@ int API_EXPORTED libusb_handle_events_timeout_completed(libusb_context *ctx,
        int r;
        struct timeval poll_timeout;
 
-       USBI_GET_CONTEXT(ctx);
+       ctx = usbi_get_context(ctx);
        r = get_next_timeout(ctx, tv, &poll_timeout);
        if (r) {
                /* timeout already expired */
@@ -2506,7 +2511,7 @@ int API_EXPORTED libusb_handle_events_locked(libusb_context *ctx,
        int r;
        struct timeval poll_timeout;
 
-       USBI_GET_CONTEXT(ctx);
+       ctx = usbi_get_context(ctx);
        r = get_next_timeout(ctx, tv, &poll_timeout);
        if (r) {
                /* timeout already expired */
@@ -2547,7 +2552,7 @@ int API_EXPORTED libusb_handle_events_locked(libusb_context *ctx,
 int API_EXPORTED libusb_pollfds_handle_timeouts(libusb_context *ctx)
 {
 #ifdef HAVE_TIMERFD
-       USBI_GET_CONTEXT(ctx);
+       ctx = usbi_get_context(ctx);
        return usbi_using_timerfd(ctx);
 #else
        UNUSED(ctx);
@@ -2592,7 +2597,7 @@ int API_EXPORTED libusb_get_next_timeout(libusb_context *ctx,
        struct timeval next_timeout = { 0, 0 };
        int r;
 
-       USBI_GET_CONTEXT(ctx);
+       ctx = usbi_get_context(ctx);
        if (usbi_using_timerfd(ctx))
                return 0;
 
@@ -2665,7 +2670,7 @@ void API_EXPORTED libusb_set_pollfd_notifiers(libusb_context *ctx,
        libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb,
        void *user_data)
 {
-       USBI_GET_CONTEXT(ctx);
+       ctx = usbi_get_context(ctx);
        ctx->fd_added_cb = added_cb;
        ctx->fd_removed_cb = removed_cb;
        ctx->fd_cb_user_data = user_data;
@@ -2763,7 +2768,8 @@ const struct libusb_pollfd ** LIBUSB_CALL libusb_get_pollfds(
        struct libusb_pollfd **ret = NULL;
        struct usbi_pollfd *ipollfd;
        size_t i = 0;
-       USBI_GET_CONTEXT(ctx);
+
+       ctx = usbi_get_context(ctx);
 
        usbi_mutex_lock(&ctx->event_data_lock);
 
index 68bbaae..62246cb 100644 (file)
@@ -234,6 +234,7 @@ static inline void *usbi_reallocf(void *ptr, size_t size)
 #ifdef ENABLE_LOGGING
 
 #if defined(_MSC_VER) && (_MSC_VER < 1900)
+#include <stdio.h>
 #define snprintf usbi_snprintf
 #define vsnprintf usbi_vsnprintf
 int usbi_snprintf(char *dst, size_t size, const char *format, ...);
@@ -263,12 +264,6 @@ void usbi_log_v(struct libusb_context *ctx, enum libusb_log_level level,
 
 #endif /* ENABLE_LOGGING */
 
-#define USBI_GET_CONTEXT(ctx)                          \
-       do {                                            \
-               if (!(ctx))                             \
-                       (ctx) = usbi_default_context;   \
-       } while(0)
-
 #define DEVICE_CTX(dev)                ((dev)->ctx)
 #define HANDLE_CTX(handle)     (DEVICE_CTX((handle)->dev))
 #define TRANSFER_CTX(transfer) (HANDLE_CTX((transfer)->dev_handle))
@@ -369,6 +364,13 @@ struct libusb_context {
        PTR_ALIGNED unsigned char os_priv[ZERO_SIZED_ARRAY];
 };
 
+extern struct libusb_context *usbi_default_context;
+
+static inline struct libusb_context *usbi_get_context(struct libusb_context *ctx)
+{
+       return ctx ? ctx : usbi_default_context;
+}
+
 enum usbi_event_flags {
        /* The list of pollfds has been modified */
        USBI_EVENT_POLLFDS_MODIFIED = 1U << 0,
@@ -381,25 +383,39 @@ enum usbi_event_flags {
 };
 
 /* Macros for managing event handling state */
-#define usbi_handling_events(ctx) \
-       (usbi_tls_key_get((ctx)->event_handling_key) != NULL)
+static inline int usbi_handling_events(struct libusb_context *ctx)
+{
+       return usbi_tls_key_get(ctx->event_handling_key) != NULL;
+}
 
-#define usbi_start_event_handling(ctx) \
-       usbi_tls_key_set((ctx)->event_handling_key, ctx)
+static inline void usbi_start_event_handling(struct libusb_context *ctx)
+{
+       usbi_tls_key_set(ctx->event_handling_key, ctx);
+}
 
-#define usbi_end_event_handling(ctx) \
-       usbi_tls_key_set((ctx)->event_handling_key, NULL)
+static inline void usbi_end_event_handling(struct libusb_context *ctx)
+{
+       usbi_tls_key_set(ctx->event_handling_key, NULL);
+}
 
-/* Update the following macro if new event sources are added */
-#define usbi_pending_events(ctx) \
-       ((ctx)->event_flags || (ctx)->device_close \
-        || !list_empty(&(ctx)->hotplug_msgs) || !list_empty(&(ctx)->completed_transfers))
+/* Update the following function if new event sources are added */
+static inline int usbi_pending_events(struct libusb_context *ctx)
+{
+       return ctx->event_flags ||
+              ctx->device_close ||
+              !list_empty(&ctx->hotplug_msgs) ||
+              !list_empty(&ctx->completed_transfers);
+}
 
+static inline int usbi_using_timerfd(struct libusb_context *ctx)
+{
 #ifdef HAVE_TIMERFD
-#define usbi_using_timerfd(ctx) ((ctx)->timerfd >= 0)
+       return ctx->timerfd >= 0);
 #else
-#define usbi_using_timerfd(ctx) (0)
+       UNUSED(ctx);
+       return 0;
 #endif
+}
 
 struct libusb_device {
        /* lock protects refcnt, everything else is finalized at initialization
@@ -1173,8 +1189,6 @@ extern const struct usbi_os_backend usbi_backend;
 extern struct list_head active_contexts_list;
 extern usbi_mutex_static_t active_contexts_lock;
 
-extern struct libusb_context *usbi_default_context;
-
 #ifdef __cplusplus
 }
 #endif
index bd8ac67..afcc233 100644 (file)
  * with a fake pipe. The read/write functions are only meant to be used in that
  * context.
  */
-#include <config.h>
 
-#include <assert.h>
+#include "libusbi.h"
+
 #include <errno.h>
 #include <intrin.h>
 #include <malloc.h>
+#include <stdbool.h>
 #include <stdlib.h>
 
-#include "libusbi.h"
-#include "windows_common.h"
-
 // public fd data
 const struct winfd INVALID_WINFD = { -1, NULL };
 
@@ -135,7 +133,7 @@ static int install_fd(struct file_descriptor *fd)
 
        for (n = 0; n < fd_table_size; n += BITMAP_BITS_PER_WORD) {
                unsigned int idx = n / BITMAP_BITS_PER_WORD;
-               unsigned long mask, pos;
+               unsigned long mask, pos = 0UL;
 
                mask = ~fd_table_bitmap[idx];
                if (mask == 0UL)
index c78c9d3..b2c94f9 100644 (file)
@@ -67,23 +67,16 @@ int usbi_close(int fd);
 /*
  * Timeval operations
  */
-#if !defined(TIMESPEC_TO_TIMEVAL)
-#define TIMESPEC_TO_TIMEVAL(tv, ts)                            \
-do {                                                           \
-       (tv)->tv_sec = (long)(ts)->tv_sec;                      \
-       (tv)->tv_usec = (long)(ts)->tv_nsec / 1000;             \
-} while (0)
-#endif
 #if !defined(timersub)
-#define timersub(a, b, result)                                 \
-do {                                                           \
-       (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;           \
-       (result)->tv_usec = (a)->tv_usec - (b)->tv_usec;        \
-       if ((result)->tv_usec < 0) {                            \
-               --(result)->tv_sec;                             \
-               (result)->tv_usec += 1000000;                   \
-       }                                                       \
-} while (0)
+#define timersub(a, b, result)                                         \
+       do {                                                            \
+               (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;           \
+               (result)->tv_usec = (a)->tv_usec - (b)->tv_usec;        \
+               if ((result)->tv_usec < 0L) {                           \
+                       --(result)->tv_sec;                             \
+                       (result)->tv_usec += 1000000L;                  \
+               }                                                       \
+       } while (0)
 #endif
 
 #endif
index 81f7945..cf72694 100644 (file)
@@ -21,8 +21,6 @@
 
 #include "libusbi.h"
 
-#include <errno.h>
-
 int usbi_cond_timedwait(usbi_cond_t *cond,
        usbi_mutex_t *mutex, const struct timeval *tv)
 {
index 9bf8ff4..618c2f3 100644 (file)
@@ -21,6 +21,8 @@
 #ifndef LIBUSB_THREADS_WINDOWS_H
 #define LIBUSB_THREADS_WINDOWS_H
 
+#include <errno.h>
+
 #define USBI_MUTEX_INITIALIZER 0L
 typedef LONG usbi_mutex_static_t;
 static inline void usbi_mutex_static_lock(usbi_mutex_static_t *mutex)
index 0279536..efc3f99 100644 (file)
@@ -673,6 +673,8 @@ static void winusb_exit(struct libusb_context *ctx)
 {
        int i;
 
+       UNUSED(ctx);
+
        for (i = 0; i < USB_API_MAX; i++) {
                if (usb_api_backend[i].exit)
                        usb_api_backend[i].exit();
@@ -990,8 +992,8 @@ static int enumerate_hcd_root_hub(struct libusb_context *ctx, const char *dev_id
 }
 
 // Returns the api type, or 0 if not found/unsupported
-static void get_api_type(struct libusb_context *ctx, HDEVINFO *dev_info,
-       SP_DEVINFO_DATA *dev_info_data, int *api, int *sub_api)
+static void get_api_type(HDEVINFO *dev_info, SP_DEVINFO_DATA *dev_info_data,
+       int *api, int *sub_api)
 {
        // Precedence for filter drivers vs driver is in the order of this array
        struct driver_lookup lookup[3] = {
@@ -1367,7 +1369,7 @@ static int winusb_get_device_list(struct libusb_context *ctx, struct discovered_
                                                dev_id, (unsigned int)install_state);
                                        continue;
                                }
-                               get_api_type(ctx, dev_info, &dev_info_data, &api, &sub_api);
+                               get_api_type(dev_info, &dev_info_data, &api, &sub_api);
                                break;
                        }
 
@@ -2031,7 +2033,7 @@ const struct windows_usb_api_backend usb_api_backend[USB_API_MAX] = {
                        pLibK_GetProcAddress((PVOID *)&WinUSBX[i].fn, i, KUSB_FNID_##fn);       \
        } while (0)
 
-#define NativeWinUSBOnly_Set(fn)                                                                       \
+#define NativeWinUSBOnly_Set(fn)                                                               \
        do {                                                                                    \
                if (native_winusb)                                                              \
                        WinUSBX[i].fn = (WinUsb_##fn##_t)GetProcAddress(h, "WinUsb_" #fn);      \
@@ -2900,6 +2902,8 @@ static int winusbx_clear_halt(int sub_api, struct libusb_device_handle *dev_hand
  */
 static int winusbx_abort_control(int sub_api, struct usbi_transfer *itransfer)
 {
+       UNUSED(sub_api);
+       UNUSED(itransfer);
        // Cancelling of the I/O is done in the parent
        return LIBUSB_SUCCESS;
 }
@@ -3310,6 +3314,8 @@ static int _hid_get_report_descriptor(struct hid_device_priv *dev, void *data, s
 static int _hid_get_descriptor(struct hid_device_priv *dev, HANDLE hid_handle, int recipient,
        int type, int _index, void *data, size_t *size)
 {
+       UNUSED(recipient);
+
        switch (type) {
        case LIBUSB_DT_DEVICE:
                usbi_dbg("LIBUSB_DT_DEVICE");
@@ -3350,6 +3356,8 @@ static int _hid_get_report(struct hid_device_priv *dev, HANDLE hid_handle, int i
        DWORD ioctl_code, read_size, expected_size = (DWORD)*size;
        int r = LIBUSB_SUCCESS;
 
+       UNUSED(dev);
+
        if (tp->hid_buffer != NULL)
                usbi_dbg("program assertion failed: hid_buffer is not NULL");
 
@@ -3429,6 +3437,8 @@ static int _hid_set_report(struct hid_device_priv *dev, HANDLE hid_handle, int i
        // If an id is reported, we must allow MAX_HID_REPORT_SIZE + 1
        size_t max_report_size = MAX_HID_REPORT_SIZE + (id ? 1 : 0);
 
+       UNUSED(dev);
+
        if (tp->hid_buffer != NULL)
                usbi_dbg("program assertion failed: hid_buffer is not NULL");
 
@@ -3499,6 +3509,8 @@ static int _hid_class_request(struct hid_device_priv *dev, HANDLE hid_handle, in
        int report_type = (value >> 8) & 0xFF;
        int report_id = value & 0xFF;
 
+       UNUSED(_index);
+
        if ((LIBUSB_REQ_RECIPIENT(request_type) != LIBUSB_RECIPIENT_INTERFACE)
                        && (LIBUSB_REQ_RECIPIENT(request_type) != LIBUSB_RECIPIENT_DEVICE))
                return LIBUSB_ERROR_INVALID_PARAM;
@@ -3518,6 +3530,8 @@ static int _hid_class_request(struct hid_device_priv *dev, HANDLE hid_handle, in
  */
 static int hid_init(struct libusb_context *ctx)
 {
+       UNUSED(ctx);
+
        DLL_GET_HANDLE(hid);
 
        DLL_LOAD_FUNC(hid, HidD_GetAttributes, TRUE);
@@ -3564,6 +3578,7 @@ static int hid_open(int sub_api, struct libusb_device_handle *dev_handle)
        const char * const type[3] = {"input", "output", "feature"};
 #endif
 
+       UNUSED(sub_api);
        CHECK_HID_AVAILABLE;
 
        if (priv->hid == NULL) {
@@ -3704,6 +3719,7 @@ static void hid_close(int sub_api, struct libusb_device_handle *dev_handle)
        HANDLE file_handle;
        int i;
 
+       UNUSED(sub_api);
        if (!api_hid_available)
                return;
 
@@ -3721,6 +3737,7 @@ static int hid_claim_interface(int sub_api, struct libusb_device_handle *dev_han
        struct winusb_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
        struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
 
+       UNUSED(sub_api);
        CHECK_HID_AVAILABLE;
 
        // NB: Disconnection detection is not possible in this function
@@ -3744,6 +3761,7 @@ static int hid_release_interface(int sub_api, struct libusb_device_handle *dev_h
        struct winusb_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
        struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
 
+       UNUSED(sub_api);
        CHECK_HID_AVAILABLE;
 
        if (priv->usb_interface[iface].path == NULL)
@@ -3761,6 +3779,9 @@ static int hid_set_interface_altsetting(int sub_api, struct libusb_device_handle
 {
        struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev);
 
+       UNUSED(sub_api);
+       UNUSED(iface);
+
        CHECK_HID_AVAILABLE;
 
        if (altsetting > 255)
@@ -3788,6 +3809,7 @@ static int hid_submit_control_transfer(int sub_api, struct usbi_transfer *itrans
        size_t size;
        int r = LIBUSB_ERROR_INVALID_PARAM;
 
+       UNUSED(sub_api);
        CHECK_HID_AVAILABLE;
 
        safe_free(transfer_priv->hid_buffer);
@@ -3884,6 +3906,7 @@ static int hid_submit_bulk_transfer(int sub_api, struct usbi_transfer *itransfer
        DWORD size;
        int r = LIBUSB_SUCCESS;
 
+       UNUSED(sub_api);
        CHECK_HID_AVAILABLE;
 
        transfer_priv->hid_dest = NULL;
@@ -3967,6 +3990,7 @@ static int hid_abort_transfers(int sub_api, struct usbi_transfer *itransfer)
        HANDLE hid_handle;
        int current_interface;
 
+       UNUSED(sub_api);
        CHECK_HID_AVAILABLE;
 
        current_interface = transfer_priv->interface_number;
@@ -3992,6 +4016,7 @@ static int hid_reset_device(int sub_api, struct libusb_device_handle *dev_handle
        HANDLE hid_handle;
        int current_interface;
 
+       UNUSED(sub_api);
        CHECK_HID_AVAILABLE;
 
        // Flushing the queues on all interfaces is the best we can achieve
@@ -4012,6 +4037,7 @@ static int hid_clear_halt(int sub_api, struct libusb_device_handle *dev_handle,
        HANDLE hid_handle;
        int current_interface;
 
+       UNUSED(sub_api);
        CHECK_HID_AVAILABLE;
 
        current_interface = interface_by_endpoint(priv, handle_priv, endpoint);
@@ -4043,6 +4069,8 @@ static int hid_copy_transfer_data(int sub_api, struct usbi_transfer *itransfer,
        int r = LIBUSB_TRANSFER_COMPLETED;
        uint32_t corrected_size = io_size;
 
+       UNUSED(sub_api);
+
        if (transfer_priv->hid_buffer != NULL) {
                // If we have a valid hid_buffer, it means the transfer was async
                if (transfer_priv->hid_dest != NULL) { // Data readout
@@ -4084,6 +4112,8 @@ static int composite_open(int sub_api, struct libusb_device_handle *dev_handle)
        // SUB_API_MAX + 1 as the SUB_API_MAX pos is used to indicate availability of HID
        bool available[SUB_API_MAX + 1] = { 0 };
 
+       UNUSED(sub_api);
+
        for (i = 0; i < USB_MAXINTERFACES; i++) {
                switch (priv->usb_interface[i].apib->id) {
                case USB_API_WINUSBX:
@@ -4128,6 +4158,8 @@ static void composite_close(int sub_api, struct libusb_device_handle *dev_handle
        // SUB_API_MAX + 1 as the SUB_API_MAX pos is used to indicate availability of HID
        bool available[SUB_API_MAX + 1] = { 0 };
 
+       UNUSED(sub_api);
+
        for (i = 0; i < USB_MAXINTERFACES; i++) {
                switch (priv->usb_interface[i].apib->id) {
                case USB_API_WINUSBX:
@@ -4155,6 +4187,7 @@ static int composite_claim_interface(int sub_api, struct libusb_device_handle *d
 {
        struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
 
+       UNUSED(sub_api);
        CHECK_SUPPORTED_API(priv->usb_interface[iface].apib, claim_interface);
 
        return priv->usb_interface[iface].apib->
@@ -4165,6 +4198,7 @@ static int composite_set_interface_altsetting(int sub_api, struct libusb_device_
 {
        struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
 
+       UNUSED(sub_api);
        CHECK_SUPPORTED_API(priv->usb_interface[iface].apib, set_interface_altsetting);
 
        return priv->usb_interface[iface].apib->
@@ -4175,6 +4209,7 @@ static int composite_release_interface(int sub_api, struct libusb_device_handle
 {
        struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
 
+       UNUSED(sub_api);
        CHECK_SUPPORTED_API(priv->usb_interface[iface].apib, release_interface);
 
        return priv->usb_interface[iface].apib->
@@ -4190,6 +4225,8 @@ static int composite_submit_control_transfer(int sub_api, struct usbi_transfer *
        WINUSB_SETUP_PACKET *setup = (WINUSB_SETUP_PACKET *)transfer->buffer;
        int iface, pass, r;
 
+       UNUSED(sub_api);
+
        // Interface shouldn't matter for control, but it does in practice, with Windows'
        // restrictions with regards to accessing HID keyboards and mice. Try to target
        // a specific interface first, if possible.
@@ -4252,6 +4289,8 @@ static int composite_submit_bulk_transfer(int sub_api, struct usbi_transfer *itr
        struct winusb_device_priv *priv = _device_priv(transfer->dev_handle->dev);
        int current_interface;
 
+       UNUSED(sub_api);
+
        current_interface = interface_by_endpoint(priv, handle_priv, transfer->endpoint);
        if (current_interface < 0) {
                usbi_err(ctx, "unable to match endpoint to an open interface - cancelling transfer");
@@ -4271,6 +4310,8 @@ static int composite_submit_iso_transfer(int sub_api, struct usbi_transfer *itra
        struct winusb_device_priv *priv = _device_priv(transfer->dev_handle->dev);
        int current_interface;
 
+       UNUSED(sub_api);
+
        current_interface = interface_by_endpoint(priv, handle_priv, transfer->endpoint);
        if (current_interface < 0) {
                usbi_err(ctx, "unable to match endpoint to an open interface - cancelling transfer");
@@ -4290,6 +4331,8 @@ static int composite_clear_halt(int sub_api, struct libusb_device_handle *dev_ha
        struct winusb_device_priv *priv = _device_priv(dev_handle->dev);
        int current_interface;
 
+       UNUSED(sub_api);
+
        current_interface = interface_by_endpoint(priv, handle_priv, endpoint);
        if (current_interface < 0) {
                usbi_err(ctx, "unable to match endpoint to an open interface - cannot clear");
@@ -4309,6 +4352,8 @@ static int composite_abort_control(int sub_api, struct usbi_transfer *itransfer)
        struct winusb_device_priv *priv = _device_priv(transfer->dev_handle->dev);
        int current_interface = transfer_priv->interface_number;
 
+       UNUSED(sub_api);
+
        if ((current_interface < 0) || (current_interface >= USB_MAXINTERFACES)) {
                usbi_err(TRANSFER_CTX(transfer), "program assertion failed: invalid interface_number");
                return LIBUSB_ERROR_NOT_FOUND;
@@ -4327,6 +4372,8 @@ static int composite_abort_transfers(int sub_api, struct usbi_transfer *itransfe
        struct winusb_device_priv *priv = _device_priv(transfer->dev_handle->dev);
        int current_interface = transfer_priv->interface_number;
 
+       UNUSED(sub_api);
+
        if ((current_interface < 0) || (current_interface >= USB_MAXINTERFACES)) {
                usbi_err(TRANSFER_CTX(transfer), "program assertion failed: invalid interface_number");
                return LIBUSB_ERROR_NOT_FOUND;
@@ -4345,6 +4392,8 @@ static int composite_reset_device(int sub_api, struct libusb_device_handle *dev_
        uint8_t i;
        bool available[SUB_API_MAX];
 
+       UNUSED(sub_api);
+
        for (i = 0; i < SUB_API_MAX; i++)
                available[i] = false;
 
@@ -4372,6 +4421,7 @@ static int composite_copy_transfer_data(int sub_api, struct usbi_transfer *itran
        struct winusb_device_priv *priv = _device_priv(transfer->dev_handle->dev);
        int current_interface = transfer_priv->interface_number;
 
+       UNUSED(sub_api);
        CHECK_SUPPORTED_API(priv->usb_interface[current_interface].apib, copy_transfer_data);
 
        return priv->usb_interface[current_interface].apib->
index 245b137..6ac39c3 100644 (file)
 
 #if defined(_MSC_VER)
 // disable /W4 MSVC warnings that are benign
-#pragma warning(disable:4100)  // unreferenced formal parameter
-#pragma warning(disable:4127)  // conditional expression is constant
 #pragma warning(disable:4201)  // nameless struct/union
 #pragma warning(disable:4214)  // bit field types other than int
-#pragma warning(disable:4996)  // deprecated API calls
-#pragma warning(disable:28159) // more deprecated API calls
 #endif
 
 // Missing from MSVC6 setupapi.h
index bda5199..e36b015 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11446
+#define LIBUSB_NANO 11447
index 840c8df..25eb6e2 100644 (file)
 #define _TIMESPEC_DEFINED 1
 #endif
 
+/* Disable: warning C4127: conditional expression is constant */
+#pragma warning(disable:4127)
 /* Disable: warning C4200: nonstandard extension used : zero-sized array in struct/union */
 #pragma warning(disable:4200)
 /* Disable: warning C4324: structure was padded due to __declspec(align()) */
 #pragma warning(disable:4324)
-/* Disable: warning C4996: 'GetVersionA': was declared deprecated */
+/* Disable: warning C4996: 'GetVersionExA': was declared deprecated */
 #pragma warning(disable:4996)
 
 #if defined(_PREFAST_)