diff --git a/numpy/f2py/crackfortran.py b/numpy/f2py/crackfortran.py index 002a2edb1275..1b8672410e4d 100755 --- a/numpy/f2py/crackfortran.py +++ b/numpy/f2py/crackfortran.py @@ -1742,6 +1742,23 @@ def updatevars(typespec, selector, attrspec, entitydecl): else: del d1[k] + if 'len' in d1 and 'array' in d1: + if d1['len'] == '': + d1['len'] = d1['array'] + del d1['array'] + elif typespec == 'character': + if ('charselector' not in edecl) or (not edecl['charselector']): + edecl['charselector'] = {} + if 'len' in edecl['charselector']: + del edecl['charselector']['len'] + edecl['charselector']['*'] = d1['len'] + del d1['len'] + else: + d1['array'] = d1['array'] + ',' + d1['len'] + del d1['len'] + errmess('updatevars: "%s %s" is mapped to "%s %s(%s)"\n' % ( + typespec, e, typespec, ename, d1['array'])) + if 'len' in d1: if typespec in ['complex', 'integer', 'logical', 'real']: if ('kindselector' not in edecl) or (not edecl['kindselector']): @@ -1763,16 +1780,6 @@ def updatevars(typespec, selector, attrspec, entitydecl): else: edecl['='] = d1['init'] - if 'len' in d1 and 'array' in d1: - if d1['len'] == '': - d1['len'] = d1['array'] - del d1['array'] - else: - d1['array'] = d1['array'] + ',' + d1['len'] - del d1['len'] - errmess('updatevars: "%s %s" is mapped to "%s %s(%s)"\n' % ( - typespec, e, typespec, ename, d1['array'])) - if 'array' in d1: dm = 'dimension(%s)' % d1['array'] if 'attrspec' not in edecl or (not edecl['attrspec']): diff --git a/numpy/f2py/tests/src/string/gh24008.f b/numpy/f2py/tests/src/string/gh24008.f new file mode 100644 index 000000000000..ab64cf771f68 --- /dev/null +++ b/numpy/f2py/tests/src/string/gh24008.f @@ -0,0 +1,8 @@ + SUBROUTINE GREET(NAME, GREETING) + CHARACTER NAME*(*), GREETING*(*) + CHARACTER*(50) MESSAGE + + MESSAGE = 'Hello, ' // NAME // ', ' // GREETING +c$$$ PRINT *, MESSAGE + + END SUBROUTINE GREET diff --git a/numpy/f2py/tests/test_character.py b/numpy/f2py/tests/test_character.py index 0bb0f4290272..373262bf96a6 100644 --- a/numpy/f2py/tests/test_character.py +++ b/numpy/f2py/tests/test_character.py @@ -574,7 +574,6 @@ def test_character_bc(self, state): class TestStringScalarArr(util.F2PyTest): sources = [util.getpath("tests", "src", "string", "scalar_string.f90")] - @pytest.mark.slow def test_char(self): for out in (self.module.string_test.string, self.module.string_test.string77): @@ -583,7 +582,6 @@ def test_char(self): expected = '|S8' assert out.dtype == expected - @pytest.mark.slow def test_char_arr(self): for out in (self.module.string_test.strarr, self.module.string_test.strarr77): @@ -591,3 +589,9 @@ def test_char_arr(self): assert out.shape == expected expected = '|S12' assert out.dtype == expected + +class TestStringAssumedLength(util.F2PyTest): + sources = [util.getpath("tests", "src", "string", "gh24008.f")] + + def test_gh24008(self): + self.module.greet("joe", "bob")