mirror of
https://github.com/shadps4-emu/ext-libusb.git
synced 2026-01-31 00:55:21 +01:00
core: Apply default options to all new contexts
The default options configured with libusb_set_option(NULL, ...) were only applied when the default context was created, and were ignored when calling libusb_init() with a non-null context pointer. Make sure the default options will be applied to all new contexts. This is important when using LIBUSB_OPTION_NO_DEVICE_DISCOVERY which must be respected during the context initialization in order to work. Closes #942 [Tormod: amend comments] Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
This commit is contained in:
committed by
Tormod Volden
parent
b88f144185
commit
f7084fea11
@@ -2316,12 +2316,8 @@ int API_EXPORTED libusb_init(libusb_context **ctx)
|
||||
list_init(&_ctx->usb_devs);
|
||||
list_init(&_ctx->open_devs);
|
||||
|
||||
/* default context should be initialized before calling usbi_dbg */
|
||||
if (!ctx) {
|
||||
usbi_default_context = _ctx;
|
||||
default_context_refcnt = 1;
|
||||
usbi_dbg(usbi_default_context, "created default context");
|
||||
|
||||
/* apply options to new contexts (also default context being created) */
|
||||
if (ctx || !usbi_default_context) {
|
||||
for (enum libusb_option option = 0 ; option < LIBUSB_OPTION_MAX ; option++) {
|
||||
if (LIBUSB_OPTION_LOG_LEVEL == option || !default_context_options[option].is_set) {
|
||||
continue;
|
||||
@@ -2332,6 +2328,13 @@ int API_EXPORTED libusb_init(libusb_context **ctx)
|
||||
}
|
||||
}
|
||||
|
||||
/* default context must be initialized before calling usbi_dbg */
|
||||
if (!ctx) {
|
||||
usbi_default_context = _ctx;
|
||||
default_context_refcnt = 1;
|
||||
usbi_dbg(usbi_default_context, "created default context");
|
||||
}
|
||||
|
||||
usbi_dbg(_ctx, "libusb v%u.%u.%u.%u%s", libusb_version_internal.major, libusb_version_internal.minor,
|
||||
libusb_version_internal.micro, libusb_version_internal.nano, libusb_version_internal.rc);
|
||||
|
||||
@@ -2353,7 +2356,6 @@ int API_EXPORTED libusb_init(libusb_context **ctx)
|
||||
goto err_io_exit;
|
||||
}
|
||||
|
||||
|
||||
if (ctx)
|
||||
*ctx = _ctx;
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define LIBUSB_NANO 11666
|
||||
#define LIBUSB_NANO 11667
|
||||
|
||||
Reference in New Issue
Block a user