Skip to content

Portability and latent-crash fixes: FE_Element guard, PythonStream format string, DistributedSuperLU name collision#30

Open
nmorabowen wants to merge 3 commits into
jaabell:ladruñofrom
nmorabowen:up/01-portability-crash-fixes
Open

Portability and latent-crash fixes: FE_Element guard, PythonStream format string, DistributedSuperLU name collision#30
nmorabowen wants to merge 3 commits into
jaabell:ladruñofrom
nmorabowen:up/01-portability-crash-fixes

Conversation

@nmorabowen

Copy link
Copy Markdown

Three small, independent, non-behavioral fixes (one commit each, so any can be dropped). None changes results for a correctly-running model.

1. Dead first-element guard in FE_Element subtype constructor

FE_Element(tag, numDOF_Group, ndof) incremented the class-wide numFEs counter before the if (numFEs == 0) guard that lazily allocates the shared theMatrices/theVectors scratch arrays, so the guard was never taken. A model whose only FE_Elements are subtype adapters (no element-backed FE_Element ever constructed) then left those arrays unallocated → null dereference in ~FE_Element when the last one is destroyed. Fix: increment after the guard, matching the element-backed constructor. Any model that owns at least one element-backed FE_Element is unaffected (numFEs > 0 by the time subtypes are built).

2. Format-string bug in PythonStream::err_out

The already-formatted message was passed as the format argument of PySys_FormatStderr, so any literal % in an opserr message (e.g. "50% of model mass") was consumed as a bogus printf conversion and the message dropped/garbled under openseespy. The Tcl stream path was unaffected. Fix: PySys_FormatStderr("%s", msg.c_str()).

3. DistributedSuperLU global stat collides with POSIX stat()

The file-scope SuperLUStat_t stat collides with the POSIX stat() declared transitively via <sys/stat.h>/<io.h> on some toolchains (notably MSVC), breaking the Windows build of the distributed SuperLU solver. Renamed to superlu_stat at all four use sites; no behavior change.

Authors: Nicolas Mora Bowen, Patricio Palacios, José A. Abell

nmorabowen and others added 3 commits July 22, 2026 21:49
The FE_Element(tag, numDOF_Group, ndof) constructor used by subtype adapters
incremented the class-wide numFEs counter BEFORE the `if (numFEs == 0)` guard
that lazily allocates the shared theMatrices/theVectors scratch arrays. The
guard was therefore never taken, so a model whose only FE_Elements are subtype
adapters (no element-backed FE_Element is ever constructed) left those arrays
unallocated and dereferenced a null pointer in ~FE_Element when the last
FE_Element was destroyed.

Move the increment below the guard, matching the element-backed constructor.
Any model that already owns an element-backed FE_Element is unaffected: numFEs
is already > 0 by the time subtype adapters are built.

Co-authored-by: Patricio Palacios <pxpalacios@miuandes.cl>
Co-authored-by: Jose A. Abell <jaabell@miuandes.cl>
err_out passed the already-formatted message directly as the format argument of
PySys_FormatStderr. Any literal '%' in an opserr message (e.g. "50% of model
mass") was interpreted as a printf conversion specifier, so the message was
silently dropped or garbled under openseespy. The Tcl StandardStream path was
unaffected. Pass the message through a "%s" format instead.

Co-authored-by: Patricio Palacios <pxpalacios@miuandes.cl>
Co-authored-by: Jose A. Abell <jaabell@miuandes.cl>
The file-scope global SuperLUStat_t stat collides with the POSIX stat()
function declared transitively through <sys/stat.h>/<io.h> on some toolchains
(notably MSVC), breaking the Windows build of the distributed SuperLU solver.
Rename it to superlu_stat at all four use sites; no behavior change.

Co-authored-by: Patricio Palacios <pxpalacios@miuandes.cl>
Co-authored-by: Jose A. Abell <jaabell@miuandes.cl>
nmorabowen added a commit to nmorabowen/OpenSees that referenced this pull request Jul 23, 2026
…es.cl fix (#606)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant