Commit Graph

503 Commits

Author SHA1 Message Date
William S Fulton f91a9cb8e4 Use SWIG_NOEXCEPT for deprecated dynamic exception specifications
SWIG_NOEXCEPT is generated instead of throw() which is deprecated in
c++11. If c++11 or later is being used, then this macro expands to
noexcept instead of throw().

Affects director code only.

Also fix up some testcase to not use throw() when using c++11 or later.
Tested with clang and -Wdeprecated-dynamic-exception-spec as gcc
doesn't seem to warn for this deprecation.

Closes #3027
2025-04-29 22:41:09 +01:00
William S Fulton 1b9d30398d Improved swig_type_info static initialisation 2024-10-20 16:25:16 +01:00
William S Fulton 94e320f4b0 Remove Ruby output_helper fragment and macro
Use SWIG_AppendOutput instead of output_helper (does not require the
output_helper macro).
2024-10-06 00:36:57 +01:00
William S Fulton 1e5eec5632 Ruby fix for non-void functions using INOUT typemaps
Add Ruby inout runtime test
2024-10-05 23:29:34 +01:00
Olly Betts 3ae765f3c7 Revert "Move fragment StdDequeTraits to std/std_deque.i"
This needs more work, meanwhile unbreak master.

This reverts commit 147a78ae6c.
2024-09-26 16:35:00 +12:00
Olly Betts 147a78ae6c Move fragment StdDequeTraits to std/std_deque.i
We had versions of it for octave, python, ruby and scilab, which were
exactly the same except for using explicit target language types instead
of SWIG_Object (which is an equivalent type for all these languages),
and except that scilab passed by const reference (but SwigSciObject is
actually an int so there's no benefit to passing by const reference).

This fixes a missing definition of this fragment for SWIG/R which was
triggering a warning when you did `%include std_deque.i` in SWIG/R:

  Warning 490: Fragment 'StdDequeTraits' not found.
2024-09-26 14:57:41 +12:00
Olly Betts ef658d32fc [ruby] Update comment in rubyerrors.swg
The removed text hasn't been true since
7d44f269fb in 2006.
2024-09-20 16:21:29 +12:00
William S Fulton 7f821bb924 Simpler Ruby exception class singleton initialisations 2024-09-19 19:51:16 +01:00
Erez Geva 2e9d570194
[python, ruby] Add Director guard file with C++ 11 std::mutex (#2870)
* Improve mutex for director use:
- Use C++ 11 mutex and lock classes.
  Most compilers support C++ 11 by default.
  Leave Win32 and POSIX support for older compiler.
- Use a single file for Python and Ruby.
- Use macro also for guard definition instead of using '#ifdef'.
- Rename old '__THREAD__' to 'SWIG_THREADS' to
  avoid collide with other libraries.
- Remove the use of '__PTHREAD__' as it may collide with other libraries.
- Remove mutex from OCaml, as it is not used in Director class.

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>

* Fixes follow @wsfulton.

Improve description of director_guard.swg.
Remove duplicate line.
Change to SWIG_GUARD_DEFINITION and SWIG_GUARD_DECLARATION
 as full English words are much more easily understood
 than abbreviations.

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>

---------

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2024-07-02 08:54:28 +01:00
William S Fulton ba9b0a35ab Merge branch 'char_binary_java_fix-tidyup'
* char_binary_java_fix-tidyup:
  Move SWIGStringWithLengthHelper to csharphead.swg
  cdata whitespace/cosmetic fixups
  cdata doc updates
  Rename `typemaps/cdata_struct.swg` to `typemaps/cdata_begin.swg`. And `typemaps/cdata.swg` to `typemaps/cdata.swg`. Move `cdata_apply.swg` content to `typemaps/cdata.swg`.
  Group the C# marshalling of STRING-LENGTH typemap  into C# class named SWIGStringWithLengthHelper.
  Leave Length & string reverse order typemap in typemaps/strings.swg
  Support old C# as "LPUTF8Str" was add in 2017.
  Improve documentation. Follow @wsfulton reviews.
  Use a dummy for MzScheme and untested OCaml cdate. To prevent compilation error.
  Further fixing follow reviews.
  Reorganise raw data typemap,  so typemaps folder contain only common part. Improve document.
  Inline SWIG_string_to_utf8_bytes SWIG_utf8_bytes_to_string code
  Fixes of STRING/BYTES LENGTH typemaps.

 Conflicts:
	CHANGES.current
2024-06-13 10:53:19 +01:00
Alexandre Wery dcd9d6d16e Fix select of std::map std::vector 2024-05-14 10:26:10 +02:00
William S Fulton 2f194c10a8 Remove some locator strings in generated code
For Javascript, MzScheme, Python, Ruby.
Removes the vast majority of the /*@SWIG:...*/ locator strings in the
generated wrappers for these 4 languages to help with reproducible builds.

Issue #202
2024-04-12 08:12:44 +01:00
William S Fulton 24a66e6125 Add const std::unique_ptr & input typemaps 2024-03-06 21:46:58 +00:00
William S Fulton 846b40793e Add non-const std::unique_ptr & input typemaps 2024-03-06 21:46:58 +00:00
William S Fulton 5712ce6464 std::unique_ptr return by reference typemaps added 2024-03-06 21:46:58 +00:00
William S Fulton 3f1e40d2f4 Add std::unique_ptr && output typemaps
Move semantics are not supported by default.
They behave as if a lvalue reference was returned.
2024-03-06 21:46:58 +00:00
William S Fulton ae22a97f1b Movable std::unique_ptr - add std::unique_ptr && typemaps
Closes #2650
2024-03-06 21:46:58 +00:00
Erez Geva 1bf59e0bbc Fixes of STRING/BYTES LENGTH typemaps.
Fix Java STRING LENGTH typemap.
Use string type in static typed languages (Java, C#, D and Go).

Add BYTES LENGTH typemap and apply it for binary data.
Use byte type in static typed languages.

Add li_cdata_cpp, li_cdata and char_binary
 tests for most of languages(apart from R and experimental).

Fix the director_binary_string test and add it to C#, D, Go,
 Perl, PHP, Python, Ruby and octave.

Update documents.

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2024-02-29 02:09:09 +01:00
William S Fulton 2cf90be74a Cosmetic variable renames to match python equivalents 2024-02-22 21:00:50 +00:00
William S Fulton 72803625a1 Fix seg fault shrinking STL containers - Ruby, Octave, R
Document change for R and add in recommendation for Octave and R
from issue #2284.

Add missing Ruby test of li_std_containers_int testcase.
2024-02-22 21:00:50 +00:00
Erez Geva 003354964d Ruby:
Fix setslice(), reinitialise iterator to begin after calling erase().
Fix comparison of integer expressions of different signedness
 in getslice() functions.
Fix __setitem__() resize use with new item only if any.
In RubySequence_Cont structure, use standard 'size_t' for size_type.
Add 'li_std_containers_int' test to ruby.

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2024-02-22 21:00:12 +00:00
William S Fulton 44b0a04255 Merge branch 'ruby-lower-bound-checking'
* ruby-lower-bound-checking:
  Ruby: Add check for lower bounds of unsigned long (long) parameters
  Ruby: Add test case for checking bounds of integral function parameters
2023-12-20 20:10:58 +00:00
Olly Betts 3ce0174a0c Fix random doubled spaces in code 2023-11-17 09:49:36 +13:00
William S Fulton ecaa052f3d carrays.i library modified to use size_t instead of int
in the %array_functions and %array_class macros.

Affects C#, D, Go, Guile, Java, Javascript, Lua, Ocaml, R, Racket.
Closes #1680

If the old types are required for backwards compatibility, use %apply to
restore the old types as follows:

  %include "carrays.i"
  %apply int { size_t nelements, size_t index }
  ... %array_functions and %array_class ...
  %clear size_t nelements, size_t index; # To be safe in case used elsewhere
2023-10-11 08:23:16 +01:00
William S Fulton 4b6b711fa3 Merge branch 'issue/2625'
* issue/2625:
  Enhanced std::map for non-default constructible types changes entry
  Add missing exception.i for std::map wrappers for MzScheme and Guile
  std::map wrappers and non-default constructible
  Fixed make file ordering
  Fixed line endings
  Added unit test
  Using #ifdef instead of #if to prevent warnings
  Fix for #2625 Using c++17 insert_or_assign for std::map when available.

Conflicts:
	CHANGES.current
2023-09-18 19:29:56 +01:00
William S Fulton 790f36c28b Ruby constants and uppercasing regression fix
Regresson introduced in c96c04c5ae
Fixes testcase ruby_naming.i:
  static const int constant10 = 10;

which was not uppercasing the constant.
2023-09-09 23:21:02 +01:00
Christophe Calmejane f7d9f5e931 Using #ifdef instead of #if to prevent warnings 2023-07-04 09:18:20 +02:00
Christophe Calmejane 2b583e9d19 Fix for #2625
Using c++17 insert_or_assign for std::map when available.
2023-07-04 09:18:20 +02:00
Olly Betts 533688291a Clean up after removal of ignore typemaps 2023-06-15 16:22:31 +12:00
Olly Betts 779fa45601 Remove deprecated BOTH typemap rule
This has been a deprecated alias for INOUT since 2002 (SWIG 1.3.14).
2023-06-15 15:07:04 +12:00
Olly Betts 6b3e7ee850 [Ruby] Fix deprecation warnings with Ruby 3.x
Fix deprecation warnings about ANYARGS when compiling  C++ code for
SWIG-generated Ruby wrappers with Ruby 3.x.

This is a recurrence of a problem fixed in 4.0.2.  Our fix was
conditional on RB_METHOD_DEFINITION_DECL being defined, but Ruby
3.0 stopped defining this.
2023-05-23 18:00:40 +12:00
Olly Betts fcf0d7deab Tweak comment formatting 2023-05-23 09:20:31 +12:00
Olly Betts 1db41eeadb Add missing new file for Ruby string_view support
Tests had passed locally, but C++17 tests aren't run by default it
seems...
2023-05-18 18:42:51 +12:00
Olly Betts 1f5ff2e6a5 Allow using snprintf() instead of sprintf() in wrappers
We aim to produce code that works with C90 or C++98 so we can't
assume snprintf() is available, but it almost always is (even
on systems from before it was standardised) so having a way to
use it is helpful.

Enable this automatically if the compiler claims conformance
with at least C90 or C++98 and check SWIG_HAVE_SNPRINTF to allow
turning on manually, but disable if SWIG_NO_SNPRINTF if defined.

The fallback is to call sprintf() without a buffer size check -
checking after the call is really shutting the stable door after
the horse has bolted, and most of our uses either have a fixed maximum
possible size or dynamically allocate a buffer that's large enough.

Fixes: #2502 (sprintf deprecation warnings on macos)
Fixes: #2548
2023-04-27 10:08:57 +12:00
Olly Betts aa2101404b Really fix "mixed declarations and code" warning 2023-04-19 12:53:45 +12:00
Maple Ong dce218e79f Fix "ISO C90 forbids mixed declarations and code" warning 2023-04-12 23:25:32 -04:00
Maple Ong 3be0110e84 Fix "undefining the allocator of T_DATA" error seen in Ruby 3.2
Ruby 3.2 issue: https://bugs.ruby-lang.org/issues/18007
Similar to 9b5d37fd17
2023-04-12 12:22:22 -04: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 c10a84c775 Cosmetic stray semi-colon removal after %typemap using quotes 2022-08-31 19:40:13 +01:00
William S Fulton ac8864bc59 ruby 2022-07-31 16:15:00 +01:00
William S Fulton d9fd09aa21 Suppress Ruby.h gcc warnings 2022-07-31 14:51:26 +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 5dd5e80a84 Cosmetic formatting and doc updates in std_unique_ptr.i files 2022-07-17 20:44:20 +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 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 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 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