PyTuple_SET_ITEM fails to compile in C++ source · Issue #93442 · python/cpython (original) (raw)
- CPython versions tested on: 3.11b3
- Operating system and architecture: Debian Linux, GCC 10.2.1-6
The kiwisolver extension doesn't compile with beta 3. The error is:
/usr/local/python3.11.0b3/include/python3.11/pyport.h:47:24: error: invalid ‘static_cast’ from type ‘int’ to type ‘_object*’
47 | return static_cast<type>(const_cast<expr_type &>(expr));
| ^~~~~
This seems to be an issue with the new inline functions for things that used to be macros. E.g. PyTuple_SET_ITEM. The C++ code triggering the issue is:
--- a/py/src/symbolics.h
+++ b/py/src/symbolics.h
@@ -123,7 +123,7 @@ PyObject* BinaryMul::operator()( Expression* first, double second )
return 0;
Py_ssize_t end = PyTuple_GET_SIZE( first->terms );
for( Py_ssize_t i = 0; i < end; ++i ) // memset 0 for safe error return
- PyTuple_SET_ITEM( terms.get(), i, 0 );
+ PyTuple_SetItem( terms.get(), i, 0 );
for( Py_ssize_t i = 0; i < end; ++i )
{
PyObject* item = PyTuple_GET_ITEM( first->terms, i );
Replacing the macro with the function version seems to allow the extension to compile.
This seems related to #92898