Repository navigation
config: Append .0 to non-finite config_set_double values - #739
Conversation
|
Tier 2 Windows (ENABLE_RUST_LIBOBS=ON) fails at link; it is not flaky. Cause: |
|
Updated from master and marked ready; everything passes except Rust Tier 2 on Windows, which fails to link libobs with The new |
C config_set_double stores os_dtostr(): %.17g with ".0" appended when
there is no '.' or 'e', which applies to inf, -inf and nan too (inf.0,
-inf.0, nan.0). Rust ON returns the bare spelling. Compare against
os_dtostr and literal spellings, with finite values as a regression guard.
The NaN sign and payload spellings belong to the C library (glibc -nan,
Apple nan, UCRT -nan(ind) and nan(snan)), so the NaN cases compare to C
only. config_set_default_double ("%g", no ".0") is compared to snprintf
for the same values.
os_dtostr() applies its ".0" rule to the %.17g text of inf and nan, so
C stores inf.0, -inf.0 and nan.0. Drop the early non-finite return in the
Rust dtostr so those spellings take the same path as finite values.
The spelling of a non-finite value is the C library's choice: glibc
prints a sign-bit NaN as "-nan", Apple libc as "nan", and UCRT prints
"-nan(ind)" and "nan(snan)". Format inf and nan with the C library's own
snprintf and the same format string as C ("%.17g" for config_set_double,
"%g" for config_set_default_double) instead of a fixed table, so both
match C on every libc.
libc::snprintf is a DLL import; on MSVC libobs's platform.obj already defines the inline snprintf, so the Tier 2 Windows link failed with LNK4217 (warning treated as error).
|
Maintainer rebase, as allowed by coordination.md §4. I rebased onto master (dropping the master merge commit), replacing head |
8023db7 to
a11a766
Compare
Problem
With
ENABLE_RUST_LIBOBS=ON,config_set_doublestoresinf,-infandnanwhere C storesinf.0,-inf.0andnan.0. The difference shows throughconfig_get_stringand in saved ini files. On macOS, ON also stored-nanfor a NaN with the sign bit set (-NAN), where Apple's libc printsnan, andconfig_set_default_double(-NAN)stored-nanwhere C storesnan. Reading the value back withconfig_get_doublegives the same number either way, so the impact is the stored text only. Severity: Low. With the Rust portOFF, nothing changes.Fixes: TBD
Root cause
On
master(3410e7b2b),rust/obs-util/src/config_file.rs:dtostr(:722-725) returned thenan_infspelling early, before the.0rule. C'sos_dtostr(libobs/util/platform.c:579) formats withsnprintf("%.17g")and then appends.0whenever the text has neither.nore(platform.c:589-600).infandnancontain neither, so C storesinf.0andnan.0.nan_inf(:668-684) is a fixed table:-nanfor any sign-bit NaN, elsenan, plusinf/-inf. That is glibc's spelling. It is wrong on Apple libc, which printsnanfor every NaN, and on the Windows UCRT, which prints-nan(ind)andnan(snan). The same table also feedsconfig_set_default_double(:1067), which C formats withdstr_printf("%g")(libobs/util/config-file.c:622).Fix
At GREEN
e76db9d223a79e6f6443244ff14b56c3d0b6f7fb:dtostr(rust/obs-util/src/config_file.rs:711-712) no longer returns early, so non-finite values go through the same.0rule and exponent code as finite ones. The exponent code itself is unchanged.g_format(config_file.rs:676-678) formats non-finite values with the C library's ownsnprintf, using the same format string as C:"%.17g"forconfig_set_doubleand"%g"forconfig_set_default_double(:1053). The C runtime chooses the spelling, so ON matches C on every libc by construction instead of through a per-platform table. Finite values keep the existing Rust formatting.snprintfcall is in the platform layer:rust/obs-util/src/platform/stdio.rs:38-54, re-exported fromplatform/mod.rs:53-54. Thelibccrate declaressnprintfon every supported target; in the CMake build the symbol resolves to thesnprintfthat libobs's own C objects already emit (on Windows, the UCRT inlinesnprintf), so the file has no per-OS code.legacy_stdio_definitions, which thelibccrate attaches on MSVC, applies only to binaries that cargo links (thecargo testexecutables), not to the CMake link. ADoubleFormatenum (stdio.rs:12) limits the call to these two format literals.ffi/is unchanged and there are no new exported symbols.dtostris corrected. It said-exponents lose leading zeros cleanly (1e-05->1e-5). In fact C'smemmoveinos_dtostrmisses the NUL for-exponents too (1.5e-05is stored as1.5e-55), and Rust mirrors that on purpose. That C bug is tracked separately and isn't changed here.Alternatives considered:
target_vendor = "apple"). Rejected: it would also need FreeBSD's libc, which is from the same family, plus UCRT's-nan(ind)/nan(snan), and the table would need to be kept in step with each libc by hand.-NANand for signalling NaNs.Evidence
Branch
fix/config-double-nonfiniteon the fork, two commits on3410e7b2b:d6cf2e8b32822b9ee9f2d6807550b824688b7ffc"config: Test config_set_double non-finite spelling (RED)"e76db9d223a79e6f6443244ff14b56c3d0b6f7fb"config: Append .0 to non-finite config_set_double values (GREEN)"The test is
test/cmocka/test_config_set_double_format.c, registered intest/cmocka/tests.d/test_config_set_double_format.cmakeon every platform. Byte-exact comparisons are against C'sos_dtostrandsnprintf("%g"), which stay C in both builds:test_set_double_nonfinite_spelling(:45):inf.0,-inf.0,nan.0as literals and againstos_dtostr.test_set_double_nan_variants(:54):-NAN, NaNs with payloads, and a signalling NaN, compared to C only, because the spelling belongs to the libc.test_set_default_double_nonfinite(:85):config_set_default_doubleagainstsnprintf("%g")for the same non-finite values, through bothconfig_get_default_stringandconfig_get_string.test_set_double_nonfinite_round_trip(:98) andtest_set_double_finite_unchanged(:113): guards for the read-back and for finite values (0.1,-0.0,1e15-1e18,1.5e-5,DBL_MAX,DBL_MIN, the smallest subnormal and others).Local runs: macOS arm64, CMake Xcode generator, Debug, the repo's own flags.
RED with
ENABLE_RUST_LIBOBS=OFFpasses 5/5. RED withON(themasterRust) fails 3 of 5:GREEN passes 5/5 with
OFFand 5/5 withON. The full cmocka suite passes 88/88 withOFFand 88/88 withON(test_svt_av1skipped).soldr cargo test -p obs-util --lockedpasses 472 tests on macOS, andclippy -D warnings,fmt --check, the repo Dylints and clang-format 22.1.3 are clean.Linux (x86_64, Debian 13, glibc 2.41, cmocka 1.1.7): the committed test, compiled against the obs-util staticlib and the C
os_dtostrfromplatform.c, fails 2 of 5 on RED ("inf" != "inf.0","-nan" != "-nan.0") and passes 5/5 on GREEN. This is a harness build, not the full CMake build; the CMake Linux run was not done and relies on upstream PR CI. It compiles with cmocka 1.1.7 without extra flags.soldr cargo test -p obs-utilpasses 475 tests there, and the obs-util tests build and link forx86_64-pc-windows-gnu(--no-run) withclippy -D warningsclean.Mutants, built and run with
ONon macOS:-nanfor any sign-bit NaN, both formats-NANintest_set_double_nan_variantsandtest_set_default_double_nonfinite-nankept on the%gpath only-NANintest_set_default_double_nonfinite("-nan" != "nan")snprintfapplied to finite values tooClocale)The surviving mutant removes the
!v.is_finite()guard so that every value goes through libcsnprintf. It passes the test and the 14-pattern public-ABI probe because it is equivalent in theClocale. Only a comma-decimalLC_NUMERICtells it apart:snprintfwould write1,5, which C'sos_dtostrrepairs withfrom_locale. The guard is correct, but nothing pins it, and a locale-dependent cmocka test was not added because it would be fragile in CI. Swapping theG17andGformats on the non-finite path is equivalent by construction (%gand%.17gprintinfandnanidentically) and was not built.The opposite table mutant (NaN sign always dropped) is killed on glibc by
-NAN("nan.0" != "-nan.0"), which an independent review showed on the previous head.Real runs: the full app was not run for this change. A public-ABI probe (
config_set_double,config_set_default_double,os_dtostr,snprintf("%g")) shows what each libc stores at GREEN.ONandOFFmatch on both:set_double/defaultset_double/defaultinf(7ff0000000000000)inf.0/infinf.0/inf-inf(fff0000000000000)-inf.0/-inf-inf.0/-infNAN(7ff8000000000000)nan.0/nannan.0/nan-NAN(fff8000000000000)nan.0/nan-nan.0/-nanfff8000000001234)nan.0/nan-nan.0/-nan7ff0000000000001)nan.0/nannan.0/nanWindows (UCRT) was not run; the Windows link has never been built or tested. From Microsoft's documented
printfbehaviour, C stores-nan(ind).0for-NANandnan(snan).0for a signalling NaN; with this change Rust calls the same CRTsnprintfand should store the same.Fork CI: not run. Our self-hosted CI is down (see our note on #699), so this relies on upstream PR CI.
Compatibility & risk
ON,config_set_doubleandconfig_set_default_doublenow store the same text as with itOFFfor non-finite values. Finite values are unchanged.snprintfbinds, in the CMake build, to the UCRT inlinesnprintfthat libobs's own C objects already emit (for exampleos_dtostrinplatform.c), so-nan(ind)andnan(snan)should match C. That is a prediction from how the pieces link, not a result. Thelegacy_stdio_definitionslibrary that thelibccrate attaches on MSVC applies only to binaries that cargo links, such as thecargo testexecutables, not to the CMake link. Upstream PR CI's Windows job will be the first place this is built. Older msvcrt-based MinGW is unverified: there C'ssnprintfcan be mingw-w64's own C99 implementation while Rust binds msvcrt's. OBS ships MSVC builds on Windows, and thex86_64-pc-windows-gnulane only links. FreeBSD and musl were not run; both now get their own libc's spelling by construction.os_dtostrexponent trim keeps a stray digit (1.5e-5is stored as1.5e-55,1e17as1e177), and Rust mirrors it for parity. That is a C bug with its own issue.How this was tested
test_config_set_double_formatwas built locally on macOS arm64 with the CMake Xcode generator (Debug, repo flags, no sanitizers). WithENABLE_RUST_LIBOBS=OFFit passes on both RED and GREEN. WithONit fails on RED with the output above and passes on GREEN. On Linux glibc, a harness build of the same test against the obs-util staticlib fails on RED and passes on GREEN. Both table mutants above are killed; the finite-valuessnprintfmutant survives (see Evidence).Status
Status: draft. Opened so upstream PR CI can run it. Branch
fix/config-double-nonfiniteate76db9d223a79e6f6443244ff14b56c3d0b6f7fb.Thank you to the obs-rust maintainers and contributors for building this project in the open. In the American spirit of free expression and individual independence, and with the principle of judging contributions on their merit alone, this PR is a small piece of what independent people can build when they come together.