Commit graph

1,045 commits

Author SHA1 Message Date
William S Fulton
ed333b6b97 std::string throws typemaps
Go, Guile, Racket, Scilab: Add throws typemaps for std::string so that
thrown string exception messages can be seen.

Test all language for std::string throws typemaps
2022-09-19 09:09:29 +01:00
William S Fulton
4a29229bab Add catches_strings test to test throws char * typemap 2022-09-19 09:09:29 +01:00
William S Fulton
e97181ebc0 Add missing typecheck typemaps for std::auto_ptr and std::unique_ptr
To fix overloading when using these types.
2022-09-17 10:23:51 +01:00
William S Fulton
dad7c93ca0 Provide SWIGTYPE MOVE typemaps in swigmove.i
For implementing full move semantics when passing parameters by value.
Based on SWIGTYPE && and std::unique_ptr typemaps which implement move
semantics.

Added for all languages, but untested for: Go, Ocaml, R, Scilab (and
unlikely to be fully functional for same reasons as for std::unique_ptr
support).

Issue #999
2022-09-16 08:36:25 +01:00
William S Fulton
2212af3f4f rvalue reference outputs
Document rvalue reference outputs behaviour
Test rvalue reference outputs
2022-09-08 08:46:32 +01:00
William S Fulton
4588c41646 Temporarily remove rvalue reference python runtime test
Work in progress: SWIGTYPE && out typemaps need to take ownership
2022-09-03 05:53:54 +01:00
William S Fulton
7934561874 Test/fixes to handle NULL pointer for unique_ptr/auto_ptr
Also add missing unique_ptr tests for Lua and Racket.
2022-08-31 19:42:55 +01:00
William S Fulton
e139a36511 SWIGTYPE && input typemaps now assume object has been moved
Replicated Java implementation.

Fully implemented for:
- C#
- D
- Guile
- Javascript (UTL)
- Lua
- MzScheme
- Octave (UTL)
- Perl (UTL)
- PHP
- Python (UTL)
- Ruby (UTL)
- Tcl (UTL)

PHP std::auto_ptr std::unique_ptr minor tweaks and testcase corrections
2022-08-31 19:40:14 +01:00
William S Fulton
0ba11023ac Rename debug in testcases to trace
To remove D specific keyword rename
2022-08-20 15:09:23 +01:00
William S Fulton
63632f80fb Correct raw pointer handling test for virtual inheritance 2022-08-11 18:44:36 +01:00
William S Fulton
d4b1152d4b Add raw pointer handling test for virtual inheritance
This is a test added for D in previous commit, now expanded to all target languages.

Tidy up counting object instances.
2022-08-05 22:30:23 +01:00
Olly Betts
c496bc9d7b cpp20_spaceship_operator_runme.py: Check ALIEN value 2022-08-05 04:53:15 +12:00
William S Fulton
a741c7dbcf auto_ptr and unique_ptr test tweaks 2022-08-04 07:14:30 +01:00
William S Fulton
ffbde7a132 Fixes for deprecated std::basic_string::reserve() 2022-07-31 01:02:08 +01:00
William S Fulton
eb8346b958 Convert cpp20_spaceship_operator php test to python 2022-07-31 00:58:35 +01:00
Olly Betts
c759da250f Add tests for binary integer literal constants 2022-07-26 15:28:51 +12:00
Olly Betts
07f0b732ba Add machinery for C++14, C++17 and C++20 testing
Support running testcases conditional on the compiler supporting
a each language version, like we already handle C++11.

Currently no testcases are actually run in this way for these
newer language versions.
2022-07-26 15:28:51 +12:00
Olly Betts
0e0f283e48 Fix friends_runme.*
Most of these test D_d twice when they really should be testing
D_d once and D_i once (the variable name is `di` and the values
assigned are integers).

This was wrong in the initial version for Python in
708021a809 and it looks like subsequent
additions for other languages have just copied that mistake.
2022-07-22 17:50:47 +12:00
Olly Betts
e23d912b49 [python] Fix inheriting from multiple director classes
Fix mishandling of a Python class inheriting from multiple SWIG-wrapped
director classes.

Fixes #422
Fixes https://sourceforge.net/p/swig/bugs/1379/
2022-07-20 14:18:49 +12:00
William S Fulton
1b63af0f2c std::unique_ptr std::auto_ptr tidyup
Add docs on additional support
Additional testing for invalid usage for parameter inputs
2022-07-19 20:23:06 +01:00
William S Fulton
db5e37a1d7 Add support for std::auto_ptr inputs
Ported from std::unique, behaviour is identical with regard to memory ownership/handling
2022-07-18 08:32:26 +01:00
William S Fulton
c3c061cac8 Add Python support for std::unique_ptr inputs
Equivalent to Java/C# implementation.
2022-07-17 15:20:20 +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
William S Fulton
1ece69cafd Test copy constructor and assignment operator calls for movable types
This is the current state of play where the copy constructor and copy
assignment operators are called, even for movable types passed as
function parameters.
2022-07-08 08:01:55 +01:00
William S Fulton
71cd6a38fe 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-04 11:19:29 +01:00
William S Fulton
299880e6a6 Add std::unique support
Simple copy of current auto_ptr support (just suppport for
functions returning std::unique_ptr).

Closes #1722
2022-07-02 16:17:18 +01:00
William S Fulton
bf36bf7d8a Movable and move-only types supported in "out" typemaps.
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 alsoand 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.

Issue #999
Closes #1044

More about the commit:
Added some missing "varout" typemaps for Ocaml which was falling back to
use "out" typemaps as they were missing.

Ruby std::set fix for SwigValueWrapper C++11 changes.
2022-06-30 17:26:48 +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
35ec8ca210 Add argcargv test case to test-suite 2022-05-15 19:49:59 +01:00
William S Fulton
bb39235c9c Add C# wchar_t * director typemaps
More Python std::wstring directors Python testing
2022-05-04 21:37:47 +01:00
William S Fulton
da07af7fe2 doxygen_autodoc_docstring test fix for Python builtin 2022-04-06 22:33:17 +01:00
William S Fulton
19a872eab7 Temporarily disable doxygen_autodoc_docstring_runme.py 2022-04-06 20:51:37 +01:00
William S Fulton
b35ebc81a9 Doxygen comments take precedence over the autodoc feature.
If a "docstring" feature is present it will still override a Doxygen comment.
If the "autodoc" feature is also present, the combined "autodoc" and "docstring"
will override the Doxygen comment. If no "docstring" is present then the
"autodoc" feature will not be generated when there is a Doxygen comment.

This way the "autodoc" feature can be specified and used to provide documentation
for 'missing' Doxygen comments.

Closes #1635
2022-04-06 08:08:14 +01:00
William S Fulton
5cc4591ae7 Consistent cpp11 testing in test-suite
Move HAVE_CXX11 into makefiles so that running test-suite
from top level directory or in the language's test-suite directory
is consistent. For example, running 'make check-java-test-suite'
behaves the same as 'cd Examples/test-suite/java && make check'.
2022-03-27 19:34:20 +01:00
William S Fulton
d1b93f2c0e Merge branch 'feature/python-builtin-separate-runtime-data'
* feature/python-builtin-separate-runtime-data:
  Rework swig_and_compile_multi_cpp makefile helper
  Different capsule names for builtin changes entry
  Use different capsule names with and without -builtin

Conflicts:
	CHANGES.current
2022-03-26 15:18:55 +00:00
William S Fulton
f2dd436a5b Rework swig_and_compile_multi_cpp makefile helper
Seems less cryptic and more maintainable to me
2022-03-26 15:16:22 +00:00
William S Fulton
3ab288dfa4 Different capsule names for builtin changes entry 2022-03-26 15:06:13 +00:00
William S Fulton
f068f2c2d6 Add Python < 3.3 support for pyabc.i
pyabc.i for abstract base classes now supports versions of Python
prior to 3.3 by using the collection module for these older versions.
Python-3.3 and later continue to use the collections.abc module.
The -py3 option no longer has any effect on the %pythonabc feature.
2022-03-23 07:58:01 +00:00
William S Fulton
2c6e7f99a6 Test -flatstaticmethod and %extend 2022-03-21 19:23:15 +00:00
Eugene Toder
f733efd3c0 Use different capsule names with and without -builtin
Types generated with and without -builtin are not compatible. Mixing
them in a common type list leads to crashes. Avoid this by using
different capsule names: "type_pointer_capsule" without -builtin and
"type_pointer_capsule_builtin" with.

See #1684
2022-03-18 13:44:54 -04:00
Jim Easterbrook
3cfc26bc30 Move low level static methods
Like the non-static methods these are no longer present when using
-builtin
2022-03-18 11:10:14 +01:00
Julien Schueller
484e5316f2 Python: Option to generate flat class methods 2022-03-18 11:10:14 +01:00
Olly Betts
c7af8eabb3 Default to running tests with Python 3
Specify PY2=1 to use Python 2.

See #1779
Closes #2235
2022-03-17 18:55:10 +13:00
William S Fulton
3159de3e9f Add support for Python variable annotations as a feature.
Both function annotations and variable annotations are turned on using the
"python:annotations" feature. Example:

  %feature("python:annotations", "c");

  struct V {
    float val;
  };

The generated code contains a variable annotation containing the C float type:

  class V(object):
      val: "float" = property(_example.V_val_get, _example.V_val_set)
      ...

Python 3.5 and earlier do not support variable annotations, so variable
annotations can be turned off with a "python:annotations:novar" feature flag.
Example turning on function annotations but not variable annotations globally:

  %feature("python:annotations", "c");
  %feature("python:annotations:novar");

or via the command line:

  -features python:annotations=c,python:annotations:novar

Closes #1951
2022-03-02 19:33:03 +00:00
William S Fulton
afc915f490 Turn on Python annotations testing again
Testing is skipped where there is no support for it, that is,
using -builtin or -fastproxy. How to add this support in needs
determining, it's not clear how to do so.
2022-02-28 19:40:35 +00:00
William S Fulton
8ce010b915 Disable Python annotations test due to incomplete support 2022-02-27 18:39:31 +00:00
William S Fulton
2072ae19c9 Python function annotations removed from -py3 option.
Python function annotations containing C/C++ types are no longer
generated when using the -py3 option. Function annotations support
has been moved to a feature to provide finer grained control.
It can be turned on globally by adding:

  %feature("python:annotations", "c");

or by using the command line argument:

  -features python:annotations=c

The implementation is designed to be expandable to support different
annotations implementations. Future implementations could implement
something like the following for generating pure Python types:

  %feature("python:annotations", "python");

or typing module types to conform to PEP-484:

  %feature("python:annotations", "typing");

Closes #1561
Issue #735
2022-02-27 10:47:50 +00:00
Seth R Johnson
f4e2a4feee Fix warning and improve description of ignore_parameter test
See https://github.com/swig/swig/pull/2205#issuecomment-1052648190
2022-02-27 18:15:39 +13:00
William S Fulton
79a1bbee8b Using declarations in inheritance hierarchy improvements.
- Improved documentation for using declarations.
- Issue new warning WARN_LANG_USING_NAME_DIFFERENT when there
  is a conflict in the target language name to be used when
  introducing a method via a using declaration. Previously
  the method was silently ignored. Issue #1840. Issue #655.
2022-02-26 12:46:06 +00:00
Seth R Johnson
1329670640 Allow referencing of typemap keywords inside of "$typemap(" 2022-02-25 10:52:33 -05:00