Skip to content

Commit 023a5b2

Browse files
committed
Call hid_init() at import time, to avoid macOS crash
fixes trezor#142 fixes trezor#148 note trezor#148 (comment) : > HIDAPI on macOS has an additional issue regarding thread-safety. > I did encountered it in my project(s) but didn't have enough time to gather info/find a root cause. > Looks like on macOS hid_init/hid_exit needs to be called in the same thread, > which is an additional restriction compared to other platforms.
1 parent 8e92053 commit 023a5b2

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

chid.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ cdef extern from "hidapi.h":
2323
hid_device* hid_open(unsigned short, unsigned short, const wchar_t*)
2424
hid_device* hid_open_path(char *path)
2525
void hid_close(hid_device *)
26+
int hid_init()
2627
int hid_exit()
2728
int hid_write(hid_device* device, unsigned char *data, int length) nogil
2829
int hid_read(hid_device* device, unsigned char* data, int max_length) nogil

hid.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ from libc.stddef cimport wchar_t, size_t
88
__version__ = "0.13.1"
99

1010

11+
hid_init()
12+
13+
1114
cdef extern from "ctype.h":
1215
int wcslen(wchar_t*)
1316

0 commit comments

Comments
 (0)