Repository navigation
feat(libc): implement memrchr - #3172
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dextroid17
left a comment
There was a problem hiding this comment.
The closure and the reopening tell the whole story, and this is the right way to answer one: #1592 was closed because no title stopped on memrchr, and now PICO-8 does — with the exact FAIL: unresolved ELF import … line and two independent runs, one of them not the author's. That is the acceptance bar answered with evidence, and the second run is what makes it more than a claim.
The implementation is the canonical one, including the detail that usually goes wrong. Scanning backwards from n to zero and comparing through static_cast<unsigned char>(c) is both FreeBSD's behaviour and the only correct reading of the argument — a signed comparison is the classic bug in this family. Carrying MarcZX100's change with their authorship kept, and describing the one conflict (the test registration, resolved by keeping both blocks), is the rest of the job done properly.
The one thing the test should pin is the difference from memchr. Returning the last match is the entire point of this function, so a case where the byte appears more than once — with the answer being the later one — is the case that distinguishes the two, alongside a not-found case. If the new file already has both, nothing to do here.
Written with AI assistance.
|
Linux check, since the fork CI's Linux job failed on unrelated lavapipe timeouts: 890169e merged onto |
Carrying @MarcZX100's #1592, which was closed because no title stopped on
memrchryet. The change is theirs (8ac8c93aand8e7a88d8, squashed onto currentmainwith MarcZX100 kept as the author; the only conflict was the test registration inlibc/CMakeLists.txt, resolved by keeping both blocks).What
Implements
memrchr(5G2ONUzRgjY) in libc: it scans the firstnbytes backwards for(unsigned char)cand returns a pointer to the last match, or null, as in FreeBSD.PICO-8 for PS5 (PPSA99808 v0.1.2, RafaelNGP/pico8-ps5, GPL-3.0) now stops on it at start-up on
main(@screamm's run on #1578, and mine below):Tested
Windows 11, WinLibs GCC 15.2.0 r7, Release:
libc.prxunwrapped: onmain5b4709f it stops at5G2ONUzRgjY(memrchr); with this change it gets past it toFAIL: unresolved ELF import oxMp8uPqa+U from libkernel.prx(pthread_set_name_np, feat(libkernel): implement pthread_set_name_np #3031).guest_memrchr(last match,cabove 255 truncated to a byte, a shortern, no match) andguest_stringspass 3/3; the patchedlibc.prxexports5G2ONUzRgjY; conventions and test registration pass.Fork CI (run): Windows and the three relinker jobs pass. Linux fails
agc_driver_image_packed16_loadandagc_driver_flat_apertures(timeout) on lavapipe; an unrelated change on the samemain(run) fails the same two, so they come frommain, not from this change.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)