Commit graph

4,269 commits

Author SHA1 Message Date
Olly Betts
54ddefe410 Revert "Modify fix for << in array size"
This reverts commit 0ff9a0959a.

The modified fix breaks Java and C#, where C constant expressions
get used in the generated target language code in some cases.

Revert this fix for now.
2022-07-27 13:45:08 +12:00
Olly Betts
0ff9a0959a Modify fix for << in array size
The previous fix broke testcase arrays for Go.
2022-07-27 12:25:27 +12:00
Zackery Spytz
cb887ed2d4 Add support for the <=> operator (C++20) 2022-07-27 09:12:40 +12:00
Olly Betts
b57248cc1a [php] Add parentheses around $value when casting
In some cases $value can be an expression without parentheses around
it, and we want to cast the result of the whole expression.
2022-07-27 08:49:15 +12:00
Olly Betts
06d375cdab [Tcl] Fix handling of long long on 32-bit platforms
Fixes https://sourceforge.net/p/swig/bugs/977/ reported by Vera and
Kjell Wooding.

Closes #2331
2022-07-27 07:53:45 +12:00
William S Fulton
5a4baece4f Remove redundant check for NULL in char * typemaps
No need to check for NULL before calling delete/free.
Anyone using typemaps_string_alloc with custom allocators and
deallocators need to ensure the custom allocators behave in the
same way as the standard deallocators in this respect.
2022-07-24 17:54:40 +01: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
8b654afdef Merge branch 'unique_ptr-inputs'
* unique_ptr-inputs:
  std::unique_ptr std::auto_ptr tidyup
  Add support for std::auto_ptr inputs
  Cosmetic formatting and doc updates in std_unique_ptr.i files
  Add Perl support for std::unique_ptr inputs
  Add Ruby support for std::unique_ptr inputs
  Add Python support for std::unique_ptr inputs
  Add C# support std::unique_ptr inputs
  Java unique_ptr test ownership enhancement to test
  Java unique_ptr enhance test for double release
  SWIGTYPE && input typemaps now assume object has been moved
  Add Java support for std::unique<T> for input parameters.

Closes #692

Conflicts:
	CHANGES.current
2022-07-19 20:26:18 +01:00
Olly Betts
0b9d4eff09 Update everything for dropping Python 3.2 support 2022-07-19 13:20:07 +12:00
Julien Schueller
a55d40dbb5 Drop support for Python 3.2
Closes #2314
2022-07-19 11:23:48 +12:00
Olly Betts
6b4d5fe3f0 Remove remaining code to support macos9
This OS has been unsupported for over 20 years.  We stopped providing
macswig builds more than 20 years ago too:

https://sourceforge.net/projects/swig/files/macswig/

The required SIOUX library doesn't seem to be available anywhere
now either.

Closes #2323
2022-07-19 11:22:37 +12:00
Olly Betts
892557e799 Improve #include guard macros
Avoid using reserved identifiers such as `_DOHINT_H` (fixes #1989),
fix cases where the name doesn't match the filename, and make the naming
more consistent and less likely to collide with include guards in other
headers.
2022-07-19 09:35:46 +12: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
5dd5e80a84 Cosmetic formatting and doc updates in std_unique_ptr.i files 2022-07-17 20:44:20 +01:00
William S Fulton
50fc600e8c Add Perl support for std::unique_ptr inputs
Equivalent to Java/C#/Python/Ruby implementations.
2022-07-17 20:23:52 +01:00
William S Fulton
f99a2e6f64 Add Ruby support for std::unique_ptr inputs
Equivalent to Java/C#/Python implementations.
2022-07-17 15:20:25 +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
c737bd5713 Add C# support std::unique_ptr inputs
Based on Java implementation.
2022-07-17 15:20:13 +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
William S Fulton
2bba78f757 Add std::auto_ptr support for Perl based on std::unique_ptr 2022-07-12 09:41:56 +01: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
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
a0fed47163 Remove duplicate typemaps 2022-06-30 09:36:29 +01: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
Olly Betts
d7ed1a8b97 [php] Eliminate sprintf to temp buffer to create ZVAL
Use zend_strpprintf() which handles this more cleanly without risk of
buffer overflow and without a fixed length limit.
2022-06-09 09:06:12 +12:00
William S Fulton
1d6f4b4eae Merge branch 'java-director-leak'
* java-director-leak:
  Cosmetic tidyup in SWIG_JAVA_DETACH_ON_THREAD_END code
  Java: Move auxiliary methods into JObjectWrapper.
  Java: Option to detach from the JVM in the thread destructor.

Conflicts:
	CHANGES.current
2022-05-28 10:24:08 +01:00
William S Fulton
aef97a5783 Cosmetic tidyup in SWIG_JAVA_DETACH_ON_THREAD_END code 2022-05-28 10:22:34 +01:00
William S Fulton
8e3f0fd793 Suppress -Wregister gcc warnings in Python.h
Such as:
/usr/include/python2.7/unicodeobject.h:534:24: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]

Closes #2227
2022-05-27 20:01:57 +01:00
William S Fulton
7f009eddf0 Merge branch 'python'
* python:
  Define PY_SSIZE_T_CLEAN macro
  Python: define PY_SSIZE_T_CLEAN

Conflicts:
	CHANGES.current
2022-05-27 19:00:05 +01:00
William S Fulton
abc8e0bb27 Define PY_SSIZE_T_CLEAN macro
before #include "Python.h" as recommended in Python 3.7 and later.

Issue #2277
2022-05-27 18:58:04 +01:00
Joachim Kuebart
36dc81808b Java: Move auxiliary methods into JObjectWrapper. 2022-05-24 14:34:09 +02:00
Joachim Kuebart
b58c554cde Java: Option to detach from the JVM in the thread destructor. 2022-05-23 17:17:18 +02:00
William S Fulton
c359f57442 Better Octave typecheck for argc argv typemaps 2022-05-23 08:51:06 +01:00
Erez Geva
34221f223a Add Octave argcargv.i
Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2022-05-21 23:07:58 +02:00
William S Fulton
d60724b636 Merge branch 'more_argcargv'
* more_argcargv:
  Document argc argv library
  argcargv.i cosmetic updates
  Typemaps for (int ARGC, char **ARGV) fixup
  Fix argcargv.i in Perl5, Tcl, PHP Add missing type map for type check. Add testing of argcargv.i for Perl5, Tcl, PHP and Ruby.
  Add Lua test for argcargv.i
  Add argcargv.i to more languages: Perl 5, Tcl, PHP
  Add argcargv.i to Lua
2022-05-15 19:42:25 +01:00
William S Fulton
6860e2bc03 Document argc argv library 2022-05-15 19:12:39 +01:00
William S Fulton
e4cdf9d98f argcargv.i cosmetic updates 2022-05-15 18:32:53 +01:00
William S Fulton
0307d0732c Typemaps for (int ARGC, char **ARGV) fixup
The default typemap should not be in this library file - this is for
users to add in if they want C default argument support.
2022-05-15 18:21:59 +01:00