From e65878f21b0a0bb96debcb292dc03ce3c4ebb701 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Wed, 19 Jan 2011 13:52:08 +0000 Subject: [PATCH] Windows: Rename various variables named "index" to avoid shadow warnings --- libusb/os/poll_windows.c | 140 +++++++++++++++++++++++------------------------ libusb/os/windows_usb.c | 36 ++++++------ 2 files changed, 88 insertions(+), 88 deletions(-) diff --git a/libusb/os/poll_windows.c b/libusb/os/poll_windows.c index 9ae9895..4eaf328 100644 --- a/libusb/os/poll_windows.c +++ b/libusb/os/poll_windows.c @@ -122,21 +122,21 @@ static volatile LONG compat_spinlock = 0; // platform headers, we hook into the Kernel32 system DLL directly to seek it. static BOOL (__stdcall *pCancelIoEx)(HANDLE, LPOVERLAPPED) = NULL; #define CancelIoEx_Available (pCancelIoEx != NULL) -__inline BOOL cancel_io(int index) +__inline BOOL cancel_io(int _index) { - if ((index < 0) || (index >= MAX_FDS)) { + if ((_index < 0) || (_index >= MAX_FDS)) { return FALSE; } - if ( (poll_fd[index].fd < 0) || (poll_fd[index].handle == INVALID_HANDLE_VALUE) - || (poll_fd[index].handle == 0) || (poll_fd[index].overlapped == NULL) ) { + if ( (poll_fd[_index].fd < 0) || (poll_fd[_index].handle == INVALID_HANDLE_VALUE) + || (poll_fd[_index].handle == 0) || (poll_fd[_index].overlapped == NULL) ) { return TRUE; } if (CancelIoEx_Available) { - return (*pCancelIoEx)(poll_fd[index].handle, poll_fd[index].overlapped); + return (*pCancelIoEx)(poll_fd[_index].handle, poll_fd[_index].overlapped); } - if (_poll_fd[index].thread_id == GetCurrentThreadId()) { - return CancelIo(poll_fd[index].handle); + if (_poll_fd[_index].thread_id == GetCurrentThreadId()) { + return CancelIo(poll_fd[_index].handle); } usbi_warn(NULL, "Unable to cancel I/O that was started from another thread"); return FALSE; @@ -439,25 +439,25 @@ struct winfd usbi_create_fd(HANDLE handle, int access_mode) return INVALID_WINFD; } -void _free_index(int index) +void _free_index(int _index) { // Cancel any async IO (Don't care about the validity of our handles for this) - cancel_io(index); + cancel_io(_index); // close fake handle for devices - if ( (poll_fd[index].handle != INVALID_HANDLE_VALUE) && (poll_fd[index].handle != 0) - && (GetFileType(poll_fd[index].handle) == FILE_TYPE_UNKNOWN) ) { - _close(poll_fd[index].fd); + if ( (poll_fd[_index].handle != INVALID_HANDLE_VALUE) && (poll_fd[_index].handle != 0) + && (GetFileType(poll_fd[_index].handle) == FILE_TYPE_UNKNOWN) ) { + _close(poll_fd[_index].fd); } // close the duplicate handle (if we have an actual duplicate) if (!CancelIoEx_Available) { - if (_poll_fd[index].original_handle != INVALID_HANDLE_VALUE) { - CloseHandle(poll_fd[index].handle); + if (_poll_fd[_index].original_handle != INVALID_HANDLE_VALUE) { + CloseHandle(poll_fd[_index].handle); } - _poll_fd[index].original_handle = INVALID_HANDLE_VALUE; - _poll_fd[index].thread_id = 0; + _poll_fd[_index].original_handle = INVALID_HANDLE_VALUE; + _poll_fd[_index].thread_id = 0; } - free_overlapped(poll_fd[index].overlapped); - poll_fd[index] = INVALID_WINFD; + free_overlapped(poll_fd[_index].overlapped); + poll_fd[_index] = INVALID_WINFD; } /* @@ -467,16 +467,16 @@ void _free_index(int index) */ void usbi_free_fd(int fd) { - int index; + int _index; CHECK_INIT_POLLING; - index = _fd_to_index_and_lock(fd); - if (index < 0) { + _index = _fd_to_index_and_lock(fd); + if (_index < 0) { return; } - _free_index(index); - LeaveCriticalSection(&_poll_fd[index].mutex); + _free_index(_index); + LeaveCriticalSection(&_poll_fd[_index].mutex); } /* @@ -568,7 +568,7 @@ struct winfd overlapped_to_winfd(OVERLAPPED* overlapped) int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout) { unsigned i; - int index, object_index, triggered; + int _index, object_index, triggered; HANDLE *handles_to_wait_on; int *handle_to_index; DWORD nb_handles_to_wait_on = 0; @@ -612,15 +612,15 @@ int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout) goto poll_exit; } - index = _fd_to_index_and_lock(fds[i].fd); - poll_dbg("fd[%d]=%d: (overlapped=%p) got events %04X", i, poll_fd[index].fd, poll_fd[index].overlapped, fds[i].events); + _index = _fd_to_index_and_lock(fds[i].fd); + poll_dbg("fd[%d]=%d: (overlapped=%p) got events %04X", i, poll_fd[_index].fd, poll_fd[_index].overlapped, fds[i].events); - if ( (index < 0) || (poll_fd[index].handle == INVALID_HANDLE_VALUE) - || (poll_fd[index].handle == 0) || (poll_fd[index].overlapped == NULL)) { + if ( (_index < 0) || (poll_fd[_index].handle == INVALID_HANDLE_VALUE) + || (poll_fd[_index].handle == 0) || (poll_fd[_index].overlapped == NULL)) { fds[i].revents |= POLLNVAL | POLLERR; errno = EBADF; - if (index >= 0) { - LeaveCriticalSection(&_poll_fd[index].mutex); + if (_index >= 0) { + LeaveCriticalSection(&_poll_fd[_index].mutex); } usbi_warn(NULL, "invalid fd"); triggered = -1; @@ -628,33 +628,33 @@ int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout) } // IN or OUT must match our fd direction - if ((fds[i].events & POLLIN) && (poll_fd[index].rw != RW_READ)) { + if ((fds[i].events & POLLIN) && (poll_fd[_index].rw != RW_READ)) { fds[i].revents |= POLLNVAL | POLLERR; errno = EBADF; usbi_warn(NULL, "attempted POLLIN on fd without READ access"); - LeaveCriticalSection(&_poll_fd[index].mutex); + LeaveCriticalSection(&_poll_fd[_index].mutex); triggered = -1; goto poll_exit; } - if ((fds[i].events & POLLOUT) && (poll_fd[index].rw != RW_WRITE)) { + if ((fds[i].events & POLLOUT) && (poll_fd[_index].rw != RW_WRITE)) { fds[i].revents |= POLLNVAL | POLLERR; errno = EBADF; usbi_warn(NULL, "attempted POLLOUT on fd without WRITE access"); - LeaveCriticalSection(&_poll_fd[index].mutex); + LeaveCriticalSection(&_poll_fd[_index].mutex); triggered = -1; goto poll_exit; } // The following macro only works if overlapped I/O was reported pending - if ( (HasOverlappedIoCompleted(poll_fd[index].overlapped)) - || (HasOverlappedIoCompletedSync(poll_fd[index].overlapped)) ) { + if ( (HasOverlappedIoCompleted(poll_fd[_index].overlapped)) + || (HasOverlappedIoCompletedSync(poll_fd[_index].overlapped)) ) { poll_dbg(" completed"); // checks above should ensure this works: fds[i].revents = fds[i].events; triggered++; } else { - handles_to_wait_on[nb_handles_to_wait_on] = poll_fd[index].overlapped->hEvent; + handles_to_wait_on[nb_handles_to_wait_on] = poll_fd[_index].overlapped->hEvent; handle_to_index[nb_handles_to_wait_on] = i; #if defined(DYNAMIC_FDS) // If this fd from the poll set is also part of the new_fd event handle table, remove it @@ -669,7 +669,7 @@ int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout) #endif nb_handles_to_wait_on++; } - LeaveCriticalSection(&_poll_fd[index].mutex); + LeaveCriticalSection(&_poll_fd[_index].mutex); } #if defined(DYNAMIC_FDS) // At this stage, new_fd[] should only contain events from fds that @@ -720,11 +720,11 @@ int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout) #endif poll_dbg(" completed after wait"); i = handle_to_index[object_index]; - index = _fd_to_index_and_lock(fds[i].fd); + _index = _fd_to_index_and_lock(fds[i].fd); fds[i].revents = fds[i].events; triggered++; - if (index >= 0) { - LeaveCriticalSection(&_poll_fd[index].mutex); + if (_index >= 0) { + LeaveCriticalSection(&_poll_fd[_index].mutex); } } else if (ret == WAIT_TIMEOUT) { poll_dbg(" timed out"); @@ -755,28 +755,28 @@ poll_exit: */ int usbi_close(int fd) { - int index; + int _index; int r = -1; CHECK_INIT_POLLING; - index = _fd_to_index_and_lock(fd); + _index = _fd_to_index_and_lock(fd); - if (index < 0) { + if (_index < 0) { errno = EBADF; } else { - if (poll_fd[index].overlapped != NULL) { + if (poll_fd[_index].overlapped != NULL) { // Must be a different event for each end of the pipe - CloseHandle(poll_fd[index].overlapped->hEvent); - free(poll_fd[index].overlapped); + CloseHandle(poll_fd[_index].overlapped->hEvent); + free(poll_fd[_index].overlapped); } - if (CloseHandle(poll_fd[index].handle) == 0) { + if (CloseHandle(poll_fd[_index].handle) == 0) { errno = EIO; } else { r = 0; } - poll_fd[index] = INVALID_WINFD; - LeaveCriticalSection(&_poll_fd[index].mutex); + poll_fd[_index] = INVALID_WINFD; + LeaveCriticalSection(&_poll_fd[_index].mutex); } return r; } @@ -786,7 +786,7 @@ int usbi_close(int fd) */ ssize_t usbi_write(int fd, const void *buf, size_t count) { - int index; + int _index; CHECK_INIT_POLLING; @@ -795,24 +795,24 @@ ssize_t usbi_write(int fd, const void *buf, size_t count) return -1; } - index = _fd_to_index_and_lock(fd); + _index = _fd_to_index_and_lock(fd); - if ( (index < 0) || (poll_fd[index].overlapped == NULL) ) { + if ( (_index < 0) || (poll_fd[_index].overlapped == NULL) ) { errno = EBADF; - if (index >= 0) { - LeaveCriticalSection(&_poll_fd[index].mutex); + if (_index >= 0) { + LeaveCriticalSection(&_poll_fd[_index].mutex); } return -1; } - poll_dbg("set pipe event (fd = %d, thread = %08X)", index, GetCurrentThreadId()); - SetEvent(poll_fd[index].overlapped->hEvent); - poll_fd[index].overlapped->Internal = STATUS_WAIT_0; + poll_dbg("set pipe event (fd = %d, thread = %08X)", _index, GetCurrentThreadId()); + SetEvent(poll_fd[_index].overlapped->hEvent); + poll_fd[_index].overlapped->Internal = STATUS_WAIT_0; // If two threads write on the pipe at the same time, we need to // process two separate reads => use the overlapped as a counter - poll_fd[index].overlapped->InternalHigh++; + poll_fd[_index].overlapped->InternalHigh++; - LeaveCriticalSection(&_poll_fd[index].mutex); + LeaveCriticalSection(&_poll_fd[_index].mutex); return sizeof(unsigned char); } @@ -821,7 +821,7 @@ ssize_t usbi_write(int fd, const void *buf, size_t count) */ ssize_t usbi_read(int fd, void *buf, size_t count) { - int index; + int _index; ssize_t r = -1; CHECK_INIT_POLLING; @@ -831,30 +831,30 @@ ssize_t usbi_read(int fd, void *buf, size_t count) return -1; } - index = _fd_to_index_and_lock(fd); + _index = _fd_to_index_and_lock(fd); - if (index < 0) { + if (_index < 0) { errno = EBADF; return -1; } - if (WaitForSingleObject(poll_fd[index].overlapped->hEvent, INFINITE) != WAIT_OBJECT_0) { + if (WaitForSingleObject(poll_fd[_index].overlapped->hEvent, INFINITE) != WAIT_OBJECT_0) { usbi_warn(NULL, "waiting for event failed: %d", (int)GetLastError()); errno = EIO; goto out; } - poll_dbg("clr pipe event (fd = %d, thread = %08X)", index, GetCurrentThreadId()); - poll_fd[index].overlapped->InternalHigh--; + poll_dbg("clr pipe event (fd = %d, thread = %08X)", _index, GetCurrentThreadId()); + poll_fd[_index].overlapped->InternalHigh--; // Don't reset unless we don't have any more events to process - if (poll_fd[index].overlapped->InternalHigh <= 0) { - ResetEvent(poll_fd[index].overlapped->hEvent); - poll_fd[index].overlapped->Internal = STATUS_PENDING; + if (poll_fd[_index].overlapped->InternalHigh <= 0) { + ResetEvent(poll_fd[_index].overlapped->hEvent); + poll_fd[_index].overlapped->Internal = STATUS_PENDING; } r = sizeof(unsigned char); out: - LeaveCriticalSection(&_poll_fd[index].mutex); + LeaveCriticalSection(&_poll_fd[_index].mutex); return r; } diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c index 83a4606..dc0d0ae 100644 --- a/libusb/os/windows_usb.c +++ b/libusb/os/windows_usb.c @@ -283,13 +283,13 @@ static int Cfgmgr32_init(void) * incremented index starting at zero) until all interfaces have been returned. */ SP_DEVICE_INTERFACE_DETAIL_DATA *get_interface_details(struct libusb_context *ctx, - HDEVINFO *dev_info, SP_DEVINFO_DATA *dev_info_data, GUID guid, unsigned index) + HDEVINFO *dev_info, SP_DEVINFO_DATA *dev_info_data, GUID guid, unsigned _index) { SP_DEVICE_INTERFACE_DATA dev_interface_data; SP_DEVICE_INTERFACE_DETAIL_DATA *dev_interface_details = NULL; DWORD size; - if (index <= 0) { + if (_index <= 0) { *dev_info = SetupDiGetClassDevs(&guid, NULL, NULL, DIGCF_PRESENT|DIGCF_DEVICEINTERFACE); } if (*dev_info == INVALID_HANDLE_VALUE) { @@ -298,10 +298,10 @@ SP_DEVICE_INTERFACE_DETAIL_DATA *get_interface_details(struct libusb_context *ct if (dev_info_data != NULL) { dev_info_data->cbSize = sizeof(SP_DEVINFO_DATA); - if (!SetupDiEnumDeviceInfo(*dev_info, index, dev_info_data)) { + if (!SetupDiEnumDeviceInfo(*dev_info, _index, dev_info_data)) { if (GetLastError() != ERROR_NO_MORE_ITEMS) { usbi_err(ctx, "Could not obtain device info data for index %u: %s", - index, windows_error_str(0)); + _index, windows_error_str(0)); } SetupDiDestroyDeviceInfoList(*dev_info); *dev_info = INVALID_HANDLE_VALUE; @@ -310,10 +310,10 @@ SP_DEVICE_INTERFACE_DETAIL_DATA *get_interface_details(struct libusb_context *ct } dev_interface_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); - if (!SetupDiEnumDeviceInterfaces(*dev_info, NULL, &guid, index, &dev_interface_data)) { + if (!SetupDiEnumDeviceInterfaces(*dev_info, NULL, &guid, _index, &dev_interface_data)) { if (GetLastError() != ERROR_NO_MORE_ITEMS) { usbi_err(ctx, "Could not obtain interface data for index %u: %s", - index, windows_error_str(0)); + _index, windows_error_str(0)); } SetupDiDestroyDeviceInfoList(*dev_info); *dev_info = INVALID_HANDLE_VALUE; @@ -325,7 +325,7 @@ SP_DEVICE_INTERFACE_DETAIL_DATA *get_interface_details(struct libusb_context *ct // The dummy call should fail with ERROR_INSUFFICIENT_BUFFER if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { usbi_err(ctx, "could not access interface data (dummy) for index %u: %s", - index, windows_error_str(0)); + _index, windows_error_str(0)); goto err_exit; } } @@ -335,7 +335,7 @@ SP_DEVICE_INTERFACE_DETAIL_DATA *get_interface_details(struct libusb_context *ct } if ((dev_interface_details = malloc(size)) == NULL) { - usbi_err(ctx, "could not allocate interface data for index %u.", index); + usbi_err(ctx, "could not allocate interface data for index %u.", _index); goto err_exit; } @@ -343,7 +343,7 @@ SP_DEVICE_INTERFACE_DETAIL_DATA *get_interface_details(struct libusb_context *ct if (!SetupDiGetDeviceInterfaceDetail(*dev_info, &dev_interface_data, dev_interface_details, size, &size, NULL)) { usbi_err(ctx, "could not access interface data (actual) for index %u: %s", - index, windows_error_str(0)); + _index, windows_error_str(0)); } return dev_interface_details; @@ -3058,7 +3058,7 @@ static int _hid_get_config_descriptor(struct hid_device_priv* dev, void *data, s return LIBUSB_COMPLETED; } -static int _hid_get_string_descriptor(struct hid_device_priv* dev, int index, +static int _hid_get_string_descriptor(struct hid_device_priv* dev, int _index, void *data, size_t *size) { void *tmp = NULL; @@ -3075,12 +3075,12 @@ static int _hid_get_string_descriptor(struct hid_device_priv* dev, int index, return LIBUSB_ERROR_OVERFLOW; } - if (index == 0) { + if (_index == 0) { tmp = string_langid; tmp_size = sizeof(string_langid)+2; } else { for (i=0; i<3; i++) { - if (index == (dev->string_index[i])) { + if (_index == (dev->string_index[i])) { tmp = dev->string[i]; tmp_size = (_hid_wcslen(dev->string[i])+1) * sizeof(WCHAR); break; @@ -3194,7 +3194,7 @@ 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) + int type, int _index, void *data, size_t *size) { switch(type) { case LIBUSB_DT_DEVICE: @@ -3202,20 +3202,20 @@ static int _hid_get_descriptor(struct hid_device_priv* dev, HANDLE hid_handle, i return _hid_get_device_descriptor(dev, data, size); case LIBUSB_DT_CONFIG: usbi_dbg("LIBUSB_DT_CONFIG"); - if (!index) + if (!_index) return _hid_get_config_descriptor(dev, data, size); return LIBUSB_ERROR_INVALID_PARAM; case LIBUSB_DT_STRING: usbi_dbg("LIBUSB_DT_STRING"); - return _hid_get_string_descriptor(dev, index, data, size); + return _hid_get_string_descriptor(dev, _index, data, size); case LIBUSB_DT_HID: usbi_dbg("LIBUSB_DT_HID"); - if (!index) + if (!_index) return _hid_get_hid_descriptor(dev, data, size); return LIBUSB_ERROR_INVALID_PARAM; case LIBUSB_DT_REPORT: usbi_dbg("LIBUSB_DT_REPORT"); - if (!index) + if (!_index) return _hid_get_report_descriptor(dev, data, size); return LIBUSB_ERROR_INVALID_PARAM; case LIBUSB_DT_PHYSICAL: @@ -3387,7 +3387,7 @@ static int _hid_set_report(struct hid_device_priv* dev, HANDLE hid_handle, int i } static int _hid_class_request(struct hid_device_priv* dev, HANDLE hid_handle, int request_type, - int request, int value, int index, void *data, struct windows_transfer_priv *tp, + int request, int value, int _index, void *data, struct windows_transfer_priv *tp, size_t *size, OVERLAPPED* overlapped) { int report_type = (value >> 8) & 0xFF; -- 2.7.4