Commit Graph

1103 Commits

Author SHA1 Message Date
William S Fulton faf1e17b45 Merge branch 'std_filesystem_python'
* std_filesystem_python:
  Add <type_traits> fragment for traits usage in std::filesystem
  Correct const std::filesystem & typemaps
  Fix memory leak wrapping const std::filesystem&
  std::filesystem pointer handling correction
  Python std::filesystem cleanup
  Cosmetic whitespace corrections
  Try to use wstring/wchar_t on windows
  Reformat
  Rename the helpers within the fragment to be more uniquely named
  Make CI rerun (and output all failed cases for the specialPath)
  Address review comments
  Need to see which assert is failing on mingw
  Verbose assert to try and see the failure on mingw
  path::string() returns a copy not a const ref.
  Remove cpp17_std_filesystem from common.mk, only defined for Python for now
  Extend roundtrip test
  Address review comment by @degasus on #1999 originally
  Had trouble getting the test to be properly ignored. If I wrap the inline line 35 in #if __cplusplus the wrapper code isn't generated
  Tweak tests setup
  Cherry pick from yasamoka/master

Conflicts:
	CHANGES.current
2023-11-18 10:50:29 +00:00
William S Fulton 9bbd176038 Correct const std::filesystem & typemaps
Marshal to pathlib.Path
2023-11-18 10:03:52 +00:00
William S Fulton ac5cd598f8 std::filesystem pointer handling correction
Only passing std:filesystem by value and const ref is marshalled to a pathlib.Path.
This is consistent with all other marhalling in SWIG.
2023-11-17 23:01:28 +00:00
William S Fulton 68b0fd809f $typemap() fix for handling variable overrides
Fix when variable override contains a pointer dereference ->.
This enables use of $1.x as a variable override value as SWIG
replaces $1.x with a pointer dereference expression, such as
(&arg1)->x.

Added a testcase showing how Python typemaps could alternatively
be written using $typemap() instead of using C++ templates as used in
the UTL. I'm not convinced this is fully reliable or even a good idea,
so the variable replacements in $typemap() remain undocumented.
2023-11-03 09:07:51 +00:00
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 d701f0b4b2 Correct the implementation of Python PEP 207.
Don't convert all exceptions into a NotImplemented return
when wrapping operators which are marked with %pythonmaybecall.

Closes #1783
2023-10-21 09:25:10 +01: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 4b6b711fa3 Merge branch 'issue/2625'
* issue/2625:
  Enhanced std::map for non-default constructible types changes entry
  Add missing exception.i for std::map wrappers for MzScheme and Guile
  std::map wrappers and non-default constructible
  Fixed make file ordering
  Fixed line endings
  Added unit test
  Using #ifdef instead of #if to prevent warnings
  Fix for #2625 Using c++17 insert_or_assign for std::map when available.

Conflicts:
	CHANGES.current
2023-09-18 19:29:56 +01:00
William S Fulton 1225b2e484 Fix testcase for python-3.12
Immortable Objects don't change reference counts, PEP 683
https://peps.python.org/pep-0683/
2023-08-16 22:42:26 +01:00
William S Fulton 8c6a0fb5cd Testcase fix for python-3.12
https://docs.python.org/3.12/whatsnew/3.12.html

A backslash-character pair that is not a valid escape sequence now
generates a SyntaxWarning
2023-08-16 21:53:16 +01:00
William S Fulton 2e1506c189 Add support for using declarations to introduce templated members
Add support for using declarations to introduce templated member
methods and for inheriting templated constructors, such as:

  struct Base {
    // templated constructor
    template <typename T> Base(const T &t, const char *s) {}
    // templated member method
    template <typename T> void template_method(const T &t, const char *s) {}
  };

  %template(Base) Base::Base<int>;
  %template(template_method) Base::template_method<double>;

  struct Derived : Base {
    using Base::Base;
    using Base::template_method;
  };

Previously the templated methods and constructors were ignored and
not introduced into the Derived class.
2023-08-07 07:37:28 +01:00
William S Fulton 93732bb195 Fix using declarations for deep inheritance hierarchies
Fixes 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. For example in the code below, Using1::usingmethod(int i)
was not wrapped for use in Using3:

  struct Using1 {
  protected:
    void usingmethod(int i) {}
  };
  struct Using2 : Using1 {
  protected:
    void usingmethod(int i, int j) {}
    using Using1::usingmethod;
  };
  struct Using3 : Using2 {
    void usingmethod(int i, int j, int k) {}
    using Using2::usingmethod;
  };

Similarly for C++11 using declarations for inheriting constructors.
2023-08-05 19:47:17 +01:00
William S Fulton 74e1deef6b Fix %copyctor used on class hierarchies with non-const copy constructor
Previously SWIG always attempted to call a copy constructor
taking a const reference parameter instead of a non-const
reference parameter.
2023-07-29 18:16:40 +01: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 a704f507b7 Expand constructor runtime tests to Ruby 2023-07-24 21:03:50 +01:00
William S Fulton eb18619178 More refactoring for internal destructor and constructor names
Further removal of template parameters from the "name" attribute for
constructors and destructors.

Add test case for templated constructor instantiations - based on the
Python and Octave only li_std_pair_extra.i test which caused problems
making this change.
2023-07-22 18:21:32 +01:00
William S Fulton 2ff9da0ce6 Constructors and destructors declared with template parameters
Recent commits for internal constructor and destructor names resulted
in destructors declared with template parameters being ignored
with warnings like:
  Illegal destructor name TemplPublicBase6< int >::~TemplPublicBase6(). Ignored.

Although declaring constructors and destructors with template parameters
are rejected by modern compilers and C++20, SWIG continues to support it.

Make sure the name stored in the parse tree is the C++20 compliant name
name, that is, without the template parameters.

Fixes using declarations for templated constructors declared with
template parameters, was warning with:
  Nothing known about 'TemplPublicBase6< int >::TemplPublicBase6'.
2023-07-18 19:29:40 +01:00
William S Fulton 6bcf612c92 C++11 using declarations for inheriting constructors
Support extended to directors.

Go protected constructors fix required for new testcase:
- Emit wrappers if director class is abstract
- If called, errors out with: accessing abstract class or protected constructor
- Now consistent with other target languages
2023-07-15 12:41:12 +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
William S Fulton a0bde3f319 C++11 using declarations for inheriting constructors - template classes with template base classes
Internal using name no longer contains template parameters.
Fixes symbol table lookup for non-instantiated template constructor.
Builds on previous few commits where the internal name no longer
contains the template parameters for constructors and destructors.
2023-07-08 20:01:39 +01:00
William S Fulton 5b9179ea7e C++11 using declarations for template classes with non-template base classes 2023-07-07 12:05:09 +01:00
William S Fulton e73a1b91a3 C++11 using declarations for inheriting overloaded constructors
Fixes for C++11 using declarations for inheriting constructors
when the constructors are overloaded.
2023-07-05 00:10:47 +01:00
William S Fulton 61e60271fe Add support for C++11 using declarations for inheriting constructors
Closes #2641
2023-07-04 12:07:16 +01:00
Christophe Calmejane e62945e273 Added unit test 2023-07-04 10:31:13 +02:00
Julien Marrec 8e80322c31
Make CI rerun (and output all failed cases for the specialPath) 2023-06-30 14:11:14 +02:00
Julien Marrec b2639da892
Address review comments 2023-06-30 14:11:14 +02:00
Julien Marrec 065c9fa1e1
Need to see which assert is failing on mingw 2023-06-30 14:11:14 +02:00
Julien Marrec eed4813d76
Verbose assert to try and see the failure on mingw 2023-06-30 14:11:14 +02:00
Julien Marrec 17a17b112f
Extend roundtrip test 2023-06-30 14:11:14 +02:00
Julien Marrec 0798a46e0d
Had trouble getting the test to be properly ignored. If I wrap the inline line 35 in #if __cplusplus the wrapper code isn't generated 2023-06-30 14:11:14 +02:00
Julien Marrec b36905e152
Tweak tests setup 2023-06-30 14:11:14 +02:00
Ramzi Sabra 2fcbd937f7
Cherry pick from yasamoka/master
Co-authored-by: Julien Marrec <julien.marrec@gmail.com>
2023-06-30 14:11:14 +02:00
Olly Betts c4ef64a3f2 Remove commented out testcase line
We'd expect char* typemaps to terminate the string at NUL, as the
enabled version of this line tests.

Looking at the history this seems to just be a left-over from original
development.

See #2608
2023-06-11 09:45:29 +12:00
William S Fulton 0893aa34ca auto without return type cleanup
- Fix undefined behaviour
- Document and test workaround for class methods
- More informative WARN_CPP14_AUTO warning message

See issue #2446
2023-06-10 16:45:50 +01:00
Olly Betts f4fbfa65be Hook up cpp17_director_string_view testcase
Rename from director_string_view (since it requires C++17) and
add it to the list of tests to run which I'd failed to do before.
2023-05-26 17:45:24 +12:00
Olly Betts 1e761f3ea7 Remove obsolete Python version checks
We only support Python 2.7 now, so no need for special handling
of earlier versions now.
2023-05-26 17:45:24 +12:00
Olly Betts 29d1f95d0d [Python] Add string_view support
Only implemented for Python 3, at least for now.

See #1567
2023-05-26 17:45:24 +12:00
Olly Betts 8a73e25fe2 argcargv.i: NULL terminate argv with empty input
Fixes needed for: C# R
2023-05-23 10:12:49 +12:00
Olly Betts 4ba7e68c28 Test empty array and empty string with argcargv.i
Adding test coverage for target languages where this already works.
2023-05-22 16:08:09 +12:00
Olly Betts 915dc93b0d [octave] Fix argcargv.i bug
The strings from the Octave array are returned in a temporary
std::string object so we need to make a copy of them or else the
final string ends up replicated as all elements.

Unfortunately argcargvtest.i was only checking the final element's
value, so fix it to test both the elements as a regression test for
this, and to catch any similar issues with other target languages.
2023-05-22 13:38:59 +12:00
Olly Betts d8887091fe Support deducing decltype for false and true 2023-05-20 09:09:48 +12:00
Olly Betts 56f82e5541 Remove obsolete debug line from callback_runme.py
We stopped wrapping C++ static method A::bar as A_bar in SWIG 4.1.0.
2023-05-17 13:38:04 +12:00
Erez Geva b6eaee8d12 Add li_constraints test, testing 'constraints.i'.
For: JavaScript, C#, go, Java, Lua, Perl, PHP, python, Ruby, TCL and Octave.

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2023-05-12 01:23:31 +02:00
William S Fulton 00d3b04b46 Merge branch 'python-iterator-protocol'
* python-iterator-protocol:
  Finish removal of SwigPySequence_Cont
  Remove undocumented and non-existent STL std::carray
  Remove assign method uses by the removed Python Sequence Protocol
  Remove now redundant use of Python Sequence protocol in STL wrappers
  Add support for all STL containers to be constructible from a Python set
  Iterator Protocol support for std::array wrappers
  STL support for copying Python objects supporting Iterator protocol

Closes #2515

Conflicts:
	CHANGES.current
2023-04-26 21:44:34 +01:00
William S Fulton 1835580589 Remove undocumented and non-existent STL std::carray 2023-04-26 18:18:15 +01:00
William S Fulton b2fd91bc41 Add support for all STL containers to be constructible from a Python set 2023-04-26 18:18:15 +01:00
Olly Betts 6f15b1419a Adjust new tests
Add a regression test based on https://sourceforge.net/p/swig/bugs/1163/
since this patch solves that case too.

Replace the __attribute__ test case from #2525 with a variant of the
1163 regression test, since __attribute__ is specific to certain
compilers.

Adjust the self-referential test case to actually work - it wasn't
valid C code before.
2023-04-19 15:50:56 +12:00
Momtchil Momtchev 3828b247be actually test the value 2023-04-14 10:59:31 +02:00
William S Fulton 2fc0edc4fd Instantiation of C++11 variadic function templates
Complete support for C++11 variadic function templates. Support was previously limited
to just one template parameter. Now zero or more template parameters are supported
in the %template instantiation.
2023-01-03 22:38:46 +00:00