Commit Graph

1049 Commits

Author SHA1 Message Date
William S Fulton e8d3c74590 Improvements to $typemap() special variable replacement overrides
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.
2023-11-03 09:07:51 +00:00
William S Fulton 791d0a5e17 Further using declarations fix for inheritance hierarchies
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
2023-10-16 20:05:34 +01:00
William S Fulton 40ed95c4f7 Swig_symbol_clookup_check bug fix
Don't drop the checkfunc when processing using nodes.
I can't find any use cases for this fix, but this
fix seems like the right thing to do.
2023-10-16 20:05:34 +01:00
Momtchil Momtchev 6b5ae59b03 to run the CI 2023-09-13 10:19:40 +02:00
William S Fulton d4abe14f7e Non-assignable detection fixes when wrapping const 2D arrays
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.
2023-09-09 12:31:33 +01:00
William S Fulton 69d5373131 Fix missing constructor generation due to abstract class test failure
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.
2023-08-05 19:47:17 +01:00
William S Fulton b9f1515514 Corrected type returned from calling nodeType 2023-08-05 19:46:15 +01:00
Olly Betts 31c73a2b85 Fix comments to match actual function return value 2023-08-01 12:03:46 +12:00
William S Fulton 5e1a37c6c5 Fix duplicate sym:overname values using %copyctor
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
2023-07-29 00:28:28 +01:00
William S Fulton 705d5b875a Warning 302 rewording update for %extend 2023-07-28 07:51:32 +01:00
William S Fulton a3e8e1fe50 Warnings 302 and 322 code refactor 2023-07-28 07:16:49 +01:00
William S Fulton 454c3bc52d Correct display of redundant typedefs in Warnings 302 and 322 2023-07-28 07:16:49 +01:00
William S Fulton 7cea399cba Correct display of class names in Warnings 302 and 322 2023-07-28 07:15:41 +01:00
William S Fulton 526bc33376 More redefinition/redeclaration warning message improvements
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).
2023-07-28 07:15:41 +01:00
William S Fulton 94ab699075 Consistency in warnings for ambiguous/redefined templated constructors
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.
2023-07-25 20:04:49 +01:00
William S Fulton c9d79386d9 Default constructor detection fix for templated constructors
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.
2023-07-21 18:30:36 +01:00
William S Fulton feb8e2e641 Fix C++11 using declarations for inheriting implicit base constructors
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.
2023-07-14 08:39:27 +01:00
William S Fulton b7332ce8ca Fix using declarations and templates with explicitly declared 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.
2023-07-12 18:44:42 +01:00
Olly Betts bcb0c6a7b1 Eliminate duplicate scanner codes
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.
2023-06-28 09:01:17 +12:00
Olly Betts a7d3c96b61 Eliminate T_ERROR
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
2023-06-25 08:57:47 +12:00
Olly Betts 808066fc1e Remove unused T_NUMERIC and T_SYMBOL
Seems these haven't been used for at least 20 years!
2023-06-23 15:56:48 +12:00
Olly Betts 24a0088960 Fix incorrect indentation 2023-06-23 15:27:58 +12:00
Olly Betts 4365084ab2 Remove redundant break after return 2023-06-23 14:52:46 +12:00
Olly Betts 602826c897 Fix handling of template in array size
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 #2486
Closes: #2575
2023-06-20 08:32:58 +12:00
Olly Betts a43602cfc5 Use non-Doh-prefixed symbols outside of DOH itself
Fix a few uses of DohDelete, DohLen, DohNone and DohSetInt.
2023-06-15 14:48:41 +12:00
Olly Betts 40033f8498 Fix parsing of <= and >= in templated lambda
Skipping between matching delimiters is now done at the token level
rather than the character level.

Partly addresses #2630
2023-06-07 15:46:20 +12:00
Olly Betts 7ba44dc62d Support deducing type of some expressions
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).
2023-05-25 11:50:47 +12:00
Olly Betts a8b1f262ef Relocate a comment to where it makes sense 2023-05-20 09:26:16 +12:00
Olly Betts 59fa42a751 Use Putc instead of Append on a temp 1 or 2 char string
Easier to read code and probably a little more efficient.
2023-05-16 11:52:29 +12:00
Olly Betts c9bcc39540 Improve docs for Scanner_skip_balanced() return value 2023-05-16 11:44:56 +12:00
Olly Betts 8a9628e2b9 Use strchr/Strchr for single character searches
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.
2023-05-15 16:19:17 +12:00
Olly Betts b1388bcbf9 Parse storage class more flexibly
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 #302
Fixes #2079 (friend constexpr)
Fixes #2474 (virtual explicit)
2023-05-11 13:54:30 +12:00
William S Fulton 65be881295 Partial revert of previous commit for typedefs
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 #2550
Closes #2551
2023-05-06 11:13:23 +01:00
Momtchil Momtchev e92ffa84ef tentative fix for typedef/using declaration to struct typedef 2023-05-06 10:54:14 +01:00
Olly Betts c538bd24c4 Restore handling for '<<' in array size
I accidentally dropped this in 8fb15fcc92.
2023-04-20 14:53:30 +12:00
Olly Betts 752ec61d27 Add missing newline on new error message 2023-04-20 14:26:53 +12:00
Olly Betts 8fb15fcc92 Improve error for array size with a '<' character
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.
2023-04-20 14:14:43 +12:00
William S Fulton 4a6f6283aa Fix duplicate const in generated code wrapping templates
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);
2023-03-08 19:45:17 +00:00
William S Fulton a92871d9d1 Cosmetic change in template terminology
Prefer terminology from C++ standard: function templates and class templates
2023-03-03 21:08:53 +00:00
William S Fulton 9924c5c3e1 Partial template specialization fixes to support default arguments
Default argments come from the primary template's parameter list.

Example:
  template<class Y, class T=int> struct X { void primary() {} };
  // Previously the specialization below resulted in:
  // Error: Inconsistent argument count in template partial specialization. 1 2
  template<class YY> struct X<YY*> { void special(YY*) {} };

  // Both of these correctly wrap the partially specialized template
  %template(StringPtr) X<const char *>;
  %template(ShortPtr) X<short *, int>;
2023-03-01 19:42:00 +00:00
William S Fulton b18b75369c Fix seg fault using %template
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
2023-01-03 23:53:34 +00:00
William S Fulton 674abaddbf Fix instantiation of variadic class templates
containing parameter pack arguments that are function pointers.

  template <typename... V> struct VariadicParms {
    void ParmsFuncPtrVal(int (*)(V...)) {}
  };

  %template(VariadicParms0) VariadicParms<>;
  %template(VariadicParms1) VariadicParms<A>;
2022-12-29 23:38:17 +00:00
William S Fulton 67c4c2186c Support multiple arguments in variadic templates.
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.
2022-12-22 21:23:39 +00:00
William S Fulton 1e73045da8 Refactor Swig_cparse_template_parms_expand()
Break up functionality in Swig_cparse_template_parms_expand() to make it
more readable / maintainable.
2022-12-21 20:15:47 +00:00
William S Fulton d3095144e1 Optimise SwigType_base implementation
Also fixes assumption that templates start '<' instead of '<('.
Checked java and python test-suite - no changes in output.
2022-11-23 20:22:40 +00:00
William S Fulton ca5c68e544 Fix seg fault handling template parameter expressions containing '>='
Similar to previous commit

Issue #1037
2022-11-22 21:40:38 +00:00
William S Fulton 0341258af7 Fix seg fault handling template parameter expressions containing '<='
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
2022-11-22 08:37:35 +00:00
William S Fulton e3ccabbd4d Simpler names when using SwigType_manglestr for templates
The default template name is generated instead of one with the default
template parameter.

Used in various places such as the type system.
2022-11-12 11:46:52 +00:00
William S Fulton 46f2778412 Consolidate name mangling functions
Swig_string_mangle      => Swig_name_mangle_string
Swig_name_mangle        => Swig_name_mangle_string
Swig_string_mangle_type => Swig_name_mangle_type
2022-11-12 09:18:19 +00:00
William S Fulton 6a9be797e1 SwigType * handling corrections - mangling
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.
2022-11-12 06:42:36 +00:00
William S Fulton 2acdfd77e9 SwigType * handling corrections
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.
2022-11-09 22:11:27 +00:00
William S Fulton ea3f043920 SwigValueWrapper and SwigType * correction
Modifying the type by adding in SwigValueWrapper needs to follow the
normal SwigType conventions for correct and proper type handling.
2022-11-08 09:11:35 +00:00
William S Fulton 52edda64c1 Fix infinite loop handling non-type template parameters
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.
2022-11-05 08:41:10 +00:00
William S Fulton 15c433c5f9 C89 fixes 2022-10-14 22:34:18 +01:00
William S Fulton 46f7501d94 Cleanup SWIG_VERSION definition
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
2022-10-13 19:47:43 +01:00
William S Fulton 2f55379687 Improve director unwrap detection for the return type
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
2022-10-10 08:45:26 +01:00
William S Fulton 4a397869a2 Merge branch 'director-unwrap-result'
* director-unwrap-result:
  Unwrap director classes only when returning a pointer or reference to an object
2022-10-07 18:41:14 +01:00
Olly Betts 80d05a1a6c Eliminate 2 redundant copies of swig banner
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.
2022-10-06 14:33:15 +13:00
Olly Betts 631b41ae7b Use https for swig.org links 2022-10-06 13:16:39 +13:00
William S Fulton 77b08daca7 Add DohSortedKeys function
Returns a list of sorted keys in a DOH Hash.
2022-09-30 22:48:04 +01:00
William S Fulton 15b2ec53e3 Runtime tables deterministic ordering (4)
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.
2022-09-29 19:40:47 +01:00
William S Fulton 5fdb591a62 Runtime tables deterministic ordering (3)
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.
2022-09-29 19:30:20 +01:00
William S Fulton 04af102578 Runtime tables deterministic ordering (2)
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.
2022-09-29 19:30:20 +01:00
William S Fulton acbe8ed49c Runtime tables deterministic ordering (1)
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.
2022-09-29 19:30:20 +01:00
Vadim Zeitlin b9fa8c23bb Make method wrappers suffix optional and disabled by default
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.
2022-09-19 12:40:03 +12:00
Vadim Zeitlin 864f32159a Merge branch 'restore-compat-wrappers-names' into C
Merge with the latest master including PR #2371.
2022-09-17 14:36:37 +02:00
Vadim Zeitlin 3caf285742 Make method wrappers suffix optional and disabled by default
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.
2022-09-17 14:27:51 +02:00
William S Fulton 3fa8e1f38f Visual C++ warning fix
conversion from '__int64' to 'long', possible loss of data
2022-07-31 01:02:08 +01:00
Olly Betts 100d4d5350 Only recognise spaceship operator for C++
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.
2022-07-27 13:46:53 +12:00
Olly Betts 54ddefe410 Revert "Modify fix for << in array size"
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.
2022-07-27 13:45:08 +12:00
Olly Betts 0ff9a0959a Modify fix for << in array size
The previous fix broke testcase arrays for Go.
2022-07-27 12:25:27 +12:00
Olly Betts 2227dc9e53 Fix handling of array whose size contains <<
Fixes https://sourceforge.net/p/swig/bugs/983/
2022-07-27 10:29:33 +12:00
Olly Betts 02b4bd8eca Fix spaceship operator bugs, document, add tests
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
2022-07-27 09:12:40 +12:00
Zackery Spytz cb887ed2d4 Add support for the <=> operator (C++20) 2022-07-27 09:12:40 +12:00
Olly Betts 6b4d5fe3f0 Remove remaining code to support macos9
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
2022-07-19 11:22:37 +12:00
Olly Betts 892557e799 Improve #include guard macros
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.
2022-07-19 09:35:46 +12:00
William S Fulton ea193a98f3 Merge two commits from movable-types-inputs
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
2022-07-12 09:48:17 +01:00
William S Fulton e777b054d5 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.

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.
2022-07-08 17:41:15 +01:00
Julien Marrec d3759a9b36 Avoid parse errors for C++ attributes
Just ignore anything in between [[ and ]] in the scanner, which is better
that failing with a parse error.

Fixes #1158
Fixes #2286
2022-07-08 15:27:02 +12:00
Olly Betts 6c4010e442 Resolve -Wstrict-prototypes warnings with clang-15
warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
2022-06-30 12:52:00 +12:00
Seth R Johnson 6254de05ef Avoid emitting locals duiring keyword typemap lookup 2022-06-04 14:19:15 +01:00
Seth R Johnson 5afc813842 Fix whitespace and memory leak 2022-06-04 13:55:24 +01:00
William S Fulton da40946aaa Merge branch 'typemap-colon'
* typemap-colon:
  Incoporate review suggestions
  Allow referencing of typemap keywords inside of "$typemap("
2022-06-01 07:57:01 +01:00
William S Fulton 2ded25d138 Fixes for ISO C89 2022-03-28 19:25:11 +01:00
William S Fulton 51a7f27d1c Minor fix to Swig_print_node 2022-03-25 23:44:07 +00:00
William S Fulton 1db04bf322 Improvements to the -debug command line options
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.
2022-03-25 23:34:52 +00:00
Olly Betts b2c58115d7 Fix previous commit
Revert changes inadvertently included, and fix `=` to `==`.
2022-03-20 19:44:23 +13:00
Olly Betts 029ddab8b5 [ci] Try to fix failing appveyor python builds 2022-03-20 18:42:50 +13:00
Olly Betts d7e83c1cbc Fix checking of "optimal" typemap attribute
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.
2022-03-19 08:13:09 +13:00
Olly Betts d7625ee6b2 Fix fatal error implemented by assert
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.
2022-03-07 14:24:48 +13:00
Olly Betts 735732d721 Eliminate calls to abort()
Call Exit(EXIT_FAILURE) instead so that output files get removed.
2022-03-06 14:21:06 +13:00
Olly Betts 55377bdc08 Add DOH Exit() and SetExitHandler()
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).
2022-03-06 12:33:54 +13:00
Olly Betts e38847f7e1 Fail cleanly on allocation failures
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.
2022-03-04 11:47:49 +13:00
Olly Betts deb7cbf741
Merge branch 'master' into director-unwrap-result 2022-03-01 11:34:59 +13:00
Seth R Johnson b38a6530e3 Incoporate review suggestions 2022-02-26 06:40:37 -05:00
Seth R Johnson 1329670640 Allow referencing of typemap keywords inside of "$typemap(" 2022-02-25 10:52:33 -05:00
William S Fulton d2e9b80be3 Merge branch 'using-declarations' into upstream-master
* using-declarations:
  Typo fixes
  Fix warning suppression for WARN_PARSE_USING_UNDEF
  Using declarations fix in symbol tables
  Revert recent using-declarations code changes

Conflicts:
	CHANGES.current
2022-02-20 17:04:56 +00:00
William S Fulton 9b131a03d5 Fix warning suppression for WARN_PARSE_USING_UNDEF
New warnings for unknown using declarations since fix in previous commit
2022-02-20 16:45:10 +00:00
William S Fulton cb963a1440 Using declarations fix in symbol tables
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.
2022-02-20 15:33:32 +00:00
William S Fulton 3f36157b39 Revert recent using-declarations code changes
Reverts code changes from 7b5a615e50
merge commit in preparation for better fix.
Issue #655 and issue #1488.
2022-02-20 11:12:16 +00:00