Skip to content

Commit dd5e330

Browse files
committed
Fix return-by-array-pointer, and for const versions
1 parent 4a4599c commit dd5e330

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

Examples/test-suite/fortran/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ CPP_TEST_CASES = \
2626
fortran_naming \
2727
fortran_onlywrapped \
2828
fortran_overloads \
29+
fortran_std_span \
2930
fortran_subroutine \
3031
li_std_set \
3132
complextest \

Examples/test-suite/fortran_std_span.i

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ class span
1111
typedef int index_type;
1212
typedef _Tp* pointer;
1313

14-
span() : d_ptr(NULL), d_size(0) {}
15-
span(pointer d, index_type s) : d_ptr(d), d_size(s) {}
16-
span(pointer first, pointer last) : d_ptr(first), d_size(last - first) {}
14+
span() : ptr_(NULL), size_(0) {}
15+
span(pointer d, index_type s) : ptr_(d), size_(s) {}
16+
span(pointer first, pointer last) : ptr_(first), size_(last - first) {}
1717

18-
pointer data() const { return d_ptr; }
19-
index_type size() const { return d_size; }
18+
pointer data() const { return ptr_; }
19+
index_type size() const { return size_; }
2020

2121
private:
22-
pointer d_ptr;
23-
index_type d_size;
22+
pointer ptr_;
23+
index_type size_;
2424
};
2525
} // namespace std
2626

@@ -30,6 +30,8 @@ class span
3030

3131
%template() std::span<int>;
3232
%template() std::span<const int>;
33+
%template() std::span<unsigned int>;
34+
%template() std::span<const unsigned int>;
3335

3436
%inline %{
3537
std::span<int> get_by_value() {

Lib/fortran/fortranarray.swg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ end subroutine}
9797
%typemap(imtype) CPPTYPE& = CPPTYPE;
9898
%typemap(ctype) CPPTYPE& = CPPTYPE;
9999

100-
// Update the resulting Fortran pointer.
101-
//%typemap(fargout, match="argout", noblock=1) CPPTYPE& = VTYPE[]&;
100+
// Update the resulting Fortran pointer, but only by reference (not const ref)
101+
%typemap(fargout, match="fin", noblock=1) CPPTYPE& = VTYPE ARRAY[];
102+
%typemap(fargout, noblock=1) const CPPTYPE& {};
102103
%enddef
103104

Lib/fortran/fundamental.swg

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,10 @@ end subroutine}
203203

204204
// Define proxy code typemaps for an array of this type
205205
%fortran_typemap_finout(CTYPE[], CTYPE ARRAY[])
206-
206+
%typemap(fargout, fragment="SWIG_fout"{CTYPE[]}, noblock=1) CTYPE ARRAY[] {
207+
call %fortrantm(fout, CTYPE[])($1, $input)
208+
}
209+
%typemap(fargout) CTYPE const ARRAY[] = CTYPE ARRAY[];
207210
%enddef
208211

209212
/*!
@@ -225,6 +228,8 @@ end subroutine}
225228

226229
%typemap(fin) DSTTYPE ARRAY[] = SRCTYPE ARRAY[];
227230
%typemap(fout) DSTTYPE ARRAY[] = SRCTYPE ARRAY[];
231+
%typemap(fargout) DSTTYPE ARRAY[] = SRCTYPE ARRAY[];
232+
%typemap(fargout) DSTTYPE const ARRAY[] = SRCTYPE const ARRAY[];
228233
%enddef
229234

230235
/* -------------------------------------------------------------------------

0 commit comments

Comments
 (0)