Skip to content

fix: make the behaviour of methods which set hid_error more consistent#425

Closed
Julusian wants to merge 1 commit intolibusb:masterfrom
Julusian:fix/global-error-consistency
Closed

fix: make the behaviour of methods which set hid_error more consistent#425
Julusian wants to merge 1 commit intolibusb:masterfrom
Julusian:fix/global-error-consistency

Conversation

@Julusian
Copy link
Contributor

@Julusian Julusian commented Jun 11, 2022

From reading through the code I found that the behaviour of hid_error() was rather inconsistent at times.

The windows implementation would only set the device error if it encountered an error, and would never clear the last error.
The linux hidraw implementation would sometimes clear it, but not always.

@Julusian
Copy link
Contributor Author

I suppose that it could be fine as it, as you know that there is a new error from the return code, so maybe none of this is necessary other than the docs fix

@Youw
Copy link
Member

Youw commented Jun 12, 2022

You are right, there is so much wrong about hid_error in general.
Starting with the inconsistency in the documentation and implementation, ending up with real thread-safety issues (despite the documentation).

We've introduced a lot problems by trying to make an improvement.
We tried to make hid_error mimic the errno behavior, on the thread-safety part, but that was practically impossible to do so for a few reasons:

  • hid_error has a per-device version of the function, and the device (struct) member cannot contain thread-local members;
  • unlike errno, which is an int - hid_error is a dynamically allocated string, which has to be freed by each thread, where the error has been happening, and that is not true for hidraw (the only backend that has global errors implementation);

Let me finally start making it right.

@Youw Youw mentioned this pull request Jun 12, 2022
@Youw Youw closed this in #428 Jun 21, 2022
@mcuee mcuee added Windows Related to Windows backend hidraw Related to Linux/hidraw backend Core Related to common codes like hidapi.h labels Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Core Related to common codes like hidapi.h hidraw Related to Linux/hidraw backend Windows Related to Windows backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments