Skip to content

Commit 5cf0b5d

Browse files
committed
Bug fix for allocatable scheme data
1 parent 7a3263e commit 5cf0b5d

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

capgen-ng/generator/suite_data.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,15 @@ def _generate_suite_data(
331331
'{}errflg = 0'.format(i2),
332332
]
333333
for suite_var in sorted_svs:
334-
if suite_var.dimensions:
334+
# Allocatable suite vars are owned-and-allocated by the producing
335+
# scheme itself (its dummy is declared ``allocatable, intent(out)``,
336+
# so the callee performs the allocation). The suite must NOT
337+
# pre-allocate them here -- doing so is at best redundant (the
338+
# scheme's intent(out) auto-deallocates on entry) and at worst
339+
# wrong (its extent may not be known until the scheme runs). The
340+
# suite still OWNS the storage, so final_fields below deallocates
341+
# it regardless of who allocated it.
342+
if suite_var.dimensions and not suite_var.allocatable:
335343
dim_exprs = [
336344
_dim_local_expr(d, suite_vars, host_dict)
337345
for d in suite_var.dimensions
@@ -360,6 +368,11 @@ def _generate_suite_data(
360368
"{}errmsg = ''".format(i2),
361369
'{}errflg = 0'.format(i2),
362370
]
371+
# Deallocate ALL dimensioned fields here -- including allocatable
372+
# ones that a scheme allocated itself. The storage is a component of
373+
# the suite-owned ``ccpp_suite_data`` DDT, so the suite owns its
374+
# teardown; the ``if (allocated(...))`` guard makes this safe whether
375+
# the scheme allocated it, never ran, or already freed it.
363376
for suite_var in sorted_svs:
364377
if suite_var.dimensions:
365378
lines.append(

0 commit comments

Comments
 (0)