Commit Graph

290 Commits

Author SHA1 Message Date
William S Fulton 22a8088a98 Fix -Wunused-variable warning in Lua and Octave wrappers
Add bool output parameter to Swig_overload_dispatch to say when it has
generated code that will use the typecheck typemap code to help Lua and
Octave to not emit unused argv[] arrays.

Alas, resorted to warning suppression for deficient cpp11_initializer_list
typecheck typemap in cpp11_std_initializer_list testcase.
2025-06-23 21:39:49 +01:00
William S Fulton 0fddc95cc2 Fix -Wunused-variable Ruby warning when using -globalmodule 2025-06-21 23:24:46 +01:00
Olly Betts f0fb79152e [Python] Fix wrapping of bool const&x=true param
Fix wrapping of a bool const& parameter with a default value.
Regression introduced in SWIG 4.3.0.

Fixes #3162
2025-06-09 11:31:19 +12:00
Olly Betts c1e0a68f86 Fix regression wrapping default const bool argument
We need to strip qualifiers before checking the type is `bool`.

This mainly affects Python.  In Ruby there's equivalent code, but
it is only use to generate documentation comments.

Fixes #3052
2024-10-19 15:48:04 +13:00
Olly Betts e528260b83 [ruby] Fix doc comments for bool parameter default value
Documentation comments now use `true` and `false` for bool parameter
default values, instead of `True` and `False` (which are the Python
names and wrong for Ruby!)
2024-10-19 15:46:25 +13:00
William S Fulton 86498e46c6 Remove -xmllang option used with -xml
which had no effect on the output.
2024-10-15 08:59:51 +01:00
William S Fulton 09001ee302 Add $isvoid special variable expansion for directors
Complete the removal of Ruby's output_helper macro and replacement
with SWIG_AppendOutput for director typemaps.
Requires $isvoid special variable support in director code.
2024-10-06 15:00:37 +01:00
Olly Betts 9cba248bec Straighten out handling of integer constants
This provides a generic framework to aid converting C/C++ integer and
boolean literals to target language literals, replacing custom code in
several target language backends (and fixing some bugs in that code).
2024-09-16 16:10:02 +12:00
Olly Betts 7a8c9fdfa8 Straighten out handling of char and string constants
Fixes #904
Fixes #1907
Fixes #2579
Fixes #2990
2024-08-17 16:12:45 +12: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 2c70a912a6 Add $isvoid special variable
The $isvoid special variable expands to 1 if the
wrapped function has a void return, otherwise expands to 0.

In the implementation, use a consistent variable name, returntype,
for a node's "type" attribute.

Issue #2907
2024-06-15 23:13:12 +01:00
William S Fulton 8157a83b59 Repair Ruby smartptr damage
Fix half baked Ruby specific changes in 3be670e8db
2024-01-31 07:51:41 +00:00
William S Fulton 3be670e8db Fix assertion handling upcasting when using %shared_ptr on some templates.
A different approach is taken for supporting casting smart pointers up the
inheritance hierarchy. We no longer try to replace the underlying pointer type,
provided in the 'feature:smartptr', with the base class type. Such as morphing
'std::shared_ptr<(Derived)>' into 'std::shared_ptr<(Base)>'. Instead, we simply
use 'feature:smartptr' from the base class. This is more reliable than trying to
pattern match the pointer type in the feature. The base class must of course
also have the 'feature:smartptr' set, and this is still checked for as before.
The feature is now parsed in one place and stored in the parse tree in the
new 'smart' attribute for handling by the target languages.

Fix also improves the handling of the type parsed in 'feature:smartptr' in that
the type is now normalized and resolved in the scope of the class it is attached
to.

Closes #2768
2024-01-30 22:24:42 +00:00
William S Fulton c0b36721a3 Replace Language::is_assignable with Language::is_immutable
Avoids confusion with newly created Allocate::is_assignable.
Language::is_immutable is just a wrapper around the
"feature:immutable" flag since previous commit.

is_mutable rename wip
2023-09-07 07:01:37 +01:00
Olly Betts 6ddcbf5959 [Ruby] Remove -feature command line option
This has been deprecated since SWIG 1.3.32 in 2007.  Use -init_name
instead.
2023-08-09 08:37:39 +12:00
William S Fulton feb8e2e641 Fix C++11 using declarations for inheriting implicit base constructors
Parser no longer checks for a declared constructor when handling a
using declaration in order to correct the name as it won't find
implicitly declared constructors. Now it checks that a using
declaration is for something that looks like a constructor instead
by checking the immediate base classes for allowed constructors.
2023-07-14 08:39:27 +01:00
William S Fulton 84542f6b59 Replace Language::directorsEnabled() with Swig_directors_enabled()
For use outside of the target languages for forthcoming commits
which move adding default constructors/destructors from Language
to Allocate.
2023-07-12 18:44:42 +01:00
Olly Betts 736c052d7d Remove long deprecated features
These features were all deprecated in 1.3.26 (October 9, 2005)
or before (many long before), so all more than 17 years and 3 new major
versions ago which seems more than enough time for users to have stopped
using them, especially as most emit a deprecation warning if used.
2023-06-15 15:05:15 +12:00
William S Fulton 46f2778412 Consolidate name mangling functions
Swig_string_mangle      => Swig_name_mangle_string
Swig_name_mangle        => Swig_name_mangle_string
Swig_string_mangle_type => Swig_name_mangle_type
2022-11-12 09:18:19 +00:00
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 2f55379687 Improve director unwrap detection for the return type
Resolve the return type to correctly determine if the type is a pointer or
reference to a director class.

SwigType_refptr_count_return() recently added as a simpler fix is no
longer needed.

The conventional approach of using the "type" rather than "decl" to
analyse the return type is used instead too.

Issue #1823
2022-10-10 08:45:26 +01:00
William S Fulton 4a397869a2 Merge branch 'director-unwrap-result'
* director-unwrap-result:
  Unwrap director classes only when returning a pointer or reference to an object
2022-10-07 18:41:14 +01:00
Olly Betts 631b41ae7b Use https for swig.org links 2022-10-06 13:16:39 +13:00
Olly Betts 55377bdc08 Add DOH Exit() and SetExitHandler()
Exit() is a wrapper for exit() by default, but SetExitHandler() allows
specifying a function to call instead.

This means that failures within DOH (e.g. Malloc() failing due to lack
of memory) will now perform cleanup such as removing output files.

This commit also cleans up exit statuses so SWIG should now reliably
exit with status 0 if the run was successful and status 1 if there was
an error (or a warning and -Werror was in effect).

Previously in some situations SWIG would try to exit with the status set
to the number of errors encountered, but that's problematic - for
example if there were 256 errors this would result in exit status 0 on
most platforms.  Also some error statuses have special meanings e.g.
those defined by <sysexits.h>.

Also SWIG/Javascript tried to exit with status -1 in a few places (which
typically results in exit status 255).
2022-03-06 12:33:54 +13:00
Olly Betts deb7cbf741
Merge branch 'master' into director-unwrap-result 2022-03-01 11:34:59 +13:00
Olly Betts 2e98189564 [Ruby] Fix remove of prefix from method name
The prefix is now only removed at the start.

Fixes https://sourceforge.net/p/swig/bugs/1136/
2022-02-02 15:53:23 +13:00
Olly Betts 561a1d843d Fix ODR violations
Detected by compiling with GCC flags `-flto -Wodr`.
2021-09-20 15:04:51 +12:00
Olly Betts 9ddc9dceb7 Remove support for $source and $target
These were officially deprecated in 2001, and attempts to use them have
resulted in a warning (including a pointer to what to update them to)
for most if not all of that time.

Fixes #1984
2021-04-30 10:20:14 +12:00
Thomas Reitmayr 01277d700c Unwrap director classes only when returning a pointer or reference to an object
This involves properly counting the number of references and pointers in the return
type of a function and only generate unwrapping code if this number is 1.
For template instances some post-processing code is added to fix the 'decl' and
'type' attributes of functions if changed in an unfavorable way during template
expansion.
This commit fixes swig#1811.
2020-06-20 12:17:55 +02: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
Thomas Reitmayr 18a3ef3911 Fix code generated for Ruby global variables
This commit fixes swig#1653 by creating a Ruby virtual variable
for a C/c++ global variable when SWIG is invoked with the
-globalmodule option.
2019-10-27 21:41:03 +01:00
Vadim Zeitlin cd526caed4 Harmonize parameters in autodoc in Ruby and Octave with Python
Backport changes to Python version of make_autodocParmList() to Ruby and
Octave modules, which use similar code.

In particular, this improves handling of parameters clashing with the
language keywords/reserved words for these languages as well.
2019-01-21 01:08:45 +01:00
William S Fulton 96d33287b4 Fix Ruby docstring feature.
The docstring was not encapsulated within /* */ comments.

The implementation had code for autodoc strings being either single or
multi-line and then adding extra newlines. However, in practice only multi-line
autodoc string are ever generated, so this bit of code handling was removed.
The docstring feature does not attempt to add newlines depending on the
existence of newlines in the docstring.

Closes #538
2019-01-05 19:21:04 +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 fc79264a48f186f8bbd367e91fa9dbf9758aa092:
"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 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
luz.paz 60dfa31a67 Misc. typos
found via `codespell` and `grep`
2018-05-17 10:04:23 -04:00
William S Fulton 5ccae6eac6 Merge branch 'goatshriek-ruby-alias'
* goatshriek-ruby-alias:
  Fix ruby %alias directive for native c functions
2018-04-07 12:34:08 +01:00
Olly Betts 3bea8f6b7e [Ruby] Pass Qnil instead of NULL to rb_funcall()
This silences GCC -Wconversion-null warning (on by default with recent
GCC).
2018-04-03 18:01:58 +12:00
Joel Anderson a1cea4f483 Fix ruby %alias directive for native c functions
Using the %alias directive on native C functions causes swig to segfault due to
a dereference of klass (which is NULL for native C functions) in the
defineAliases function of the Ruby module. This commit adds support for an alias
of native C functions for both separate module as well as global functions, as
well as three test cases for the %alias directive of the Ruby module.

Fixes:
mod.i
%module ruby_alias
%alias get_my_name "nickname,fullname";
%inline %{
const char *get_my_name(){
  return "Chester Tester";
}
%}
$ swig -ruby mod.i
Segmentation fault

Signed-off-by: Joel Anderson <joelanderson333@gmail.com>
2018-03-22 08:05:01 -04:00
William S Fulton ae044c1c2f Generation of director method declarations fixes
- Fixes generation of director method declarations containing C++11 ref-qualifiers.
- Fixes generation of director method declarations returning more complex types such
  as const ref pointers.
- Rewrite Swig_method_call to use more up to date code in the core.
2017-10-23 18:55:14 +01:00
William S Fulton 3f8b8fe734 Enhancements for directorin typemaps
The directorin typemaps will now generate a temporary variable
(specified after the type), such as:
%typemap(directorin) MyType (MyType *temp) { ... use temp ... }

The shared_ptr director typemaps have been fixed for use in functions
that take more than one parameter.
2017-10-16 19:28:27 +01:00
William S Fulton ebd37155a8 Fix potential use of uninitialized variables in directors 2017-05-13 22:40:59 +01:00
Christophe Duvernois 4777a0ad3c #526 : propagate c++11 noexcept to director classes 2017-04-27 23:37:15 +02:00
Olly Betts 7a3cfdb013 Fix GCC 7 warnings
From -Wimplicit-fallthrough which is now enabled by -W.
2016-12-21 13:05:20 +13:00
Olly Betts f474577d5b Fix "set but not used" warning 2016-12-13 13:58:51 +13:00
William S Fulton a91d1b5a42 Remove unused kwnames generated variable in Ruby wrappers
This seems to be from some left over Python kwargs / unfinished kwargs support
2016-05-28 00:45:24 +01:00
William S Fulton 70f5a9ceed Merge branch 'tamuratak-master'
* tamuratak-master:
  Revert introduction of minor memory leak in Ruby wrappers
  ruby: use nodeType attribute to determine whether functions are constructors.       get return type each time.
2016-05-17 20:05:20 +01:00