Commit Graph

480 Commits

Author SHA1 Message Date
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
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
Robin Stocker 962f090001 Fix Ruby 3.2 warning "undefining the allocator of T_DATA class swig_runtime_data"
Ruby 3.2 (still in development) started warning about this, see
https://bugs.ruby-lang.org/issues/18007.

Note that the extension docs mention it in
https://ruby-doc.org/core-3.1.1/doc/extension_rdoc.html#label-C+struct+to+Ruby+object:

> The klass argument is the class for the object. The klass should
> derive from `rb_cObject`, and the allocator must be set by calling
> `rb_define_alloc_func` or `rb_undef_alloc_func`.

So in this case we call `rb_undef_alloc_func` to fix the warning.
Verified that this works in robinst/taglib-ruby#115.

Fixes #2257.
2022-04-12 08:32:42 +12:00
Olly Betts b127e11f1e Fix typos in docs and comments 2022-02-27 18:15:46 +13:00
Seth R Johnson de78b80de9 Renames performed by `%namewarn` with `rename=` are printed in warning message
This is necessary for regex-like renames (where you can't use the #define trick
as is done in many of the %keywordwarn directives). It's now unnecessary to print
the "renaming to '`x`'" code explicitly by the kw.swg files.
2022-02-06 13:51:37 -05:00
Thomas Reitmayr 5a10e10399 Ruby: Fix warnings in generated code about missing parameter in variadic macro
The Ruby C API function 'rb_funcall' is used in various places in generated
code for invoking a Ruby method without parameters. The C function uses a
variadic parameter list for the arguments passed to Ruby, therefore in these
cases the list of variadic parameters is empty.
As an optimization Ruby may implement the 'rb_funcall' function as a macro
which however will not accept an empty list of arguments for '...' as of
C99 and C++11.
In order to prevent compiler warnings, this commit replaces all such
occurrences with a call to 'rb_funcall2' (which in its current name
'rb_funcallv' is invoked by the 'rb_funcall' macro anyway, at least for
Ruby 2.6.6).
2022-01-29 11:07:57 +13:00
Dimitris Apostolou f586d920f7
Fix typos 2021-11-17 07:07:02 +02:00
Olly Betts f198ff0a43 Fix more "allows to" and other typos 2021-04-21 15:54:46 +12:00
William S Fulton 4b5baf0a60 0.0 float warning fix 2020-10-10 15:02:26 +01:00
William S Fulton 938c3bbb54 Merge branch 'fix-1199'
* fix-1199:
  fix #1199
2020-06-07 10:29:55 +01:00
Andreas Schwab 58ffbe616f Ruby wstring - only include endian.h on linux
This file is not always available on other systems.
See #1801
2020-06-06 08:39:47 +01:00
William S Fulton 4ce77ffb77 Ruby - catch exceptions by const reference 2020-02-18 22:06:20 +00:00
William S Fulton c08e0d19f9 Merge branch 'catch-value'
* catch-value:
  Catch exceptions by reference rather than by value.
2020-02-18 22:00:45 +00:00
Daniel Mach 70f6ee9656 Catch exceptions by reference rather than by value.
Fixes -Wcatch-value gcc warnings.
2020-02-14 12:58:49 +01:00
William S Fulton 6cec69ef7b Remove an unnecessary shared_ptr reference count increment in Ruby wrappers
When wrapping STL containers, remove a shared_ptr reference count
increment when an upcast is needed when checking type conversion
in traits_check::check.
2020-02-13 19:48:30 +00:00
Viktor Gal 7d2dbe3670 fix #1199 2020-02-01 11:25:30 +01:00
Vadim Zeitlin 7cc94808b6 Extend std::auto_ptr<> support to Ruby
This is trivial as exactly the same typemap as for Python can be used
for Ruby too, all the differenced are abstracted by the unified typemap
library.
2020-01-17 15:09:17 +01:00
Thomas Reitmayr f5908eca76 Improve description of cast macros for Ruby
The macros for casting function pointers are now fully described and also
clarify why the macros act transparently for C even before Ruby 2.7.

In addition, an "if (CPlusPlus)" was removed in the code generator for
global variables in order to keep the distinction between C and C++ in
one place, which is at the definition of said macros.
2020-01-04 18:37:35 +01:00
Thomas Reitmayr 5542cc228a Move new macros for Ruby to their dedicated namespace 2020-01-03 21:45:53 +01:00
Thomas Reitmayr 00e291b319 Add support for Ruby 2.7
This commit fixes the signatures of various callback methods
and cleans up the macro definitions used for casting callbacks.

Note that the transparent version of the macro RUBY_METHOD_FUNC
is currently masked behind RUBY_DEVEL, see commit
1d91feaf13
In order to still support strict signature checking and prevent
nasty deprecation warnings, the use of RUBY_METHOD_FUNC had to
be replaced with VALUEFUNC.
2019-12-31 17:53:53 +01:00
William S Fulton 86cb3a9532 Python STL container method overloading fix
Fix method overloading of methods that take STL containers of different types.
Due to some error handling that was not cleared during typehecking.
2019-08-06 19:36:14 +01:00
William S Fulton b655d3138b Remove the UnknownExceptionHandler director error handling class
Done in order to be C++17 compliant as it uses std::unexpected_handler
which was removed in C++17. This class was intended for director
exception handling but was never used by SWIG and was never documented.

Closes #1538
2019-06-27 07:40:49 +01:00