Fix bug in registry-generated code to set up derived dimensions#1458
Merged
mgduda merged 2 commits intoMay 26, 2026
Merged
Conversation
Contributor
Author
|
For the record, it's entirely my fault that this issue made its way into the |
abishekg7
reviewed
May 26, 2026
Collaborator
There was a problem hiding this comment.
The changes look good overall and able to build and run without issues. Just had a small comment re. indentation of this line in the generated code.
Contributor
Author
There was a problem hiding this comment.
Although this line isn't part of any of my changes in this PR, I can push an update to correct the indentation of this line as well as line 1082.
Contributor
Author
There was a problem hiding this comment.
I've added a separate commit to address indentation issues in the generated Fortran code.
The previous commit (ae45a18) aimed to fix memory leaks that occurred while setting up derived dimensions by deallocating dimensions after they were allocated and added to the dimension pool (since the pool assigns the value of the dimension to its own internal memory, it is up to calling code to free any memory allocated for the dimension argument to mpas_pool_add_dimension). However, any later derived dimensions that depended on a dimension whose value came from a namelist or other registry definiton would generate a segmentation fault after referencing an unassociated pointer to the now deallocated dimension. For example, in the init_atmosphere core, the 'nVertLevels' dimension is set based on the namelist option 'config_nvertlevels', and the 'nVertLevelsP1' dimension is subsequently set to 'nVertLevels+1'. This commit fixes this issue by re-setting pointers to point to pool-owned memory after a dimension has been allocated, added to the dimension pool, and freed.
…utines.inc The parse_dimensions_from_registry C code in the registry is responsible for generating the block_dimension_routines.inc file, and this commit makes changes in parse_dimensions_from_registry to clean up whitespace / indentation issues in the generated Fortran code. The changes in this commit otherwise have no impact on results.
cbf8441 to
4069eb3
Compare
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.
This PR fixes a bug in registry-generated code for setting up derived dimensions.
Previous work (in PR #1451, commit ae45a18) introduced changes to eliminate memory leaks that occurred while setting up derived dimensions. The approach taken in that work involved deallocating dimensions after they were allocated and added to the dimension pool, since the pool assigns the value of the dimension to its own internal memory, and it is up to calling code to free any memory allocated for the dimension argument to
mpas_pool_add_dimension. However, as an unintended side effect, any later derived dimensions that depended on a dimension whose value came from a namelist or other registry definiton would generate a segmentation fault after referencing an unassociated pointer to the now deallocated dimension.For example, in the
init_atmospherecore, thenVertLevelsdimension is set based on the namelist optionconfig_nvertlevels, and thenVertLevelsP1dimension is subsequently set tonVertLevels+1.This PR fixes this issue by re-setting pointers to point to pool-owned memory after a dimension has been allocated, added to the dimension pool, and freed.