8000 Merge pull request #22657 from HaoZeke/fix22648 · numpy/numpy@050dbc6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 050dbc6

Browse files
authored
Merge pull request #22657 from HaoZeke/fix22648
BUG: Fix common block handling in f2py
2 parents 899e735 + d6bdb08 commit 050dbc6

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

numpy/f2py/crackfortran.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,8 @@ def readfortrancode(ffile, dowithline=show, istop=1):
614614
r'endinterface|endsubroutine|endfunction')
615615
endpattern = re.compile(
616616
beforethisafter % ('', groupends, groupends, '.*'), re.I), 'end'
617-
endifs = r'end\s*(if|do|where|select|while|forall|associate|block|' + \
617+
# block, the Fortran 2008 construct needs special handling in the rest of the file
618+
endifs = r'end\s*(if|do|where|select|while|forall|associate|' + \
618619
r'critical|enum|team)'
619620
endifpattern = re.compile(
620621
beforethisafter % (r'[\w]*?', endifs, endifs, '.*'), re.I), 'endif'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
python module iri16py ! in
2+
interface ! in :iri16py
3+
block data ! in :iri16py:iridreg_modified.for
4+
COMMON /fircom/ eden,tabhe,tabla,tabmo,tabza,tabfl
5+
end block data
6+
end interface
7+
end python module iri16py

numpy/f2py/tests/test_crackfortran.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from . import util
99
from numpy.f2py import crackfortran
1010
import textwrap
11+
import contextlib
12+
import io
1113

1214

1315
class TestNoSpace(util.F2PyTest):
@@ -338,3 +340,11 @@ def test_end_if_comment(self):
338340
crackfortran.crackfortran([str(fpath)])
339341
except Exception as exc:
340342
assert False, f"'crackfortran.crackfortran' raised an exception {exc}"
343+
344+
345+
class TestF77CommonBlockReader():
346+
def test_gh22648(self, tmp_path):
347+
fpath = util.getpath("tests", "src", "crackfortran", "gh22648.pyf")
348+
with contextlib.redirect_stdout(io.StringIO()) as stdout_f2py:
349+
mod = crackfortran.crackfortran([str(fpath)])
350+
assert "Mismatch" not in stdout_f2py.getvalue()

0 commit comments

Comments
 (0)
0