-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add better windows error handling #388
Conversation
Regarding global error: From the
The only backend that tries to implement this correctly is While I understand your best inentions of preparing this PR, I'd rather want to accept an implementation that strictly follows all requirements as per documentation: uses a thread-local storage of some kind, and correctly releases all the error strings when not required anymore. Or we need to change initial requirement, to make it easier to implement. I don't see a perfect solution as of yet. The device error improvement I'll gladly accept. |
Hmm, yeah, that makes sense. I'll alter the PR to remove the global error handling. I noticed when I tried adding the device error to the windows error that there was some heap corruption on freeing the memory via We've been having issues with a downstream library ( Anyway, I'll remove the global error handling, do some more testing, and push the changes to this PR. |
Alright, removed global error messaging. I also had to switch the device specific error message to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see two general issues with this implementation:
-
No early return in case if
dev == NULL
; if it is NULL (for whatever reason) - we would silently get a memory leak; -
Double memory allocation (I guess no need to explain);
More comments regarding 2) :
Would be be willing to perform some additional refactoring?
I.e.: get rid of FORMAT_MESSAGE_ALLOCATE_BUFFER
to use preallocated memory in the first place, and use FORMAT_MESSAGE_ARGUMENT_ARRAY
to make the formatting.
UPD: ok, after checking the doc, I see that we need FORMAT_MESSAGE_FROM_SYSTEM
to have string representation of the rror code so the FORMAT_MESSAGE_FROM_STRING
isn't a viable option, but still, calling FormatMessageW
two times without the FORMAT_MESSAGE_ALLOCATE_BUFFER
flag is enough to do both: concatenate the op
/"error code message" and avoid double memory allocation.
Yes, these are good recommendations. |
The usage of these wide chars makes the concatenation annoying (can't just |
I believe we can easily and safely replace the type for |
That was a surprise for me. Most WinAPI functions allow passing NULL for buffer to get the required buffer size. |
I took liberty to update the implementation on my own |
Oops, accidentally launched this PR before I intended. This PR merges the Windows messaging with what's already done in the Windows side of the library so that we can get better error reporting.