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.
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.
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
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).
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.
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
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.
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.
This restores commit ff5c118aaa which
was rolled back by commit fe3a7af855
because Go was generating C code that uses declarations after
statements. The original commit now works because 1) commit
e0ecea47b1 sets the C standard to use,
and 2) the current minor versions of the relevant Go releases were
fixed to put the declarations first.
Fixes#3125
Use -Wno-unused-variable warnings for scilab and go which need further
work.
Remove no longer needed -Wunused-function warning suppression in javascript.
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.
* 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
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.
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
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.
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.
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).
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
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.
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.
- 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
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