11use crate :: object:: * ;
22#[ cfg( not( PyPy ) ) ]
33use crate :: pyport:: Py_ssize_t ;
4+ #[ cfg( any( GraalPy , PyPy ) ) ]
5+ use crate :: { PyTuple_GetItem , PyTuple_SetItem } ;
46
57#[ repr( C ) ]
68pub struct PyTupleObject {
@@ -21,16 +23,26 @@ pub unsafe fn PyTuple_GET_SIZE(op: *mut PyObject) -> Py_ssize_t {
2123}
2224
2325#[ inline]
24- #[ cfg( not( any( PyPy , GraalPy ) ) ) ]
2526pub unsafe fn PyTuple_GET_ITEM ( op : * mut PyObject , i : Py_ssize_t ) -> * mut PyObject {
26- * ( * ( op as * mut PyTupleObject ) ) . ob_item . as_ptr ( ) . offset ( i)
27+ #[ cfg( not( any( GraalPy , PyPy ) ) ) ]
28+ return * ( * ( op as * mut PyTupleObject ) ) . ob_item . as_ptr ( ) . offset ( i) ;
29+ #[ cfg( any( GraalPy , PyPy ) ) ]
30+ return PyTuple_GetItem ( op, i) ;
2731}
2832
2933/// Macro, *only* to be used to fill in brand new tuples
3034#[ inline]
31- #[ cfg( not( any( PyPy , GraalPy ) ) ) ]
3235pub unsafe fn PyTuple_SET_ITEM ( op : * mut PyObject , i : Py_ssize_t , v : * mut PyObject ) {
33- * ( * ( op as * mut PyTupleObject ) ) . ob_item . as_mut_ptr ( ) . offset ( i) = v;
36+ #[ cfg( not( any( GraalPy , PyPy ) ) ) ]
37+ {
38+ * ( * ( op as * mut PyTupleObject ) ) . ob_item . as_mut_ptr ( ) . offset ( i) = v;
39+ }
40+ #[ cfg( any( GraalPy , PyPy ) ) ]
41+ {
42+ let previous = PyTuple_GetItem ( op, i) ;
43+ Py_XINCREF ( previous) ;
44+ PyTuple_SetItem ( op, i, v) ;
45+ }
3446}
3547
3648// skipped _PyTuple_DebugMallocStats
0 commit comments