8000 Merge pull request #24134 from charris/backport-23971 · numpy/numpy@eb68150 · GitHub
[go: up one dir, main page]

Skip to content

Commit eb68150

Browse files
authored
Merge pull request #24134 from charris/backport-23971
BUG: Fix private procedures in f2py modules
2 parents 231f01c + a8279f1 commit eb68150

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

numpy/f2py/crackfortran.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,6 +2179,13 @@ def analyzebody(block, args, tab=''):
21792179
global usermodules, skipfuncs, onlyfuncs, f90modulevars
21802180

21812181
setmesstext(block)
2182+
2183+
maybe_private = {
2184+
key: value
2185+
for key, value in block['vars'].items()
2186+
if 'attrspec' not in value or 'public' not in value['attrspec']
2187+
}
2188+
21822189
body = []
21832190
for b in block['body']:
21842191
b['parent_block'] = block
@@ -2187,6 +2194,9 @@ def analyzebody(block, args, tab=''):
21872194
continue
21882195
else:
21892196
as_ = b['args']
2197+
# Add private members to skipfuncs for gh-23879
2198+
if b['name'] in maybe_private.keys():
2199+
skipfuncs.append(b['name'])
21902200
if b['name'] in skipfuncs:
21912201
continue
21922202
if onlyfuncs and b['name'] not in onlyfuncs:
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module gh23879
2+
implicit none
3+
private
4+
public :: foo
5+
6+
contains
7+
8+
subroutine foo(a, b)
9+
integer, intent(in) :: a
10+
integer, intent(out) :: b
11+
b = a
12+
call bar(b)
13+
end subroutine
14+
15+
subroutine bar(x)
16+
integer, intent(inout) :: x
17+
x = 2*x
18+
end subroutine
19+
20+
end module gh23879

numpy/f2py/tests/test_crackfortran.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ def test_access_type(self, tmp_path):
5757
assert set(tt['b_']['attrspec']) == {'public', 'bind(c)'}
5858
assert set(tt['c']['attrspec']) == {'public'}
5959

60+
def test_nowrap_private_proceedures(self, tmp_path):
61+
fpath = util.getpath("tests", "src", "crackfortran", "gh23879.f90")
62+
mod = crackfortran.crackfortran([str(fpath)])
63+
assert len(mod) == 1
64+
pyf = crackfortran.crack2fortran(mod)
65+
assert 'bar' not in pyf
6066

6167
class TestModuleProcedure():
6268
def test_moduleOperators(self, tmp_path):
@@ -182,9 +188,6 @@ class TestDimSpec(util.F2PyTest):
182188
! the value of n is computed in f2py wrapper
183189
!f2py intent(out) n
184190
integer, dimension({dimspec}), intent(in) :: a
185-
if (a({first}).gt.0) then
186-
print*, "a=", a
187-
endif
188191
end subroutine
189192
""")
190193

0 commit comments

Comments
 (0)
0