Skip to content

Commit 2c48e8b

Browse files
committed
Make char* take native Fortran character type
1 parent 2ca2feb commit 2c48e8b

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

Examples/test-suite/fortran/char_binary_runme.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ program char_binary_runme
66
use char_binary
77
use ISO_C_BINDING
88
implicit none
9-
character(kind=C_CHAR, len=*), parameter :: withnull = "hil" // C_NULL_CHAR
9+
character(len=*), parameter :: withnull = "hil" // C_NULL_CHAR
1010
type(Test) :: t
1111

1212
if (len(withnull) /= 4) stop 2

Examples/test-suite/fortran/extend_template_method_runme.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ program extend_template_method_runme
99
type(ExtendMe) :: em
1010
type(TemplateExtend) :: tm
1111
real(C_DOUBLE) :: dbl
12-
character(kind=C_CHAR, len=:), allocatable :: str
12+
character(len=:), allocatable :: str
1313

1414
em = ExtendMe()
1515
dbl = em%do_stuff_double(1, 1.1d0)

Examples/test-suite/fortran/inctest_runme.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ program inctest_runme
66
use inctest
77
use ISO_C_BINDING
88
implicit none
9-
character(kind=C_CHAR, len=:), allocatable :: instr, outstr
9+
character(len=:), allocatable :: instr, outstr
1010
! If the 'includes' fail, these will produce compiler errors
1111
type(A) :: ai
1212
type(B) :: bi

Lib/fortran/fortranstrings.swg

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
%fragment("SWIG_fin"{char*}, "fsubprograms", fragment="SwigArrayWrapper_f", noblock=1) {
1616
subroutine %fortrantm(fin, char*)(finp, iminp, temp)
1717
use, intrinsic :: ISO_C_BINDING
18-
character(kind=C_CHAR, len=*), intent(in) :: finp
18+
character(len=*), intent(in) :: finp
1919
type(SwigArrayWrapper), intent(out) :: iminp
2020
character(kind=C_CHAR), dimension(:), target, allocatable, intent(out) :: temp
2121
integer :: i
2222

2323
allocate(character(kind=C_CHAR) :: temp(len(finp) + 1))
2424
do i=1,len(finp)
25-
temp(i) = finp(i:i)
25+
temp(i) = char(ichar(finp(i:i)), kind=C_CHAR)
2626
end do
2727
i = len(finp) + 1
2828
temp(i) = C_NULL_CHAR ! C finp compatibility
@@ -36,13 +36,13 @@ end subroutine
3636
subroutine %fortrantm(fout, char*)(imout, fout)
3737
use, intrinsic :: ISO_C_BINDING
3838
type(SwigArrayWrapper), intent(in) :: imout
39-
character(kind=C_CHAR, len=:), allocatable, intent(out) :: fout
39+
character(len=:), allocatable, intent(out) :: fout
4040
character(kind=C_CHAR), dimension(:), pointer :: chars
4141
integer(kind=C_SIZE_T) :: i
4242
call c_f_pointer(imout%data, chars, [imout%size])
4343
allocate(character(kind=C_CHAR, len=imout%size) :: fout)
4444
do i=1, imout%size
45-
fout(i:i) = chars(i)
45+
fout(i:i) = char(ichar(chars(i)))
4646
end do
4747
end subroutine
4848
}
@@ -69,8 +69,8 @@ end subroutine
6969
}
7070

7171
// Fortran proxy code: return allocatable string
72-
%typemap(ftype, in="character(kind=C_CHAR, len=*), target") char *
73-
"character(kind=C_CHAR, len=:), allocatable"
72+
%typemap(ftype, in="character(len=*), target") char *
73+
"character(len=:), allocatable"
7474

7575
%typemap(fin, fragment="SWIG_fin"{char*}, noblock=1,
7676
temp="character(kind=C_CHAR), dimension(:), allocatable, target"
@@ -107,8 +107,8 @@ end subroutine
107107
$2 = $input->size;
108108
}
109109

110-
%typemap(ftype, in="character(kind=C_CHAR, len=*), target") (char *STRING, size_t LENGTH)
111-
"character(kind=C_CHAR, len=:), allocatable"
110+
%typemap(ftype, in="character(len=*), target") (char *STRING, size_t LENGTH)
111+
"character(len=:), allocatable"
112112

113113
%typemap(fin, fragment="SWIG_fin"{char*}, noblock=1,
114114
temp="character(kind=C_CHAR), dimension(:), allocatable, target")

0 commit comments

Comments
 (0)