Skip to content

Commit 90c93a9

Browse files
committed
Fix string typemap when including std_string *after* other typemaps
1 parent 6787b6e commit 90c93a9

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Examples/test-suite/fortran_ownership.i

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,18 @@ void do_nothing(TemplTricky<int>) {};
7676
%}
7777

7878
%template(TemplTrickyInt) myns::TemplTricky<int>;
79+
80+
// Test autofree declaration *before* including std:string
81+
%fortran_autofree_rvalue(std::string)
82+
namespace std {
83+
class string {
84+
};
85+
}
86+
87+
%include <std_string.i>
88+
89+
%inline %{
90+
std::string str_value(std::string s) { return s; }
91+
const std::string& str_cref(const std::string& s) { return s; }
92+
std::string& str_ref(std::string& s) { return s; }
93+
%}

Lib/fortran/std_string.i

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class string;
3232

3333
/* ---- CONST REFERENCE: NATIVE STRING ---- */
3434

35+
%clear const std::string &;
3536
%typemap(ctype) const std::string & = char*;
3637
%typemap(imtype) const std::string & = char*;
3738
%typemap(ftype) const std::string & = char*;
@@ -57,6 +58,7 @@ class string;
5758

5859
/* ---- VALUE: NATIVE STRING ---- */
5960

61+
%clear std::string;
6062
%apply const std::string & { std::string };
6163

6264
%typemap(globalin) std::string {

0 commit comments

Comments
 (0)