In $typemap(), the $n special variables are replaced by the appropriate
value for the type associated with the typemap calling $typemap().
The (undocumented) special variable overrides now also support
controlling what the $n special variables are replaced with from the
calling typemap, for example:
%typemap(in) std::pair<std::string, int> {
int& input_value_second = $1.second;
$typemap(in, int, 1=input_value_second);
...
}
replaces $1 in the int typemap with input_value_second instead of
whatever is the default for the target language (a variable that holds
the int value after marshalling from the target language).
This additional functionality might make it possible to replace the C++
templates used in the UTL with a much simpler system of typemaps utilising
$typemap(). See follow on commit to typemaps.c.
more than two deep and the using declarations are overloaded.
Using declarations from a base class' base were not available for use
in the target language when the using declaration was before a method
declaration.
Closes#2687
Const member variables such as the following are non-assignable by
by default:
const int x[2][2];
Variable setters are not generated when wrapping these non-assignable
variables and classes containing such non-assignable variables.
when a method is declared in the class along with a
using declaration and the using declaration is declared before
the method that implemented the pure virtual method, such as:
struct ConcreteDerived : AbstractBase {
ConcreteDerived() {} // was not wrapped
using AbstractBase::f;
virtual void f(int n) override {}
};
SourceForge bug: https://sourceforge.net/p/swig/bugs/932/
check_implemented in allocate.cxx was correctly finding a
non-abstract method, however, Swig_symbol_clookup_local_check, was
using the using declaration node instead of using the node returned
by check_implemented. The checkfunc is now given more control by
returning the node to use rather than Swig_symbol_clookup_local_check
always using the head of the csym linked list.
The sym:overname attribute was not being updated when templates were
included in the list of overloaded methods/constructors, leading to
duplicate target language symbols in some language like java/csharp.
Closes#2541
Replicate redefinition/redeclaration warning message improvements
in previous commit to nested classes.
Adding the symtab to all nodes in Swig_symbol_add() has also fixed some
warning displays with %extend 302 warnings, which were completely
missing before (extend_placement.i testcase).
Constructors used to warn with:
Warning 302: Identifier 'Json' redefined (ignored)
But now warn with:
Warning 322: Redundant redeclaration of 'Json'
Note that 320 is a warning that is shown by default and 322 is a
hidden warning by default.
The warning is now consistent for both templated methods and constructors
that are deemed redefined. See cpp11_template_parameters_decltype
testcase. This testcase has been enhanced with a runtime test to check
that the workarounds for overloaded templated constructors/methods do
work.
Don't generate a default constructor wrapper when a class has a
templated constructor, as there isn't actually an implied default
constructor. For example:
struct TConstructor3 {
template<typename T> TConstructor3(T val) {}
};
Previously wrappers were generated for a non-existent default
constructor which failed to compile.
Parser no longer checks for a declared constructor when handling a
using declaration in order to correct the name as it won't find
implicitly declared constructors. Now it checks that a using
declaration is for something that looks like a constructor instead
by checking the immediate base classes for allowed constructors.
Corner case problem fix for when the base template class was
instantiated with %template including the default arguments and
the base class had an explicitly declared constructor.
Swig_symbol_template_deftype() was sometimes incorrectly finding
a constructor instead of a template and thus failing to correctly
expand the template default args. Problem noticed since
9cf049186b where constructors are
stored simply by their name instead of name plus template args.
Probably fixes a few other subtle template problems when a template
class contains default args.
Having more than one name for the same token is unnecessary and makes
the code harder to follow.
These aliases were also mostly unused:
SWIG_TOKEN_TIMES was defined to the same value as SWIG_TOKEN_STAR,
but is not used anywhere.
SWIG_TOKEN_DIVIDE was defined to the same value as SWIG_TOKEN_SLASH but
also not used.
SWIG_TOKEN_MODULO was defined to the same value as SWIG_TOKEN_PERCENT
but only used in one place so just use SWIG_TOKEN_PERCENT there too.
This was only being used in one very specific case where we failed
to parse a type string, which seems like it really is just an
internal error so try handling it as such.
Closes: #2643
This was being rejected by SWIG because the type string contains '<'
not followed by '('. Drop this check as it should be unnecessary now
since the fixes for #1036 ensure that template parameters are enclosed
within '<(' and ')>'.
Fixes#2486Closes: #2575
This change only supports expressions involving literals of built-in
types, and `int` expressions aren't supported (due to the parser
currently setting .type=T_INT when in situations where that isn't
or may not be the correct type).
This can be more efficient than using strstr/Strstr with a single
character search string.
GCC is able to optimise strstr() with a single character literal
search string to strchr(), but clang doesn't, and likely no compiler
can for Strstr() (unless some sort of inter-object optimisation such
as LTO is used) since the literal string is in a different source file
to the strstr() call.
Previously we had a hard-coded list of allowed combinations in the
grammar, but this suffers from combinatorial explosion, and results
in a vague `Syntax error in input` error for invalid (and missing)
combinations.
This means we now support a number of cases which are valid C++
but weren't supported.
Fixes#302Fixes#2079 (friend constexpr)
Fixes#2474 (virtual explicit)
Setting current symbol table for a typedef seems wrong.
No difference to test-suite though.
Testcase rename for C++11 testing and minor adjustments.
Issue #2550Closes#2551
Previously we'd fail an assertion and dump core, which isn't nice:
Bad template type passed to SwigType_remember: a(std::numeric_limits< unsigned char >::max()).unsigned char
swig: ../../Source/Swig/typesys.c:1709: SwigType_remember_clientdata: Assertion `0' failed.
Aborted (core dumped)
We also now know that this situation can be triggered by particular
user inputs, so an assertion is not an appropriate check anyway.
Now we report an error and exit with non-zero status:
:1: Error: Array size expressions containing a '<' character not fully supported
The `:1:` part isn't ideal but happens because the SwigType doesn't seem
to have file:line information.
See #2486.
Fix duplicate const in generated code when template instantiation type is const
and use of template parameter is also explicitly const, such as:
template <typename T> struct Conster {
void cccc1(T const& t) {}
};
%template(ConsterInt) Conster<const int>;
Above previously led to generated code:
(arg1)->cccc1((int const const &)*arg2);
instead of
(arg1)->cccc1((int const &)*arg2);
Fix seg fault when instantiating templates with parameters that are function
parameters containing templates, such as:
%template(MyC) C<int(std::vector<int>)>;
Closes#983
Remove warning SWIGWARN_CPP11_VARIADIC_TEMPLATE which was issued if more
than one argument was used for a variadic template.
SwigType enhancement: 'v.' now represents a variadic argument.
Recent commits ensure types are correctly stored in SwigType *. In
particular template parameters are enclosed within '<(' and ')>'.
Now we can confidently handle template parameters as really being
delimited as such to fix an infinite loop handling template expressions
containing '<' or '>'. The previous implementation only assumed
template parameters were delimited by '<' and '>'.
Issue #1037
Further corrections to pass SwigType * to methods expecting types
instead of passing readable type strings.
Swig_string_mangle() takes a generic String *, but it was calling
functions that require SwigType *. Swig_string_mangle_type() is
now provided for SwigType *r. The special template handling
on types now occurs in this function.
Further corrections to pass SwigType * to methods expecting types
instead of passing readable type strings.
Required reworking code that adds a fake inheritance for smart pointers
using the smartptr feature. Swig_smartptr_upcast() added as a support
function for this.
Fixes infinite loop due to () brackets in a non-type template
parameter containing an expression
Fixes#2418
Non-trivial expressions are still not qualified properly though.
Add Swig_obligatory_macros which must be called by each
target language to define SWIG_VERSION correctly
in the generated code, as well as the language specific
macro SWIGXXX where XXX is the target language name.
Drop the #ifdef SWIGXXX that was previously generated -
I can't see the point of this and if users are defining
this macro somehow, then users will need to change this
Closes#1050
Resolve the return type to correctly determine if the type is a pointer or
reference to a director class.
SwigType_refptr_count_return() recently added as a simpler fix is no
longer needed.
The conventional approach of using the "type" rather than "decl" to
analyse the return type is used instead too.
Issue #1823
We had a banner for C, a banner for target languages (parameterised
to allow the comment sequence to be specified) and a special banner
for XML files in scilab.cxx.
The XML variant was only needed because the standard banner contains
`--` for a hyphen, so we now use ` - ` for that instead.
The C banner now calls Swig_banner_target_lang() with a suitable
comment sequence to print the actual banner text.
Output C/C++ type strings (| separated) in swig_type_info tables in
fixed order. The types are output in alphabetically sorted order,
with an exception. The final type is a fully resolved type, but
does not necessarily include default template parameters.
This type is the one used by SWIG_TypePrettyName which is commonly
used to display a type when the wrong type is passed in as a
parameter.
Previously the order was not very deterministic due to the use of
internal hash tables which do not have an ordering guarantee.
Output conversion functions used in the type tables in sorted order.
Sorted order in this case is the type being converted from.
So _p_BarTo_p_Foo comes before _p_ZarTo_p_Foo.
Previously the order was roughly in the order that the types were
parsed, but not necessarily due to the use of internal hash tables
which do not have an ordering guarantee.
Output conversion functions used in the type tables in sorted order.
Sorted order in this case is the type being converted to.
So _p_BarTo_p_Foo comes before _p_BarTo_p_Zoo.
Previously the order was roughly in the order that the types were
parsed, but not necessarily due to the use of internal hash tables
which do not have an ordering guarantee.
Many parts of the runtime tables are alphabetically sorted before
for the generated code. This patch sorts the elements within the
swig_cast_info lists. Order now is first the elements without a
converter then the elements with a converter.
For example:
new:
static swig_cast_info _swigc__p_Foo[] = {
{&_swigt__p_Foo, 0, 0, 0},
{&_swigt__p_Bar, _p_BarTo_p_Foo, 0, 0},
{&_swigt__p_Spam, _p_SpamTo_p_Foo, 0, 0},
{0, 0, 0, 0}};
old:
static swig_cast_info _swigc__p_Foo[] = {
{&_swigt__p_Bar, _p_BarTo_p_Foo, 0, 0},
{&_swigt__p_Foo, 0, 0, 0},
{&_swigt__p_Spam, _p_SpamTo_p_Foo, 0, 0},
{0, 0, 0, 0}};
Previously the order was roughly in the order that the types were
parsed, but not necessarily due to the use of internal hash tables
which do not have an ordering guarantee.
Unfortunately the changes of 26bf86322 (Use SWIG-specific for
non-overloaded synthesized functions too, 2021-11-09) did break some
existing code bases using SWIG as they hardcoded the old wrapper
function names.
So turn this off by default and add a global variable allowing to enable
this, which can be done for a specific language only. This is ugly but,
unfortunately, there is no way to use the Language object from the C
function Swig_MethodToFunction(), so the only alternative would be to
add another parameter to it, but it already has 6 of them, so it
wouldn't really be that much better.
See #2366, #2368, #2370.
Unfortunately the changes of 26bf86322 (Use SWIG-specific for
non-overloaded synthesized functions too, 2021-11-09) did break some
existing code bases using SWIG as they hardcoded the old wrapper
function names.
So turn this off by default and add a global variable allowing to enable
this, which can be done for a specific language only. This is ugly but,
unfortunately, there is no way to use the Language object from the C
function Swig_MethodToFunction(), so the only alternative would be to
add another parameter to it, but it already has 6 of them, so it
wouldn't really be that much better.
See #2366, #2368, #2370.
I don't think any valid C program can contain `<=>` in a tokenisable
context, but it's more helpful to fail with a syntax error at SWIG
parse time and not potentially generate C code trying to use `<=>` in
an expression which then fails at compile time.
This reverts commit 0ff9a0959a.
The modified fix breaks Java and C#, where C constant expressions
get used in the generated target language code in some cases.
Revert this fix for now.
Remove some erroneously added brackets_increment() calls.
Reject <=> in preprocessor expressions with a clear error message (it
seems it isn't supported here - clang and gcc don't at least).
The type returned by `<=>` is not `bool`. We pretend it's
`int` for now, which should work for how it's likely to be used
in constant expressions.
Fixes#1622
This OS has been unsupported for over 20 years. We stopped providing
macswig builds more than 20 years ago too:
https://sourceforge.net/projects/swig/files/macswig/
The required SIOUX library doesn't seem to be available anywhere
now either.
Closes#2323
Avoid using reserved identifiers such as `_DOHINT_H` (fixes#1989),
fix cases where the name doesn't match the filename, and make the naming
more consistent and less likely to collide with include guards in other
headers.
Performance optimisation for parameters passed by value that are C++11 movable.
Test copy constructor and assignment operator calls for movable types
Conflicts:
CHANGES.current
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.
Note that the implementation calls std::move for all user-defined types
(non-primitive types passed by value), this excludes anything passed by pointer,
reference and arrays. It does also include any type that has not been
defined/parsed by SWIG, that is, unknown types. std::move is called via the
SWIG_STD_MOVE macro which only calls std::move for C++11 and later code.
The debug command line options that display parse tree nodes
(-debug-module, -debug-top, -debug-symtabs) now display previously hidden
linked list pointers which are useful for debugging parse trees.
Added new command line option -debug-quiet. This suppresses the display
of most linked list pointers and symbol table pointers in the parse tree nodes.
The keys in the parse tree node are now shown in alphabetical order.
Previously SWIG checked that the typemap action contained ";\n" not
followed by an identifier character, and that it contained no other
`;`, but that incorrectly allows some cases it shouldn't.
Instead check that the action ends with `;\n` and contains no other
`;`, which is simpler and correctly rejects these cases.
Calling assert() on a condition that's always false is not an
appropriate way to exit after emitting "Fatal error [...]" because
if NDEBUG is defined the assert() becomes a no-op and the error
stops actually being fatal.
Exit() is a wrapper for exit() by default, but SetExitHandler() allows
specifying a function to call instead.
This means that failures within DOH (e.g. Malloc() failing due to lack
of memory) will now perform cleanup such as removing output files.
This commit also cleans up exit statuses so SWIG should now reliably
exit with status 0 if the run was successful and status 1 if there was
an error (or a warning and -Werror was in effect).
Previously in some situations SWIG would try to exit with the status set
to the number of errors encountered, but that's problematic - for
example if there were 256 errors this would result in exit status 0 on
most platforms. Also some error statuses have special meanings e.g.
those defined by <sysexits.h>.
Also SWIG/Javascript tried to exit with status -1 in a few places (which
typically results in exit status 255).
Previously code in the SWIG tool didn't handle allocation failures
well. Most places didn't check for NULL return from
malloc()/realloc()/calloc() at all, typically resulting in undefined
behaviour, and some places used assert() to check for a NULL return
(which is a misuse of assert() and such checks disappear if built with
NDEBUG defined leaving us back with undefined behaviour).
All C allocations are now done via wrapper functions (Malloc(),
Realloc() and Calloc()) which emit and error and exit with non-zero
status on failure, so a non-NULL return can be relied upon.
Fixes#1901.
Implementation is very similar to typedef implementation.
Issue #655 and closes#1488.
Testcase using_member.i.
Better implementation to that reverted in previous commit 3f36157b.
Symbol tables shown with -debug-csymbols and -debug-symbols now correct
and are similar to when using a typedef.