@@ -2113,8 +2113,9 @@ PyDoc_STRVAR(alloc_doc,
2113
2113
Return the number of bytes actually allocated." );
2114
2114
2115
2115
static PyObject *
2116
- bytearray_alloc (PyByteArrayObject * self , PyObject * Py_UNUSED (ignored ))
2116
+ bytearray_alloc (PyObject * op , PyObject * Py_UNUSED (ignored ))
2117
2117
{
2118
+ PyByteArrayObject * self = _PyByteArray_CAST (op );
2118
2119
return PyLong_FromSsize_t (self -> ob_alloc );
2119
2120
}
2120
2121
@@ -2313,7 +2314,7 @@ static PyBufferProcs bytearray_as_buffer = {
2313
2314
};
2314
2315
2315
2316
static PyMethodDef bytearray_methods [] = {
2316
- {"__alloc__" , ( PyCFunction ) bytearray_alloc , METH_NOARGS , alloc_doc },
2317
+ {"__alloc__" , bytearray_alloc , METH_NOARGS , alloc_doc },
2317
2318
BYTEARRAY_REDUCE_METHODDEF
2318
2319
BYTEARRAY_REDUCE_EX_METHODDEF
2319
2320
BYTEARRAY_SIZEOF_METHODDEF
@@ -2464,24 +2465,29 @@ typedef struct {
2464
2465
PyByteArrayObject * it_seq ; /* Set to NULL when iterator is exhausted */
2465
2466
} bytesiterobject ;
2466
2467
2468
+ #define _bytesiterobject_CAST (op ) ((bytesiterobject *)(op))
2469
+
2467
2470
static void
2468
- bytearrayiter_dealloc (bytesiterobject * it )
2471
+ bytearrayiter_dealloc (PyObject * self )
2469
2472
{
2473
+ bytesiterobject * it = _bytesiterobject_CAST (self );
2470
2474
_PyObject_GC_UNTRACK (it );
2471
2475
Py_XDECREF (it -> it_seq );
2472
2476
PyObject_GC_Del (it );
2473
2477
}
2474
2478
2475
2479
static int
2476
- bytearrayiter_traverse (bytesiterobject * it , visitproc visit , void * arg )
2480
+ bytearrayiter_traverse (PyObject * self , visitproc visit , void * arg )
2477
2481
{
2482
+ bytesiterobject * it = _bytesiterobject_CAST (self );
2478
2483
Py_VISIT (it -> it_seq );
2479
2484
return 0 ;
2480
2485
}
2481
2486
2482
2487
static PyObject *
2483
- bytearrayiter_next (bytesiterobject * it )
2488
+ bytearrayiter_next (PyObject * self )
2484
2489
{
2490
+ bytesiterobject * it = _bytesiterobject_CAST (self );
2485
2491
PyByteArrayObject * seq ;
2486
2492
2487
2493
assert (it != NULL );
@@ -2501,8 +2507,9 @@ bytearrayiter_next(bytesiterobject *it)
2501
2507
}
2502
2508
2503
2509
static PyObject *
2504
- bytearrayiter_length_hint (bytesiterobject * it , PyObject * Py_UNUSED (ignored ))
2510
+ bytearrayiter_length_hint (PyObject * self , PyObject * Py_UNUSED (ignored ))
2505
2511
{
2512
+ bytesiterobject * it = _bytesiterobject_CAST (self );
2506
2513
Py_ssize_t len = 0 ;
2507
2514
if (it -> it_seq ) {
2508
2515
len = PyByteArray_GET_SIZE (it -> it_seq ) - it -> it_index ;
@@ -2517,14 +2524,14 @@ PyDoc_STRVAR(length_hint_doc,
2517
2524
"Private method returning an estimate of len(list(it))." );
2518
2525
2519
2526
static PyObject *
2520
- bytearrayiter_reduce (bytesiterobject * it , PyObject * Py_UNUSED (ignored ))
2527
+ bytearrayiter_reduce (PyObject * self , PyObject * Py_UNUSED (ignored ))
2521
2528
{
2522
2529
PyObject * iter = _PyEval_GetBuiltin (& _Py_ID (iter ));
2523
2530
2524
2531
/* _PyEval_GetBuiltin can invoke arbitrary code,
2525
2532
* call must be before access of iterator pointers.
2526
2533
* see issue #101765 */
2527
-
2534
+ bytesiterobject * it = _bytesiterobject_CAST ( self );
2528
2535
if (it -> it_seq != NULL ) {
2529
2536
return Py_BuildValue ("N(O)n" , iter , it -> it_seq , it -> it_index );
2530
2537
} else {
@@ -2533,11 +2540,13 @@ bytearrayiter_reduce(bytesiterobject *it, PyObject *Py_UNUSED(ignored))
2533
2540
}
2534
2541
2535
2542
static PyObject *
2536
- bytearrayiter_setstate (bytesiterobject * it , PyObject * state )
2543
+ bytearrayiter_setstate (PyObject * self , PyObject * state )
2537
2544
{
2538
2545
Py_ssize_t index = PyLong_AsSsize_t (state );
2539
2546
if (index == -1 && PyErr_Occurred ())
2540
2547
return NULL ;
2548
+
2549
+ bytesiterobject * it = _bytesiterobject_CAST (self );
2541
2550
if (it -> it_seq != NULL ) {
2542
2551
if (index < 0 )
2543
2552
index = 0 ;
@@ -2551,11 +2560,11 @@ bytearrayiter_setstate(bytesiterobject *it, PyObject *state)
2551
2560
PyDoc_STRVAR (setstate_doc , "Set state information for unpickling." );
2552
2561
2553
2562
static PyMethodDef bytearrayiter_methods [] = {
2554
- {"__length_hint__" , ( PyCFunction ) bytearrayiter_length_hint , METH_NOARGS ,
2563
+ {"__length_hint__" , bytearrayiter_length_hint , METH_NOARGS ,
2555
2564
length_hint_doc },
2556
- {"__reduce__" , ( PyCFunction ) bytearrayiter_reduce , METH_NOARGS ,
2565
+ {"__reduce__" , bytearrayiter_reduce , METH_NOARGS ,
2557
2566
bytearray_reduce__doc__ },
2558
- {"__setstate__" , ( PyCFunction ) bytearrayiter_setstate , METH_O ,
2567
+ {"__setstate__" , bytearrayiter_setstate , METH_O ,
2559
2568
setstate_doc },
2560
2569
{NULL , NULL } /* sentinel */
2561
2570
};
@@ -2566,7 +2575,7 @@ PyTypeObject PyByteArrayIter_Type = {
2566
2575
sizeof (bytesiterobject ), /* tp_basicsize */
2567
2576
0 , /* tp_itemsize */
2568
2577
/* methods */
2569
- ( destructor ) bytearrayiter_dealloc , /* tp_dealloc */
2578
+ bytearrayiter_dealloc , /* tp_dealloc */
2570
2579
0 , /* tp_vectorcall_offset */
2571
2580
0 , /* tp_getattr */
2572
2581
0 , /* tp_setattr */
@@ -2583,12 +2592,12 @@ PyTypeObject PyByteArrayIter_Type = {
2583
2592
0 , /* tp_as_buffer */
2584
2593
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC , /* tp_flags */
2585
2594
0 , /* tp_doc */
2586
- ( traverseproc ) bytearrayiter_traverse , /* tp_traverse */
2595
+ bytearrayiter_traverse , /* tp_traverse */
2587
2596
0 , /* tp_clear */
2588
2597
0 , /* tp_richcompare */
2589
2598
0 , /* tp_weaklistoffset */
2590
2599
PyObject_SelfIter , /* tp_iter */
2591
- ( iternextfunc ) bytearrayiter_next , /* tp_iternext */
2600
+ bytearrayiter_next , /* tp_iternext */
2592
2601
bytearrayiter_methods , /* tp_methods */
2593
2602
0 ,
2594
2603
};
0 commit comments