
On Tue, Oct 5, 2021 at 2:26 PM Ronald Oussoren ronaldoussoren@mac.com wrote:
A problem with Py_SET_TYPE is that it has no way to report errors, which means it is not compatible with tagged pointers.
IMHO future proof API should always have a way to report errors (for example through a return value), even if the current CPython implementation will always succed.
Btw. I don’t particularly mind minor changes like the introduction of Py_SET_TYPE because adopting these is can almost be done mechanically.
Py_SET_TYPE() is weird workaround for limited C compilers (Windows MSC) which don't support referencing a base type using "&PyLong_Type" syntax when defining a type statically in C (".tp_base = &PyLong_Type,").
If you only define heap types, it's not needed.
Py_SET_REFCNT() and Py_SET_TYPE() should not be part of the limited C API. I chose to add them anyway because it was possible to access directly PyObject.ob_refcnt and PyObject.ob_type in Python 3.9 and older. I'm not sure about Py_SET_SIZE() and the limited C API. Again, I added it since it was already possible to access PyVarObject.ob_size before.
Victor
Night gathers, and now my watch begins. It shall not end until my death.