Skip to content

Commit fb415db

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 645acea + 3a0721b commit fb415db

File tree

286 files changed

+6854
-1648
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

286 files changed

+6854
-1648
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ jobs:
131131
c++11) export CSTD=c11 ;;
132132
c++14) export CSTD=c11 ;;
133133
c++17) export CSTD=c17 ;;
134+
c++20) export CSTD=c17 ;;
134135
esac
135136
echo CSTD="$CSTD" >> $GITHUB_ENV
136137
fi

CHANGES.current

Lines changed: 191 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,196 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
77
Version 4.1.0 (in progress)
88
===========================
99

10+
2022-08-11: wsfulton
11+
[Lua] Add support for std::unique_ptr in std_unique_ptr.i.
12+
Add support for std::auto_ptr in std_auto_ptr.i.
13+
14+
2022-08-05: wsfulton
15+
[D] Fix occasional undefined behaviour with inheritance hierarchies, particularly
16+
when using virtual inheritance as the pointers weren't correctly upcast from derived
17+
class to base class when stored in the base's proxy class.
18+
19+
2022-08-05: wsfulton
20+
[D] Add support for std::unique_ptr in std_unique_ptr.i.
21+
Add support for std::auto_ptr in std_auto_ptr.i.
22+
23+
2022-08-03: wsfulton
24+
[Javascript] Add support for std::unique_ptr in std_unique_ptr.i.
25+
Add support for std::auto_ptr in std_auto_ptr.i.
26+
27+
2022-08-02: wsfulton
28+
[Octave] Add support for std::unique_ptr in std_unique_ptr.i.
29+
Add support for std::auto_ptr in std_auto_ptr.i.
30+
31+
2022-08-01: wsfulton
32+
[Python] Add initialisers for additional members in PyHeapTypeObject
33+
(builtin mode) for Python-3.11 - _ht_tpname, _spec_cache.
34+
35+
2022-07-30: wsfulton
36+
C++20 has deprecated std::basic_string<>::reserve() and the C++11 method
37+
std::basic_string<>::shrink_to_fit() is a replacement that can be used.
38+
std_string.i and std_wstring.i provided wrappers for reserve with the following
39+
template instantiations:
40+
41+
%template(string) std::basic_string<char>;
42+
%template(wstring) std::basic_string<wchar_t>;
43+
44+
The reserve method is no longer wrapped, however the shrink_to_fit() method
45+
can be used as an alternative from the target language (the generated wrappers
46+
call reserve() instead if C++<=20).
47+
48+
Note that std::basic_string<>::reserve(size_t n) is still wrapped unchanged.
49+
50+
*** POTENTIAL INCOMPATIBILITY ***
51+
52+
2022-07-30: wsfulton
53+
[Tcl] Add support for std::unique_ptr in std_unique_ptr.i.
54+
Add support for std::auto_ptr in std_auto_ptr.i.
55+
56+
2022-07-27: ZackerySpytz, olly
57+
#1678 Support parsing C++20 templated lambdas.
58+
59+
2022-07-27: ZackerySpytz, olly
60+
#1622 Add support for the C++20 spaceship operator (<=>).
61+
62+
2022-07-26: olly
63+
[Tcl] https://sourceforge.net/p/swig/bugs/977/
64+
Fix handling of long long on 32-bit platforms. This fix raises
65+
SWIG's minimum supported Tcl version to 8.4.0 (which was released
66+
just under 20 years ago).
67+
68+
2022-07-26: olly
69+
Fix incorrect operator precedence in preprocessor expressions.
70+
71+
2022-07-25: olly
72+
Support for C++14 binary integer literals in preprocessor expressions.
73+
74+
2022-07-20: wsfulton
75+
[C#, Java] Ensure the order of interfaces generated in proxy interfaces for the
76+
%interface family of macros is the same as that parsed from the bases in C++.
77+
78+
2022-07-20: jicks, Ingener74, olly
79+
#422 [Python] Fix mishandling of a Python class inheriting from
80+
multiple SWIG-wrapped director classes.
81+
82+
2022-07-19: wsfulton
83+
#692 [C#, Java, Perl, Python, Ruby] std::unique_ptr and std::auto_ptr typemaps
84+
provided for inputs types in std_unique_ptr.i and std_auto_ptr.i.
85+
86+
Now these smart pointers can be used as input parameters to functions. A proxy
87+
class instance transfers memory ownership of the underlying C++ object from the
88+
proxy class to a smart pointer instance passed to the wrapped function.
89+
90+
2022-07-19: jschueller
91+
[Python] #2314 Drop support for Python 3.2.
92+
93+
2022-07-19: olly
94+
Remove remaining support code for classic macos, which has not been
95+
supported by Apple for over 20 years now.
96+
97+
2022-07-12: wsfulton
98+
Performance optimisation for parameters passed by value that are C++11 movable.
99+
The C++ wrappers create a temporary variable for a parameter to be passed to a
100+
function. This is initially default constructed and then copy assigned from the
101+
instance being passed in from the target language. This is unchanged, however,
102+
when the temporary variable is passed to wrapped function, it is now done using
103+
std::move. If the type is move constructible, the move constructor will be used
104+
instead of the copy constructor.
105+
106+
2022-07-12: wsfulton
107+
[Perl] Add std::auto_ptr support in std_auto_ptr.i library file.
108+
109+
2022-07-12: erezgeva
110+
[Perl] Add std::unique_ptr support in std_unique_ptr.i library file.
111+
112+
2022-07-07: olly
113+
[xml] #2213 XML has been moved to "Experimental" target language
114+
status. It's not in good shape and is likely to be removed unless
115+
somebody steps up to bring it up to the expected standard (it fails
116+
to even meet the criteria for "Experimental" currently).
117+
118+
2022-07-07: jmarrec
119+
#1158 #2286 Add basic support for C++11 attributes. These are now
120+
crudely ignored by SWIG's parser's tokeniser, which is better that
121+
failing with a parse error.
122+
123+
2022-07-05: ianlancetaylor
124+
[Go] #2245 Handle NULL pointers for string* conversions.
125+
Rearrange generation of director methods and rename
126+
receiver argument from p to swig_p.
127+
128+
2022-07-03: wsfulton
129+
Performance optimisation for directors for classes passed by value. The directorin
130+
typemaps in the director methods now use std::move on the input parameter when
131+
copying the object from the stack to the heap prior to the callback into the target
132+
language, thereby taking advantage of move semantics if available.
133+
134+
2022-07-02: wsfulton
135+
#1722 [C#, Java, Python, Ruby] Add std::unique_ptr support. Ported from std::auto_ptr.
136+
Use the %unique_ptr(T) macro as follows for usage std::unique_ptr<T>. For example, for
137+
a class called Klass:
138+
139+
%include "std_unique_ptr.i"
140+
%unique_ptr(Klass)
141+
142+
Support is currently limited to only returning a std::unique_ptr from a function.
143+
144+
2022-06-29: wsfulton
145+
#999 #1044 Enhance SWIGTYPE "out" typemaps to use std::move when copying
146+
objects, thereby making use of move semantics when wrapping a function returning
147+
by value if the returned type supports move semantics.
148+
149+
Wrapping functions that return move only types 'by value' now work out the box
150+
without having to provide custom typemaps.
151+
152+
The implementation removed all casts in the "out" typemaps to allow the compiler to
153+
appropriately choose calling a move constructor, where possible, otherwise a copy
154+
constructor. The implementation also required modifying SwigValueWrapper to
155+
change a cast operator from:
156+
157+
SwigValueWrapper::operator T&() const;
158+
159+
to
160+
161+
#if __cplusplus >=201103L
162+
SwigValueWrapper::operator T&&() const;
163+
#else
164+
SwigValueWrapper::operator T&() const;
165+
#endif
166+
167+
This is not backwards compatible for C++11 and later when using the valuewrapper feature
168+
if a cast is explicitly being made in user supplied "out" typemaps. Suggested change
169+
in custom "out" typemaps for C++11 and later code:
170+
171+
1. Try remove the cast altogether to let the compiler use an appropriate implicit cast.
172+
2. Change the cast, for example, from static_cast<X &> to static_cast<X &&>, using the
173+
__cplusplus macro if all versions of C++ need to be supported.
174+
175+
*** POTENTIAL INCOMPATIBILITY ***
176+
177+
2022-06-15: wsfulton
178+
#2039 Add move assignment operator to SwigValueWrapper used by the
179+
valuewrapper feature.
180+
181+
2022-06-04: sethrj
182+
Enhance $typemap to support typemap attributes.
183+
184+
$typemap(method:attribute, typepattern)
185+
186+
For example:
187+
188+
%typemap(cstype, out="object") XClass "XClass"
189+
%typemap(cscode) BarClass %{
190+
$typemap(cstype:out, XClass) bar() {
191+
return null;
192+
}
193+
194+
which expands to
195+
196+
object bar() {
197+
return null;
198+
}
199+
10200
2022-05-30: wsfulton
11201
[C#, D] Add new special variable expansion: $imfuncname.
12202
Expands to the function name called in the intermediary class.
@@ -38,7 +228,7 @@ Version 4.1.0 (in progress)
38228

39229
2022-05-26: rokups
40230
[C#] #1323 Modify SwigDerivedClassHasMethod for a more efficient director
41-
implementation when calling virtual methods that are not overidden.
231+
implementation when calling virtual methods that are not overridden.
42232

43233
2022-05-15: erezgeva, eiselekd
44234
[Lua, Perl, Octave, PHP, Tcl] #2275 #2276 #2283 Add argcargv.i library containing

Doc/Devel/scanner.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ <h2>Token Codes</h2>
204204
SWIG_TOKEN_GREATERTHAN &gt;
205205
SWIG_TOKEN_LTEQUAL &lt;=
206206
SWIG_TOKEN_GTEQUAL &gt;=
207+
SWIG_TOKEN_LTEQUALGT &lt;=&gt;
207208
SWIG_TOKEN_NOT ~
208209
SWIG_TOKEN_LNOT !
209210
SWIG_TOKEN_LBRACKET [

Doc/Manual/CPlusPlus11.html

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ <H1><a name="CPlusPlus11">7 SWIG and C++11</a></H1>
1515
<li><a href="#CPlusPlus11_core_language_changes">Core language changes</a>
1616
<ul>
1717
<li><a href="#CPlusPlus11_rvalue_reference_and_move_semantics">Rvalue reference and move semantics</a>
18+
<ul>
19+
<li><a href="#CPlusPlus11_move_only">Movable and move-only types</a>
20+
</ul>
1821
<li><a href="#CPlusPlus11_generalized_constant_expressions">Generalized constant expressions</a>
1922
<li><a href="#CPlusPlus11_extern_template">Extern template</a>
2023
<li><a href="#CPlusPlus11_initializer_lists">Initializer lists</a>
@@ -123,6 +126,82 @@ <H3><a name="CPlusPlus11_rvalue_reference_and_move_semantics">7.2.1 Rvalue refer
123126
</pre>
124127
</div>
125128

129+
<H4><a name="CPlusPlus11_move_only">7.2.1.1 Movable and move-only types</a></H4>
130+
131+
132+
<p>
133+
SWIG has traditionally relied on wrapped C++ types to be copy constructible or copy assignable, either via an explicit or implicit copy constructor and copy assignment operator.
134+
Prior to C++11, a function could not return nor take a type by value that was not copyable.
135+
In C++11 this is no longer the case. A type can also be movable if it has has a move constructor and a move assignment operator.
136+
A move-only type is movable but not copyable; it has both the copy constructor and copy assignment operator deleted.
137+
Movable types can appear in function signatures for passing 'by value' and in C++11 the object can then be moved rather than copied.
138+
</p>
139+
140+
<p>
141+
SWIG has been enhanced with support for both copyable and/or movable types but this is currently just for function return values.
142+
</p>
143+
144+
<p>
145+
The support for function return values is generically implemented in the "out" <tt>SWIGTYPE</tt> typemap which supports any type, including copyable, movable and move-only types.
146+
The typemap code is very simple and written so that the compiler will call the move constructor if possible,
147+
otherwise the copy constructor:
148+
</p>
149+
150+
<div class="code"><pre>
151+
%typemap(out) SWIGTYPE %{
152+
$result = new $1_ltype($1);
153+
%}
154+
</pre></div>
155+
156+
<p>
157+
The above typemap is for C# and when used to wrap a move-only type such as:
158+
</p>
159+
160+
<div class="code"><pre>
161+
struct MoveOnly {
162+
int val;
163+
MoveOnly(): val(0) {}
164+
165+
MoveOnly(const MoveOnly &amp;) = delete;
166+
MoveOnly(MoveOnly &amp;&amp;) = default;
167+
168+
MoveOnly &amp; operator=(const MoveOnly &amp;) = delete;
169+
MoveOnly &amp; operator=(MoveOnly &amp;&amp;) = default;
170+
171+
static MoveOnly create() { return MoveOnly(); }
172+
};
173+
</pre></div>
174+
175+
<p>
176+
will generate wrapper code for the <tt>create</tt> factory method:
177+
</p>
178+
179+
<div class="code"><pre>
180+
SWIGEXPORT void * SWIGSTDCALL CSharp_MoveOnly_create() {
181+
void * jresult ;
182+
SwigValueWrapper&lt; MoveOnly &gt; result;
183+
184+
result = MoveOnly::create();
185+
jresult = new MoveOnly(result);
186+
return jresult;
187+
}
188+
</pre></div>
189+
190+
<p>
191+
<tt>SwigValueWrapper</tt> is covered in <a href="SWIGPlus.html#SWIGPlus_nn19">Pass and return by value</a>.
192+
Note that the generated code could be optimised further using the <a href="Typemaps.html#Typemaps_optimal">"optimal" attribute</a> in the "out" typemap.
193+
</p>
194+
195+
<p>
196+
There is currently only partial support for move-only types as
197+
support for move-only types used as a parameter in a function, that are passed 'by value', is not yet available.
198+
</p>
199+
200+
<p>
201+
<b>Compatibility note:</b>
202+
SWIG-4.1.0 introduced support for taking advantage of types with move semantics and wrapping functions that return movable or move-only types 'by value'.
203+
</p>
204+
126205

127206
<H3><a name="CPlusPlus11_generalized_constant_expressions">7.2.2 Generalized constant expressions</a></H3>
128207

@@ -1010,7 +1089,9 @@ <H3><a name="CPlusPlus11_attributes">7.2.29 Attributes</a></H3>
10101089

10111090

10121091
<p>
1013-
Attributes such as those shown below, are not yet supported and will give a syntax error.
1092+
Attributes such as those shown below, are supported since SWIG 4.1.0 but are
1093+
currently crudely ignored by the parser's tokeniser so they have no effect on
1094+
SWIG's code generation.
10141095
</p>
10151096

10161097
<div class="code"><pre>
@@ -1157,8 +1238,10 @@ <H3><a name="CPlusPlus11_general_purpose_smart_pointers">7.3.5 General-purpose s
11571238

11581239
<p>
11591240
SWIG provides special smart pointer handling for <tt>std::shared_ptr</tt> in the same way it has support for <tt>boost::shared_ptr</tt>.
1160-
Please see the <a href="Library.html#Library_std_shared_ptr">shared_ptr smart pointer</a> library section.
1161-
There is no special smart pointer handling available for <tt>std::weak_ptr</tt> and <tt>std::unique_ptr</tt> yet.
1241+
Please see the <a href="Library.html#Library_std_shared_ptr">shared_ptr smart pointer</a>
1242+
and <a href="Library.html#Library_std_unique_ptr">unique_ptr smart pointer</a> library sections.
1243+
There is no special smart pointer handling available for <tt>std::weak_ptr</tt>.
1244+
11621245
</p>
11631246

11641247
<H3><a name="CPlusPlus11_extensible_random_number_facility">7.3.6 Extensible random number facility</a></H3>

Doc/Manual/CPlusPlus20.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ <H1><a name="CPlusPlus20">10 SWIG and C++20</a></H1>
1313
<ul>
1414
<li><a href="#CPlusPlus20_introduction">Introduction</a>
1515
<li><a href="#CPlusPlus20_core_language_changes">Core language changes</a>
16+
<ul>
17+
<li><a href="#CPlusPlus20_spaceship_operator">Spaceship operator</a>
18+
<li><a href="#CPlusPlus20_lambda_templates">Lambda templates</a>
19+
</ul>
1620
<li><a href="#CPlusPlus20_standard_library_changes">Standard library changes</a>
1721
</ul>
1822
</div>
@@ -35,6 +39,32 @@ <H2><a name="CPlusPlus20_introduction">10.1 Introduction</a></H2>
3539
<H2><a name="CPlusPlus20_core_language_changes">10.2 Core language changes</a></H2>
3640

3741

42+
<H3><a name="CPlusPlus20_spaceship_operator">10.2.1 Spaceship operator</a></H3>
43+
44+
45+
<p>
46+
SWIG supports the spaceship operator <tt>&lt;=&gt;</tt> in constant
47+
expressions. To simplify handling of the return value type, it is currently
48+
treated as an integer rather than <tt>std::strong_ordering</tt>, etc.
49+
In practice we think that should do the right thing in most cases.
50+
</p>
51+
52+
<p>
53+
SWIG also recognises <tt>operator&lt;=&gt;</tt> which can be wrapped
54+
if renamed. There is not currently any default renaming for the operator
55+
or any attempt to automatically map it to a three-way comparison operator
56+
in any of the target languages.
57+
</p>
58+
59+
<H3><a name="CPlusPlus20_lambda_templates">10.2.2 Lambda templates</a></H3>
60+
61+
62+
<p>
63+
SWIG should parse lambda templates, but like
64+
<a href="CPlusPlus11.html#CPlusPlus11_lambda_functions_and_expressions">
65+
non-templated lambdas</a> they aren't currently wrapped.
66+
</p>
67+
3868
<H2><a name="CPlusPlus20_standard_library_changes">10.3 Standard library changes</a></H2>
3969

4070

0 commit comments

Comments
 (0)