Heap types and Py_LIMITED_API cannot support __tp_dictoffset__.
As this tp_dictoffset slot is only used by the builtin wrappers
(-builtin), builtin wrappers and Py_LIMITED_API will require python-3.9
or later.
Issue #3196
Compilation fix as tp_dictoffset is not available when defining
Py_LIMITED_ABI.
This still needs addressing in the case of multiple modules, mixing
builtin modules and non-builtin (proxy classes) modules in one python
interpreter session.
Add python 3.8 -builtin to GHA
structmember.h inclusion moved for external runtime to work without
requiring users to include structmember.h and the Py_READONLY and
Py_ST_PYSSIZE_T definitions. Including Python.h remains the requirement
for using the external runtime (Examples/python/external_runtime).
Note that stddef.h is not always included by structmember.h
Rename dict to swigdict in PySwigObject for easier identification.
SWIG_HEAPTYPES definition is moved to support both external runtime
and Python Stable ABI.
Issue #3196
Fixes "TypeError: multiple bases have instance lay-out conflict"
for python-3.11 and earlier for multiple inheritance, see 22d9fda0 and 4908133e.
Fix is achieved by moving __dictoffset__ to the single common base class SwigPyObject.
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.
Rename to use naming conventions used in the Python C code base and
typically used in extensions when creating types:
SwigPyObject_type -> SwigPyObject_Type
SwigPyPacked_type -> SwigPyPacked_Type
swig_varlink_type -> SwigVarLink_Type
to also match other type creating functions SwigPyObjectType_Type
and SwigPyStaticVar_Type.
Add SwigVarLink singleton creation to init function for thread safety.
for default case (they have just been added for -builtin and
SWIG_HEAPTYPES in previous couple of commits).
These are only used by -builtin and were missed when when moving
SwigPyObject, SwigPyPacked and SwigVarLink were added to the swig
runtime module. Should fix potential warnings for these two types:
DeprecationWarning: builtin type has no __module__ attribute
although this has not been seen in the test-suite.
Python error instead of abort due to assert failure in python-3.8 and
earlier versions which fail using -builtin.
For li_std_vector_back_reference testcase when defining SWIG_HEAPTYPES.
The pybuffer typemaps use a new fragment for issuing the helpful warning
to help clarify when the old Buffer Protocol can be used. This prevents
it being issued when the typemaps are not used and makes it clearer in
the generated code when the old Protocol Buffer is being used.
Define SWIG_NO_PYTHON_OLD_BUFFER_PROTOCOL to override the choice of when
to define SWIG_PYTHON_OLD_BUFFER_PROTOCOL.
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.
DeprecationWarning fixes when using 'python -Walways' or if using one of the types being warned about:
DeprecationWarning: builtin type SwigPyPacked has no __module__ attribute
DeprecationWarning: builtin type SwigPyObject has no __module__ attribute
DeprecationWarning: builtin type swigvarlink has no __module__ attribute
The warning was present if code was generated without using -builtin in 4.3.x.
The warning was only present if using the Python limited API in 4.2.1 and earlier.
These 3 types were not in any module at all. Now they are in the swig runtime module.
Docs to follow.
Issue #2881
Issue #3061
Issue #3160
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
Call correct functions when unlocking/destroying a mutex implemented
using Python API: they were accidentally exchanged in 21f1c923c (Make
directors implementation for Python work with limited API, 2019-12-23)
resulting in crashes when using directors and threads together.
Closes#2889, #3112.
Problem reported as starting with python-3.13.
Due to error not being cleared before calling Python C APIs.
The alternative could have been to ensure SWIG_AsCharPtrAndSize
never returns with a pending error (not that easy).
Closes#3051
This header pollutes the namespace and can cause clashes with the
API being wrapped so it's helpful to only include it when we actually
need to (we actually never need to currently, but will if/when
SWIG_HEAPTYPES is fixed to work with -builtin).
See #2350
This reverts commit 7911683101.
but keeps the SWIG_name generation into the f_runtime rather than f_headers.
This change was breaking tests that use SwigPyPacked (callbacks/function
pinters) eg callback test when using Py_LIMITED_API.
Most languages now use "NullReferenceError" in the error message
where they previously used "ValueError". Also exception changes:
Guile: "swig-null-reference-error" instead of "swig-value-error"
MzScheme: "swig-null-reference-error" instead of "swig-value-error"
PHP: zend_ce_type_error instead of zend_ce_value_error
Python: Consistently raises TypeError instead of a mix of ValueError
and TypeError.
Ruby: Consistently raises NullReferenceError instead of a mix of
ArgumentError and NullReferenceErrorError.
The consistent raising of a TypeError instead of ValueError for Python
ensures that incorrectly passing 'None' into a C++ reference argument
will correctly convert the error into a NotImplemented error for
the rich comparisons implementations per PEP 207. Fixes#2987
Note that the li_constraints checking implementation for the NONNULL
typemap for pointers also makes the same error change from
SWIG_ValueError to SWIG_NullReferenceError.
The D typemaps use SWIG_DNullReferenceException instead of
SWIG_DIllegalArgumentException, although this ultimately has no change
as the same D Exception is still thrown.
* github-win-ci:
No need to test so many versions of Python
More cosmetic tweaks
Cosmetic corrections - MinGW-w64
Revert PYTHON_LIB change
fromdos consistency for removing CR
Show notest in name
Restore appveyor testing
Follow @wsfulton feedback
Remove win32 userenv library.
Replace 'cmd' with 'powershell'. As powershell stop on error. With 'Install MSYS2', as 'pacman' works with cmd, add checks after each command for errors. Revert Windows 'SWIG_LIB'. SWIG Main, check SWIG_LIB environment for null and empty string. Build with MING w64 compiler. Configure improve Windows python 3, try python-config first.
Add "Machine Info" to CMAKE-WIN workflows. Replace here-documents and tabs with multiple echo lines. Add comments.
As we add a new GitHub Windows test in ".github/workflows/win_ci.yml"
Add windows actions using GitHub. Update Windows document. Small update in configuration. Remove SWIG_LIB_SET, windows should use the same value. Add better striping for multiple test in common make file. Add library path to dynamic python linking, MSVC need to find the windows library linking file (*.lib). For other GCC, it does not change.
Closes issue #2813
Add 'PYLIB' and 'PY3LIB' with '-L' in configure.
Revert python 3 probing in configure.ac
Add ruby with MingW64 instead.
Signed-off-by: Erez Geva <ErezGeva2@gmail.com>