Repository navigation
Emit HAVE__FSTAT/HAVE__FSTATI64 so fstat matches struct stat on Windows - #9259
Merged
joa-quim merged 2 commits intoOct 13, 2026
Merged
Conversation
ConfigureChecks.cmake tests for _fstat and _fstati64, but gmt_config.h.in never emitted HAVE__FSTAT or HAVE__FSTATI64. As a result gmt_notposix.h mapped stat to _stati64 but left fstat unmapped, so fstat() received a struct _stati64 while expecting a struct stat with a 32-bit st_size: a struct layout mismatch with MSVC and a hard error with GCC 14+ (-Wincompatible-pointer-types). Issue GenericMappingTools#8825 was worked around with an _WIN64-only call to _fstat64 in gmtlib_read_ps; with the defines in place the generic code is correct on all Windows builds, so the hack is removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
Thanks. Let me find some time to tests this under a MSVC build. |
joa-quim
approved these changes
Oct 13, 2026
joa-quim
left a comment
Member
There was a problem hiding this comment.
Ok, tested and run the tests locally (MSVC build) run OK.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of proposed changes
ConfigureChecks.cmakechecks for_fstatand_fstati64on Windows, butgmt_config.h.innever writesHAVE__FSTATorHAVE__FSTATI64into the header. As a result,gmt_notposix.hmapsstatto_stati64(becauseHAVE__STATI64is set) but leavesfstatunmapped. So ingmtlib_read_ps,struct stat bufbecomesstruct _stati64, whilefstat()still expects the CRT's ownstruct stat, which has a different layout:-Wincompatible-pointer-types), as reported in mingw64 compiling failure #8825.fstatwrites a struct of a different size thanbuf.#8826 worked around this for 64-bit builds only, by calling
_fstat64under#ifdef _WIN64. 32-bit MinGW builds still fail, and 6.6.0 fails on both.This PR adds the two missing
#cmakedefinelines.fstatis then mapped to_fstati64, which pairs with_stati64on every Windows target. That makes the_WIN64special case unnecessary, so it is removed.How it was tested
I used MinGW-w64 GCC 13 with
-Werror=incompatible-pointer-types, which behaves like GCC 14:A CMake configure under MinGW detects all four of
HAVE__STAT,HAVE__STATI64,HAVE__FSTATandHAVE__FSTATI64. The 6.7.0 Windows installer'sgmt_config.h(an MSVC build) also definesHAVE__STATandHAVE__STATI64.I compiled
src/gmt_plot.cagainst the generated headers:_WIN64workaround)With this PR the object files import matching stat/fstat pairs:
_stat64/_fstat64on x64 and_stati64/_fstati64on i686.gmtlib_read_psis the onlyfstatcaller. The checks only run insideif (WIN32), so non-Windows builds are unchanged.Follow-up to #8825 / #8826.
The fix and its analysis were developed with help from Claude (AI assistant). I checked the analysis myself, and the MinGW x64/i686 build results above are from real compiles.
Reminders
Add testsN/A: this is a MinGW/GCC 14 compile-time error that the test suite can't catch. GMT's Windows CI builds with MSVC only, and a MinGW CI job would be the real safeguard; I'm happy to propose one separately.Describe changes to function behaviorN/A: no function's behavior or arguments change.Add documentationN/A: no new functionality.