feat(libSceNKWebKit): implement WTF atom strings #14918
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14918"
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 w4rc0n on 2026-11-02T01:31:29Z.
What
The
WTF::AtomStringImplandWTF::AtomStringexports threwNotImplemented, so guest code stopped as soon as it made an atom string from characters, a literal or aString. Fifteen of them now follow the pinned PS5 WebKit 11.x AtomStringImpl.cpp and AtomString.cpp:AtomStringImpl::addfor 8-bit and 16-bit buffers, literals, static strings and substrings;addSlowCase(StringImpl&);lookUpfor 8-bit and 16-bit buffers;lookUpSlowCase.AtomString::numberforint,unsigned,unsigned longandunsigned long long;fromUTF8Internal;convertToASCIIUppercase.Each thread has its own table, as with WebKit's per-thread
AtomStringTable. Like WebKit's, it holds no references:The table is held through
HostThreadLocal, not a plainthread_local, so the MinGW build frees it safely at thread exit (as ine017894bb4).The cases the source leaves to parts that aren't modelled throw a
std::runtime_errorand are recorded indocs/dev/debt/libSceNKWebKit.md:addSlowCase(AtomStringTable&, StringImpl&), because the guest table layout is unknown;AtomString::number(float)andAtomString::number(double)still callNotImplemented: they need the shortest-form number formatter, which #14259 adds forString::number.Adapted source. The atom operations adapted from the pinned source are now in their own file,
src/WtfAtoms.cpp, under a "Derived from" line and the upstream notice for each pinned source file, verbatim apart from trailing whitespace, the form #13766 uses: the table destructor (AtomStringTable.cpp:28); removal, static atoms,addand the substring-sharing add (AtomStringImpl.cpp:473,:358,:384and:245); andfromUTF8Internal(AtomString.cpp:120). Independent: the per-thread table, which stays inWtfString.cpp.tools/pr_overlap.pyon this head, withmainat0eba5db30d: no other open PR changes these exports or adds the same files. For the PRs it couldn't compare because they no longer merge withmain, GitHub's file lists show none of them changing these exports either. #13992, #14172, #14607, #15214, #15241 and #15867 change nearby lines in the same files; whichever merges later keeps both sides. The only exports it shares are with #14917, #14919 and #14920, in the same stack.Tested
Debian 12, GCC 12.2, Linux 6.18, Release, at the head
129fe3b329162644709464a22d3f1e129f9f1a8b, no local changes:guest_nkwebkit_dates,guest_nkwebkit_numbers,nkwebkit_base,nkwebkit_config,nkwebkit_constants,nkwebkit_fastbitvector,nkwebkit_jsc,nkwebkit_palsessionid,nkwebkit_preferences,nkwebkit_resourceresponse,nkwebkit_webcoregeometry,nkwebkit_wtf,guest_nkwebkit_urlsandpublic_headerspass.nkwebkit_wtfcases cover:StringImpl::destroy;addSlowCaseadopting an ordinary string, or returning the existing atom for it;number;convertToASCIIUppercasereturning the same atom when the string is already uppercase.tools/progress.py: the 15 exports count as implemented (libSceNKWebKit 1328, against 1313 with only #14917).tools/check_conventions.pypasses.feat/nkwebkit-external-stringsat its previous head9d1e021975e6ecbdaf395584d055bc9653d825d2, which contains this PR's commit. It is AnyPS5'sBuildworkflow, dispatched in the author's fork withselect=true: the branch merged intomainatb11c7bf84f5d2f636ff60166cc3371bd071e24d5, built onwindows-latestwith WinLibs GCC 15.2 (MinGW-w64, UCRT). All 1390 selected tests passed, none skipped, including the twelve NKWebKit tests,public_headersandpatched_libraries. The run started before the fork had a test graph for thismain, so it selected more tests than usual. A fork-internal pull request existed only to give the workflow a number. The rebase ontomainat0eba5db30d8a3d03789e52e5c1a9ff853e4e33e4after #15911 changed onlydocs/dev/debt/libSceNKWebKit.md, sogit range-diffshows the code and tests under test are the same as at that run.Not built or run: macOS. The Windows run includes the test where a thread creates an atom and exits, so the MinGW thread-exit path ran there. No title or homebrew was run.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T03:55:07Z.
Review: APPROVED
I compared each export with the pinned
AtomStringImpl.cpp/AtomString.cppat 80f77e94 and ran the tests.What I compared with the source
addSlowCase(StringImpl&)returns empty for length 0 and goes the static path whenisStatic. Otherwise it inserts the impl itself and sets the atom flag (16), asstringTable().add(&string)+setIsAtom(true)do.add(StringImpl*, start, length):!length || start >= length()gives empty;length() - start;add(baseString);SharedSubstring, which keeps the copy-when-short rule ofcreateSubstringSharingImpl).addLiteralandadd(StaticStringImpl*)create a non-copying impl over the static data (BufferFromStaticDataTranslator). The test checks that the static impl itself stays untouched.lookUp/lookUpSlowCasefind by content and never insert. Empty givesStringImpl::empty()in the slow case.fromUTF8Internalreturns null for invalid UTF-8, as theaddUTF8hash returning 0 does. A nullendmeans NUL-terminated. The cases the source only asserts on (null start,end <= start) throw.convertToASCIIUppercase: a null impl gives null, an unchanged string gives itself, otherwise the converted string is interned.number(...)values intern the decimal text, which is whatnumberToString{Signed,Unsigned}<AtomString>produce.hashAndFlags >> 8(the masked 24-bit hash), the same valueRemoveAtomuses. The test cross-checks it againstconcurrentHash.Tests run (Windows 11, WinLibs GCC 15.2.0, Release; head 4683b72a71 merged onto main
93dbd0f82a)nkwebkit_wtfpasses.nkwebkit*tests pass, including the guest dates and numbers tests. This matters becauseReleasenow goes throughDestroyfor every string.WtfString.cpp,Export.cppandInventoryExports.hppfrom main, the test doesn't build, because these exports are missing there.check_conventions.py --base upstream/mainpasses.Non-blocking notes
addSlowCase: upstream'saddSymbolonly interns aSubstringLocation{&base, 0, length}, a substring sharing the symbol's buffer. It never touches the symbol registry. So that path could be implemented later without modelling the registry. Throwing for now is fine, and the debt entry covers it.RemoveAtomthrow from insideRelease. Upstream only has anASSERT_WITH_MESSAGEthere. SinceReleaseis reached from destructors, that ends instd::terminaterather than a catchable error. Arguably right for a guest bug, but worth knowing if a title trips it.LGTM.
Pull request closed