@@ -2268,6 +2268,8 @@ typedef struct channelid {
2268
2268
_channels * channels ;
2269
2269
} channelid ;
2270
2270
2271
+ #define channelid_CAST (op ) ((channelid *)(op))
2272
+
2271
2273
struct channel_id_converter_data {
2272
2274
PyObject * module ;
2273
2275
int64_t cid ;
@@ -2396,10 +2398,11 @@ _channelid_new(PyObject *mod, PyTypeObject *cls,
2396
2398
}
2397
2399
2398
2400
static void
2399
- channelid_dealloc (PyObject * self )
2401
+ channelid_dealloc (PyObject * op )
2400
2402
{
2401
- int64_t cid = ((channelid * )self )-> cid ;
2402
- _channels * channels = ((channelid * )self )-> channels ;
2403
+ channelid * self = channelid_CAST (op );
2404
+ int64_t cid = self -> cid ;
2405
+ _channels * channels = self -> channels ;
2403
2406
2404
2407
PyTypeObject * tp = Py_TYPE (self );
2405
2408
tp -> tp_free (self );
@@ -2420,7 +2423,7 @@ channelid_repr(PyObject *self)
2420
2423
PyTypeObject * type = Py_TYPE (self );
2421
2424
const char * name = _PyType_Name (type );
2422
2425
2423
- channelid * cidobj = ( channelid * ) self ;
2426
+ channelid * cidobj = channelid_CAST ( self ) ;
2424
2427
const char * fmt ;
2425
2428
if (cidobj -> end == CHANNEL_SEND ) {
2426
2429
fmt = "%s(%" PRId64 ", send=True)" ;
@@ -2437,21 +2440,21 @@ channelid_repr(PyObject *self)
2437
2440
static PyObject *
2438
2441
channelid_str (PyObject * self )
2439
2442
{
2440
- channelid * cidobj = ( channelid * ) self ;
2443
+ channelid * cidobj = channelid_CAST ( self ) ;
2441
2444
return PyUnicode_FromFormat ("%" PRId64 "" , cidobj -> cid );
2442
2445
}
2443
2446
2444
2447
static PyObject *
2445
2448
channelid_int (PyObject * self )
2446
2449
{
2447
- channelid * cidobj = ( channelid * ) self ;
2450
+ channelid * cidobj = channelid_CAST ( self ) ;
2448
2451
return PyLong_FromLongLong (cidobj -> cid );
2449
2452
}
2450
2453
2451
2454
static Py_hash_t
2452
2455
channelid_hash (PyObject * self )
2453
2456
{
2454
- channelid * cidobj = ( channelid * ) self ;
2457
+ channelid * cidobj = channelid_CAST ( self ) ;
2455
2458
PyObject * pyid = PyLong_FromLongLong (cidobj -> cid );
2456
2459
if (pyid == NULL ) {
2457
2460
return -1 ;
@@ -2483,10 +2486,10 @@ channelid_richcompare(PyObject *self, PyObject *other, int op)
2483
2486
goto done ;
2484
2487
}
2485
2488
2486
- channelid * cidobj = ( channelid * ) self ;
2489
+ channelid * cidobj = channelid_CAST ( self ) ;
2487
2490
int equal ;
2488
2491
if (PyObject_TypeCheck (other , state -> ChannelIDType )) {
2489
- channelid * othercidobj = (channelid * )other ;
2492
+ channelid * othercidobj = (channelid * )other ; // fast safe cast
2490
2493
equal = (cidobj -> end == othercidobj -> end ) && (cidobj -> cid == othercidobj -> cid );
2491
2494
}
2492
2495
else if (PyLong_Check (other )) {
@@ -2606,17 +2609,18 @@ _channelid_shared(PyThreadState *tstate, PyObject *obj, _PyXIData_t *data)
2606
2609
return -1 ;
2607
2610
}
2608
2611
struct _channelid_xid * xid = (struct _channelid_xid * )_PyXIData_DATA (data );
2609
- xid -> cid = ((channelid * )obj )-> cid ;
2610
- xid -> end = ((channelid * )obj )-> end ;
2611
- xid -> resolve = ((channelid * )obj )-> resolve ;
2612
+ channelid * cidobj = channelid_CAST (obj );
2613
+ xid -> cid = cidobj -> cid ;
2614
+ xid -> end = cidobj -> end ;
2615
+ xid -> resolve = cidobj -> resolve ;
2612
2616
return 0 ;
2613
2617
}
2614
2618
2615
2619
static PyObject *
2616
2620
channelid_end (PyObject * self , void * end )
2617
2621
{
2618
2622
int force = 1 ;
2619
- channelid * cidobj = ( channelid * ) self ;
2623
+ channelid * cidobj = channelid_CAST ( self ) ;
2620
2624
if (end != NULL ) {
2621
2625
PyObject * obj = NULL ;
2622
2626
int err = newchannelid (Py_TYPE (self ), cidobj -> cid , * (int * )end ,
@@ -2649,11 +2653,11 @@ static int _channelid_end_send = CHANNEL_SEND;
2649
2653
static int _channelid_end_recv = CHANNEL_RECV ;
2650
2654
2651
2655
static PyGetSetDef channelid_getsets [] = {
2652
- {"end" , ( getter ) channelid_end , NULL ,
2656
+ {"end" , channelid_end , NULL ,
2653
2657
PyDoc_STR ("'send', 'recv', or 'both'" )},
2654
- {"send" , ( getter ) channelid_end , NULL ,
2658
+ {"send" , channelid_end , NULL ,
2655
2659
PyDoc_STR ("the 'send' end of the channel" ), & _channelid_end_send },
2656
- {"recv" , ( getter ) channelid_end , NULL ,
2660
+ {"recv" , channelid_end , NULL ,
2657
2661
PyDoc_STR ("the 'recv' end of the channel" ), & _channelid_end_recv },
2658
2662
{NULL }
2659
2663
};
@@ -2662,16 +2666,16 @@ PyDoc_STRVAR(channelid_doc,
2662
2666
"A channel ID identifies a channel and may be used as an int." );
2663
2667
2664
2668
static PyType_Slot channelid_typeslots [] = {
2665
- {Py_tp_dealloc , ( destructor ) channelid_dealloc },
2669
+ {Py_tp_dealloc , channelid_dealloc },
2666
2670
{Py_tp_doc , (void * )channelid_doc },
2667
- {Py_tp_repr , ( reprfunc ) channelid_repr },
2668
- {Py_tp_str , ( reprfunc ) channelid_str },
2671
+ {Py_tp_repr , channelid_repr },
2672
+ {Py_tp_str , channelid_str },
2669
2673
{Py_tp_hash , channelid_hash },
2670
2674
{Py_tp_richcompare , channelid_richcompare },
2671
2675
{Py_tp_getset , channelid_getsets },
2672
2676
// number slots
2673
- {Py_nb_int , ( unaryfunc ) channelid_int },
2674
- {Py_nb_index , ( unaryfunc ) channelid_int },
2677
+ {Py_nb_int , channelid_int },
2678
+ {Py_nb_index , channelid_int },
2675
2679
{0 , NULL },
2676
2680
};
2677
2681
@@ -2904,10 +2908,10 @@ channelsmod_create(PyObject *self, PyObject *args, PyObject *kwds)
2904
2908
if (state == NULL ) {
2905
2909
return NULL ;
2906
2910
}
2907
- PyObject * cidobj = NULL ;
2911
+ channelid * cidobj = NULL ;
2908
2912
int err = newchannelid (state -> ChannelIDType , cid , 0 ,
2909
2913
& _globals .channels , 0 , 0 ,
2910
- ( channelid * * ) & cidobj );
2914
+ & cidobj );
2911
2915
if (handle_channel_error (err , self , cid )) {
2912
2916
assert (cidobj == NULL );
2913
2917
err = channel_destroy (& _globals .channels , cid );
@@ -2917,8 +2921,8 @@ channelsmod_create(PyObject *self, PyObject *args, PyObject *kwds)
2917
2921
return NULL ;
2918
2922
}
2919
2923
assert (cidobj != NULL );
2920
- assert ((( channelid * ) cidobj ) -> channels != NULL );
2921
- return cidobj ;
2924
+ assert (cidobj -> channels != NULL );
2925
+ return ( PyObject * ) cidobj ;
2922
2926
}
2923
2927
2924
2928
PyDoc_STRVAR (channelsmod_create_doc ,
@@ -3553,7 +3557,7 @@ module_traverse(PyObject *mod, visitproc visit, void *arg)
3553
3557
{
3554
3558
module_state * state = get_module_state (mod );
3555
3559
assert (state != NULL );
3556
- traverse_module_state (state , visit , arg );
3560
+ ( void ) traverse_module_state (state , visit , arg );
3557
3561
return 0 ;
3558
3562
}
3559
3563
@@ -3564,18 +3568,18 @@ module_clear(PyObject *mod)
3564
3568
assert (state != NULL );
3565
3569
3566
3570
// Now we clear the module state.
3567
- clear_module_state (state );
3571
+ ( void ) clear_module_state (state );
3568
3572
return 0 ;
3569
3573
}
3570
3574
3571
3575
static void
3572
3576
module_free (void * mod )
3573
3577
{
3574
- module_state * state = get_module_state (mod );
3578
+ module_state * state = get_module_state (( PyObject * ) mod );
3575
3579
assert (state != NULL );
3576
3580
3577
3581
// Now we clear the module state.
3578
- clear_module_state (state );
3582
+ ( void ) clear_module_state (state );
3579
3583
3580
3584
_globals_fini ();
3581
3585
}
0 commit comments