Skip to content

BUG: Fix crackfortran parsing error when a division occurs within a common block #28633

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 1 commit into from
Apr 2, 2025
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
21 changes: 2 additions & 19 deletions numpy/f2py/crackfortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -1489,26 +1489,9 @@ def analyzeline(m, case, line):
line = m.group('after').strip()
if not line[0] == '/':
line = '//' + line

cl = []
f = 0
bn = ''
ol = ''
for c in line:
if c == '/':
f = f + 1
continue
if f >= 3:
bn = bn.strip()
if not bn:
bn = '_BLNK_'
cl.append([bn, ol])
f = f - 2
bn = ''
ol = ''
if f % 2:
bn = bn + c
else:
ol = ol + c
[_, bn, ol] = re.split('/', line, maxsplit=2)
bn = bn.strip()
if not bn:
bn = '_BLNK_'
Expand Down
17 changes: 17 additions & 0 deletions numpy/f2py/tests/src/crackfortran/common_with_division.f
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
subroutine common_with_division
integer lmu,lb,lub,lpmin
parameter (lmu=1)
parameter (lb=20)
c crackfortran fails to parse this
c parameter (lub=(lb-1)*lmu+1)
c crackfortran can successfully parse this though
parameter (lub=lb*lmu-lmu+1)
parameter (lpmin=2)

c crackfortran fails to parse this correctly
c common /mortmp/ ctmp((lub*(lub+1)*(lub+1))/lpmin+1)

common /mortmp/ ctmp(lub/lpmin+1)

return
end
6 changes: 5 additions & 1 deletion numpy/f2py/tests/test_crackfortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,16 @@ def incr(x):

class TestCrackFortran(util.F2PyTest):
# gh-2848: commented lines between parameters in subroutine parameter lists
sources = [util.getpath("tests", "src", "crackfortran", "gh2848.f90")]
sources = [util.getpath("tests", "src", "crackfortran", "gh2848.f90"),
util.getpath("tests", "src", "crackfortran", "common_with_division.f")
]

def test_gh2848(self):
r = self.module.gh2848(1, 2)
assert r == (1, 2)

def test_common_with_division(self):
assert len(self.module.mortmp.ctmp) == 11

class TestMarkinnerspaces:
# gh-14118: markinnerspaces does not handle multiple quotations
Expand Down
Loading