Skip to content

Commit 000e06e

Browse files
committed
Update libusb to lastet master
Merge commit 'd4f681c61451f28378dce3a9e3e16e731a43af26'
2 parents 92e156b + d4f681c commit 000e06e

27 files changed

+1403
-262
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: MSYS2 aarch64 clang64
2+
on: [push, pull_request]
3+
4+
jobs:
5+
build:
6+
runs-on: windows-11-arm
7+
defaults:
8+
run:
9+
shell: msys2 {0}
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: msys2/setup-msys2@v2
13+
with:
14+
msystem: clangarm64
15+
update: true
16+
install: git mingw-w64-clang-aarch64-cc mingw-w64-clang-aarch64-autotools
17+
- name: CI-Build
18+
run: |
19+
echo 'Running in MSYS2!'
20+
./bootstrap.sh
21+
./.private/ci-build.sh --no-asan --build-dir build-msys2-clang64-aarch64
22+
23+
- uses: actions/upload-artifact@v4
24+
with:
25+
name: build-msys2-clang64-aarch64
26+
path: |
27+
build-msys2-clang64-aarch64/libusb/.libs/libusb-1.0.dll.a
28+
build-msys2-clang64-aarch64/libusb/.libs/libusb-1.0.a
29+
build-msys2-clang64-aarch64/libusb/.libs/libusb-1.0.dll
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Windows build and Package
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
strategy:
8+
matrix:
9+
os:
10+
- 'windows-2022'
11+
- 'windows-2025'
12+
configuration:
13+
- 'Debug'
14+
- 'Release'
15+
- 'Debug-MT'
16+
- 'Release-MT'
17+
- 'Debug-Hotplug'
18+
- 'Release-Hotplug'
19+
- 'Debug-Hotplug-MT'
20+
- 'Release-Hotplug-MT'
21+
architecture:
22+
- 'Win32'
23+
- 'x64'
24+
- 'ARM64'
25+
26+
runs-on: ${{ matrix.os }}
27+
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v2
31+
32+
- name: Setup MSBuild
33+
uses: microsoft/[email protected]
34+
35+
- name: Build solution
36+
run: |
37+
msbuild msvc/libusb.sln /m -property:Configuration=${{ matrix.configuration }} -property:Platform=${{ matrix.architecture }}

libusb/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ Debug
6161
Release
6262
Debug-MT
6363
Release-MT
64+
Debug-Hotplug
65+
Release-Hotplug
66+
Debug-Hotplug-MT
67+
Release-Hotplug-MT
6468
*.db
6569
*.user
6670
*.suo

libusb/configure.ac

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,20 @@ AM_CONDITIONAL([OS_EMSCRIPTEN], [test "x$backend" = xemscripten])
397397
AM_CONDITIONAL([PLATFORM_POSIX], [test "x$platform" = xposix])
398398
AM_CONDITIONAL([PLATFORM_WINDOWS], [test "x$platform" = xwindows])
399399
AM_CONDITIONAL([USE_UDEV], [test "x$use_udev" = xyes])
400+
AM_CONDITIONAL([LIBUSB_WINDOWS_HOTPLUG], [test "x$enable_windows_hotplug" = xyes])
400401

401402
dnl The -Wcast-function-type warning causes a flurry of warnings when compiling
402403
dnl Windows with GCC 8 or later because of dynamically loaded functions
403404
if test "x$backend" = xwindows; then
405+
AC_ARG_ENABLE([windows-hotplug],
406+
AS_HELP_STRING([--enable-windows-hotplug], [Enable Windows hotplug support]),
407+
[enable_windows_hotplug="$enableval"],
408+
[enable_windows_hotplug=no])
409+
410+
if test "x$enable_windows_hotplug" = "xyes"; then
411+
AC_DEFINE([LIBUSB_WINDOWS_HOTPLUG], [1], [Define to enable Windows hotplug support])
412+
fi
413+
404414
saved_CFLAGS="${CFLAGS}"
405415
CFLAGS="-Werror -Wcast-function-type"
406416
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],

libusb/examples/hotplugtest.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@
2323

2424
#include "libusb.h"
2525

26-
int done = 0;
26+
int done_attach = 0;
27+
int done_detach = 0;
2728
libusb_device_handle *handle = NULL;
2829

2930
static int LIBUSB_CALL hotplug_callback(libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event, void *user_data)
3031
{
3132
struct libusb_device_descriptor desc;
33+
libusb_device_handle *new_handle;
3234
int rc;
3335

3436
(void)ctx;
@@ -45,18 +47,23 @@ static int LIBUSB_CALL hotplug_callback(libusb_context *ctx, libusb_device *dev,
4547
libusb_strerror((enum libusb_error)rc));
4648
}
4749

48-
if (handle) {
49-
libusb_close (handle);
50-
handle = NULL;
51-
}
52-
53-
rc = libusb_open (dev, &handle);
54-
if (LIBUSB_SUCCESS != rc) {
50+
rc = libusb_open (dev, &new_handle);
51+
if (LIBUSB_SUCCESS == rc) {
52+
if (handle) {
53+
libusb_close (handle);
54+
}
55+
handle = new_handle;
56+
} else if (LIBUSB_ERROR_ACCESS != rc
57+
#if defined(PLATFORM_WINDOWS)
58+
&& LIBUSB_ERROR_NOT_SUPPORTED != rc
59+
&& LIBUSB_ERROR_NOT_FOUND != rc
60+
#endif
61+
) {
5562
fprintf (stderr, "No access to device: %s\n",
5663
libusb_strerror((enum libusb_error)rc));
5764
}
5865

59-
done++;
66+
done_attach++;
6067

6168
return 0;
6269
}
@@ -85,7 +92,7 @@ static int LIBUSB_CALL hotplug_callback_detach(libusb_context *ctx, libusb_devic
8592
handle = NULL;
8693
}
8794

88-
done++;
95+
done_detach++;
8996

9097
return 0;
9198
}
@@ -130,14 +137,15 @@ int main(int argc, char *argv[])
130137
return EXIT_FAILURE;
131138
}
132139

133-
while (done < 2) {
140+
while (done_detach < done_attach || done_attach == 0) {
134141
rc = libusb_handle_events (NULL);
135142
if (LIBUSB_SUCCESS != rc)
136143
printf ("libusb_handle_events() failed: %s\n",
137144
libusb_strerror((enum libusb_error)rc));
138145
}
139146

140147
if (handle) {
148+
printf ("Warning: Closing left-over open handle\n");
141149
libusb_close (handle);
142150
}
143151

libusb/examples/xusb.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
#if defined(_MSC_VER)
3232
#define snprintf _snprintf
3333
#define putenv _putenv
34+
/* Disable: warning C5287: operands are different enum types */
35+
#if (_MSC_VER > 1800)
36+
/* Disable: warning C5287: operands are different enum types, supported after Visual Studio 2013 */
37+
#pragma warning(disable:5287)
38+
#endif
3439
#endif
3540

3641
// Future versions of libusb will use usb_interface instead of interface

libusb/libusb/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ OS_WINDOWS_SRC = libusb-1.0.def libusb-1.0.rc \
3030
os/windows_usbdk.h os/windows_usbdk.c \
3131
os/windows_winusb.h os/windows_winusb.c
3232

33+
if LIBUSB_WINDOWS_HOTPLUG
34+
OS_WINDOWS_SRC += os/windows_hotplug.h os/windows_hotplug.c
35+
endif
36+
3337
if OS_DARWIN
3438
OS_SRC = $(OS_DARWIN_SRC)
3539
endif

libusb/libusb/core.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -728,20 +728,24 @@ struct libusb_device *usbi_alloc_device(struct libusb_context *ctx,
728728
return dev;
729729
}
730730

731-
void usbi_connect_device(struct libusb_device *dev)
731+
void usbi_attach_device(struct libusb_device *dev)
732732
{
733733
struct libusb_context *ctx = DEVICE_CTX(dev);
734734

735735
usbi_atomic_store(&dev->attached, 1);
736736

737-
usbi_mutex_lock(&dev->ctx->usb_devs_lock);
738-
list_add(&dev->list, &dev->ctx->usb_devs);
739-
usbi_mutex_unlock(&dev->ctx->usb_devs_lock);
737+
usbi_mutex_lock(&ctx->usb_devs_lock);
738+
list_add(&dev->list, &ctx->usb_devs);
739+
usbi_mutex_unlock(&ctx->usb_devs_lock);
740+
}
740741

741-
usbi_hotplug_notification(ctx, dev, LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED);
742+
void usbi_connect_device(struct libusb_device *dev)
743+
{
744+
usbi_attach_device(dev);
745+
usbi_hotplug_notification(DEVICE_CTX(dev), dev, LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED);
742746
}
743747

744-
void usbi_disconnect_device(struct libusb_device *dev)
748+
void usbi_detach_device(struct libusb_device *dev)
745749
{
746750
struct libusb_context *ctx = DEVICE_CTX(dev);
747751

@@ -750,8 +754,12 @@ void usbi_disconnect_device(struct libusb_device *dev)
750754
usbi_mutex_lock(&ctx->usb_devs_lock);
751755
list_del(&dev->list);
752756
usbi_mutex_unlock(&ctx->usb_devs_lock);
757+
}
753758

754-
usbi_hotplug_notification(ctx, dev, LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT);
759+
void usbi_disconnect_device(struct libusb_device *dev)
760+
{
761+
usbi_detach_device(dev);
762+
usbi_hotplug_notification(DEVICE_CTX(dev), dev, LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT);
755763
}
756764

757765
/* Perform some final sanity checks on a newly discovered device. If this

libusb/libusb/descriptor.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,9 +1311,10 @@ int API_EXPORTED libusb_get_string_descriptor_ascii(libusb_device_handle *dev_ha
13111311
r = libusb_get_string_descriptor(dev_handle, 0, 0, str.buf, 4);
13121312
if (r < 0)
13131313
return r;
1314-
else if (r != 4 || str.desc.bLength < 4 || str.desc.bDescriptorType != LIBUSB_DT_STRING)
1314+
else if (r != 4 || str.desc.bLength < 4 || str.desc.bDescriptorType != LIBUSB_DT_STRING) {
1315+
usbi_warn(HANDLE_CTX(dev_handle), "invalid language ID string descriptor");
13151316
return LIBUSB_ERROR_IO;
1316-
else if (str.desc.bLength & 1)
1317+
} else if (str.desc.bLength & 1)
13171318
usbi_warn(HANDLE_CTX(dev_handle), "suspicious bLength %u for language ID string descriptor", str.desc.bLength);
13181319

13191320
langid = libusb_le16_to_cpu(str.desc.wData[0]);

libusb/libusb/libusb.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ typedef SSIZE_T ssize_t;
6565
#if defined(interface)
6666
#undef interface
6767
#endif
68-
#if !defined(__CYGWIN__)
69-
#include <winsock.h>
70-
#endif
7168
#endif /* _WIN32 || __CYGWIN__ */
7269

7370
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
@@ -192,7 +189,7 @@ extern "C" {
192189
* \param x the host-endian value to convert
193190
* \returns the value in little-endian byte order
194191
*/
195-
static inline uint16_t libusb_cpu_to_le16(const uint16_t x)
192+
static inline uint16_t libusb_cpu_to_le16(uint16_t x)
196193
{
197194
union {
198195
uint8_t b8[2];
@@ -1182,16 +1179,16 @@ struct libusb_device_handle;
11821179
*/
11831180
struct libusb_version {
11841181
/** Library major version. */
1185-
const uint16_t major;
1182+
uint16_t major;
11861183

11871184
/** Library minor version. */
1188-
const uint16_t minor;
1185+
uint16_t minor;
11891186

11901187
/** Library micro version. */
1191-
const uint16_t micro;
1188+
uint16_t micro;
11921189

11931190
/** Library nano version. */
1194-
const uint16_t nano;
1191+
uint16_t nano;
11951192

11961193
/** Library release candidate suffix string, e.g. "-rc4". */
11971194
const char *rc;

0 commit comments

Comments
 (0)