Commit graph

5,419 commits

Author SHA1 Message Date
William S Fulton
7bdc708e5f Template parameters handling tidy up
Technical correction on how template parameters are stored in a Parm*.
Doesn't actually make any change, but they are now displayed correctly
when using debug options such as -debug-module.
2022-12-02 19:44:59 +00:00
William S Fulton
05b93b1f06 Improved template template parameters support.
Previously, specifying more than one simple template template parameter
resulted in a parse error. Now multiple template template parameters are
working including instantiation with %template. Example:

  template <template<template<class> class, class> class Op, template<class> class X, class Y>
    class C { ... };

Closes #624
Closes #1021
2022-12-02 19:16:02 +00:00
William S Fulton
c5e02bf327 Ocaml name mangling fix
Fixes testcase template_expr which was resulting in OCaml syntax errors.
2022-11-29 08:04:37 +00:00
William S Fulton
2a1711e436 Slightly better decltype() support for expressions
decltype now accepts C++ expressions instead of just an ID, such as:

  int i,j;
  ...  decltype(i+j) ...
  ...  decltype(&i) ...

These result in a warning for non-trivial expressions which SWIG cannot evaluate:

  Warning 344: Unable to deduce decltype for 'i+j'.

See 'Type Inference' in CPlusPlus.html for workarounds.

Issue #1589
Issue #1590
2022-11-26 01:16:20 +00:00
William S Fulton
9b91b24d6b Fix syntax error parsing unnamed template parameters with a default.
Closes #961
2022-11-25 08:37:39 +00:00
Olly Betts
081d44d45e Follow-on fix for previous change
These cases don't trigger ubsan warnings and seem to work locally
for me, but CI was failing on a number of builds.

See #2447
2022-11-25 12:29:52 +13:00
Olly Betts
81c6a63898 Fix undefined behaviour in parser
Fix undefined behaviour in swig's parser when handling default parameter
expressions containing method calls.

Fixes #2447
2022-11-25 09:51:58 +13: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
29bc7492a2 SwigType * handling corrections - Python builtin 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 *.

The previous commit is a pre-requisite in order to prevent duplicate
symbols from being generated in the C++ wrappers.
2022-11-18 19:44:00 +00:00
William S Fulton
4729cf2b1f Duplicate class template instantiations via %template changes
Named duplicate class template instantiations now issue a warning and are ignored.
Duplicate empty class template instantiations are quietly ignored.

The test cases are fixed for this new behaviour.

This commit is a pre-requisite for the near future so that the Python
builtin wrappers can correctly use the SwigType_namestr function without
generating duplicate symbol names.
2022-11-18 19:35:47 +00:00
William S Fulton
777fd2c280 Minor refactor of D, C#, Java director code
for overloaded methods. Fixes regression (crash) in director_ignore D
testcase since string mangling names change.
2022-11-12 16:30:25 +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
3364c18d06 Remove unused code in mzscheme.cxx 2022-11-12 09:06:26 +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
973590ff91 R rtypecheck typemaps
Further switch to use rtypecheck typemaps instead of hard coded logic.
The full switch to typemaps is deferred until swig-4.2 as it can't be fully
backwards compatible. For now a warning is provided to help the
transition. It provides the full typemap that should be placed into
a user's interface file, for example:

%typemap("rtype") int32_t * "integer"
void testmethod(int32_t * i);
void testmethod();

If there is no rtypecheck typemap for int32_t *, the warning shown is:

example.i:7: Warning 750: Optional rtypecheck code is deprecated. Add the
following typemap to fix as the next version of SWIG will not work without it:
%typemap("rtypecheck") int32_t * %{ (is.integer($arg) || is.numeric($arg)) %}

The warning is shown for any code that previously used "numeric", "integer" or
"character" for the rtype typemap. Copying the rtypecheck typemap as
shown into the user interface file will provide the appropriate fix and
the warning will disappear. This is important to do as swig-4.2 will
not be able to provide this helpful warning.
2022-11-05 08:40:26 +00:00
William S Fulton
d6d83f4df4 Overloading fixes for R and rtypecheck typemap
- Fix for special variable $argtype expansion in rtypecheck typemap.
- Remove unnecessary () brackets when using rtypecheck typemap for
  single parameter functions.
- Add rtypecheck typemaps for shared_ptr so that NULL can be used
  in overloaded functions taking shared_ptr.
2022-11-05 08:40:26 +00:00
William S Fulton
f2da4f2ade Improve R wrapper error message calling overloaded methods
when incorrect types passed are passed to the overloaded methods.

Old unhelpful error message:
  Error in f(...) : could not find function "f"

Example of new improved error message:
  Error in use_count(k) :
    cannot find overloaded function for use_count with argtypes (NULL)
2022-11-05 08:40:19 +00:00
Olly Betts
df716b8f00 Document that -php7 is for PHP 7 *or later*
This was already in the manual, but not in -help output.

Fixes #2420
2022-10-31 13:41:10 +13:00
William S Fulton
a5b4a4389c Merge branch 'rfix-cleaned-up'
* rfix-cleaned-up:
  Whitespace cleanup in R testcase
  R shared_ptr fixes
  align implementation of smartname to r class name
  enable test for pointerreftest fixed by 752b7e8
  switched implementation reference from java to python
  fixes from code review
  enable li_boost_shared_ptr in r-test-suite
  typo in comment
  fix naming of RClass when template of a shared_ptr
2022-10-24 19:39:34 +01:00
William S Fulton
6c4dcbb8fe R shared_ptr fixes
Fix problems in shared_ptr wrappers where the class names were
not consistent when using the shared_ptr template or the actual
underlying type. Move $R_class substitution to typemaps.

Issue #2386
2022-10-24 19:37:56 +01:00
William S Fulton
4a8f7a9c46 Visual C++ warning fixes 2022-10-24 18:43:31 +01:00
AndLLA
0fec14ba34 align implementation of smartname to r class name 2022-10-24 18:20:10 +01:00
AndLLA
b885c22f11 fixes from code review 2022-10-24 18:20:10 +01:00
AndLLA
b15e058a27 typo in comment 2022-10-24 18:20:10 +01:00
AndLLA
a71bb2bc6e fix naming of RClass when template of a shared_ptr 2022-10-24 18:20:10 +01:00
William S Fulton
38c2c15e61 Merge branch 'MSB8027'
* MSB8027:
  CMake: Avoid including parser.c twice
  Fix -Wunused-variable warning
2022-10-24 16:28:29 +01:00
William S Fulton
6370fab025 R - fix $typemap() for R specific typemaps
Add support for special variable replacement in the $typemap()
special variable macro for R specific typemaps (rtype, rtypecheck,
scoercein, scoereout).
2022-10-24 16:27:54 +01:00
William S Fulton
1d73341aa4 Polymorphism in R wrappers fixed for C++ structs 2022-10-24 08:56:55 +01:00
Julien Schueller
0d523d337d Fix -Wunused-variable warning 2022-10-24 09:34:10 +02:00
Olly Betts
747a6a264f [php] Fix handling of multi-module cases
Look up unknown base classes using SWIG_MangledTypeQueryModule().

Revert to using SWIG_TypeCheck() instead of SWIG_TypeCheckStruct()
as the latter doesn't seem to work for this case (at least for PHP
right now).

Add mod_runme.php as a regression test for this.

Adjust the PHP test harness not to set up reflection for the module
unless it's actually needed for a testcase.  Currently the approach
to find the module name doesn't work for multi-module testcases.

See #2126
2022-10-18 10:28:17 +13:00
William S Fulton
15c433c5f9 C89 fixes 2022-10-14 22:34:18 +01:00
Olly Betts
5f96d15943 [R] Run destructors of local C++ objects on SWIG_fail
Arrange that destructors of local C++ objects in the wrapper function
get run on SWIG_fail (which calls Rf_error() which calls longjmp()).

We achieve this by putting almost everything in the function in its
own block, and end that right before Rf_error() at which point those
destructors will get called.
2022-10-14 14:44:19 +13:00
Olly Betts
9ab9c71623 [lua] Run destructors of local C++ objects on SWIG_fail
Arrange that destructors of local C++ objects in the wrapper function
get run on SWIG_fail (which calls lua_error() which calls longjmp()).

We achieve this by putting almost everything in the function in its
own block, and end that right before lua_error() at which point those
destructors will get called.
2022-10-14 14:44:19 +13:00
William S Fulton
f13de56e5f Revert "[xml] Move to "Experimental" target language status"
This reverts commit 22a4355f34.

Conflicts:
	CHANGES.current
	RELEASENOTES
2022-10-13 21:14:44 +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
d5a0201c54 XML whitespace changes
Remove non-conventional whitespace before closing tag with '>'.
2022-10-10 23:58:39 +01:00
William S Fulton
0239ba5536 OCaml director return fix
Fixes director_unwrap_result testcase when returning Element *const *&
2022-10-10 18:55:37 +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
William S Fulton
cea25abca5 Completely remove CFFI
No meaningful progress to update CFFI to experimental status
has been made since CFFI was disabled in SWIG-4.0.0 as the first
stage to removal. This commit is the final stage to remove it.

See issue #1966 for an attempt at updating CFFI to experimental
status. Anyone wishing for SWIG to support CFFI again might
want to utilise this work.
2022-10-06 23:29:33 +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
2e678369e6 Make licence boilterplate for go.cxx match other files
The existing text refers the reader to LICENSE for the actual
license like the standard boilerplate does.
2022-10-06 13:17:06 +13:00
Olly Betts
631b41ae7b Use https for swig.org links 2022-10-06 13:16:39 +13:00
William S Fulton
bc87fe151e Fix python/c++ coding confusion!
Visual c++ does not support 'and' yet.
2022-10-06 00:45:53 +01:00