8000 BUG: Fix common block handling in f2py by HaoZeke · Pull Request #22657 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
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
3 changes: 2 additions & 1 deletion numpy/f2py/crackfortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,8 @@ def readfortrancode(ffile, dowithline=show, istop=1):
r'endinterface|endsubroutine|endfunction')
endpattern = re.compile(
beforethisafter % ('', groupends, groupends, '.*'), re.I), 'end'
endifs = r'end\s*(if|do|where|select|while|forall|associate|block|' + \
# block, the Fortran 2008 construct needs special handling in the rest of the file
endifs = r'end\s*(if|do|where|select|while|forall|associate|' + \
r'critical|enum|team)'
8000 endifpattern = re.compile(
beforethisafter % (r'[\w]*?', endifs, endifs, '.*'), re.I), 'endif'
Expand Down
7 changes: 7 additions & 0 deletions numpy/f2py/tests/src/crackfortran/gh22648.pyf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
python module iri16py ! in
interface ! in :iri16py
block data ! in :iri16py:iridreg_modified.for
COMMON /fircom/ eden,tabhe,tabla,tabmo,tabza,tabfl
end block data
end interface
end python module iri16py
10 changes: 10 additions & 0 deletions numpy/f2py/tests/test_crackfortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -8, 75BD 6 +8,8 @@
from . import util
from numpy.f2py import crackfortran
import textwrap
import contextlib
import io


class TestNoSpace(util.F2PyTest):
Expand Down Expand Up @@ -335,3 +337,11 @@ def test_end_if_comment(self):
crackfortran.crackfortran([str(fpath)])
except Exception as exc:
assert False, f"'crackfortran.crackfortran' raised an exception {exc}"


class TestF77CommonBlockReader():
def test_gh22648(self, tmp_path):
fpath = util.getpath("tests", "src", "crackfortran", "gh22648.pyf")
with contextlib.redirect_stdout(io.StringIO()) as stdout_f2py:
mod = crackfortran.crackfortran([str(fpath)])
assert "Mismatch" not in stdout_f2py.getvalue()
0