@@ -181,8 +181,9 @@ PyTuple_Pack(Py_ssize_t n, ...)
181181/* Methods */
182182
183183static void
184- tupledealloc ( PyTupleObject * op )
184+ tuple_dealloc ( PyObject * self )
185185{
186+ PyTupleObject * op = _PyTuple_CAST (self );
186187 if (Py_SIZE (op ) == 0 ) {
187188 /* The empty tuple is statically allocated. */
188189 if (op == & _Py_SINGLETON (tuple_empty )) {
@@ -199,7 +200,7 @@ tupledealloc(PyTupleObject *op)
199200 }
200201
201202 PyObject_GC_UnTrack (op );
202- Py_TRASHCAN_BEGIN (op , tupledealloc )
203+ Py_TRASHCAN_BEGIN (op , tuple_dealloc )
203204
204205 Py_ssize_t i = Py_SIZE (op );
205206 while (-- i >= 0 ) {
@@ -214,29 +215,29 @@ tupledealloc(PyTupleObject *op)
214215}
215216
216217static PyObject *
217- tuplerepr ( PyTupleObject * v )
218+ tuple_repr ( PyObject * self )
218219{
219- Py_ssize_t i , n ;
220- _PyUnicodeWriter writer ;
221-
222- n = Py_SIZE (v );
223- if (n == 0 )
220+ PyTupleObject * v = _PyTuple_CAST (self );
221+ Py_ssize_t n = PyTuple_GET_SIZE (v );
222+ if (n == 0 ) {
224223 return PyUnicode_FromString ("()" );
224+ }
225225
226226 /* While not mutable, it is still possible to end up with a cycle in a
227227 tuple through an object that stores itself within a tuple (and thus
228228 infinitely asks for the repr of itself). This should only be
229229 possible within a type. */
230- i = Py_ReprEnter ((PyObject * )v );
231- if (i != 0 ) {
232- return i > 0 ? PyUnicode_FromString ("(...)" ) : NULL ;
230+ int res = Py_ReprEnter ((PyObject * )v );
231+ if (res != 0 ) {
232+ return res > 0 ? PyUnicode_FromString ("(...)" ) : NULL ;
233233 }
234234
235+ _PyUnicodeWriter writer ;
235236 _PyUnicodeWriter_Init (& writer );
236237 writer .overallocate = 1 ;
237- if (Py_SIZE ( v ) > 1 ) {
238+ if (n > 1 ) {
238239 /* "(" + "1" + ", 2" * (len - 1) + ")" */
239- writer .min_length = 1 + 1 + (2 + 1 ) * (Py_SIZE ( v ) - 1 ) + 1 ;
240+ writer .min_length = 1 + 1 + (2 + 1 ) * (n - 1 ) + 1 ;
240241 }
241242 else {
242243 /* "(1,)" */
@@ -247,7 +248,7 @@ tuplerepr(PyTupleObject *v)
247248 goto error ;
248249
249250 /* Do repr() on each element. */
250- for (i = 0 ; i < n ; ++ i ) {
251+ for (Py_ssize_t i = 0 ; i < n ; ++ i ) {
251252 PyObject * s ;
252253
253254 if (i > 0 ) {
@@ -316,13 +317,14 @@ tuplerepr(PyTupleObject *v)
316317/* Tests have shown that it's not worth to cache the hash value, see
317318 https://bugs.python.org/issue9685 */
318319static Py_hash_t
319- tuplehash ( PyTupleObject * v )
320+ tuple_hash ( PyObject * op )
320321{
321- Py_ssize_t i , len = Py_SIZE (v );
322+ PyTupleObject * v = _PyTuple_CAST (op );
323+ Py_ssize_t len = Py_SIZE (v );
322324 PyObject * * item = v -> ob_item ;
323325
324326 Py_uhash_t acc = _PyHASH_XXPRIME_5 ;
325- for (i = 0 ; i < len ; i ++ ) {
327+ for (Py_ssize_t i = 0 ; i < len ; i ++ ) {
326328 Py_uhash_t lane = PyObject_Hash (item [i ]);
327329 if (lane == (Py_uhash_t )- 1 ) {
328330 return -1 ;
@@ -342,25 +344,27 @@ tuplehash(PyTupleObject *v)
342344}
343345
344346static Py_ssize_t
345- tuplelength ( PyTupleObject * a )
347+ tuple_length ( PyObject * self )
346348{
349+ PyTupleObject * a = _PyTuple_CAST (self );
347350 return Py_SIZE (a );
348351}
349352
350353static int
351- tuplecontains ( PyTupleObject * a , PyObject * el )
354+ tuple_contains ( PyObject * self , PyObject * el )
352355{
353- Py_ssize_t i ;
354- int cmp ;
355-
356- for (i = 0 , cmp = 0 ; cmp == 0 && i < Py_SIZE (a ); ++ i )
356+ PyTupleObject * a = _PyTuple_CAST (self );
357+ int cmp = 0 ;
358+ for (Py_ssize_t i = 0 ; cmp == 0 && i < Py_SIZE (a ); ++ i ) {
357359 cmp = PyObject_RichCompareBool (PyTuple_GET_ITEM (a , i ), el , Py_EQ );
360+ }
358361 return cmp ;
359362}
360363
361364static PyObject *
362- tupleitem ( PyTupleObject * a , Py_ssize_t i )
365+ tuple_item ( PyObject * op , Py_ssize_t i )
363366{
367+ PyTupleObject * a = _PyTuple_CAST (op );
364368 if (i < 0 || i >= Py_SIZE (a )) {
365369 PyErr_SetString (PyExc_IndexError , "tuple index out of range" );
366370 return NULL ;
@@ -432,7 +436,7 @@ _PyTuple_FromArraySteal(PyObject *const *src, Py_ssize_t n)
432436}
433437
434438static PyObject *
435- tupleslice (PyTupleObject * a , Py_ssize_t ilow ,
439+ tuple_slice (PyTupleObject * a , Py_ssize_t ilow ,
436440 Py_ssize_t ihigh )
437441{
438442 if (ilow < 0 )
@@ -454,16 +458,13 @@ PyTuple_GetSlice(PyObject *op, Py_ssize_t i, Py_ssize_t j)
454458 PyErr_BadInternalCall ();
455459 return NULL ;
456460 }
457- return tupleslice ((PyTupleObject * )op , i , j );
461+ return tuple_slice ((PyTupleObject * )op , i , j );
458462}
459463
460464static PyObject *
461- tupleconcat ( PyTupleObject * a , PyObject * bb )
465+ tuple_concat ( PyObject * aa , PyObject * bb )
462466{
463- Py_ssize_t size ;
464- Py_ssize_t i ;
465- PyObject * * src , * * dest ;
466- PyTupleObject * np ;
467+ PyTupleObject * a = _PyTuple_CAST (aa );
467468 if (Py_SIZE (a ) == 0 && PyTuple_CheckExact (bb )) {
468469 return Py_NewRef (bb );
469470 }
@@ -479,34 +480,38 @@ tupleconcat(PyTupleObject *a, PyObject *bb)
479480 return Py_NewRef (a );
480481 }
481482 assert ((size_t )Py_SIZE (a ) + (size_t )Py_SIZE (b ) < PY_SSIZE_T_MAX );
482- size = Py_SIZE (a ) + Py_SIZE (b );
483+ Py_ssize_t size = Py_SIZE (a ) + Py_SIZE (b );
483484 if (size == 0 ) {
484485 return tuple_get_empty ();
485486 }
486487
487- np = tuple_alloc (size );
488+ PyTupleObject * np = tuple_alloc (size );
488489 if (np == NULL ) {
489490 return NULL ;
490491 }
491- src = a -> ob_item ;
492- dest = np -> ob_item ;
493- for (i = 0 ; i < Py_SIZE (a ); i ++ ) {
492+
493+ PyObject * * src = a -> ob_item ;
494+ PyObject * * dest = np -> ob_item ;
495+ for (Py_ssize_t i = 0 ; i < Py_SIZE (a ); i ++ ) {
494496 PyObject * v = src [i ];
495497 dest [i ] = Py_NewRef (v );
496498 }
499+
497500 src = b -> ob_item ;
498501 dest = np -> ob_item + Py_SIZE (a );
499- for (i = 0 ; i < Py_SIZE (b ); i ++ ) {
502+ for (Py_ssize_t i = 0 ; i < Py_SIZE (b ); i ++ ) {
500503 PyObject * v = src [i ];
501504 dest [i ] = Py_NewRef (v );
502505 }
506+
503507 _PyObject_GC_TRACK (np );
504508 return (PyObject * )np ;
505509}
506510
507511static PyObject *
508- tuplerepeat ( PyTupleObject * a , Py_ssize_t n )
512+ tuple_repeat ( PyObject * self , Py_ssize_t n )
509513{
514+ PyTupleObject * a = _PyTuple_CAST (self );
510515 const Py_ssize_t input_size = Py_SIZE (a );
511516 if (input_size == 0 || n == 1 ) {
512517 if (PyTuple_CheckExact (a )) {
@@ -621,17 +626,17 @@ tuple_count(PyTupleObject *self, PyObject *value)
621626}
622627
623628static int
624- tupletraverse ( PyTupleObject * o , visitproc visit , void * arg )
629+ tuple_traverse ( PyObject * self , visitproc visit , void * arg )
625630{
626- Py_ssize_t i ;
627-
628- for (i = Py_SIZE (o ); -- i >= 0 ; )
631+ PyTupleObject * o = _PyTuple_CAST (self );
632+ for (Py_ssize_t i = Py_SIZE (o ); -- i >= 0 ; ) {
629633 Py_VISIT (o -> ob_item [i ]);
634+ }
630635 return 0 ;
631636}
632637
633638static PyObject *
634- tuplerichcompare (PyObject * v , PyObject * w , int op )
639+ tuple_richcompare (PyObject * v , PyObject * w , int op )
635640{
636641 PyTupleObject * vt , * wt ;
637642 Py_ssize_t i ;
@@ -770,26 +775,27 @@ tuple_subtype_new(PyTypeObject *type, PyObject *iterable)
770775}
771776
772777static PySequenceMethods tuple_as_sequence = {
773- ( lenfunc ) tuplelength , /* sq_length */
774- ( binaryfunc ) tupleconcat , /* sq_concat */
775- ( ssizeargfunc ) tuplerepeat , /* sq_repeat */
776- ( ssizeargfunc ) tupleitem , /* sq_item */
778+ tuple_length , /* sq_length */
779+ tuple_concat , /* sq_concat */
780+ tuple_repeat , /* sq_repeat */
781+ tuple_item , /* sq_item */
777782 0 , /* sq_slice */
778783 0 , /* sq_ass_item */
779784 0 , /* sq_ass_slice */
780- ( objobjproc ) tuplecontains , /* sq_contains */
785+ tuple_contains , /* sq_contains */
781786};
782787
783788static PyObject *
784- tuplesubscript ( PyTupleObject * self , PyObject * item )
789+ tuple_subscript ( PyObject * op , PyObject * item )
785790{
791+ PyTupleObject * self = _PyTuple_CAST (op );
786792 if (_PyIndex_Check (item )) {
787793 Py_ssize_t i = PyNumber_AsSsize_t (item , PyExc_IndexError );
788794 if (i == -1 && PyErr_Occurred ())
789795 return NULL ;
790796 if (i < 0 )
791797 i += PyTuple_GET_SIZE (self );
792- return tupleitem ( self , i );
798+ return tuple_item ( op , i );
793799 }
794800 else if (PySlice_Check (item )) {
795801 Py_ssize_t start , stop , step , slicelength , i ;
@@ -843,7 +849,7 @@ static PyObject *
843849tuple___getnewargs___impl (PyTupleObject * self )
844850/*[clinic end generated code: output=25e06e3ee56027e2 input=1aeb4b286a21639a]*/
845851{
846- return Py_BuildValue ("(N)" , tupleslice (self , 0 , Py_SIZE (self )));
852+ return Py_BuildValue ("(N)" , tuple_slice (self , 0 , Py_SIZE (self )));
847853}
848854
849855static PyMethodDef tuple_methods [] = {
@@ -855,8 +861,8 @@ static PyMethodDef tuple_methods[] = {
855861};
856862
857863static PyMappingMethods tuple_as_mapping = {
858- ( lenfunc ) tuplelength ,
859- ( binaryfunc ) tuplesubscript ,
864+ tuple_length ,
865+ tuple_subscript ,
860866 0
861867};
862868
@@ -867,16 +873,16 @@ PyTypeObject PyTuple_Type = {
867873 "tuple" ,
868874 sizeof (PyTupleObject ) - sizeof (PyObject * ),
869875 sizeof (PyObject * ),
870- ( destructor ) tupledealloc , /* tp_dealloc */
876+ tuple_dealloc , /* tp_dealloc */
871877 0 , /* tp_vectorcall_offset */
872878 0 , /* tp_getattr */
873879 0 , /* tp_setattr */
874880 0 , /* tp_as_async */
875- ( reprfunc ) tuplerepr , /* tp_repr */
881+ tuple_repr , /* tp_repr */
876882 0 , /* tp_as_number */
877883 & tuple_as_sequence , /* tp_as_sequence */
878884 & tuple_as_mapping , /* tp_as_mapping */
879- ( hashfunc ) tuplehash , /* tp_hash */
885+ tuple_hash , /* tp_hash */
880886 0 , /* tp_call */
881887 0 , /* tp_str */
882888 PyObject_GenericGetAttr , /* tp_getattro */
@@ -886,9 +892,9 @@ PyTypeObject PyTuple_Type = {
886892 Py_TPFLAGS_BASETYPE | Py_TPFLAGS_TUPLE_SUBCLASS |
887893 _Py_TPFLAGS_MATCH_SELF | Py_TPFLAGS_SEQUENCE , /* tp_flags */
888894 tuple_new__doc__ , /* tp_doc */
889- ( traverseproc ) tupletraverse , /* tp_traverse */
895+ tuple_traverse , /* tp_traverse */
890896 0 , /* tp_clear */
891- tuplerichcompare , /* tp_richcompare */
897+ tuple_richcompare , /* tp_richcompare */
892898 0 , /* tp_weaklistoffset */
893899 tuple_iter , /* tp_iter */
894900 0 , /* tp_iternext */
0 commit comments