Commit Graph

5528 Commits

Author SHA1 Message Date
William S Fulton dcf69d3e0f Ocaml - add STRING LENGTH multi-argument typemaps 2025-07-28 23:03:15 +01:00
William S Fulton 29daa0fe34 Guile STRING LENGTH typemap fixes
Fix leak in (char *STRING, size_t LENGTH) family of typemaps.
Add (size_t LENGTH, const char *STRING) family of typemaps.
2025-07-28 23:03:15 +01:00
Erez Geva cb68446ece Fix Length & string reverse order typemap.
And add it to missing languages: C#, Java, Lua, PHP.

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2025-07-28 17:07:42 +02:00
William S Fulton 07ce064814 Prefer testcase code over build system code for C testcases 2025-07-26 10:24:23 +01:00
William S Fulton 3438289cad Python weakref support for builtin wrappers and limited API
Adds weakref support to the SwigPyObject class used as a base for all
builtin wrapper types defined as heap types (the default).

However, like __dictoffset__, the __weaklistoffset__ members slot is only
available in the limited API from python-3.9 onwards.

Document the previous commit which adds the bulk of the weakref support
to builtin wrappers.
2025-07-23 22:32:54 +01:00
Jim Easterbrook 0242c35936 Tweak weakref tests for Python 2 2025-07-22 10:20:55 +01:00
Jim Easterbrook 18b3b62d43 More tests of weakref implementation
Ensure the object is accessible via the weak reference, that the
object's weak ref count is incremented and decremented correctly, that
the weak refs are invalidated when the object is deleted, and that any
weak ref callback is called when the object is deleted.
2025-07-22 10:05:22 +01:00
Jim Easterbrook 3a37288e06 Merge branch 'master' into fix_1792 2025-07-19 09:53:34 +01:00
crusaderky 6b556a6a1c Add -nogil opt-in flag to remove need for PYTHON_GIL=0
Closes #3215
2025-07-18 22:41:36 +01:00
Jim Easterbrook 20da01780f Enable Python builtin heap types buffer interface (#3219)
For Python < 3.9 the tp_as_buffer member is set explicitly if the
interface has a bf_getbuffer slot defined. This fixes #3211.

Enabled buffer interface for non-builtin test.
This only works with Python >= 3.12, where methods __buffer__ and
__release_buffer__ were added. Unfortunately it's not practical for
these methods to reuse the slot methods (or vice versa).

Disable Py_LIMITED_API if below 3.11. The Py_buffer struct and
associated functions are not defined in earlier stable API versions.

Closes #3211
2025-07-18 07:43:34 +01:00
Jim Easterbrook 976205ef0d Python: add weakref support to builtin types
These changes add a weakreflist member to SwigPyObject, and set
tp_weaklistoffset to its offset. This fixes #1792.

The Py_TPFLAGS_MANAGED_WEAKREF introduced in Python 3.12 requires
Py_TPFLAGS_HAVE_GC to be set as well, which it currently isn't for
SwigPyObjectType. (See https://github.com/python/cpython/issues/134786).
2025-07-10 08:11:38 +01:00
William S Fulton af6120329c Replace use of tp_name in builtin wrappers for Py_LIMITED_API support
Add SWIG_PyType_GetFullyQualifiedName which is just a wrapper around
PyType_GetFullyQualifiedName, but is only available in python-3.13.
Code up the equivalent for earlier versions - loosely based on the
python-3.13 implementation.

PyType_GetFullyQualifiedName is recommended in PEP-737 for getting the
fully qualified type name of a type.
2025-07-09 19:19:01 +01:00
Tim Felgentreff 5ea4449c3e Correct SwigPyObject_richcompare and SwigPyObject_compare undefined behaviour (#3216)
Correct SwigPyObject_richcompare and SwigPyObject_compare signatures
and avoid potential read beyond object memory.

Squashed commit of #3216 plus changes file entry and whitespace fixes.

Closes #3217
2025-07-09 19:07:44 +01:00
William S Fulton 00b59d73b5 Fix testcase error message text which changed in python-3.11 2025-06-27 08:03:39 +01:00
William S Fulton 31dba786a2 Raise Python AttributeError instead of TypeError for member variable errors
The previous commit which fixes the handling of 'del' on a wrappred member variable now
raises an AttributeError now consistently for builtin werappers and non-builtin wrappers.

Also change some other unexpected/internal error handling for wrapped members
to AttributeError instead of TypeError for complete consistency.
2025-06-26 19:35:16 +01:00
William S Fulton 1f8684eb54 Turn on -Wunused-variable testing in GHA
Use -Wno-unused-variable warnings for scilab and go which need further
work.

Remove no longer needed -Wunused-function warning suppression in javascript.
2025-06-23 21:39:49 +01:00
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 56b768f258 Fix -Wunused-variable warnings in testcases 2025-06-21 23:24:42 +01:00
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
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 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 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