Commit e8243e1
authored
libusb: make hid.c compile cleanly as C++ (#811)
libusb/hid.c relied on three C-only patterns that produce errors when
the file is built with a C++ compiler (as reported in #671):
- void* from malloc/calloc/pthread-style params implicitly assigned
to typed pointers (6 sites);
- int libusb return codes implicitly stored in `enum libusb_error`
struct fields and passed to a function taking `enum libusb_error`
(13 sites);
- `#define _GNU_SOURCE` without an #ifndef guard, which produces a
"redefined" warning when the macro is also supplied via -D.
Fix:
- Guard _GNU_SOURCE with #ifndef.
- Change `hidapi_error_ctx`'s error_code / last_error_code_cache
fields and `register_libusb_error()`'s error parameter from
`enum libusb_error` to plain int. The struct is internal, the
values stored are already a mix of libusb_error codes and a `1`
sentinel used by register_string_error(), and int removes the
13 call-site conversions in one go.
- Add explicit casts on the 6 malloc/calloc/void* sites, matching
the convention already used in windows/hid.c and mac/hid.c.
- Drop a now-redundant `(enum libusb_error)` cast.
After this, `g++ -xc++ -Wall -Wextra -c libusb/hid.c` and the
equivalent gcc invocation both build cleanly, and the full CMake
build of the libusb backend (including hidtest_libusb) links
unchanged.
Closes: #671
Assisted-by: Claude:claude-opus-4.71 parent 5bec589 commit e8243e1
1 file changed
Lines changed: 17 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
86 | 88 | | |
87 | 89 | | |
88 | 90 | | |
89 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
90 | 97 | | |
91 | 98 | | |
92 | 99 | | |
93 | | - | |
| 100 | + | |
94 | 101 | | |
95 | 102 | | |
96 | 103 | | |
| |||
334 | 341 | | |
335 | 342 | | |
336 | 343 | | |
337 | | - | |
| 344 | + | |
338 | 345 | | |
339 | 346 | | |
340 | 347 | | |
| |||
382 | 389 | | |
383 | 390 | | |
384 | 391 | | |
385 | | - | |
| 392 | + | |
386 | 393 | | |
387 | 394 | | |
388 | 395 | | |
| |||
719 | 726 | | |
720 | 727 | | |
721 | 728 | | |
722 | | - | |
| 729 | + | |
723 | 730 | | |
724 | 731 | | |
725 | 732 | | |
| |||
923 | 930 | | |
924 | 931 | | |
925 | 932 | | |
926 | | - | |
| 933 | + | |
927 | 934 | | |
928 | 935 | | |
929 | 936 | | |
| |||
1091 | 1098 | | |
1092 | 1099 | | |
1093 | 1100 | | |
1094 | | - | |
| 1101 | + | |
1095 | 1102 | | |
1096 | 1103 | | |
1097 | 1104 | | |
| |||
1160 | 1167 | | |
1161 | 1168 | | |
1162 | 1169 | | |
1163 | | - | |
| 1170 | + | |
1164 | 1171 | | |
1165 | 1172 | | |
1166 | 1173 | | |
| |||
1636 | 1643 | | |
1637 | 1644 | | |
1638 | 1645 | | |
1639 | | - | |
| 1646 | + | |
1640 | 1647 | | |
1641 | 1648 | | |
1642 | 1649 | | |
| |||
2100 | 2107 | | |
2101 | 2108 | | |
2102 | 2109 | | |
2103 | | - | |
| 2110 | + | |
2104 | 2111 | | |
2105 | 2112 | | |
2106 | 2113 | | |
| |||
0 commit comments