Commit graph

22,912 commits

Author SHA1 Message Date
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
c737bd5713 Add C# support std::unique_ptr inputs
Based on Java implementation.
2022-07-17 15:20:13 +01:00
William S Fulton
8bd9eb3f16 Java unique_ptr test ownership enhancement to test
Make sure the object is owned before releasing ownership
and passing ownership to unique_ptr instance.
2022-07-17 15:15:24 +01:00
William S Fulton
1bf15210ef Java unique_ptr enhance test for double release 2022-07-17 15:15:24 +01:00
William S Fulton
bf761998ed SWIGTYPE && input typemaps now assume object has been moved
Change these typemaps to assume that after a function call,
the parameter has been moved. The parameter's proxy class
that owns the C++ object thus has the underlying pointer set
to null so the object cannot be used again and the object is deleted.

Scrap new javarelease typemap and move contents into javabody typemap.
2022-07-17 15:15:24 +01:00
William S Fulton
6b361bf050 Add Java support for std::unique<T> for input parameters.
This works by transferring ownership of the underlying C++ memory
from the target language proxy class to an instance of the unique_ptr
which is passed to the wrapped function via std::move.

The proxy class has a new swigRelease() method which sets the
underlying C++ pointer for the proxy class to null, so working
in much the same way as std::unique_ptr::release(). Any attempt at
using the proxy class will be the same as if the delete() function
has been called on the proxy class. That is, using a C++ null pointer,
when a non-null pointer is usually expected.

This commit relies on the previous commit that uses std::move
on the temporary variable used for the wrapped function's input parameter
as std::unique_ptr is not copyable, it has move-only semantics.
2022-07-17 15:15:24 +01:00
Olly Betts
64fa88c0eb [php] Omit incompatible return type declaraction
Under %feature("php:type", "compat") we don't generate return type
declaration for virtual methods if directors are enabled for that class.
However if a base class of the class has a method of the same name which
isn't directed this was still getting a return type declaration which
caused PHP to give an error when it tried to load the module.

Now we detect this situation and suppress the base class method's
return type declaration too.

Re-enable testcase director_redefined which now works again (it was
failing under PHP8 due to this issue).

See #2151
2022-07-13 16:01:59 +12:00
Olly Betts
1f925867f4 [ci] Drop duplicate octave build
This was created by fc6269a3ca which
converted the non-functioning Octave 6.4 into a duplicate of the
other Octave build instead of dropping it completely.
2022-07-13 15:33:41 +12:00
Olly Betts
6c083b208c [php] Reenable 3 testcases which now pass
See #2151
2022-07-13 15:21:12 +12:00
Olly Betts
732af1d7b8 Tweak testcase comments 2022-07-13 15:21:12 +12:00
Olly Betts
cfc3888cba [php] Emit arginfo after all the code
Another step in preparation for a fix for the incompatible overridden
method problem discussed in #2151.
2022-07-13 15:21:12 +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
2bba78f757 Add std::auto_ptr support for Perl based on std::unique_ptr 2022-07-12 09:41:56 +01:00
William S Fulton
3cbcdbf681 Merge branch 'unique_ptr'
* unique_ptr:
  Add std::unique_ptr<type> to Perl5.
2022-07-12 08:23:28 +01:00
Olly Betts
216c7f72cf Revert "Adjust the DOH string hash function"
Changing the hash function breaks some testcases.

It seems there's a latent bug here (I suspect something somewhere in
SWIG depends on the hash iteration order), but I didn't see where and
we can't really have CI continuing to fail.

See #2303.

This reverts commit 5a96a39aa4.
2022-07-12 12:51:48 +12:00
Olly Betts
7cf91c12dc php: Move ME and FE generation back out of PHPTypes
It's more natural to leave it where it was, and will work better
when we delay the arginfo generation.
2022-07-11 17:38:34 +12:00
Olly Betts
6503200684 php: Encapsulate arginfo generation
Encapsulate the code to generate arginfo in the PHPTypes class.
By itself this should result in no functional changes, but it's
a step towards being able to delay arginfo generation which I
think is necessary to address the incompatible overridden
method problem discussed in #2151.
2022-07-11 17:23:20 +12:00
Olly Betts
c25d0d707a Minor PHP documentation improvements 2022-07-11 16:39:17 +12:00
Olly Betts
63c681a513 TODO: Remove nested typemaps since now supported 2022-07-11 16:39:14 +12:00
Olly Betts
cf9422b4d9 [php] Stop setting unused php:proxy attribute
This is no longer used since we changed how classes are wrapped.
2022-07-11 15:32:43 +12:00
Olly Betts
29354ed19d Update comment in PHP testcase
The PHP7 workaround we currently use has evolved a bit since this
comment was written.
2022-07-11 13:20:25 +12:00
Erez Geva
adb85d3d05 Add std::unique_ptr<type> to Perl5.
Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2022-07-09 13:52:43 +02: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
Olly Betts
22a4355f34 [xml] Move to "Experimental" target language status
The XML target language support is not in good shape and is likely to be
removed unless somebody steps up to bring it up to the expected standard
(it fails to even meet the criteria for "Experimental" currently).

Closes #2213
2022-07-08 16:34:19 +12:00
Olly Betts
655da94f36 CHANGES.current: Fix some typos 2022-07-08 16:13:33 +12:00
Olly Betts
e56ce01dfe Merge branch 'simple-c++-attribute-support' 2022-07-08 15:58:35 +12:00
Olly Betts
a5380ed1c5 Update docs for C++ attribute support 2022-07-08 15:57:29 +12:00
Olly Betts
04abbcf4ae Turn an unmatched ]] back into two ]
Needed to handle e.g. `a[a[0]]`.  SWIG's parser doesn't seem to handle
that currently though.  See #2286.
2022-07-08 15:50:51 +12:00
Olly Betts
5ddcbac56b Test [[ and ]] in string literal are preserved
Suggested by wsfulton in #1158
2022-07-08 15:33:01 +12: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
5a96a39aa4 Adjust the DOH string hash function
The one we're currently using only considers the last five characters
plus the least significant bit of the last-but-sixth character, which
unsurprisingly generates a lot of many-way collisions.

This change seems to give about a 4% reduction in wallclock time for
processing li_std_list_wrap.i from the testsuite for Python.  The
hash collision rate for this example drops from 39% to 0!

Closes #2303
2022-07-07 11:50:00 +12:00
Olly Betts
8987259959 Fix ticket reference in comment 2022-07-07 11:44:51 +12:00
Ian Lance Taylor
87cbf8c341 [Go] #2245 Handle NULL pointers for string* conversions.
Rearrange generation of director methods and rename
receiver argument from p to swig_p.

Fixes #2245
2022-07-05 17:00:48 -07:00
William S Fulton
e1173cac26 Tcl std_vector.i functions not static
Closes #2305
2022-07-05 10:53:08 +01:00
William S Fulton
5e06e0931e Remove Tcl SWIGTYPE CLASS typemap
Odd typemap cleanup - this typemap can't be used - SWIG_new_copy does not exist
2022-07-04 11:19:50 +01:00
William S Fulton
319442a8c4 More move semantics improvements
More removal of casts in the out typemaps when copying objects to enable
C++ compilers to possibly make use of move semantics.
2022-07-04 11:19:50 +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
e75095e6c5 Add OCaml throws typemaps for std::string 2022-07-03 13:35:08 +01:00
William S Fulton
980e21a3bf Cosmetic changes to auto_ptr library files 2022-07-02 16:17:23 +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
1993b334a6 Generate swiglabels code earlier on in runtime code
Since the recent inclusion of <utility>, the warning suppressions in
swiglabels.swg stopped working as they appear after this include file.

In particular, The _MSC_VER warnings were not working.
2022-06-30 17:28:25 +01:00
William S Fulton
7cab5accef SwigValueWrapper::operator& should always have been const 2022-06-30 17:26:56 +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
6ccef6dae1 Ocaml clean fixes 2022-06-30 09:36:29 +01:00
William S Fulton
a0fed47163 Remove duplicate typemaps 2022-06-30 09:36:29 +01:00
Olly Betts
f5e2d044df Remove set but not used variables
Highlighted by clang-15 warnings such as:

warning: variable 'index' set but not used [-Wunused-but-set-variable]
2022-06-30 12:52:37 +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
William S Fulton
4dd285fad7 Cosmetic rename SwigMovePointer -> SwigSmartPointer
This smart pointer doesn't really offer move semantics as is commonly
understood in C++11, so rename accordingly.
2022-06-16 08:02:02 +01:00
William S Fulton
088dc6e870 Add move assignment operator to SwigValueWrapper
Closes #2039
2022-06-16 08:02:02 +01:00