Skip to content

Zero the PetscBool output refs - #269

Merged
boriskaus merged 1 commit into
JuliaParallel:mainfrom
singhharsh1708:petscbool-zero-init
Sep 18, 2026
Merged

boriskaus merged 1 commit into
JuliaParallel:mainfrom
singhharsh1708:petscbool-zero-init

Conversation

@singhharsh1708

Copy link
Copy Markdown
Contributor

PetscBool outputs were passed as an uninitialised Ref{PetscBool}(). On 3.25 the library writes only the low byte of that 4-byte slot, so a false result reads as true whenever the top three bytes aren't zero, since Bool is true if any bit is set. Zeroing the slot is correct for both releases on little-endian: 3.22 writes four bytes, 3.25 writes one.

Declaring the type as 8 bits instead would break 3.22, and 0.4.x binds both, so the slot rather than the declaration is what has to change.

446 refs across 43 files, plus the one emission site in wrapping/generatejuliabindings.jl so regeneration keeps it. src/startup.jl isn't included (src/PETSc.jl:66), but I fixed the ref there too rather than leave a copy of the bug behind.

Tests pass on 3.22.2 with Julia 1.10 and on 3.25.4 with Julia 1.12.

No regression test: a freshly allocated ref is always zero in practice, which is why this is latent undefined behaviour rather than a reproducible wrong answer.

Fixes #268

@boriskaus
boriskaus merged commit 555ad4a into JuliaParallel:main Sep 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PetscBool output refs are uninitialised, so 3.25's one-byte write leaves the top three bytes undefined

2 participants