Commit Graph

6740 Commits

Author SHA1 Message Date
Olly Betts 55d82e0d8a Fix comment and doc typos 2025-06-18 10:24:03 +12:00
Olly Betts 600685dfd8 [go] Remove workaround in cpp11_decltype.i
This case was fixed by 7a8c9fdfa8.

(SWIG/Go still has problems wrapping constant strings in some cases
though - the example in #2724 still fails.)
2025-06-18 09:53:46 +12:00
Olly Betts 2d717988c2 Add another recently fixed case
Fixed by 3f4ed82945.

See #1589 and #3011.
2025-06-17 18:32:41 +12:00
Olly Betts 61c542162c Fix parsing of a::b.c() and x::y.z
Fixes #3197
2025-06-17 15:23:15 +12:00
Olly Betts 3f4ed82945 Improve parsing of expressions related to functions calls
For example, the following no longer give parse errors:  `g().d()`,
`g().D`, `(f(1) < g(2))`, `sizeof f(a,b)`

Partly addresses #3197
2025-06-17 14:59:54 +12:00
William S Fulton 9c4aa6099d Merge branch 'builtin-heap-types'
* builtin-heap-types:
  Changes entry for python -builtin and heap types
  Revert previous commit as it breaks setting arbitrary attributes on builtin wrapped types
  Fix TypeError: multiple bases have instance lay-out conflict
  Py_LIMITED_API support in SwigPyObject_Check for -builtin
  Py_LIMITED_API support in SwigPyBuiltin_SetMetaType for -builtin
  Remove pyname_compat.i
  Python type creation functions refactor
  Small move towards Py_LIMITED_API for -builtin
  Add SwigPyObjectType and SwigPyStaticVar to the swig runtime module
  SWIG_HEAPTYPES for SwigPyStaticVar and add it to the runtime module
  Cosmetic whitespace formatting around PY_VERSION_HEX
  SWIG_HEAPTYPES for SwigPyObjectType and add it to the runtime module
  Better error handling creating types with python -builtin
  Gracefully handle errors in PyType_FromSpecWithBases for -builtin
  Gracefully handle errors in PyModule_AddObject for -builtin
  More graceful error in failures calling back_reference
  Show ref count before final decrement when using SWIG_REFCNT_DEBUG
2025-06-11 08:16:48 +01:00
William S Fulton f3672e2d6f Py_LIMITED_API support in SwigPyObject_Check for -builtin
Simplify implementation for -builtin, which does not need a fallback to
use strcmp as PyType_IsSubtype() 'just works' even when using multiple
modules (I think perhaps because SwigPyObject_stype->clientdata->pytype is
common across modules due to the implementation in SwigPyObject_Type()).

In the non-builtin case SwigPyObject is not a base type and usage is
different and when multiple modules are being used, SwigPyObject_Type()
returns two implementations of SwigPyObject which is solved in a hacky
way by comparing the types as strings when the pointer comparison fails.

Add import_callback test - tests %import and %callback to exercise
all of SwigPyPacked_Check(). Python only - the main callback example is
not widely tested and needs work in most of the other languages.
2025-06-09 18:36:13 +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 31668d98e1 Fix warnings from cpp11_auto_variable_runme.php 2025-06-08 09:58:30 +12:00
vincentcouvert dd0e14ad22
Add support for Scilab 2025.x.0
Add support for Scilab 2025.0.0 and 2025.1.0 (const-related changes, error management).

Add CI job for Scilab 2025.1.0.

Fixes #3155
2025-06-07 07:23:07 +12:00
Olly Betts 739997707c Handle C++14 auto return type function declaraction
Fix parse error for C++14 forward declaration of function with auto
return type and no trailing return type.

Fixes #3186
2025-05-28 14:10:03 +12:00
William S Fulton 307b474769 Fix regression expanding templates in function parameter values
Only using the parameter value in the generated code, such as when using
kwargs. This is known to be fundamentally flawed as sometimes the
generated value is not accessible outside of the class it is defined in.

Fixes regression due to a037e2f2e2.
The new fix now attempts to treat all value and name attributes as
a SwigType instead of an unparsed type in a String. However, it does
it more consistently instead of just for the "value" attribute in
add_parms.

Also subtle problem fix where cpatchlist was incorrectly being used
instead of patchlist.

Closes #3179
2025-05-17 00:21:51 +01:00
William S Fulton 53f4751ffa Fix undefined behaviour in directorout typemaps for void * and const char *&
if the same wrapped function is called more than once. Note that using returning
pointers in directors is still full of traps and not recommended. As such,
warning SWIGWARN_TYPEMAP_DIRECTOROUT_PTR (473) continues to be issued.

The debug Python interpreter failed 3 director testcases which have been
modified in this patch to work around unrecommended director usage
returning from director methods. These are C strings and std::string_view.

A Pyton reference count leak is chosen over undefined behaviour for
returning std::string_view.
2025-05-14 22:10:39 +01:00
William S Fulton 9156ecc669 Add -Walways when running Python interpreter to find more warnings
I tried with -Werror but observed the warning messages disappearing
and tests not failing - probably because the wrapper code is swallowing
warnings and catching the resulting error. Seen in python_overload_simple_cast_runme.py
on Linux (not Windows!). Also when the warning is turned into an error
just a seg fault can occur without the warning message. All round better
to actually see the warning.
2025-05-13 21:49:37 +01:00
William S Fulton ff7ab351a3 Suppress DeprecatedWarning in python_overload_simple_cast_runme testcase
I think these are due to problems inside the Python interpreter sorted out in 3.10.
From 3.10 release notes:

Builtin and extension functions that take integer arguments no longer accept Decimals,
Fractions and other objects that can be converted to integers only with a loss (e.g.
that have the __int__() method but do not have the __index__() method).
2025-05-13 21:49:37 +01:00
William S Fulton d966fd3ba1 Test swig runtime module contains expected names 2025-05-13 21:49:37 +01:00
William S Fulton 818ea4cc74 Fix clang [-Wconstant-logical-operand] warning in testcase
warning: use of logical '&&' with constant operand [-Wconstant-logical-operand]
2025-04-29 22:41:15 +01:00
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 deadb05bd6 Fix clang [-Wundefined-inline] warning in testcase 2025-04-29 22:13:30 +01:00
Julien Schueller 55237efa72 Python: Amend annotations test 2025-04-25 22:13:46 +02:00
William S Fulton f456174408 Test latest ruby-3.1.x ruby-3.2.x and ruby-3.3.x versions again
Avoid import_fragments testcase testing for buggy ruby-3.1.x and ruby-3.2.x.
Closes #2800.

I've run ruby-3.3 testing on Github Actions 8 times and flakiness in
cpp11_rvalue_reference_move testcase seems to have gone away using
latest 3.3.x version (3.3.8). Restoring latest 3.3.x testing to see how
it goes.
Closes issue #3030.
2025-04-22 21:56:03 +01:00
William S Fulton 4574198553 Javascript jsc c++20 testing quirk fix 2025-04-21 12:41:29 +01:00
William S Fulton 24de76daeb Update/fix hugemod test case to work again 2025-04-20 15:27:28 +01:00
William S Fulton b16a7c958a Fix crash in c_copy_struct R testcase
Workaround initialises additional members in the A struct when created
using new(A) as opposed to created with A().
Probably the typemaps for int etc should be fixed to not crash if the
input is not initialised though.
2025-04-19 16:20:17 +01:00
William S Fulton 298c489dc6 Add docs for free threading Python
'make check-python-version' now uses -VV so that a free threading build
can be identified.
2025-04-17 18:51:33 +01:00
William S Fulton 1b09f4f111 Refactor python no-gil detection
Also additional python interpreter flags cleanup, use PYFLAGS consistently and remove PYTHONFLAGS.
2025-04-17 17:44:02 +01:00
klaus spanderen a75b7b8b9c Added support for Python free threading (aka no-gil) 2025-04-16 19:00:48 +01:00
William S Fulton 61f0bbe97d Python external_runtime example fixup
- Modify example to actually use the external runtime in example.cxx.
- Correct formatting of files.
- Add exception handling.
- Rename two main classes in example for better clarity.

This commit fixes the previous commit so that the example now correctly
tests the commmit prior to it.

Note that -builtin is not run as it does not work (seg faults - needs
investigation).

Issue #3067
2025-04-10 08:13:07 +01:00
Julien Schueller 0954292130 Add external runtime Python example using typemap
See issue #3067
2025-04-10 08:13:07 +01:00
William S Fulton 124d8a8c37 Test code for removed methods from std::list for compatibility with java.util.List 2025-04-03 09:07:50 +01:00
William S Fulton ef0d38bffd Support JDK 21 and std::list
Fixes removeFirst() and removeLast() incompatibilities with methods
of the same name in the Java base class java.util.AbstractSequentialList
which were added in JDK 21 as part of JEP-431.

configure.ac has been modified to detect the version of JDK/Java for use
in testing the test-suite via the JAVA_VERSION_MAJOR variable.

Needed to continue testing removeFirst(), removeLast(), addFirst(), addLast().

Closes #3156
2025-04-02 22:56:11 +01:00
William S Fulton 83be871eec Remove unused JAVA_TOOLS_JAR make variable 2025-04-02 22:55:18 +01:00
William S Fulton c2ad64d0a8 Java compiler lint warnings fixes in test code
Fixes:
[cast] redundant cast
[rawtypes] found raw type
[serial] serializable class has no definition of serialVersionUID

Also suppress warning: auxiliary class TargetLanguageBase in ./inherit_target_language.java should not be accessed from outside its own source file
2025-04-02 22:52:30 +01:00
William S Fulton a16e3cb8ce Add Java compiler linting checks javac -Xlint 2025-04-02 22:52:30 +01:00
Olly Betts f3ea85af0b [MzScheme/Racket] Drop support
Closes #920
Closes #2830
2025-04-01 14:05:28 +13:00
William S Fulton a5568a7286 deprecated boost atomic_count.hpp
Fix:
boost/detail/atomic_count.hpp(10): note: This header is deprecated. Use <boost/smart_ptr/detail/atomic_count.hpp> instead.
2025-03-28 07:54:47 +00:00
Olly Betts 6dbf867d23 Fix handling of corner cases by previous change
Don't collapse runs of whitespace to a single space, instead replace
each whitespace with one space.

Leave the expression as-is if it contains one or more double quotes
as we don't want to change the value of string literals, and any
expression containing double quotes won't currently work in the context
where we need to replace newlines anyway.

Fixes #3127 better
2025-03-03 11:22:37 +13:00
Olly Betts 4a0372aacc Improve parsing multi-line expr via skip_balanced()
Fix bad generated code in some cases when a constant expression is split
over multiple lines and used as part of a type.  This manifested in
cases where SWIG's parser calls skip_balanced('(', ')') then grabs the
skipped expression's program text from scanner_ccode.

Fixes #3127
2025-02-28 17:30:08 +13:00
William S Fulton 26b0911a74 Add support for $n special variable expansion in the names of typemap local variables
For example:

  %typemap(in) int MYINT (int $1_temp) { ... }

$1_temp is typically expanded to arg1_temp, arg2_temp etc depending on
which argument the typemap is applied to.
2025-02-19 20:44:40 +00:00
William S Fulton fe3a7af855 Revert "[Go] Use unsafe.Slice and unsafe.String in Go fragments"
This reverts commit ff5c118aaa.
2025-02-14 19:09:18 +00:00
Ian Lance Taylor ff5c118aaa [Go] Use unsafe.Slice and unsafe.String in Go fragments
The existing code didn't work correctly for strings longer than 2GB.

This does require using at least Go 1.20, but that should be OK as
the last currently supported version of Go is 1.22.
2025-02-13 09:54:20 -08:00
William S Fulton e8787615a7 Regression fix when using -keyword, kwargs or compactdefaultargs option
Restore generating a non-const cast to the default value when
wrapping const pointer default arguments.

Fixes #3075.
2025-02-05 08:09:44 +00:00
Armin Brauns e2c3e568fd Add Lua test case for long long 2024-12-05 15:38:08 +00:00
Olly Betts dfe9d8ea2f [Java] Fix regression wrapping enum values
Fix regression wrapping enum values which don't fit in a Java signed
int.

Fixes #3070
2024-11-21 17:05:31 +13:00
William S Fulton d9edb22d1c %apply and typedefs improvement
Perform repeated typedef lookups instead of a single typedef
lookup on the type being applied in %apply when looking for a family
of typemaps to apply.

Closes #3064
2024-11-09 13:30:19 +00:00
William S Fulton 5c2e83dd1a Typedefs to references fix for the compactdefaultargs feature
Fixes error: SwigType_del_reference applied to non-reference type
2024-11-04 23:21:25 +00:00
William S Fulton 3cda507e57 Fix initializer lists used with -keyword or compactdefaultargs option
Remove casts to local variables that have initial values taken from the
default arguments being wrapped. This is for the default case, that is,
for all types, except references.

This fixes handling of parameters with default arguments that are initializer
lists by removing a cast to the initializer.

For wrapping parameter X x = {}, the generated code previously would have
contained:
  X arg2 = (X) {};
Now it is:
  X arg2 = {};

Closes #1851
2024-11-04 23:21:25 +00:00
William S Fulton 7af22e929a Fix pedantic warning in tests 2024-11-04 23:20:43 +00:00
Olly Betts ada653aaf0 Suppress unhelpful GCC/clang warnings in new tests 2024-10-27 15:04:52 +13:00
Olly Betts 4e315cdd7c Fix precedence of casts
Casts should have the same high precedence as unary plus and minus, but
actually had a lower precedence than anything else.

This could lead to the wrong type being deduced in obscure cases, but
also prevented SWIG deducing a type for expressions such as (0)*1+2
which SWIG parses as a cast and then fixes up afterwards.

A bug fixed in 4.3.0 made this latter problem manifest more often
(previously type deduction happened to work for (0)*1+2 due to an
internal field not getting cleared properly).

Fixes #3058
2024-10-27 10:02:11 +13:00