Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: Fix private procedures in f2py modules #24134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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