Adapt to annotated Libc and add missing safe wrapper functions#2
Open
delcypher wants to merge 2 commits into
Open
Adapt to annotated Libc and add missing safe wrapper functions#2delcypher wants to merge 2 commits into
delcypher wants to merge 2 commits into
Conversation
Following the "Safe Wrappers for Public APIs" pattern, every public function whose parameters carried __unsafe_indexable now has a `<name>Safe` variant that takes an explicit count parameter and uses __counted_by_or_null. The legacy entry points are reduced to thin shims that forge from __unsafe_indexable to a counted pointer and delegate to the *Safe variant; their declarations gain __ptrcheck_unavailable_r so -fbounds-safety adopters are pushed to the *Safe API. ABI is preserved for non-adopters: counted_by pointers stay single-word. The three pre-existing static *Safe helpers in dgif_lib.c (which used the ABI-incompatible __bidi_indexable wide pointer for their out-parameter) are promoted to the public API by switching them to __counted_by_or_null with an explicit size_t out-count. Direct assignment from the static Private->Buf array means no __unsafe_forge_bidi_indexable is needed in their bodies — the array's natural bound narrows to Buf+1 implicitly. Also fixes an annotation oversight from cebf81e: EGifPutCode's GifCodeBlock parameter was missing __unsafe_indexable even though the function takes the same Pascal-string buffer shape as EGifPutCodeNext. Public *Safe variants: - EGifPutCodeSafe - EGifPutCodeNextSafe - DGifGetExtensionSafe - DGifGetExtensionNextSafe - DGifGetCodeSafe - DGifGetCodeNextSafe GifUnionColorMapSafe already existed; this change adds the __ptrcheck_unavailable_r marker to the legacy GifUnionColorMap declaration so it joins the same pattern. Sample tools (gifbuild, giffix, giftext, gif2rgb, gifhisto, giffilter, gifclrmp) are unaffected — they aren't built with -fbounds-safety so __ptrcheck_unavailable_r doesn't apply, and they keep linking against the legacy shims via the unchanged ABI.
Member
|
Do the safe wrappers need |
apple-fcloutier
approved these changes
May 21, 2026
Collaborator
Author
Good observation. At a glance at least some of them could be and as the safe APIs are new we know there are no external callers that would say otherwise so we can decide the convention. I'll try it out and if I don't hit any problems I'll use that instead. |
patrykstefanski
approved these changes
May 21, 2026
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.
This PR does two things
-fbounds-safetyannotations