summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2021-01-18 10:28:18 +0200
committerGitHub <noreply@github.com>2021-01-18 10:28:18 +0200
commit2908338b19c26c043eab61c2af7bdff96b02b1bc (patch)
treed584f5feb361568d091ca989ebae2155bdaeee28 /numpy
parent59a2c17a7851b4cd88d2631654d5fe5d50f0ba11 (diff)
parent0e3aaeb275a023c0f13df25ad55bb3b20acc1cd5 (diff)
downloadnumpy-2908338b19c26c043eab61c2af7bdff96b02b1bc.tar.gz
Merge pull request #18181 from pearu/pearu/17859
ENH: [f2py] Add external attribute support.
Diffstat (limited to 'numpy')
-rwxr-xr-xnumpy/f2py/crackfortran.py4
-rw-r--r--numpy/f2py/tests/test_crackfortran.py29
2 files changed, 33 insertions, 0 deletions
diff --git a/numpy/f2py/crackfortran.py b/numpy/f2py/crackfortran.py
index 16a9a6fab..d27845796 100755
--- a/numpy/f2py/crackfortran.py
+++ b/numpy/f2py/crackfortran.py
@@ -1611,6 +1611,10 @@ def updatevars(typespec, selector, attrspec, entitydecl):
edecl['charselector'] = copy.copy(charselect)
edecl['typename'] = typename
edecl['attrspec'] = copy.copy(attrspec)
+ if 'external' in (edecl.get('attrspec') or []) and e in groupcache[groupcounter]['args']:
+ if 'externals' not in groupcache[groupcounter]:
+ groupcache[groupcounter]['externals'] = []
+ groupcache[groupcounter]['externals'].append(e)
if m.group('after'):
m1 = lenarraypattern.match(markouterparen(m.group('after')))
if m1:
diff --git a/numpy/f2py/tests/test_crackfortran.py b/numpy/f2py/tests/test_crackfortran.py
index 735804024..827c71ae9 100644
--- a/numpy/f2py/tests/test_crackfortran.py
+++ b/numpy/f2py/tests/test_crackfortran.py
@@ -86,3 +86,32 @@ class TestPublicPrivate():
assert 'public' not in mod['vars']['a']['attrspec']
assert 'private' not in mod['vars']['seta']['attrspec']
assert 'public' in mod['vars']['seta']['attrspec']
+
+class TestExternal(util.F2PyTest):
+ # issue gh-17859: add external attribute support
+ code = """
+ integer(8) function external_as_statement(fcn)
+ implicit none
+ external fcn
+ integer(8) :: fcn
+ external_as_statement = fcn(0)
+ end
+
+ integer(8) function external_as_attribute(fcn)
+ implicit none
+ integer(8), external :: fcn
+ external_as_attribute = fcn(0)
+ end
+ """
+
+ def test_external_as_statement(self):
+ def incr(x):
+ return x + 123
+ r = self.module.external_as_statement(incr)
+ assert r == 123
+
+ def test_external_as_attribute(self):
+ def incr(x):
+ return x + 123
+ r = self.module.external_as_attribute(incr)
+ assert r == 123