Skip to content

Commit 85e0e02

Browse files
committed
Fix operators and mark failing director tests
Operators require `intent(in)` on classes.
1 parent 00a121d commit 85e0e02

File tree

4 files changed

+100
-32
lines changed

4 files changed

+100
-32
lines changed

Examples/test-suite/fortran/Makefile.in

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,50 @@ FAILING_CPP_TESTS += \
5656
cpp11_rvalue_reference2 \
5757
cpp11_rvalue_reference3 \
5858
cpp11_default_delete \
59+
allprotected \
60+
apply_strings \
61+
apply_signed_char \
62+
director_abstract \
63+
director_binary_string \
64+
director_classic \
65+
director_basic \
66+
director_default \
67+
director_detect \
68+
director_classes \
69+
director_exception_catches \
70+
director_exception_nothrow \
71+
director_exception \
72+
director_enum \
73+
director_frob \
74+
director_nested \
75+
director_extend \
76+
director_nspace_director_name_collision \
77+
director_nspace \
78+
director_keywords \
79+
director_overload \
80+
director_namespace_clash \
81+
director_pass_by_value \
82+
director_ignore \
83+
director_ownership \
84+
director_protected \
85+
director_ref \
86+
director_property \
87+
director_primitives \
88+
director_smartptr \
89+
director_unroll \
90+
director_overload2 \
91+
director_protected_overloaded \
92+
director_using \
93+
director_redefined \
94+
director_wombat \
95+
director_void \
96+
li_boost_shared_ptr_director \
97+
nested_directors \
98+
typemap_directorout \
99+
director_string \
100+
cpp11_director_enums \
101+
cpp11_directors \
102+
cpp11_function_objects \
59103

60104
FAILING_C_TESTS += \
61105
char_constant \

Examples/test-suite/fortran/director_simple_runme.F90

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,44 @@ module director_simple_mod
88
use director_simple, only : IntBase, BoolBase
99
implicit none
1010

11-
type, extends(IntBase), public :: MyIntDerived
12-
integer(C_INT) :: multiply_by = 1
13-
integer(C_INT) :: add_to = 0
14-
contains
15-
procedure :: apply => MyIntDerived_apply
16-
end type MyIntDerived
17-
18-
type, extends(BoolBase), public :: MyBoolDerived
19-
integer :: call_count = 0
20-
contains
21-
procedure :: apply => MyBoolDerived_apply
22-
end type MyBoolDerived
23-
11+
integer :: call_count
12+
13+
type, extends(IntBase), public :: MyIntDerived
14+
integer(C_INT) :: multiply_by = 1
15+
integer(C_INT) :: add_to = 0
16+
contains
17+
procedure :: apply => MyIntDerived_apply
18+
end type MyIntDerived
19+
20+
type, extends(BoolBase), public :: MyBoolDerived
21+
integer :: call_count = 0
22+
contains
23+
procedure :: apply => MyBoolDerived_apply
24+
end type MyBoolDerived
25+
2426
contains
25-
27+
2628
function MyIntDerived_apply(self, x) &
27-
result(myresult)
28-
use, intrinsic :: ISO_C_BINDING
29-
class(MyIntDerived) :: self
30-
integer(C_INT), intent(in) :: x
31-
integer(C_INT) :: myresult
29+
result(myresult)
30+
use, intrinsic :: ISO_C_BINDING
31+
class(MyIntDerived), intent(in) :: self
32+
integer(C_INT), intent(in) :: x
33+
integer(C_INT) :: myresult
3234

33-
myresult = x * self%multiply_by + self%add_to
35+
myresult = x * self%multiply_by + self%add_to
3436
end function
3537

3638
function MyBoolDerived_apply(self, a, b) &
37-
result(myresult)
38-
use, intrinsic :: ISO_C_BINDING
39-
class(MyBoolDerived) :: self
40-
logical, intent(in) :: a
41-
logical, intent(in) :: b
42-
logical :: myresult
43-
44-
myresult = a .or. b
45-
self%call_count = self%call_count + 1
39+
result(myresult)
40+
use, intrinsic :: ISO_C_BINDING
41+
class(MyBoolDerived), intent(in) :: self
42+
logical, intent(in) :: a
43+
logical, intent(in) :: b
44+
logical :: myresult
45+
46+
myresult = a .or. b
47+
call_count = call_count + 1
4648
end function
47-
4849
end module
4950

5051
program director_simple_runme
@@ -101,12 +102,13 @@ subroutine test_director_bool
101102
call swig_initialize(myclass, source=BoolBase())
102103

103104
! Direct Fortran call
105+
call_count = 0
104106
ASSERT(myclass%apply(.true., .false.))
105107
ASSERT(.not. myclass%apply(.false., .false.))
106108
! Call through C director
107109
ASSERT(apply(myclass, .true., .false.))
108110
ASSERT(.not. apply(myclass, .false., .false.))
109-
ASSERT(myclass%call_count == 4)
111+
ASSERT(call_count == 4)
110112

111113
call myclass%release()
112114

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
! File : equality_runme.F90
2+
3+
#include "fassert.h"
4+
5+
program equality_runme
6+
use equality
7+
use ISO_C_BINDING
8+
implicit none
9+
type(EqualOpDefined) :: a
10+
type(EqualOpDefined) :: b
11+
12+
a = EqualOpDefined(5)
13+
b = EqualOpDefined() ! default in C++ is 5
14+
ASSERT(a%get_x() == b%get_x())
15+
ASSERT(a == b)
16+
! ASSERT(a /= b) No inequality operator is defined
17+
call b%set_x(4)
18+
ASSERT(.not. (a == b))
19+
20+
end program
21+
22+

Lib/fortran/classes.swg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ SWIGINTERN void SWIG_assign(SwigClassWrapper* self, SwigClassWrapper other) {
352352
// Raw pointers act mostly like value types, but they don't have to accept the exact type (polymorphic input, non-polymorphic output). Intent is 'in' because
353353
// we're not modifying the pointer or memory status.
354354
%apply SWIGTYPE { SWIGTYPE* };
355-
%typemap(ftype, in="class($fortranclassname)", nofortransubroutine=1) SWIGTYPE*
355+
%typemap(ftype, in="class($fortranclassname), intent(in)", nofortransubroutine=1) SWIGTYPE*
356356
"type($fortranclassname)"
357357
%typemap(in, noblock=1) SWIGTYPE* {
358358
$1 = ($1_ltype)$input->cptr;

0 commit comments

Comments
 (0)