Skip to content

ares_status_t enum for status codes - #567

Merged
bradh352 merged 6 commits into
c-ares:mainfrom
bradh352:ares_status
Oct 10, 2023
Merged

ares_status_t enum for status codes#567
bradh352 merged 6 commits into
c-ares:mainfrom
bradh352:ares_status

Conversation

@bradh352

Copy link
Copy Markdown
Member

The list of possible error codes in c-ares was a #define list. This not only doesn't provide for any sort of type safety but it also lacks clarification on what a function may return or what it takes, as an int could be an ares status, a boolean, or possibly even a length in the current code.

We are not changing any public APIs as though the C standard states the underlying size and type of an enum is int, there are compiler attributes to override this as well as compiler flags like -fshort-enums. GCC in particular is known to expand an enum's width based on the data values (e.g., it can emit a 64bit integer enum).

All internal usages should be changed by this PR, but of course, there may be some I missed.

Fix By: Brad House (@bradh352)

@bradh352
bradh352 requested a review from bagder October 10, 2023 14:14
Comment thread src/lib/ares__addrinfo_localhost.c Outdated
Comment thread src/lib/ares_process.c Outdated
Comment thread src/lib/ares_process.c Outdated
bradh352 and others added 3 commits October 10, 2023 12:01
err -> status

Co-authored-by: Daniel Stenberg <daniel@haxx.se>
err -> status

Co-authored-by: Daniel Stenberg <daniel@haxx.se>
@bradh352
bradh352 merged commit 973023b into c-ares:main Oct 10, 2023
@bradh352
bradh352 deleted the ares_status branch October 10, 2023 16:42
@gvanem

gvanem commented Oct 11, 2023

Copy link
Copy Markdown
Contributor

What about ares_set_sortlist()etc.? Still many hits for int ares_.

@bradh352

bradh352 commented Oct 11, 2023

Copy link
Copy Markdown
Member Author

What about ares_set_sortlist()etc.? Still many hits for int ares_.

I have intentionally not changed any public API interfaces as it could break ABI compatibility. Compilers aren't guaranteed to internally use int for an enum, especially if someone is compiling their code using GCC and are specifying -fshort-enums.

non-public hits for int ares_* might be addressed by #570 ... as I think I got all of them that don't return weird codes like -1, 0, 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants