Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit df9d175

Browse filesBrowse files
authored
BUG: Fix crackfortran parsing error when a division occurs within a common block (#28396)
* BUG: Fix crackpython parsing error when a division occurs within a common block * Add test for more complicated array sizing expression * fix typos * Simplify tests to currently supported syntax * Use regular expression to find common block name * Revert from broken regular expression version to prior version, add comment * Add space before inline comment * Use regular expression to split line * Add missing white space to appease linter * More linting fixes * Pass maxsplit as a keyword argument
1 parent 89595a5 commit df9d175
Copy full SHA for df9d175

File tree

3 files changed

+24
-20
lines changed
Filter options

3 files changed

+24
-20
lines changed

‎numpy/f2py/crackfortran.py

Copy file name to clipboardExpand all lines: numpy/f2py/crackfortran.py
+2-19Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,26 +1490,9 @@ def analyzeline(m, case, line):
14901490
line = m.group('after').strip()
14911491
if not line[0] == '/':
14921492
line = '//' + line
1493+
14931494
cl = []
1494-
f = 0
1495-
bn = ''
1496-
ol = ''
1497-
for c in line:
1498-
if c == '/':
1499-
f = f + 1
1500-
continue
1501-
if f >= 3:
1502-
bn = bn.strip()
1503-
if not bn:
1504-
bn = '_BLNK_'
1505-
cl.append([bn, ol])
1506-
f = f - 2
1507-
bn = ''
1508-
ol = ''
1509-
if f % 2:
1510-
bn = bn + c
1511-
else:
1512-
ol = ol + c
1495+
[_, bn, ol] = re.split('/', line, maxsplit=2)
15131496
bn = bn.strip()
15141497
if not bn:
15151498
bn = '_BLNK_'
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
subroutine common_with_division
2+
integer lmu,lb,lub,lpmin
3+
parameter (lmu=1)
4+
parameter (lb=20)
5+
c crackfortran fails to parse this
6+
c parameter (lub=(lb-1)*lmu+1)
7+
c crackfortran can successfully parse this though
8+
parameter (lub=lb*lmu-lmu+1)
9+
parameter (lpmin=2)
10+
11+
c crackfortran fails to parse this correctly
12+
c common /mortmp/ ctmp((lub*(lub+1)*(lub+1))/lpmin+1)
13+
14+
common /mortmp/ ctmp(lub/lpmin+1)
15+
16+
return
17+
end

‎numpy/f2py/tests/test_crackfortran.py

Copy file name to clipboardExpand all lines: numpy/f2py/tests/test_crackfortran.py
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,16 @@ def incr(x):
114114

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

119121
def test_gh2848(self):
120122
r = self.module.gh2848(1, 2)
121123
assert r == (1, 2)
122124

125+
def test_common_with_division(self):
126+
assert len(self.module.mortmp.ctmp) == 11
123127

124128
class TestMarkinnerspaces:
125129
# gh-14118: markinnerspaces does not handle multiple quotations

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.