Partially revert issue #3137.
This change did nothing to improve thread safety.
e.g. to get an item from a list you can use:
- PyList_GET_ITEM - thread unsafe vs. list element swap due to borrowed references; thread unsafe against list shrinking; no bounds checking regardless of threading
- PyList_GetItem - thread unsafe vs. list element swap; unsure about thread safety vs. list shrinking; bounds checked. Slower than PyList_GET_ITEM.
- PyList_GetItemRef. Thread safe and bounds checked; slower than both of the above.
To clarify there is absolutely nothing wrong with using PyList_GET_ITEM or PyList_GetItem in free-threading Python, as long as you can guaranteed that either
- the list is private to the thread; or
- your code is protected by a critical section and is not going to be suspended within it; or
- your code is protected by a lock
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.
- More robust implementation calling PyWeakref_GetRef.
- Remove check for PyWeakref_CheckProxy, it's been available since python-2.2.
- Remove redundant Py_LIMITED_API code (only called when SWIG_PYTHON_SLOW_GETSET_THIS is defined
which is only for python<3 and python-2 does not have a limited API.
SWIG_PYTHON_SLOW_GETSET_THIS code should be removed when python-2 support is removed.
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
This was added in an attempt to avoid warnings from a static analysis
tool which wants us to use nullptr instead of NULL, but we can't do so
unconditionally while continuing to support C++98.
SWIG_NULLPTR is ugly, verbose and non-standard and NULL is still
standard C++ so we've decided to just use NULL instead. Users of tools
which don't like NULL can just suppress this warning for SWIG-generated
code.
Closes#3165Closes#3166
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
The windows-2019 image with Visual Studio 2019 support is ending,
see https://github.com/actions/runner-images/issues/12045.
Switch to latest windows-2025. The windows-2022 and windows-2025
images have the same version of Visual Studio installed (and just
about everything else), so just use the windows-2025 image.
Implements https://peps.python.org/pep-0489/
Bumps minimal python3 version from 3.4 to 3.5.
The idea is to move the initialization of the module into a new SWIG_mod_exec function.
Closes#3168
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.