Commit graph

229 commits

Author SHA1 Message Date
William S Fulton
46f7501d94 Cleanup SWIG_VERSION definition
Add Swig_obligatory_macros which must be called by each
target language to define SWIG_VERSION correctly
in the generated code, as well as the language specific
macro SWIGXXX where XXX is the target language name.

Drop the #ifdef SWIGXXX that was previously generated -
I can't see the point of this and if users are defining
this macro somehow, then users will need to change this

Closes #1050
2022-10-13 19:47:43 +01:00
William S Fulton
c82aa3bb41 Quick fix SWIG_VERSION not being defined correctly in wrappers 2022-10-13 07:57:09 +01:00
William S Fulton
2268d6ee96 Fix compile error when using directors
Fix when using templates with more than one template parameter
and used as an input parameter in a virtual method in a
director class (problem affecting most of the scripting languages).

Fixes #2160
2022-10-10 19:51:08 +01:00
Olly Betts
4ac3c87a29 Sort out predefined SWIG-specific macros
Ensure that SWIG_VERSION is defined both at SWIG-time and in the
generated C/C++ wrapper code (it was only defined in the wrapper
for some target languages previously).

SWIGGO and SWIGJAVASCRIPT are now defined in the generated wrappers
to match behaviour for all other target languages.

Stop defining SWIGVERSION in the wrapper.  This only happened as a
side-effect of how SWIG_VERSION was defined but was never documented and
is redundant.

The new testcase also checks that SWIG is defined at SWIG-time but not
in the generated wrapper, and that exactly one of a list of
target-language specific macros is defined.

Fixes #1050
2022-10-05 12:40:15 +13: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
c5495fea79 Remove broken %implicitconv for const SWIGTYPE &&
Typemaps should be for SWIGTYPE &&, not just const SWIGTYPE &&.
Needs updating for new approach where the proxy object is moved
for a parameter containing an rvalue reference.
2022-09-05 09:20:59 +01:00
William S Fulton
859264ab94 Remove unnecessary const SWIGTYPE & typemap
This is a duplicate of SWIGTYPE & and the typemap rules result
in SWIGTYPE & being used if there is no const SWIGTYPE & tyemap.
2022-09-05 08:23:58 +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
c10a84c775 Cosmetic stray semi-colon removal after %typemap using quotes 2022-08-31 19:40:13 +01: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
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
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
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
72f7b82935 Correct warning message for wchar_t * typemaps
Use separate warning for char * and wchar_t * typemaps
SWIGWARN_TYPEMAP_CHARLEAK_MSG and SWIGWARN_TYPEMAP_WCHARLEAK_MSG
2022-05-06 18:44:02 +01:00
Olly Betts
e1bb265bf7 Remove redundant conditional
clang defines __GNUC__ and __GNUC_MINOR__ as if it were GCC 4.2.1
and has since clang 2.4, which was before __has_builtin() was added.

Closes #1239
2022-03-07 09:11:50 +13:00
Olly Betts
31af3ce9bf Avoid -Wempty-body warnings from SWIG_contract_assert 2022-02-11 18:39:08 +13:00
William S Fulton
aef4a0f90a Merge branch 'doc-work' into upstream-master
* doc-work:
  Move the attribute.i docs into Library.html
  Move %attribute documentation into the manual
2022-02-05 20:52:42 +00:00
Justus Winter
5691f3f685 Fix function prototypes of generated pointer functions
Previously, the emitted constructors were incomplete prototypes.  When
compiling the wrapper code using gcc 6 and -Wstrict-prototypes, the
following warnings were emitted:

  warning: function declaration isn’t a prototype [-Wstrict-prototypes]

See #801
2022-02-03 17:25:44 +13:00
Olly Betts
7ec2f89fe2
Remove redundant NULL checks before free()/delete (#2184)
Remove redundant NULL checks before free()/delete

The ISO C and C++ standards guarantee that it's safe to call these
on a NULL pointer, so it's not necessary for the calling code to
also check.

Fixes https://sourceforge.net/p/swig/feature-requests/70/
2022-01-29 22:03:48 +13:00
Corey Minyard
f77af57bd7 Move %attribute documentation into the manual
It's fairly hidden where it is, put it where users can see it more
easily.

Fixes #2166
2022-01-26 09:18:55 -06:00
William S Fulton
13158bda9a Member function pointer typemap tweaks
Use sizeof variable name rather than variable type.
Workaround Visual C++ unable to parse some complex C++11 types, such as
  sizeof(short (Funcs::*)(bool) const &&)
2021-04-26 22:32:52 +01:00
Zackery Spytz
bcfa927298 Fix typos in attribute2ref() in Lib/typemaps/attribute.swg
AccessorName was being used instead of AttributeName.

Closes #1872.
2021-02-09 09:21:14 -07:00
William S Fulton
3efea1f4ab Fix typecheck typemaps for non-pointers and NULL
The typecheck typemaps succeed for non pointers (SWIGTYPE, SWIGTYPE&,
SWIGTYPE&&) when the equivalent to C NULL is passed from the target
language. This commit implements a fix for Python to not accept a Python
None for non-pointer types.

Issue #1202
2018-12-29 11:45:46 +00:00
William S Fulton
027a38c71c Remove -cppcast and -nocppcast command line options
The -cppcast option is still turned on by default. The -nocppcast option
to turn off the use of c++ casts (const_cast, static_cast etc) has been
removed. However, defining SWIG_NO_CPLUSPLUS_CAST will still generate C casts
instead of C++ casts for C++ wrappers.

This a revert of commit fc79264a48:
"Revert "Remove -cppcast and -nocppcast command line options""

The Scilab and Javascript casting problems are now fixed, so -cppcast
is now switched on as default.
2018-11-13 07:36:09 +00:00
William S Fulton
ebce018542 Fix constant function pointer typemaps
The function pointer typemaps were not being used when the function
pointer is const, like ADD_BY_VALUE_C in the funcptr_cpp.i testcase:

  %constant int (* const ADD_BY_VALUE_C)(const int &, int) = addByValue;

Problem affecting Javascript and observable when running test-suite with -cppcast.
2018-11-13 07:35:44 +00:00
William S Fulton
fc79264a48 Revert "Remove -cppcast and -nocppcast command line options"
This reverts commit c06f2b4497.

More work to be done as it breaks Scilab and Javascript tests.
2018-11-06 17:22:05 +00:00
William S Fulton
c06f2b4497 Remove -cppcast and -nocppcast command line options
The -cppcast option is still turned on by default. The -nocppcast option
to turn off the use of c++ casts (const_cast, static_cast etc) has been
removed. However, defining SWIG_NO_CPLUSPLUS_CAST will still generate C casts
instead of C++ casts for C++ wrappers.
2018-11-06 10:26:06 +00:00
William S Fulton
3e4b7269c0 Enhance SWIG_isfinite for older standards: C++03/C++98/C89
Fixes testcase overload_numeric with -std=c++98 (clang and gcc 6 and later)

Issue #1239
2018-05-04 20:02:13 +01:00
William S Fulton
ebd6558a30 __cplusplus macro usage tweak 2018-05-04 20:02:13 +01:00
William S Fulton
e86c881a70 Fix directorout typemaps which were causing undefined behaviour when returning pointers by reference.
Closes #1167
2017-12-14 07:00:42 +00:00
William S Fulton
dafe2d6949 Add director typemaps for pointer const ref types 2017-10-24 23:47:40 +01:00
William S Fulton
8a40327aa8 Add unignore for rvalue ref-qualifiers
Use std::move on this pointer as the default approach to supporting
rvalue ref-qualifiers if a user really wants to wrap.

std::move requires <memory> headers so add swigfragments.swg for all
languages to use common fragments. Just header file fragments for now.
2017-08-30 18:17:04 +01:00
William S Fulton
72ba741d1c Fix wrapping of references/pointers and qualifiers to member pointers
Also fix Go wrapping of member const function pointers.
2017-03-16 21:04:38 +00:00
Karl Wette
e24ec40895 Octave: add support for version 4.2
- .travis.yml:
  - ppa:kwwette/octaves has Octave version 4.2, also run C++11 tests
- configure.ac:
  - prefer Octave program "octave-cli" to "octave"
  - extract any -std=* flags from CXX, add to OCTAVE_CXXFLAGS
- Lib/typemaps/fragments.swg:
  - SWIG_isfinite_func(): extern "C++" is required as this fragment can
    end up inside an extern "C" { } block
- Lib/octave:
  - add std_wstring.i (copied from std_string.i) for C++11 tests
- Lib/octave/octrun.swg:
  - move Octave version-checking macros to octruntime.swg
  - Octave single()/double() functions now call .as_single()/.as_double()
    methods; redirect calls to __float__() method as per .scalar_value()
  - << and >> operators are no longer supported by Octave
- Lib/octave/octruntime.swg:
  - move Octave version-checking macros here for conditional #includes
  - #include interpreter.h instead of #toplev.h
  - #include call-stack.h (now needed for octave_call_stack)
  - unwind_protect is now in octave:: namespace
  - error_state and warning_state are deprecated; use try/catch to catch
    errors in feval() instead
  - always set octave_exit = ::_Exit, to try to prevent segfault on exit
- Lib/octave/octopers.swg:
  - << and >> operators are no longer supported by Octave
- Lib/octave/exception.i:
  - Add macro SWIG_RETHROW_OCTAVE_EXCEPTIONS which rethrows any
    exceptions raised by Octave >= 4.2
- Examples/test-suite/exception_order.i:
  - Use macro SWIG_RETHROW_OCTAVE_EXCEPTIONS to rethrow exceptions
    raised by error() function in Octave >= 4.2
- Update Doc/Manual/Octave.html and CHANGES.current
2017-01-22 11:53:12 +13:00
William S Fulton
d9db3cf628 Add some missing SWIGINTERN usage 2017-01-17 20:08:46 +00:00
Olly Betts
76d1aac47a Fix isfinite() checks to work with all C++11 compilers
Fixes https://github.com/swig/swig/issues/615,
https://github.com/swig/swig/pull/788 and https://github.com/swig/swig/pull/849.
2016-12-21 11:22:26 +13:00
William S Fulton
bdf71b0067 Zero initialize %array_functions and %array_class 2016-12-18 17:50:47 +00:00
William S Fulton
cc56765a7a Zero initialize newly created arrays
For consistency to previous fixes:
https://github.com/swig/swig/pull/208
https://github.com/swig/swig/issues/440
2016-12-18 17:50:47 +00:00
Daniel Vollmer
dd7a5a6e6e Fix missed files 2016-09-17 19:01:42 +02:00
Marcin Wojdyr
902f5d3f32 cstrings.swg: fix function names inside comments (#790) 2016-09-16 12:26:35 +12:00
William S Fulton
91aba9f719 UTL STL container descriptor checks
The vector of pointers (just fixed) were not working correctly because the
descriptors returned from swig::type_info() were sometimes returning
zero. Zero should only be used for void * as the subsequent call to
SWIG_ConvertPtr will blindly cast the pointer without checking
descriptor.

std::vector<void *> does not work and will require further changes:
specializing traits_info<void *> to return 0 and traits_asptr<void *>.
I tried this and traits_asptr<void> also needs to be added in which
seems odd and requires further investigation...

Lib/python/pystdcommon.swg:
  template <> struct traits_info<void *> {
    static swig_type_info *type_info() {
      static swig_type_info *info = 0;
    }
  };

Lib/std/std_common.i:
  template <>
  struct traits_asptr<void *> {
    static int asptr(PyObject *obj, void ***val) {
      void **p;
      swig_type_info *descriptor = 0;
      int res = SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0);
      if (SWIG_IsOK(res)) {
	if (val) *val = p;
      }
      return res;
    }
  };

  // this is needed, but am not sure this is expected
  template <>
  struct traits_asptr<void> {
    static int asptr(PyObject *obj, void **val) {
      void **p;
      swig_type_info *descriptor = 0;
      int res = SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0);
      if (SWIG_IsOK(res)) {
	if (val) *val = p;
      }
      return res;
    }
  };
2016-07-28 22:51:29 +01:00
William S Fulton
9c3f608ef7 Remove unused traits.swg
This file has code that looks like it was migrated to Lib/std/std_common.i
2016-07-27 18:46:23 +01:00
William S Fulton
98a31ff633 Fix directorin SWIGTYPE typemaps to make a copy as these are used for pass by value.
Closes #434
2016-05-14 21:32:24 +01:00
Paweł Tomulik
350d43d988 handle const pointers to functions 2016-03-24 10:59:23 +01:00
Olly Betts
75510a121d [Python] Use std::isfinite() under C++11
Follow-up fix for https://github.com/swig/swigissues/615
2016-03-01 19:10:03 +13:00
Olly Betts
5733cc1d2a [Python] Fix isfinite() check to work with GCC6
Fixes https://github.com/swig/swig/issues/615 reported by jplesnik.
2016-03-01 15:26:33 +13:00
Alec Cooper
d2ab7e8bad Add support for ptrdiff_t and size_t == long long
New fragment to check if long long is available using LLONG_MAX
AsVal and From functions for ptrdiff_t and size_t now use long long if available and sizeof(ptrdiff_t) > sizeof(long)
2016-01-06 16:52:37 -05:00
William S Fulton
0236435c48 Scilab typemap fixes for C89 2015-02-11 23:24:40 +00:00
William S Fulton
3dcc501ac0 Spelling fix 2014-10-21 07:55:07 +01:00
Oliver Buchtala
158c8b6732 Merge branch 'master' into devel
Conflicts:
	.travis.yml
	Examples/test-suite/common.mk
2014-03-30 23:07:56 +02:00