From b8af21ff494d1e93cbf6514283824da0c54ddc82 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Wed, 23 Nov 2022 05:25:15 +0000 Subject: [PATCH 1/2] BUG: Hotfix for handling common blocks in f2py --- numpy/f2py/crackfortran.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/numpy/f2py/crackfortran.py b/numpy/f2py/crackfortran.py index 4871d2628b7e..acdcf74853f7 100755 --- a/numpy/f2py/crackfortran.py +++ b/numpy/f2py/crackfortran.py @@ -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)' endifpattern = re.compile( beforethisafter % (r'[\w]*?', endifs, endifs, '.*'), re.I), 'endif' From d6bdb0817e40a323e33aac178252fac372c3d981 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Sun, 29 Jan 2023 23:01:50 +0000 Subject: [PATCH 2/2] TST: Add a test for gh-22648 --- numpy/f2py/tests/src/crackfortran/gh22648.pyf | 7 +++++++ numpy/f2py/tests/test_crackfortran.py | 10 ++++++++++ 2 files changed, 17 insertions(+) create mode 100644 numpy/f2py/tests/src/crackfortran/gh22648.pyf diff --git a/numpy/f2py/tests/src/crackfortran/gh22648.pyf b/numpy/f2py/tests/src/crackfortran/gh22648.pyf new file mode 100644 index 000000000000..b3454f18635f --- /dev/null +++ b/numpy/f2py/tests/src/crackfortran/gh22648.pyf @@ -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 diff --git a/numpy/f2py/tests/test_crackfortran.py b/numpy/f2py/tests/test_crackfortran.py index 49bfc13af5ee..2d4cd175d26a 100644 --- a/numpy/f2py/tests/test_crackfortran.py +++ b/numpy/f2py/tests/test_crackfortran.py @@ -8,6 +8,8 @@ from . import util from numpy.f2py import crackfortran import textwrap +import contextlib +import io class TestNoSpace(util.F2PyTest): @@ -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()