8000 TST: Test the cracked intrinsic module · HaoZeke/numpy@0c4e6cc · GitHub
[go: up one dir, main page]

Skip to content

Commit 0c4e6cc

Browse files
committed
TST: Test the cracked intrinsic module
Modified after numpygh-24555
1 parent e888829 commit 0c4e6cc

File tree

6 files changed

+52
-40
lines changed

6 files changed

+52
-40
lines changed

numpy/f2py/_isocbind.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Partially from:
2+
# https://gcc.gnu.org/onlinedocs/gfortran/ISO_005fC_005fBINDING.html
13
iso_c_binding_map = {
24
'integer': {
35
'c_int': 'int',
@@ -44,3 +46,10 @@
4446
for fortran_type, c_type_dict in iso_c_binding_map.items():
4547
for c_type in c_type_dict.keys():
4648
isoc_kindmap[c_type] = fortran_type
49+
50+
# For derived type maps
51+
flatisoc = {
52+
c_type: ctype
53+
for type_category in iso_c_binding_map.values()
54+
for c_type, ctype in type_category.items()
55+
}

numpy/f2py/capi_maps.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -132,44 +132,6 @@
132132
'type': {'': 'struct'},
133133
'character': {'': 'string'}
134134
}
135-
# From:
136-
# https://gcc.gnu.org/onlinedocs/gfortran/ISO_005fC_005fBINDING.html
137-
iso_c_binding_map = {
138-
# Integers
139-
'c_int': 'int',
140-
'c_short': 'short int',
141-
'c_long': 'long int',
142-
'c_long_long': 'long long int',
143-
'c_signed_char': 'signed char',
144-
'c_size_t': 'size_t',
145-
'c_int8_t': 'int8_t',
146-
'c_int16_t': 'int16_t',
147-
'c_int32_t': 'int32_t',
148-
'c_int64_t': 'int64_t',
149-
'c_int_least8_t': 'int_least8_t',
150-
'c_int_least16_t': 'int_least16_t',
151-
'c_int_least32_t': 'int_least32_t',
152-
'c_int_least64_t': 'int_least64_t',
153-
'c_int_fast8_t': 'int_fast8_t',
154-
'c_int_fast16_t': 'int_fast16_t',
155-
'c_int_fast32_t': 'int_fast32_t',
156-
'c_int_fast64_t': 'int_fast64_t',
157-
'c_intmax_t': 'intmax_t',
158-
'c_intptr_t': 'intptr_t',
159-
'c_ptrdiff_t': 'ptrdiff_t',
160-
# Floating Point Numbers
161-
'c_float': 'float',
162-
'c_double': 'double',
163-
'c_long_double': 'long double',
164-
# Complex Numbers
165-
'c_float_complex': 'float _Complex',
166-
'c_double_complex': 'double _Complex',
167-
'c_long_double_complex': 'long double _Complex',
168-
# Logical
169-
'c_bool': '_Bool',
170-
# Char
171-
'c_char': 'char',
172-
}
173135
# TODO:Support ["iso_fortran_env", "ieee_exceptions", "ieee_arithmetic", "ieee_features"]
174136

175137
f2cmap_all = deep_merge(f2cmap_all, iso_c_binding_map)

numpy/f2py/crackfortran.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@
162162
from . import auxfuncs as aux
163163
from . import symbolic
164164
from . import capi_maps as capim
165+
from . import _isocbind as _isoc
165166

166167
f2py_version = __version__.version
167168

@@ -1494,7 +1495,7 @@ def analyzeline(m, case, line):
14941495
else:
14951496
rl[l] = l
14961497
if name == "iso_c_binding":
1497-
rl = {k:capim.iso_c_binding_map.get(k) for k,v in rl.items()}
1498+
rl = {k:_isoc.flatisoc.get(k) for k,v in rl.items()}
14981499
groupcache[groupcounter]['use'][name]['map'] = rl
14991500
elif mintrin:
15001501
# Intrinsic check
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module vec
2+
use, intrinsic :: iso_c_binding
3+
implicit none
4+
5+
type, bind(c) :: cartesian
6+
real(c_float) :: x(2),y,z
7+
end type cartesian
8+
9+
type, bind(c) :: radial
10+
real(c_double) :: rad, theta
11+
end type radial
12+
13+
end module vec
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module vec
2+
use iso_c_binding, only: c_float, c_double
3+
implicit none
4+
5+
type, bind(c) :: cartesian
6+
real(c_float) :: x(2),y,z
7+
end type cartesian
8+
9+
type, bind(c) :: radial
10+
real(c_double) :: rad, theta
11+
end type radial
12+
13+
end module vec

numpy/f2py/tests/test_crackfortran.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ def test_nameargspattern_backtracking(self, adversary):
323323
good_version_of_adversary = repeated_adversary + '@)@'
324324
assert nameargspattern.search(good_version_of_adversary)
325325

326-
327326
class TestFunctionReturn(util.F2PyTest):
328327
sources = [util.getpath("tests", "src", "crackfortran", "gh23598.f90")]
329328

@@ -348,3 +347,18 @@ def test_gh22648(self, tmp_path):
348347
with contextlib.redirect_stdout(io.StringIO()) as stdout_f2py:
349348
mod = crackfortran.crackfortran([str(fpath)])
350349
assert "Mismatch" not in stdout_f2py.getvalue()
350+
351+
352+
class TestIntrinsicModule:
353+
def test_dependencies_only(self, tmp_path):
354+
fpath = util.getpath("tests", "src", "crackfortran", "isocbindonly.f90")
355+
mod = crackfortran.crackfortran([str(fpath)])
356+
assert len(mod) == 1
357+
assert mod[0]["use"] == {'iso_c_binding': {'map': {'c_double': 'double', 'c_float': 'float'}, 'only': 1}}
358+
359+
def test_dependencies(self, tmp_path):
360+
fpath = util.getpath("tests", "src", "crackfortran", "isocbind.f90")
361+
mod = crackfortran.crackfortran([str(fpath)])
362+
assert len(mod) == 1
363+
from numpy.f2py import capi_maps as capim
364+
assert list(mod[0]["use"].values())[0] == capim.iso_c_binding_map

0 commit comments

Comments
 (0)
0