Skip to content

Adapt to annotated Libc and add missing safe wrapper functions#2

Open
delcypher wants to merge 2 commits into
mainfrom
dliew/new-sdks-and-add-missing-safe-wrappers
Open

Adapt to annotated Libc and add missing safe wrapper functions#2
delcypher wants to merge 2 commits into
mainfrom
dliew/new-sdks-and-add-missing-safe-wrappers

Conversation

@delcypher
Copy link
Copy Markdown
Collaborator

@delcypher delcypher commented May 20, 2026

This PR does two things

  • (First commit) Makes the code compile with newer SDKs where Libc contains -fbounds-safety annotations
  • (Second commit) Adds missing Safe wrappers to the public interface.

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.
@hnrklssn
Copy link
Copy Markdown
Member

Do the safe wrappers need __counted_by_or_null, or could they be __counted_by? __counted_by can be null as long as the count is 0.

@delcypher
Copy link
Copy Markdown
Collaborator Author

Do the safe wrappers need __counted_by_or_null, or could they be __counted_by? __counted_by can be null as long as the count is 0.

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.

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.

5 participants