fix(libc): convert Windows time zone names to UTF-8 #10987
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10987"
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 MarcZX10 on 2026-10-25T12:26:28Z.
What
Windows exposes CRT time-zone names in the active ANSI code page, while the guest expects UTF-8. Convert the names returned through
tznameandtm_zoneto UTF-8, retaining the original name if conversion fails. This fixes non-ASCII Windows zone names in%Zand wide time formatting.The wide formatting regression test now decodes the narrow UTF-8 result to UTF-16 before comparing it with
wcsftime; its prior byte-for-code-unit comparison failed for multi-byte UTF-8. The time conversion test covers a fixed CP1252 name and the host CRT names.Tested
-fsyntax-onlypassed forTime.cpp,GuestTimeConversion.cpp, andGuestWideFormatting.cpp._fflush_nolockdeclaration inFileStream.hpp.3rdparty/SDL2/CMakeLists.txtand the environment reports missing XRandR support. Runtime tests were not run here.tools/check_conventions.py --base upstream/main --head HEAD: passed.tools/pr_overlap.py --branch marc/fix-windows-timezone-name-utf8: no overlap with open PRs.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 repositoryImported from boykopovar/AnyPS5. Originally posted by thepoppfish on 2026-10-25T12:42:36Z.
Review: CHANGES_REQUESTED
I built and ran the actual changed sources at
445ecdef58fc53f3498d09a2e232f7ba37384471on Windows and found the two blocking issues below.Windows 11 build26200; MSYS2 UCRT64 GCC16.2.0-6; CMake4.3.1; Ninja1.13.2; Release with explicit
-O1 -g, no LTO. Observed OS name is ASCIIJerusalem Standard Time(23 bytes), ACP1252, so the lifetime finding does not require a German/non-ASCII host.Built complete, unmodified
Time.cpp,Environment.cpp,Multibyte.cppandFormattingWide.cpp, plus the complete submittedGuestTimeConversion.cpp,GuestWideFormatting.cppand existingGuestStrftime.cpp. The standalone harness supplies errno, the existing NotImplemented throw, and a fail-fast stream-I/O adapter; it does not replace time/formatting/conversion logic. This is an isolated native executable build, not the whole shared libc/runtime or NID-patched product.29ce6d87ebFinal full harness: 3/5 pass on the PR, 4/5 on the baseline control; the remaining baseline failure is the newly introduced incorrect test expectation. A passing wide-formatting run does not disprove the independently observed lifetime issue. Earlier runs also caught the published name being freed by the very next localtime call rather than during tzset itself.
The lifetime diagnostic statically links libstdc++/libgcc so its ordinary malloc/free-backed global new/delete hooks can observe the string library's deallocations. It records freed addresses, clears them on reuse and never reads the freed name. The same hooks/flags are used for the baseline control. The other three submitted fixtures use the normal dynamic C++ runtime. No OS time-zone/locale settings changed, only each test process's TZ.
Conventions and whitespace pass against main
29ce6d87eb5b3050b4f08f60ed9ee52195979d14. Both builds show the existing__dstbiasdllimport redeclaration warning in GuestTimeConversion.cpp. No full product/shared-library build, sanitizer, Linux/macOS, PS5, game or hosted-CI result claimed. AI-assisted review and harness: yes, OpenAI Codex.Complete standalone reproduction harness and commands
Check out this PR at
445ecdef58fc53f3498d09a2e232f7ba37384471, and a separate baseline checkout at29ce6d87eb5b3050b4f08f60ed9ee52195979d14. Put these four files in a new harness folder. Put the GCC16/UCRT64 bin directory and CMake/Ninja bin directory on PATH, then use absolute forward-slash paths for the placeholders:The baseline command intentionally retains all PR headers and tests and changes only the production Time.cpp. On a system whose OS zone name fits the string's inline capacity (15 bytes here), the lifetime probe returns77 rather than claiming a reproduction. The observed host here needs no such adjustment.
CMakeLists.txt
Support.cpp
IoPoison.cpp
TimeZoneLifetime.cpp
Imported from boykopovar/AnyPS5. Originally posted by thepoppfish on 2026-10-25T13:31:11Z.
Review: DISMISSED
Reran the complete native Windows harness against
7c8eb3b531b1c6481398af4d162d754e8e6ef2f8as requested. All five checks from my original review now pass (1.87s): the three complete repository time-conversion/wide-formatting/strftime fixtures, the direct-localtime allocation probe, and the no-DST probe. That verifies the two originally reproduced sequences are corrected.There is one remaining lifetime path. After
localtime_sreturns a caller-owned GuestTm, callingstrftimeorwcsftimeon that same struct causes another tzset refresh and frees its tm_zone buffer under an unchanged time zone. The exported tzname is refreshed; the existing GuestTm still contains the old address. Reading that field afterward accesses released storage.Same environment: Windows11 build26200, GCC16.2.0-6/UCRT64, CMake4.3.1, Ninja1.13.2, Release with explicit O1-g/noLTO. The actual OS name is ASCII
Jerusalem Standard Time(23 bytes), ACP1252. No German-host or PS5 measurement claimed by me.%Z)%Z)The minimal diagnostic change below also passes the five original checks (5/5,1.87s), retaining the revised fixture's timezone changes, restoration and blank-daylight coverage. I changed only a scratch copy of Time.cpp; your checkout is unmodified.
This is also consistent with the pinned FreeBSD implementation reusing its active state for an unchanged TZ, with tm_zone referring into that state. I am reporting a native regression against main, not asserting console lifetime measurements.
The extra harness builds complete, unmodified Time.cpp/Environment.cpp/Multibyte.cpp and uses the same errno/NotImplemented support adapter as before. The only allocation hooks are ordinary malloc/free-backed global new/delete, statically linking libstdc++/libgcc so deallocations are observable. The probe watches a live returned pointer and never reads it after release. No time-zone, decoder or formatter implementation is replaced. Its baseline/guard controls change only TIME_SOURCE, retaining all other sources, headers, code, flags and API calls.
Conventions and whitespace pass against local origin/main4017310678; checkout remains clean. The five-check harness still shows the existing __dstbias dllimport warning. No full shared-libc/runtime/product build, sanitizer, Linux/macOS, title, GPU, PS5 or hosted-CI validation claimed. AI-assisted: yes.
Complete additional probe and replay
Save these three files in a separate harness folder and place the same GCC16 UCRT64 and CMake/Ninja bin directories on PATH. Use absolute forward-slash paths for the placeholders. The PR checkout must be at
7c8eb3b531b1c6481398af4d162d754e8e6ef2f8; use a separate baseline checkout at29ce6d87eb5b3050b4f08f60ed9ee52195979d14.For the guard control, copy the exact PR Time.cpp outside the checkout, replace only the unconditional refresh loop with the guarded loop above, and use that file as TIME_SOURCE in another build directory. Both new checks pass. The original five-check harness also passes with REPO pointing at this PR checkout, both with the unmodified Time.cpp and with the guard-control TIME_SOURCE. No previous source/binary was overwritten. On a host whose name fits the observed GCC string's 15-byte inline capacity, this additional probe returns77 instead of claiming a reproduction.
CMakeLists.txt
Support.cpp
FormatLifetime.cpp