Skip to content

libgis: Fix G_init_locale recursion and add GISBASE fallback for resource dirs#28

Open
wenzeslaus wants to merge 2 commits into
nilason:fix_cmake_share_dirfrom
wenzeslaus:fix-5630-locale-recursion
Open

libgis: Fix G_init_locale recursion and add GISBASE fallback for resource dirs#28
wenzeslaus wants to merge 2 commits into
nilason:fix_cmake_share_dirfrom
wenzeslaus:fix-5630-locale-recursion

Conversation

@wenzeslaus

Copy link
Copy Markdown

This fixes the Windows CI failure in OSGeo#5630 and makes the new resource variables degrade gracefully, as offered in OSGeo#5630 (comment).

Two commits:

  1. Avoid infinite recursion in G_init_locale(). When GRASS_LOCALEDIR is unset, G_locale_dir() calls G_fatal_error(_(...)), and translating that message re-enters G_init_locale() before its initialized flag is set, recursing until the stack overflows. This is the g.proj exit code 3221225725 (0xC00000FD, STATUS_STACK_OVERFLOW) on Windows CI; it only shows there because the OSGeo4W build configures --with-nls while the Ubuntu CI builds do not. The fix reads the variable directly and skips bindtextdomain() when it is unset, matching the previous GISBASE-based behavior. Locale initialization must never be fatal, since fatal errors themselves translate messages.

  2. Fall back to GISBASE-relative paths in get_g_env(). When a GRASS_* resource variable is unset, fall back to the legacy location relative to GISBASE, and fail fatally only when neither yields an existing path. This keeps environments constructed from GISBASE alone (third-party launchers, older grass.script versions) working with legacy-layout installations, while an FHS installation without a properly created session still gets the clean "Incomplete GRASS session" error.

Verified on a branch carrying these fixes on top of this PR's changes: legacy and FHS CMake builds complete, an installed tree passes session smoke tests, and a bare-GISBASE environment lists color rules through the fallback on the legacy build while the FHS build reports the incomplete-session error cleanly.

The diagnosis and the fixes were developed with Claude Code and reviewed and tested locally.

G_locale_dir() calls G_fatal_error() when GRASS_LOCALEDIR is not set,
and G_fatal_error() translates its message, which re-enters
G_init_locale() and recurses until the stack overflows. Read the
variable directly and skip bindtextdomain() when it is not set,
matching the pre-existing behavior for GISBASE. Likely the cause of
the g.proj stack overflow (0xC00000FD) seen on Windows CI in the FHS
preparation PR. Found and fixed with Claude Code.
When a GRASS_* resource variable is not set, fall back to the legacy
layout location relative to GISBASE so that environments created from
GISBASE alone keep working with legacy installations. Fail fatally
only when the variable is not set and the fallback directory does not
exist, which is the case for an FHS installation without a properly
created session.

Verified with a bare-GISBASE environment: legacy build lists color
rules through the fallback; FHS build reports the incomplete session
error cleanly.

Written with Claude Code.
@wenzeslaus
wenzeslaus force-pushed the fix-5630-locale-recursion branch from 967d466 to e650ea6 Compare July 12, 2026 15:19
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