feat(libc): implement __inet_aton #1848
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1848"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-08T21:50:35Z.
What
PICO-8 for PS5 (PPSA99808 v0.1.2, RafaelNGP/pico8-ps5, GPL-3.0) stops at start-up on
main:a7ToDPsIQrcis__inet_aton(tools/nid_names.py). It is the only title in @SleglJan's run of the catalog (#1578) that stops there.The parser follows FreeBSD's
inet_aton(lib/libc/inet/inet_addr.c):0) or hex (0x);a.b→a.0.0.bwithbup to 24 bits,a.b.cwithcup to 16 bits, a single number for all 32 bits);Windows has no
inet_aton, and glibc's differs in its overflow checks, so the parser is written out instead of calling the host's. It is inStringExtensions.cpprather than a new file, so it does not collide with theNetwork.cppthat #1766 (__inet_addr,__inet_ntoa) adds.Tested
Windows 11, MinGW-w64 GCC 15.2.0, Release,
main364a56b6:+2thxYZ4sykfromlibkernel.prx(environ).guest_strings, 3/3, also after rebasing ontomain94b1eecb. New checks:192.0.2.42,10.1.2,127.1,3232235777;08,1..2, letters, trailing garbage, a bare0x, a trailing dot, a sign.tools/check_conventions.pypasses.Linux and Windows: fork CI https://github.com/LeandroLP23/AnyPS5/actions/runs/37846914473, all jobs pass (on the same change based on
364a56b6).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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T21:51:03Z.
Progress report (
94b1eec→7449e51)➖ System libraries: 84.76% (+0.0%, +1 implemented functions)
✅ 1 implemented
__inet_aton_nid_postfixImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T03:32:55Z.
Review: CHANGES_REQUESTED
The one-part limit is too large:
limits[0]isUINT64_MAX, but the documentedaform occupies 32 bits. As written,4294967296is accepted and truncated to0.0.0.0. Also, the digit accumulation wraps inuint64_t:18446744073709551617wraps to1and is accepted as0.0.0.1. Please cap the one-part form at0xffffffffand reject overflow during multiply/add (or otherwise parse with checked bounds). Add boundary tests for4294967295(valid),4294967296(invalid), and a value that exceedsuint64_t; the same checked accumulation should cover hex and octal.Imported from boykopovar/AnyPS5. Originally posted by CouchRiv on 2026-10-09T03:37:29Z.
On the one-part limit: FreeBSD's
inet_atonaccepts values above 32 bits there.valis au_long(L102), accumulated without an overflow check (L132), the one-part case has no range check (L174), and the result is truncated byhtonl(val)(L197). So on FreeBSD amd64,4294967296gives0.0.0.0and18446744073709551617gives0.0.0.1, as this PR does.I compared FreeBSD's parser (that file, built unchanged on Linux x86-64) against a parser written to the same rules for 24,806 inputs: part-boundary and 32/64-bit wrap values, every trailing byte, all whitespace characters, malformed prefixes. There were no differences. glibc rejects
4294967297, so capping at0xffffffffwould follow glibc rather than the PS5's FreeBSD libc.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T03:41:53Z.
Review: COMMENTED
Correction to my earlier review: I verified the pinned FreeBSD
inet_atonsource you linked. On amd64, the one-part form intentionally has no 32-bit range check, and accumulation inu_longwraps beforehtonl; the examples you gave match that implementation. I retract both the 32-bit cap request and the request to reject unsigned accumulation wrap. My earlier requested boundary tests would encode the wrong semantics. Sorry for the incorrect review. I cannot dismiss my prior review with this account; please treat this correction as withdrawing it.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T03:41:55Z.
Review: APPROVED
Approved after verifying the FreeBSD source semantics; my prior change request was incorrect and is withdrawn.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T12:33:55Z.
PR #2231 is now the canonical, more complete IPv4-helper change. It includes this implementation along with the other parsing/formatting helpers, preserves the original author commits in its history, and adds cross-function round-trip coverage. The exact head has a local Linux full-build result with the documented GCC 12 SaveData workaround, and I requested the upstream Build. Please close this overlapping PR as superseded once the current-head Build on #2231 is reviewed.
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-09T13:05:37Z.
Thanks for preserving the commit. I'd rather keep #1848 open until a maintainer decides: today #1839 was closed for putting three exports in one PR, and library functions go in when a title stops on them on main. #1848 is one export with PICO-8's stop on main (and your approval), while
__inet_ntoahas no title stop shown yet. If #2231 is preferred, I'll close #1848 then.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T13:50:13Z.
That concern is fair. For the combined IPv4-helper topic, I think #2231 is the better canonical PR: it preserves your
__inet_atonimplementation and attribution, adds__inet_addrand__inet_ntoa, and covers cross-function round trips. The title-run report is explicitly documented as external evidence, not a test with #2231. Its exact-head upstream Build is still pending, and I agree the maintainers should decide whether this cohesive set belongs in one PR under the one-topic rule. I will follow that decision; please keep #1848 open until then.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T17:42:14Z.
Update after rebase: #2231 is now on current
main(f8c2f072) at863ff49f; its Linuxguest_stringstest passes 1/1 and Conventions passes. The Windows results in its description are from the pre-rebase head6923a54e, not this head, and the exact-head upstream Build is still pending.I still consider #2231 the better canonical target for the IPv4 helper family because it preserves and combines the three implementations and adds cross-function tests. The overlapping PRs remain open until maintainers decide whether this cohesive family should land together; I am not treating the old Windows batch as current-head validation.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T21:53:54Z.
Checked against FreeBSD
lib/libc/inet/inet_addr.c(part limits, bases, whitespace terminator, untouched output on failure, no 32-bit cap on the one-part form, as in FreeBSD amd64), built and ranguest_strings(the new checks fail to link without the change); Linux/Windows/conventions CI green. Merging.