@@ -424,11 +424,14 @@ def readfortrancode(ffile, dowithline=show, istop=1):
424
424
if l [- 1 ] not in "\n \r \f " :
425
425
break
426
426
l = l [:- 1 ]
427
+ # Do not lower for directives, gh-2547, gh-27697, gh-26681
428
+ is_f2py_directive = False
427
429
# Unconditionally remove comments
428
430
(l , rl ) = split_by_unquoted (l , '!' )
429
431
l += ' '
430
432
if rl [:5 ].lower () == '!f2py' : # f2py directive
431
433
l , _ = split_by_unquoted (l + 4 * ' ' + rl [5 :], '!' )
434
+ is_f2py_directive = True
432
435
if l .strip () == '' : # Skip empty line
433
436
if sourcecodeform == 'free' :
434
437
# In free form, a statement continues in the next line
@@ -448,8 +451,10 @@ def readfortrancode(ffile, dowithline=show, istop=1):
448
451
if l [0 ] in ['*' , 'c' , '!' , 'C' , '#' ]:
449
452
if l [1 :5 ].lower () == 'f2py' : # f2py directive
450
453
l = ' ' + l [5 :]
454
+ is_f2py_directive = True
451
455
else : # Skip comment line
452
456
cont = False
457
+ is_f2py_directive = False
453
458
continue
454
459
elif strictf77 :
455
460
if len (l ) > 72 :
@@ -475,6 +480,7 @@ def readfortrancode(ffile, dowithline=show, istop=1):
475
480
else :
476
481
# clean up line beginning from possible digits.
477
482
l = ' ' + l [5 :]
483
+ # f2py directives are already stripped by this point
478
484
if localdolowercase :
479
485
finalline = ll .lower ()
480
486
else :
@@ -504,7 +510,11 @@ def readfortrancode(ffile, dowithline=show, istop=1):
504
510
origfinalline = ''
505
511
else :
506
512
if localdolowercase :
507
- finalline = ll .lower ()
513
+ # lines with intent() should be lowered otherwise
514
+ # TestString::test_char fails due to mixed case
515
+ # f2py directives without intent() should be left untouched
516
+ # gh-2547, gh-27697, gh-26681
517
+ finalline = ll .lower () if "intent" in ll .lower () or not is_f2py_directive else ll
508
518
else :
509
519
finalline = ll
510
520
origfinalline = ll
@@ -536,6 +546,7 @@ def readfortrancode(ffile, dowithline=show, istop=1):
536
546
else :
537
547
dowithline (finalline )
538
548
l1 = ll
549
+ # Last line should never have an f2py directive anyway
539
550
if localdolowercase :
540
551
finalline = ll .lower ()
541
552
else :
0 commit comments