Add test case for issue #306: module-level allocatable arrays#310
Add test case for issue #306: module-level allocatable arrays#310jameskermode wants to merge 2 commits into
Conversation
This test case demonstrates the reported issue where module-level allocatable arrays may fail after reallocation. Investigation findings: - Tests pass on this system (sizeof_fortran_t = 4) - The generated wrapper uses `dummy_this(4)` but this parameter is unused for module-level arrays (only for derived types) - Issue may be platform-specific when sizeof_fortran_t differs between wrapper generation time and runtime Test files: - alloc_mod.f90: Fortran module with allocatable array - tests.py: Tests for allocation and reallocation - Makefile/Makefile.meson: Build files Related to #306
|
This was with GCC 13.3.0, not GCC 15. Continuing to investigate. |
|
Analysis from Claude which looks plausible but which I haven't carefully checked: Root Cause IdentifiedI've identified the root cause of this issue. It's a mismatch between the The Problem
Your EnvironmentYour error "0-th dimension must be fixed to 2 but got 4" indicates:
I can reproduce the exact error by simulating this mismatch: >>> import _alloc_mod
>>> _alloc_mod.f90wrap_alloc_mod__array__data_array([0, 0]) # size 2 handle
ValueError: 0-th dimension must be fixed to 4 but got 2Why GCC 15?sizeof_fortran_t is computed by measuring the size of a Fortran derived type pointer using transfer(). GCC 15 may have changed the internal representation of type/class pointers, reducing their size from 4 integers to 2. Questions
from f90wrap.sizeof_fortran_t import sizeof_fortran_t
print(sizeof_fortran_t())
Potential FixFor module-level arrays, dummy_this is actually unused (the compiler even warns about it). We could:
|
Root cause identified: sizeof_fortran_t mismatch between wrapper generation time (4 on GCC 13/14) and runtime (2 on GCC 15). The generated Fortran wrappers hardcode dummy_this(4) but this parameter is unused for module-level arrays. Proposed fix is to remove dummy_this from module-level array accessors entirely.
|
@jameskermode I try to build on this now... |
|
I have a similar issue, answering the questions here: The test passes on my system, but my wrapped code gives similar errors to those of @krystophny. code: SPECTRE (revised edition of SPEC, not public yet)
Both SPECTRE and SIMPLE use It might be related with the wrapper generation through CMake, since that is also the backend of SIMPLE (see file). Here the wrapper generation command is: (and very similar for SPECTRE). Could the issue somehow be related to this? |
|
@krystophny Thanks, missed that! Yes SPECTRE is still private, and will be until it is in a presentable state... The branch |
@smiet no problem, let me know if you want to invite me to the project just for fixing f90wrap, or if we should rather go ahead and patch it later when your code is ready to be released. |
|
Closed in favour of #321 |
This test case demonstrates the reported issue where module-level allocatable arrays may fail after reallocation.
Investigation findings:
dummy_this(4)but this parameter is unused for module-level arrays (only for derived types)Test files:
Related to #306