Global (FreeBSD): fixes build when libc defines memrchr as a macro - #2599
Merged
Merged
Conversation
FreeBSD 16.0-CURRENT's <string.h> now provides C23-style
qualifier-preserving wrappers for the string search functions. Besides
the prototype, `memrchr` (like `memchr`, `strchr`, `strstr`, `memmem`,
...) is also defined as a function-like macro built on `_Generic`:
#define memrchr(b, c, n) __qualsel((b), \
(const void *)(memrchr)((b), (c), (n)), (memrchr)((b), (c), (n)))
`common/memrchr.h` redeclares the function unconditionally. When
<string.h> has already been included, that declaration is expanded by
the macro and every translation unit fails with:
src/common/memrchr.h:11:7: error: expected identifier or '('
11 | void* memrchr(const void* s, int c, size_t n);
A libc that defines `memrchr` as a macro has necessarily declared the
function it wraps, so skip our declaration in that case. Nothing
changes on platforms where `memrchr` is not a macro, and the fallback
implementation is still selected by `check_function_exists`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FreeBSD 16.0-CURRENT's <string.h> now provides C23-style
qualifier-preserving wrappers for the string search functions. Besides
the prototype,
memrchr(likememchr,strchr,strstr,memmem,...) is also defined as a function-like macro built on
_Generic:common/memrchr.hredeclares the function unconditionally. When<string.h> has already been included, that declaration is expanded by
the macro and every translation unit fails with:
A libc that defines
memrchras a macro has necessarily declared thefunction it wraps, so skip our declaration in that case. Nothing
changes on platforms where
memrchris not a macro, and the fallbackimplementation is still selected by
check_function_exists.Checklist