Commit Graph

1027 Commits

Author SHA1 Message Date
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
Olly Betts e36e898c0a
Merge pull request #2205 from swig-fortran/extend-tests
Fix and add additional tests to test suite
2022-02-25 10:16:22 +13:00
William S Fulton 8e4868af75 More director const std::string& testing and C# leak fix
Issue #998
2022-02-13 23:00:04 +00:00
Seth R Johnson 8cf62a3325 Remove assertions from python test cases 2022-02-14 10:33:10 +13:00
Seth R Johnson b08713f09f Add test of null shared pointers emitted from C++
This tests nulls emitted as pointers and values of shared pointers,
created from null, from references, and from default constructors.
2022-02-12 19:40:03 -05:00
Seth R Johnson 0da8a9bb44 Test ability to manipulate a daughter class from its base class wrapper
Even in the case of just creating a `DerivedClass` this test says:
```
swig/python detected a memory leak of type 'DerivedClass *', no destructor found.
```
even though the destructor is defined in the base class.
2022-02-12 19:40:03 -05:00
Seth R Johnson fc2b90acd1 Add a "diamond" pattern to multi-impmort test
This tests whether multiple modules can correctly import
the same common module.

```
a -> d
  -> b -> c -> d*
```
2022-02-12 19:40:03 -05:00
William S Fulton f32a20fc2f Enhance Python director_property test 2022-02-12 12:17:43 +00:00
Olly Betts b624d17f3f Merge branch 'swig-fortran/extern-c-int'
Fixes #2199
2022-02-11 08:28:27 +13:00
Seth R Johnson befc9bc1f0 Mark 'externc' storage for variables 2022-02-06 20:49:01 -05:00
Seth R Johnson 307c9814a0 Prevent "__dummy_0__" template methods from matching name warnings 2022-02-06 13:51:37 -05:00
Olly Betts 25f996a5c8 [python] Replace uses of assert in testsuite
We're not supposed to assert for this, as mentioned in #1488.
2022-01-30 13:38:56 +13:00
Frank Schlimbach 63452e9fc1 better handling of using directives 2022-01-30 10:55:00 +13:00
Olly Betts f0c0816cde Update out-of-date docs re _runme3.py 2022-01-27 16:10:10 +13:00
Olly Betts 6db66bc350 Drop is_python_modern() in testcase
Python is always "modern" since e4fceee12f.
2022-01-26 12:30:44 +13:00
romin.tomasetti 8be363eae3 parser(C++11) : explicit template function support, see https://github.com/swig/swig/issues/2131 2022-01-22 15:05:23 +00:00
Olly Betts 4d3d4839b0 [python] Add multivalue_runme.py 2022-01-21 11:10:30 +13:00
William S Fulton 2272d00c1a Add Python testcase for testing flatstaticmethod syntax
For testing legacy flattened static method access for when
issue #2137 is applied.
2022-01-15 00:05:06 +00:00
William S Fulton 3aa302c08f %callback and Python class access for C++ static member functions fixes
Fix access to C++ static member functions using Python class
staticmethod syntax, such as Klass.memberfunction instead of
Klass_memberfunction, when using -fastproxy and -builtin in
combination with %callback.

The docstring containing the callback pointers were not being patched
during module initialisation.
2022-01-14 23:00:59 +00:00