Skip to content

Commit

Permalink
Merge pull request #24134 from charris/backport-23971
Browse files Browse the repository at this point in the history
BUG: Fix private procedures in f2py modules
  • Loading branch information
charris committed Jul 6, 2023
2 parents 231f01c + a8279f1 commit eb68150
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
10 changes: 10 additions & 0 deletions numpy/f2py/crackfortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,13 @@ def analyzebody(block, args, tab=''):
global usermodules, skipfuncs, onlyfuncs, f90modulevars

setmesstext(block)

maybe_private = {
key: value
for key, value in block['vars'].items()
if 'attrspec' not in value or 'public' not in value['attrspec']
}

body = []
for b in block['body']:
b['parent_block'] = block
Expand All @@ -2187,6 +2194,9 @@ def analyzebody(block, args, tab=''):
continue
else:
as_ = b['args']
# Add private members to skipfuncs for gh-23879
if b['name'] in maybe_private.keys():
skipfuncs.append(b['name'])
if b['name'] in skipfuncs:
continue
if onlyfuncs and b['name'] not in onlyfuncs:
Expand Down
20 changes: 20 additions & 0 deletions numpy/f2py/tests/src/crackfortran/gh23879.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module gh23879
implicit none
private
public :: foo

contains

subroutine foo(a, b)
integer, intent(in) :: a
integer, intent(out) :: b
b = a
call bar(b)
end subroutine

subroutine bar(x)
integer, intent(inout) :: x
x = 2*x
end subroutine

end module gh23879
9 changes: 6 additions & 3 deletions numpy/f2py/tests/test_crackfortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ def test_access_type(self, tmp_path):
assert set(tt['b_']['attrspec']) == {'public', 'bind(c)'}
assert set(tt['c']['attrspec']) == {'public'}

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

class TestModuleProcedure():
def test_moduleOperators(self, tmp_path):
Expand Down Expand Up @@ -182,9 +188,6 @@ class TestDimSpec(util.F2PyTest):
! the value of n is computed in f2py wrapper
!f2py intent(out) n
integer, dimension({dimspec}), intent(in) :: a
if (a({first}).gt.0) then
print*, "a=", a
endif
end subroutine
""")

Expand Down

0 comments on commit eb68150

Please sign in to comment.