Description
Following on from #2350 from @clintonstimpson, where heap types replaced static types for the default Python wrappers (proxy classes), there is a need to finish this for the builtin SWIG wrappers when using the -builtin
option.
See https://docs.python.org/3.13/howto/isolating-extensions.html#heap-types for heap types vs static types.
The goal is to completely remove the original static types and replace them with heap types. Currently, the proxy classes
approach to generating wrappers only uses 3 builtin types (SwigPyObject, SwigPyPacked, SwigVarLink) and these 3 builtin types are now using heap types instead of static types by default. So we can consider this complete. However, the builtin approach to wrapping generates builtin types instead of Python proxy classes.
The pull request in 9c4aa60 has nearly finished the conversion to heap types for the builtin wrappers. Currently it requires adding -DSWIG_HEAPTYPES
when compiling the wrappers as it not turned on by default, eg running the test-suite
env SWIG_FEATURES=-builtin make check-python-test-suite CXXFLAGS="-DSWIG_HEAPTYPES -std=c++20"
The test-suite passes when using python-3.12 and higher with the above.
I really need some help in order to be fix earlier versions of Python. The problems are (again only for <= python-3.11):
- As it stands, we have a TypeError: multiple bases have instance lay-out conflict in the case of multiple inheritance. It only appears when a type has two or more base types. The only fix I could find was to remove
__dictoffset__
, but then this introduces issue 2: - Unable to set arbitrary attributes on the wrapped types. Setting arbitrary types works with the proxy classes approach to wrapping as well as the builtin wrappers with static types.
Adding further confusion is according to the Python docs, https://docs.python.org/3.13/howto/isolating-extensions.html#heap-types,
setting arbitrary types is not mean to work on static types but does for heap types. I'm not sure why this documentation says static types are immutable, as we are able to set arbitrary attributes on the static builtin types.
See commit 22d9fda which switches the problem from 1 to 2 and commit 4908133 to reverse it. The commits have details of the error messages and failing test cases.
Pinging @encukou and @vstinner, hope you don't mind given your Python development credentials and the fact you've contributed to SWIG. This is the final blocker switching to heap types and I just can't figure out how to support these older versions of Python.