diff options
| author | Charles Harris <charlesr.harris@gmail.com> | 2022-06-10 07:19:33 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-10 07:19:33 -0600 |
| commit | 7d39b0f1135859598ed6bd086a11124a52d8a969 (patch) | |
| tree | eb932390f601f6d678bfb55cf055cbee7a3f0e4b | |
| parent | 6b43d9a3901d3713ae350776914c827a33753538 (diff) | |
| parent | 43fe8d6775a2a9db63fd00c63c14c7ee2efae01f (diff) | |
| download | numpy-7d39b0f1135859598ed6bd086a11124a52d8a969.tar.gz | |
Merge pull request #21712 from HaoZeke/f2cmapTypeDefs
BUG: `.f2py_f2cmap` doesn't map `long_long` and other options
| -rw-r--r-- | numpy/f2py/capi_maps.py | 2 | ||||
| -rwxr-xr-x | numpy/f2py/rules.py | 3 | ||||
| -rw-r--r-- | numpy/f2py/tests/src/f2cmap/.f2py_f2cmap | 1 | ||||
| -rw-r--r-- | numpy/f2py/tests/src/f2cmap/isoFortranEnvMap.f90 | 9 | ||||
| -rw-r--r-- | numpy/f2py/tests/test_f2cmap.py | 15 |
5 files changed, 30 insertions, 0 deletions
diff --git a/numpy/f2py/capi_maps.py b/numpy/f2py/capi_maps.py index e5dc2331a..f07066a09 100644 --- a/numpy/f2py/capi_maps.py +++ b/numpy/f2py/capi_maps.py @@ -176,6 +176,7 @@ f2cmap_all = {'real': {'': 'float', '4': 'float', '8': 'double', f2cmap_default = copy.deepcopy(f2cmap_all) +f2cmap_mapped = [] def load_f2cmap_file(f2cmap_file): global f2cmap_all @@ -212,6 +213,7 @@ def load_f2cmap_file(f2cmap_file): f2cmap_all[k][k1] = d[k][k1] outmess('\tMapping "%s(kind=%s)" to "%s"\n' % (k, k1, d[k][k1])) + f2cmap_mapped.append(d[k][k1]) else: errmess("\tIgnoring map {'%s':{'%s':'%s'}}: '%s' must be in %s\n" % ( k, k1, d[k][k1], d[k][k1], list(c2py_map.keys()))) diff --git a/numpy/f2py/rules.py b/numpy/f2py/rules.py index c9c3b2383..63c48a878 100755 --- a/numpy/f2py/rules.py +++ b/numpy/f2py/rules.py @@ -1323,6 +1323,9 @@ def buildmodule(m, um): rd = dictappend(rd, ar) needs = cfuncs.get_needs() + # Add mapped definitions + needs['typedefs'] += [cvar for cvar in capi_maps.f2cmap_mapped # + if cvar in typedef_need_dict.values()] code = {} for n in needs.keys(): code[n] = [] diff --git a/numpy/f2py/tests/src/f2cmap/.f2py_f2cmap b/numpy/f2py/tests/src/f2cmap/.f2py_f2cmap new file mode 100644 index 000000000..a4425f887 --- /dev/null +++ b/numpy/f2py/tests/src/f2cmap/.f2py_f2cmap @@ -0,0 +1 @@ +dict(real=dict(real32='float', real64='double'), integer=dict(int64='long_long')) diff --git a/numpy/f2py/tests/src/f2cmap/isoFortranEnvMap.f90 b/numpy/f2py/tests/src/f2cmap/isoFortranEnvMap.f90 new file mode 100644 index 000000000..3f0e12c76 --- /dev/null +++ b/numpy/f2py/tests/src/f2cmap/isoFortranEnvMap.f90 @@ -0,0 +1,9 @@ + subroutine func1(n, x, res) + use, intrinsic :: iso_fortran_env, only: int64, real64 + implicit none + integer(int64), intent(in) :: n + real(real64), intent(in) :: x(n) + real(real64), intent(out) :: res +Cf2py intent(hide) :: n + res = sum(x) + end diff --git a/numpy/f2py/tests/test_f2cmap.py b/numpy/f2py/tests/test_f2cmap.py new file mode 100644 index 000000000..d2967e4f7 --- /dev/null +++ b/numpy/f2py/tests/test_f2cmap.py @@ -0,0 +1,15 @@ +from . import util +import numpy as np + +class TestF2Cmap(util.F2PyTest): + sources = [ + util.getpath("tests", "src", "f2cmap", "isoFortranEnvMap.f90"), + util.getpath("tests", "src", "f2cmap", ".f2py_f2cmap") + ] + + # gh-15095 + def test_long_long_map(self): + inp = np.ones(3) + out = self.module.func1(inp) + exp_out = 3 + assert out == exp_out |
