Skip to content

Commit

Permalink
Merge pull request #172 from swig-fortran/merge-upstream
Browse files Browse the repository at this point in the history
Merge upstream SWIG
  • Loading branch information
sethrj authored Aug 14, 2022
2 parents 645acea + fb415db commit 9e3f404
Show file tree
Hide file tree
Showing 286 changed files with 6,854 additions and 1,648 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ jobs:
c++11) export CSTD=c11 ;;
c++14) export CSTD=c11 ;;
c++17) export CSTD=c17 ;;
c++20) export CSTD=c17 ;;
esac
echo CSTD="$CSTD" >> $GITHUB_ENV
fi
Expand Down
192 changes: 191 additions & 1 deletion CHANGES.current
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,196 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.1.0 (in progress)
===========================

2022-08-11: wsfulton
[Lua] Add support for std::unique_ptr in std_unique_ptr.i.
Add support for std::auto_ptr in std_auto_ptr.i.

2022-08-05: wsfulton
[D] Fix occasional undefined behaviour with inheritance hierarchies, particularly
when using virtual inheritance as the pointers weren't correctly upcast from derived
class to base class when stored in the base's proxy class.

2022-08-05: wsfulton
[D] Add support for std::unique_ptr in std_unique_ptr.i.
Add support for std::auto_ptr in std_auto_ptr.i.

2022-08-03: wsfulton
[Javascript] Add support for std::unique_ptr in std_unique_ptr.i.
Add support for std::auto_ptr in std_auto_ptr.i.

2022-08-02: wsfulton
[Octave] Add support for std::unique_ptr in std_unique_ptr.i.
Add support for std::auto_ptr in std_auto_ptr.i.

2022-08-01: wsfulton
[Python] Add initialisers for additional members in PyHeapTypeObject
(builtin mode) for Python-3.11 - _ht_tpname, _spec_cache.

2022-07-30: wsfulton
C++20 has deprecated std::basic_string<>::reserve() and the C++11 method
std::basic_string<>::shrink_to_fit() is a replacement that can be used.
std_string.i and std_wstring.i provided wrappers for reserve with the following
template instantiations:

%template(string) std::basic_string<char>;
%template(wstring) std::basic_string<wchar_t>;

The reserve method is no longer wrapped, however the shrink_to_fit() method
can be used as an alternative from the target language (the generated wrappers
call reserve() instead if C++<=20).

Note that std::basic_string<>::reserve(size_t n) is still wrapped unchanged.

*** POTENTIAL INCOMPATIBILITY ***

2022-07-30: wsfulton
[Tcl] Add support for std::unique_ptr in std_unique_ptr.i.
Add support for std::auto_ptr in std_auto_ptr.i.

2022-07-27: ZackerySpytz, olly
#1678 Support parsing C++20 templated lambdas.

2022-07-27: ZackerySpytz, olly
#1622 Add support for the C++20 spaceship operator (<=>).

2022-07-26: olly
[Tcl] https://sourceforge.net/p/swig/bugs/977/
Fix handling of long long on 32-bit platforms. This fix raises
SWIG's minimum supported Tcl version to 8.4.0 (which was released
just under 20 years ago).

2022-07-26: olly
Fix incorrect operator precedence in preprocessor expressions.

2022-07-25: olly
Support for C++14 binary integer literals in preprocessor expressions.

2022-07-20: wsfulton
[C#, Java] Ensure the order of interfaces generated in proxy interfaces for the
%interface family of macros is the same as that parsed from the bases in C++.

2022-07-20: jicks, Ingener74, olly
#422 [Python] Fix mishandling of a Python class inheriting from
multiple SWIG-wrapped director classes.

2022-07-19: wsfulton
#692 [C#, Java, Perl, Python, Ruby] std::unique_ptr and std::auto_ptr typemaps
provided for inputs types in std_unique_ptr.i and std_auto_ptr.i.

Now these smart pointers can be used as input parameters to functions. A proxy
class instance transfers memory ownership of the underlying C++ object from the
proxy class to a smart pointer instance passed to the wrapped function.

2022-07-19: jschueller
[Python] #2314 Drop support for Python 3.2.

2022-07-19: olly
Remove remaining support code for classic macos, which has not been
supported by Apple for over 20 years now.

2022-07-12: wsfulton
Performance optimisation for parameters passed by value that are C++11 movable.
The C++ wrappers create a temporary variable for a parameter to be passed to a
function. This is initially default constructed and then copy assigned from the
instance being passed in from the target language. This is unchanged, however,
when the temporary variable is passed to wrapped function, it is now done using
std::move. If the type is move constructible, the move constructor will be used
instead of the copy constructor.

2022-07-12: wsfulton
[Perl] Add std::auto_ptr support in std_auto_ptr.i library file.

2022-07-12: erezgeva
[Perl] Add std::unique_ptr support in std_unique_ptr.i library file.

2022-07-07: olly
[xml] #2213 XML has been moved to "Experimental" target language
status. It's not in good shape and is likely to be removed unless
somebody steps up to bring it up to the expected standard (it fails
to even meet the criteria for "Experimental" currently).

2022-07-07: jmarrec
#1158 #2286 Add basic support for C++11 attributes. These are now
crudely ignored by SWIG's parser's tokeniser, which is better that
failing with a parse error.

2022-07-05: ianlancetaylor
[Go] #2245 Handle NULL pointers for string* conversions.
Rearrange generation of director methods and rename
receiver argument from p to swig_p.

2022-07-03: wsfulton
Performance optimisation for directors for classes passed by value. The directorin
typemaps in the director methods now use std::move on the input parameter when
copying the object from the stack to the heap prior to the callback into the target
language, thereby taking advantage of move semantics if available.

2022-07-02: wsfulton
#1722 [C#, Java, Python, Ruby] Add std::unique_ptr support. Ported from std::auto_ptr.
Use the %unique_ptr(T) macro as follows for usage std::unique_ptr<T>. For example, for
a class called Klass:

%include "std_unique_ptr.i"
%unique_ptr(Klass)

Support is currently limited to only returning a std::unique_ptr from a function.

2022-06-29: wsfulton
#999 #1044 Enhance SWIGTYPE "out" typemaps to use std::move when copying
objects, thereby making use of move semantics when wrapping a function returning
by value if the returned type supports move semantics.

Wrapping functions that return move only types 'by value' now work out the box
without having to provide custom typemaps.

The implementation removed all casts in the "out" typemaps to allow the compiler to
appropriately choose calling a move constructor, where possible, otherwise a copy
constructor. The implementation also required modifying SwigValueWrapper to
change a cast operator from:

SwigValueWrapper::operator T&() const;

to

#if __cplusplus >=201103L
SwigValueWrapper::operator T&&() const;
#else
SwigValueWrapper::operator T&() const;
#endif

This is not backwards compatible for C++11 and later when using the valuewrapper feature
if a cast is explicitly being made in user supplied "out" typemaps. Suggested change
in custom "out" typemaps for C++11 and later code:

1. Try remove the cast altogether to let the compiler use an appropriate implicit cast.
2. Change the cast, for example, from static_cast<X &> to static_cast<X &&>, using the
__cplusplus macro if all versions of C++ need to be supported.

*** POTENTIAL INCOMPATIBILITY ***

2022-06-15: wsfulton
#2039 Add move assignment operator to SwigValueWrapper used by the
valuewrapper feature.

2022-06-04: sethrj
Enhance $typemap to support typemap attributes.

$typemap(method:attribute, typepattern)

For example:

%typemap(cstype, out="object") XClass "XClass"
%typemap(cscode) BarClass %{
$typemap(cstype:out, XClass) bar() {
return null;
}

which expands to

object bar() {
return null;
}

2022-05-30: wsfulton
[C#, D] Add new special variable expansion: $imfuncname.
Expands to the function name called in the intermediary class.
Expand Down Expand Up @@ -38,7 +228,7 @@ Version 4.1.0 (in progress)

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

2022-05-15: erezgeva, eiselekd
[Lua, Perl, Octave, PHP, Tcl] #2275 #2276 #2283 Add argcargv.i library containing
Expand Down
1 change: 1 addition & 0 deletions Doc/Devel/scanner.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ <h2>Token Codes</h2>
SWIG_TOKEN_GREATERTHAN &gt;
SWIG_TOKEN_LTEQUAL &lt;=
SWIG_TOKEN_GTEQUAL &gt;=
SWIG_TOKEN_LTEQUALGT &lt;=&gt;
SWIG_TOKEN_NOT ~
SWIG_TOKEN_LNOT !
SWIG_TOKEN_LBRACKET [
Expand Down
89 changes: 86 additions & 3 deletions Doc/Manual/CPlusPlus11.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ <H1><a name="CPlusPlus11">7 SWIG and C++11</a></H1>
<li><a href="#CPlusPlus11_core_language_changes">Core language changes</a>
<ul>
<li><a href="#CPlusPlus11_rvalue_reference_and_move_semantics">Rvalue reference and move semantics</a>
<ul>
<li><a href="#CPlusPlus11_move_only">Movable and move-only types</a>
</ul>
<li><a href="#CPlusPlus11_generalized_constant_expressions">Generalized constant expressions</a>
<li><a href="#CPlusPlus11_extern_template">Extern template</a>
<li><a href="#CPlusPlus11_initializer_lists">Initializer lists</a>
Expand Down Expand Up @@ -123,6 +126,82 @@ <H3><a name="CPlusPlus11_rvalue_reference_and_move_semantics">7.2.1 Rvalue refer
</pre>
</div>

<H4><a name="CPlusPlus11_move_only">7.2.1.1 Movable and move-only types</a></H4>


<p>
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.
Prior to C++11, a function could not return nor take a type by value that was not copyable.
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.
A move-only type is movable but not copyable; it has both the copy constructor and copy assignment operator deleted.
Movable types can appear in function signatures for passing 'by value' and in C++11 the object can then be moved rather than copied.
</p>

<p>
SWIG has been enhanced with support for both copyable and/or movable types but this is currently just for function return values.
</p>

<p>
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.
The typemap code is very simple and written so that the compiler will call the move constructor if possible,
otherwise the copy constructor:
</p>

<div class="code"><pre>
%typemap(out) SWIGTYPE %{
$result = new $1_ltype($1);
%}
</pre></div>

<p>
The above typemap is for C# and when used to wrap a move-only type such as:
</p>

<div class="code"><pre>
struct MoveOnly {
int val;
MoveOnly(): val(0) {}

MoveOnly(const MoveOnly &amp;) = delete;
MoveOnly(MoveOnly &amp;&amp;) = default;

MoveOnly &amp; operator=(const MoveOnly &amp;) = delete;
MoveOnly &amp; operator=(MoveOnly &amp;&amp;) = default;

static MoveOnly create() { return MoveOnly(); }
};
</pre></div>

<p>
will generate wrapper code for the <tt>create</tt> factory method:
</p>

<div class="code"><pre>
SWIGEXPORT void * SWIGSTDCALL CSharp_MoveOnly_create() {
void * jresult ;
SwigValueWrapper&lt; MoveOnly &gt; result;

result = MoveOnly::create();
jresult = new MoveOnly(result);
return jresult;
}
</pre></div>

<p>
<tt>SwigValueWrapper</tt> is covered in <a href="SWIGPlus.html#SWIGPlus_nn19">Pass and return by value</a>.
Note that the generated code could be optimised further using the <a href="Typemaps.html#Typemaps_optimal">"optimal" attribute</a> in the "out" typemap.
</p>

<p>
There is currently only partial support for move-only types as
support for move-only types used as a parameter in a function, that are passed 'by value', is not yet available.
</p>

<p>
<b>Compatibility note:</b>
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'.
</p>


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

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


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

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

<p>
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>.
Please see the <a href="Library.html#Library_std_shared_ptr">shared_ptr smart pointer</a> library section.
There is no special smart pointer handling available for <tt>std::weak_ptr</tt> and <tt>std::unique_ptr</tt> yet.
Please see the <a href="Library.html#Library_std_shared_ptr">shared_ptr smart pointer</a>
and <a href="Library.html#Library_std_unique_ptr">unique_ptr smart pointer</a> library sections.
There is no special smart pointer handling available for <tt>std::weak_ptr</tt>.

</p>

<H3><a name="CPlusPlus11_extensible_random_number_facility">7.3.6 Extensible random number facility</a></H3>
Expand Down
30 changes: 30 additions & 0 deletions Doc/Manual/CPlusPlus20.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ <H1><a name="CPlusPlus20">10 SWIG and C++20</a></H1>
<ul>
<li><a href="#CPlusPlus20_introduction">Introduction</a>
<li><a href="#CPlusPlus20_core_language_changes">Core language changes</a>
<ul>
<li><a href="#CPlusPlus20_spaceship_operator">Spaceship operator</a>
<li><a href="#CPlusPlus20_lambda_templates">Lambda templates</a>
</ul>
<li><a href="#CPlusPlus20_standard_library_changes">Standard library changes</a>
</ul>
</div>
Expand All @@ -35,6 +39,32 @@ <H2><a name="CPlusPlus20_introduction">10.1 Introduction</a></H2>
<H2><a name="CPlusPlus20_core_language_changes">10.2 Core language changes</a></H2>


<H3><a name="CPlusPlus20_spaceship_operator">10.2.1 Spaceship operator</a></H3>


<p>
SWIG supports the spaceship operator <tt>&lt;=&gt;</tt> in constant
expressions. To simplify handling of the return value type, it is currently
treated as an integer rather than <tt>std::strong_ordering</tt>, etc.
In practice we think that should do the right thing in most cases.
</p>

<p>
SWIG also recognises <tt>operator&lt;=&gt;</tt> which can be wrapped
if renamed. There is not currently any default renaming for the operator
or any attempt to automatically map it to a three-way comparison operator
in any of the target languages.
</p>

<H3><a name="CPlusPlus20_lambda_templates">10.2.2 Lambda templates</a></H3>


<p>
SWIG should parse lambda templates, but like
<a href="CPlusPlus11.html#CPlusPlus11_lambda_functions_and_expressions">
non-templated lambdas</a> they aren't currently wrapped.
</p>

<H2><a name="CPlusPlus20_standard_library_changes">10.3 Standard library changes</a></H2>


Expand Down
Loading

0 comments on commit 9e3f404

Please sign in to comment.