8000 Merge pull request #27731 from HaoZeke/fortrannameFunc · numpy/numpy@cd63250 · GitHub
[go: up one dir, main page]

Skip to content

Commit cd63250

Browse files
authored
Merge pull request #27731 from HaoZeke/fortrannameFunc
BUG: Fix `fortranname` for functions
2 parents 0db65f8 + a39d91c commit cd63250

File tree

6 files changed

+59
-1
lines changed

6 files changed

+59
-1
lines changed

numpy/f2py/rules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@
459459
{
460460
extern #ctype# #F_FUNC#(#name_lower#,#NAME#)(void);
461461
PyObject* o = PyDict_GetItemString(d,"#name#");
462-
tmp = F2PyCapsule_FromVoidPtr((void*)#F_FUNC#(#name_lower#,#NAME#),NULL);
462+
tmp = F2PyCapsule_FromVoidPtr((void*)#F_WRAPPEDFUNC#(#name_lower#,#NAME#),NULL);
463463
PyObject_SetAttrString(o,"_cpointer", tmp);
464464
Py_DECREF(tmp);
465465
s = PyUnicode_FromString("#name#");
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
REAL*8 FUNCTION FUNCFORTRANNAME(A,B)
2+
REAL*8 A, B
3+
FUNCFORTRANNAME = A + B
4+
RETURN
5+
END FUNCTION
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
python module funcfortranname ! in
2+
interface ! in :funcfortranname
3+
function funcfortranname_default(a,b) ! in :funcfortranname:funcfortranname.f
4+
fortranname funcfortranname
5+
real*8 :: a
6+
real*8 :: b
7+
real*8 :: funcfortranname_default
8+
real*8, intent(out) :: funcfortranname
9+
end function funcfortranname_default
10+
end interface
11+
end python module funcfortranname
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SUBROUTINE SUBROUT(A,B,C)
2+
REAL*8 A, B, C
3+
C = A + B
4+
END SUBROUTINE
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
python module subrout ! in
2+
interface ! in :subrout
3+
subroutine subrout_default(a,b,c) ! in :subrout:subrout.f
4+
fortranname subrout
5+
real*8 :: a
6+
real*8 :: b
7+
real*8, intent(out) :: c
8+
end subroutine subrout_default
9+
end interface
10+
end python module subrout

numpy/f2py/tests/test_routines.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pytest
2+
from . import util
3+
4+
5+
@pytest.mark.slow
6+
class TestRenamedFunc(util.F2PyTest):
7+
sources = [
8+
util.getpath("tests", "src", "routines", "funcfortranname.f"),
9+
util.getpath("tests", "src", "routines", "funcfortranname.pyf"),
10+
]
11+
module_name = "funcfortranname"
12+
13+
def test_gh25799(self):
14+
assert dir(self.module)
15+
assert self.module.funcfortranname_default(200, 12) == 212
16+
17+
18+
@pytest.mark.slow
19+
class TestRenamedSubroutine(util.F2PyTest):
20+
sources = [
21+
util.getpath("tests", "src", "routines", "subrout.f"),
22+
util.getpath("tests", "src", "routines", "subrout.pyf"),
23+
]
24+
module_name = "subrout"
25+
26+
def test_renamed_subroutine(self):
27+
assert dir(self.module)
28+
assert self.module.subrout_default(200, 12) == 212

0 commit comments

Comments
 (0)
0