Commit Graph

25336 Commits

Author SHA1 Message Date
William S Fulton 7c478b5e17 Note the LENGTH STRING typemap changes and tidy up 2025-07-28 23:02:52 +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
Guido Imperiale a5576af6d1
Free-threading Python: revert special treatment for PyList_GET_ITEM etc. (#3225)
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
2025-07-25 08:17:38 +01:00
Guido Imperiale 5cfb333da6
.gitignore (#3228)
[skip-ci]
2025-07-25 07:44:55 +01:00
William S Fulton 9dc48b2628 Add missing initializer for new PyMemberDef array member 2025-07-23 23:02:21 +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 e5d0c8e3cf Merge branch 'master' into fix_1792 2025-07-22 09:35:41 +01:00
William S Fulton 738db8f288 SWIG_Python_GetSwigThis implementation tidyup
- 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.
2025-07-21 21:53:12 +01:00
Jim Easterbrook 44684b9b55 Don't call PyWeakref_GET_OBJECT if limited API (#3223)
PyWeakref_GET_OBJECT is not part of the limited API/stable ABI so call
PyWeakref_GetObject instead.
2025-07-21 21:53:00 +01:00
Jim Easterbrook 3a37288e06 Merge branch 'master' into fix_1792 2025-07-19 09:53:34 +01:00
William S Fulton 0f58f9872d Restore plain python-3.12 testing without -nogil 2025-07-18 22:42:17 +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
William S Fulton 7a7aba03b6 Polish off heap types buffer support
Clean up generated code and make it c90 compliant.
Add changes entry for this work in issue #3219.
2025-07-18 18:59:43 +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
Even Rouault 0c8f427475
pyrun.swg: fix -Wparentheses warning (#3221)
Fixes gcc 14.3 warning
```
 extensions/gnm_wrap.cpp: In function 'PyObject* SwigPyObject_richcompare(PyObject*, PyObject*, int)':
extensions/gnm_wrap.cpp:2031:21: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
 2031 |     if (op != Py_EQ && op != Py_NE || !SwigPyObject_Check(w)) {
```
2025-07-13 10:58:01 +01:00
Jim Easterbrook c6a99c6953 Don't set tp_weaklistoffset if Py_LIMITED_API
I hope this will fix the 'linux / python 3.8 abi=3.5 gcc (pull_request)'
failure. (Not tested as I don't have Python 3.8)
2025-07-10 10:36:40 +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 9c2a1bc39c Remove unused -SWIG_Python_TypeError
This method is not used and is not fully implemented for the limited API
2025-07-09 19:19:01 +01:00
William S Fulton 75c2928454 Limited API fix in SwigPyPacked_Check for builtin wrappers 2025-07-09 19:19:01 +01:00
William S Fulton 61909fbdf7 Limited API fix in SwigPyObject_Check for builtin wrappers
Further removal of dependency on tp_name which is not in the limited API.
2025-07-09 19:19:01 +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
Jim Easterbrook 40378d0405
Remove PyErr_SetString if type init fails (#3210)
PyType_Ready sets an exception which should not be over written.
Closes #3209.
2025-07-02 21:27:05 +01:00
Olly Betts 491994c836 Use NULL instead of SWIG_NULLPTR
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 #3165
Closes #3166
2025-07-02 08:43:32 +01:00
William S Fulton d37739fab2 Remove outdated practice of truncating string lengths in PyErr_Format
As suggested in PEP-737.
2025-07-02 08:24:51 +01:00
William S Fulton 98641c78a2 Correct some docs about javapackage
Closes issue #2776

[ci-skip]
2025-06-28 16:09:06 +01:00
William S Fulton 1fa70fb4a7 Java docs enhancement for handling deleted objects
[skip-ci]
2025-06-27 18:36:04 +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
Jim Easterbrook e5a76eef91 Check for NULL in Python builtin setter closure
This prevents a segfault, as reported in issue #3203

Use Py_TYPE macro / function to get type object
2025-06-26 19:35:08 +01:00
Ian Lance Taylor 93d67c9549 [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.

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
2025-06-25 13:55:43 -07:00
William S Fulton 64fcc45920 GHA - drop windows-2019 image testing
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.
2025-06-25 08:12:21 +01:00
William S Fulton 2e363dc8b2 Formatting changes for the multi-phase Python module initialization 2025-06-23 23:44:52 +01:00
Julien Schueller 6c3bc2d18a Python: Use multi-phase initialization
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
2025-06-23 22:04:47 +01:00
William S Fulton cfe8c2a1cf -Wunused variable warning changes file entry 2025-06-23 22:03:29 +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 4bf9547982 Fix -Wunused-variable warning for overloaded methods in Octave
Fixes testcases: cpp11_director_using_constructor and cpp11_using_constructor.
2025-06-23 21:39:49 +01:00
William S Fulton dd7415f4b3 Fix -Wunused-variable warning in Octave
Introduced in e8fa1a5018
2025-06-23 21:39:49 +01:00
William S Fulton 25dd59287e Cosmetic formatting of typemaps in strings.swg 2025-06-21 23:24:51 +01:00
William S Fulton b4ee44fad4 Fix -Wunused-variable warnings in R 2025-06-21 23:24:51 +01:00
William S Fulton 9df911b907 Fix -Wunused-variable warning in PHP wrappers
Unused variables removed following on from 17a294cec4
2025-06-21 23:24:47 +01:00
William S Fulton 91bcdae967 Fix -Wunused-variable warning when using -java assumeoverride feature 2025-06-21 23:24:46 +01:00
William S Fulton 0fddc95cc2 Fix -Wunused-variable Ruby warning when using -globalmodule 2025-06-21 23:24:46 +01:00
William S Fulton 56b768f258 Fix -Wunused-variable warnings in testcases 2025-06-21 23:24:42 +01:00
William S Fulton 6e83542054 Only generate Python swig_obj[] if required
Removes warning -Wunused-variable
2025-06-21 22:49:17 +01:00
William S Fulton 7d2e854ee0 GHA: Test python builtin on Windows 2025-06-21 22:45:49 +01:00