@@ -181,8 +181,9 @@ PyTuple_Pack(Py_ssize_t n, ...)
181
181
/* Methods */
182
182
183
183
static void
184
- tupledealloc ( PyTupleObject * op )
184
+ tuple_dealloc ( PyObject * self )
185
185
{
186
+ PyTupleObject * op = _PyTuple_CAST (self );
186
187
if (Py_SIZE (op ) == 0 ) {
187
188
/* The empty tuple is statically allocated. */
188
189
if (op == & _Py_SINGLETON (tuple_empty )) {
@@ -199,7 +200,7 @@ tupledealloc(PyTupleObject *op)
199
200
}
200
201
201
202
PyObject_GC_UnTrack (op );
202
- Py_TRASHCAN_BEGIN (op , tupledealloc )
203
+ Py_TRASHCAN_BEGIN (op , tuple_dealloc )
203
204
204
205
Py_ssize_t i = Py_SIZE (op );
205
206
while (-- i >= 0 ) {
@@ -214,29 +215,29 @@ tupledealloc(PyTupleObject *op)
214
215
}
215
216
216
217
static PyObject *
217
- tuplerepr ( PyTupleObject * v )
218
+ tuple_repr ( PyObject * self )
218
219
{
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 ) {
224
223
return PyUnicode_FromString ("()" );
224
+ }
225
225
226
226
/* While not mutable, it is still possible to end up with a cycle in a
227
227
tuple through an object that stores itself within a tuple (and thus
228
228
infinitely asks for the repr of itself). This should only be
229
229
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 ;
233
233
}
234
234
235
+ _PyUnicodeWriter writer ;
235
236
_PyUnicodeWriter_Init (& writer );
236
237
writer .overallocate = 1 ;
237
- if (Py_SIZE ( v ) > 1 ) {
238
+ if (n > 1 ) {
238
239
/* "(" + "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 ;
240
241
}
241
242
else {
242
243
/* "(1,)" */
@@ -247,7 +248,7 @@ tuplerepr(PyTupleObject *v)
247
248
goto error ;
248
249
249
250
/* Do repr() on each element. */
250
- for (i = 0 ; i < n ; ++ i ) {
251
+ for (Py_ssize_t i = 0 ; i < n ; ++ i ) {
251
252
PyObject * s ;
252
253
253
254
if (i > 0 ) {
@@ -316,13 +317,14 @@ tuplerepr(PyTupleObject *v)
316
317
/* Tests have shown that it's not worth to cache the hash value, see
317
318
https://bugs.python.org/issue9685 */
318
319
static Py_hash_t
319
- tuplehash ( PyTupleObject * v )
320
+ tuple_hash ( PyObject * op )
320
321
{
321
- Py_ssize_t i , len = Py_SIZE (v );
322
+ PyTupleObject * v = _PyTuple_CAST (op );
323
+ Py_ssize_t len = Py_SIZE (v );
322
324
PyObject * * item = v -> ob_item ;
323
325
324
326
Py_uhash_t acc = _PyHASH_XXPRIME_5 ;
325
- for (i = 0 ; i < len ; i ++ ) {
327
+ for (Py_ssize_t i = 0 ; i < len ; i ++ ) {
326
328
Py_uhash_t lane = PyObject_Hash (item [i ]);
327
329
if (lane == (Py_uhash_t )- 1 ) {
328
330
return -1 ;
@@ -342,25 +344,27 @@ tuplehash(PyTupleObject *v)
342
344
}
343
345
344
346
static Py_ssize_t
345
- tuplelength ( PyTupleObject * a )
347
+ tuple_length ( PyObject * self )
346
348
{
349
+ PyTupleObject * a = _PyTuple_CAST (self );
347
350
return Py_SIZE (a );
348
351
}
349
352
350
353
static int
351
- tuplecontains ( PyTupleObject * a , PyObject * el )
354
+ tuple_contains ( PyObject * self , PyObject * el )
352
355
{
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 ) {
357
359
cmp = PyObject_RichCompareBool (PyTuple_GET_ITEM (a , i ), el , Py_EQ );
360
+ }
358
361
return cmp ;
359
362
}
360
363
361
364
static PyObject *
362
- tupleitem ( PyTupleObject * a , Py_ssize_t i )
365
+ tuple_item ( PyObject * op , Py_ssize_t i )
363
366
{
367
+ PyTupleObject * a = _PyTuple_CAST (op );
364
368
if (i < 0 || i >= Py_SIZE (a )) {
365
369
PyErr_SetString (PyExc_IndexError , "tuple index out of range" );
366
370
return NULL ;
@@ -432,7 +436,7 @@ _PyTuple_FromArraySteal(PyObject *const *src, Py_ssize_t n)
432
436
}
433
437
434
438
static PyObject *
435
- tupleslice (PyTupleObject * a , Py_ssize_t ilow ,
439
+ tuple_slice (PyTupleObject * a , Py_ssize_t ilow ,
436
440
Py_ssize_t ihigh )
437
441
{
438
442
if (ilow < 0 )
@@ -454,16 +458,13 @@ PyTuple_GetSlice(PyObject *op, Py_ssize_t i, Py_ssize_t j)
454
458
PyErr_BadInternalCall ();
455
459
return NULL ;
456
460
}
457
- return tupleslice ((PyTupleObject * )op , i , j );
461
+ return tuple_slice ((PyTupleObject * )op , i , j );
458
462
}
459
463
460
464
static PyObject *
461
- tupleconcat ( PyTupleObject * a , PyObject * bb )
465
+ tuple_concat ( PyObject * aa , PyObject * bb )
462
466
{
463
- Py_ssize_t size ;
464
- Py_ssize_t i ;
465
- PyObject * * src , * * dest ;
466
- PyTupleObject * np ;
467
+ PyTupleObject * a = _PyTuple_CAST (aa );
467
468
if (Py_SIZE (a ) == 0 && PyTuple_CheckExact (bb )) {
468
469
return Py_NewRef (bb );
469
470
}
@@ -479,34 +480,38 @@ tupleconcat(PyTupleObject *a, PyObject *bb)
479
480
return Py_NewRef (a );
480
481
}
481
482
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 );
483
484
if (size == 0 ) {
484
485
return tuple_get_empty ();
485
486
}
486
487
487
- np = tuple_alloc (size );
488
+ PyTupleObject * np = tuple_alloc (size );
488
489
if (np == NULL ) {
489
490
return NULL ;
490
491
}
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 ++ ) {
494
496
PyObject * v = src [i ];
495
497
dest [i ] = Py_NewRef (v );
496
498
}
499
+
497
500
src = b -> ob_item ;
498
501
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 ++ ) {
500
503
PyObject * v = src [i ];
501
504
dest [i ] = Py_NewRef (v );
502
505
}
506
+
503
507
_PyObject_GC_TRACK (np );
504
508
return (PyObject * )np ;
505
509
}
506
510
507
511
static PyObject *
508
- tuplerepeat ( PyTupleObject * a , Py_ssize_t n )
512
+ tuple_repeat ( PyObject * self , Py_ssize_t n )
509
513
{
514
+ PyTupleObject * a = _PyTuple_CAST (self );
510
515
const Py_ssize_t input_size = Py_SIZE (a );
511
516
if (input_size == 0 || n == 1 ) {
512
517
if (PyTuple_CheckExact (a )) {
@@ -621,17 +626,17 @@ tuple_count(PyTupleObject *self, PyObject *value)
621
626
}
622
627
623
628
static int
624
- tupletraverse ( PyTupleObject * o , visitproc visit , void * arg )
629
+ tuple_traverse ( PyObject * self , visitproc visit , void * arg )
625
630
{
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 ; ) {
629
633
Py_VISIT (o -> ob_item [i ]);
634
+ }
630
635
return 0 ;
631
636
}
632
637
633
638
static PyObject *
634
- tuplerichcompare (PyObject * v , PyObject * w , int op )
639
+ tuple_richcompare (PyObject * v , PyObject * w , int op )
635
640
{
636
641
PyTupleObject * vt , * wt ;
637
642
Py_ssize_t i ;
@@ -770,26 +775,27 @@ tuple_subtype_new(PyTypeObject *type, PyObject *iterable)
770
775
}
771
776
772
777
static 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 */
777
782
0 , /* sq_slice */
778
783
0 , /* sq_ass_item */
779
784
0 , /* sq_ass_slice */
780
- ( objobjproc ) tuplecontains , /* sq_contains */
785
+ tuple_contains , /* sq_contains */
781
786
};
782
787
783
788
static PyObject *
784
- tuplesubscript ( PyTupleObject * self , PyObject * item )
789
+ tuple_subscript ( PyObject * op , PyObject * item )
785
790
{
791
+ PyTupleObject * self = _PyTuple_CAST (op );
786
792
if (_PyIndex_Check (item )) {
787
793
Py_ssize_t i = PyNumber_AsSsize_t (item , PyExc_IndexError );
788
794
if (i == -1 && PyErr_Occurred ())
789
795
return NULL ;
790
796
if (i < 0 )
791
797
i += PyTuple_GET_SIZE (self );
792
- return tupleitem ( self , i );
798
+ return tuple_item ( op , i );
793
799
}
794
800
else if (PySlice_Check (item )) {
795
801
Py_ssize_t start , stop , step , slicelength , i ;
@@ -843,7 +849,7 @@ static PyObject *
843
849
tuple___getnewargs___impl (PyTupleObject * self )
844
850
/*[clinic end generated code: output=25e06e3ee56027e2 input=1aeb4b286a21639a]*/
845
851
{
846
- return Py_BuildValue ("(N)" , tupleslice (self , 0 , Py_SIZE (self )));
852
+ return Py_BuildValue ("(N)" , tuple_slice (self , 0 , Py_SIZE (self )));
847
853
}
848
854
849
855
static PyMethodDef tuple_methods [] = {
@@ -855,8 +861,8 @@ static PyMethodDef tuple_methods[] = {
855
861
};
856
862
857
863
static PyMappingMethods tuple_as_mapping = {
858
- ( lenfunc ) tuplelength ,
859
- ( binaryfunc ) tuplesubscript ,
864
+ tuple_length ,
865
+ tuple_subscript ,
860
866
0
861
867
};
862
868
@@ -867,16 +873,16 @@ PyTypeObject PyTuple_Type = {
867
873
"tuple" ,
868
874
sizeof (PyTupleObject ) - sizeof (PyObject * ),
869
875
sizeof (PyObject * ),
870
- ( destructor ) tupledealloc , /* tp_dealloc */
876
+ tuple_dealloc , /* tp_dealloc */
871
877
0 , /* tp_vectorcall_offset */
872
878
0 , /* tp_getattr */
873
879
0 , /* tp_setattr */
874
880
0 , /* tp_as_async */
875
- ( reprfunc ) tuplerepr , /* tp_repr */
881
+ tuple_repr , /* tp_repr */
876
882
0 , /* tp_as_number */
877
883
& tuple_as_sequence , /* tp_as_sequence */
878
884
& tuple_as_mapping , /* tp_as_mapping */
879
- ( hashfunc ) tuplehash , /* tp_hash */
885
+ tuple_hash , /* tp_hash */
880
886
0 , /* tp_call */
881
887
0 , /* tp_str */
882
888
PyObject_GenericGetAttr , /* tp_getattro */
@@ -886,9 +892,9 @@ PyTypeObject PyTuple_Type = {
886
892
Py_TPFLAGS_BASETYPE | Py_TPFLAGS_TUPLE_SUBCLASS |
887
893
_Py_TPFLAGS_MATCH_SELF | Py_TPFLAGS_SEQUENCE , /* tp_flags */
888
894
tuple_new__doc__ , /* tp_doc */
889
- ( traverseproc ) tupletraverse , /* tp_traverse */
895
+ tuple_traverse , /* tp_traverse */
890
896
0 , /* tp_clear */
891
- tuplerichcompare , /* tp_richcompare */
897
+ tuple_richcompare , /* tp_richcompare */
892
898
0 , /* tp_weaklistoffset */
893
899
tuple_iter , /* tp_iter */
894
900
0 , /* tp_iternext */
0 commit comments