Skip to content

Commit fdeb79a

Browse files
authored
Merge pull request numpy#27695 from HaoZeke/fixModuleF2PYdat
BUG: Fix multiple modules in F2PY and COMMON handling
2 parents bd1f606 + 531a694 commit fdeb79a

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

numpy/f2py/auxfuncs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
'isunsigned_long_long', 'isunsigned_long_longarray', 'isunsigned_short',
4444
'isunsigned_shortarray', 'l_and', 'l_not', 'l_or', 'outmess', 'replace',
4545
'show', 'stripcomma', 'throw_error', 'isattr_value', 'getuseblocks',
46-
'process_f2cmap_dict'
46+
'process_f2cmap_dict', 'containscommon'
4747
]
4848

4949

numpy/f2py/f90mod_rules.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ def dadd(line, s=doc):
9797

9898
usenames = getuseblocks(pymod)
9999
for m in findf90modules(pymod):
100-
contains_functions_or_subroutines = any(
101-
item for item in m["body"] if item["block"] in ["function", "subroutine"]
102-
)
103100
sargs, fargs, efargs, modobjs, notvars, onlyvars = [], [], [], [], [
104101
m['name']], []
105102
sargsp = []
@@ -120,8 +117,9 @@ def dadd(line, s=doc):
120117
outmess(f"\t\t\tSkipping {m['name']} since there are no public vars/func in this module...\n")
121118
continue
122119

123-
if m['name'] in usenames and not contains_functions_or_subroutines:
124-
outmess(f"\t\t\tSkipping {m['name']} since it is in 'use'...\n")
120+
# gh-25186
121+
if m['name'] in usenames and containscommon(m):
122+
outmess(f"\t\t\tSkipping {m['name']} since it is in 'use' and contains a common block...\n")
125123
continue
126124
if onlyvars:
127125
outmess('\t\t Variables: %s\n' % (' '.join(onlyvars)))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module datonly
2+
implicit none
3+
integer, parameter :: max_value = 100
4+
real, dimension(:), allocatable :: data_array
5+
end module datonly
6+
7+
module dat
8+
implicit none
9+
integer, parameter :: max_= 1009
10+
end module dat
11+
12+
subroutine simple_subroutine(ain, aout)
13+
use dat, only: max_
14+
integer, intent(in) :: ain
15+
integer, intent(out) :: aout
16+
aout = ain + max_
17+
end subroutine simple_subroutine

numpy/f2py/tests/test_regression.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ def test_inout(self):
2424
assert np.allclose(x, [3, 1, 2])
2525

2626

27+
class TestDataOnlyMultiModule(util.F2PyTest):
28+
# Check that modules without subroutines work
29+
sources = [util.getpath("tests", "src", "regression", "datonly.f90")]
30+
31+
@pytest.mark.slow
32+
def test_mdat(self):
33+
assert self.module.datonly.max_value == 100
34+
assert self.module.dat.max_ == 1009
35+
int_in = 5
36+
assert self.module.simple_subroutine(5) == 1014
37+
38+
2739
class TestNegativeBounds(util.F2PyTest):
2840
# Check that negative bounds work correctly
2941
sources = [util.getpath("tests", "src", "negative_bounds", "issue_20853.f90")]

0 commit comments

Comments
 (0)