@@ -2268,6 +2268,8 @@ typedef struct channelid {
22682268 _channels * channels ;
22692269} channelid ;
22702270
2271+ #define channelid_CAST (op ) ((channelid *)(op))
2272+
22712273struct channel_id_converter_data {
22722274 PyObject * module ;
22732275 int64_t cid ;
@@ -2396,10 +2398,11 @@ _channelid_new(PyObject *mod, PyTypeObject *cls,
23962398}
23972399
23982400static void
2399- channelid_dealloc (PyObject * self )
2401+ channelid_dealloc (PyObject * op )
24002402{
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 ;
24032406
24042407 PyTypeObject * tp = Py_TYPE (self );
24052408 tp -> tp_free (self );
@@ -2420,7 +2423,7 @@ channelid_repr(PyObject *self)
24202423 PyTypeObject * type = Py_TYPE (self );
24212424 const char * name = _PyType_Name (type );
24222425
2423- channelid * cidobj = ( channelid * ) self ;
2426+ channelid * cidobj = channelid_CAST ( self ) ;
24242427 const char * fmt ;
24252428 if (cidobj -> end == CHANNEL_SEND ) {
24262429 fmt = "%s(%" PRId64 ", send=True)" ;
@@ -2437,21 +2440,21 @@ channelid_repr(PyObject *self)
24372440static PyObject *
24382441channelid_str (PyObject * self )
24392442{
2440- channelid * cidobj = ( channelid * ) self ;
2443+ channelid * cidobj = channelid_CAST ( self ) ;
24412444 return PyUnicode_FromFormat ("%" PRId64 "" , cidobj -> cid );
24422445}
24432446
24442447static PyObject *
24452448channelid_int (PyObject * self )
24462449{
2447- channelid * cidobj = ( channelid * ) self ;
2450+ channelid * cidobj = channelid_CAST ( self ) ;
24482451 return PyLong_FromLongLong (cidobj -> cid );
24492452}
24502453
24512454static Py_hash_t
24522455channelid_hash (PyObject * self )
24532456{
2454- channelid * cidobj = ( channelid * ) self ;
2457+ channelid * cidobj = channelid_CAST ( self ) ;
24552458 PyObject * pyid = PyLong_FromLongLong (cidobj -> cid );
24562459 if (pyid == NULL ) {
24572460 return -1 ;
@@ -2483,10 +2486,10 @@ channelid_richcompare(PyObject *self, PyObject *other, int op)
24832486 goto done ;
24842487 }
24852488
2486- channelid * cidobj = ( channelid * ) self ;
2489+ channelid * cidobj = channelid_CAST ( self ) ;
24872490 int equal ;
24882491 if (PyObject_TypeCheck (other , state -> ChannelIDType )) {
2489- channelid * othercidobj = (channelid * )other ;
2492+ channelid * othercidobj = (channelid * )other ; // fast safe cast
24902493 equal = (cidobj -> end == othercidobj -> end ) && (cidobj -> cid == othercidobj -> cid );
24912494 }
24922495 else if (PyLong_Check (other )) {
@@ -2606,17 +2609,18 @@ _channelid_shared(PyThreadState *tstate, PyObject *obj, _PyXIData_t *data)
26062609 return -1 ;
26072610 }
26082611 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 ;
26122616 return 0 ;
26132617}
26142618
26152619static PyObject *
26162620channelid_end (PyObject * self , void * end )
26172621{
26182622 int force = 1 ;
2619- channelid * cidobj = ( channelid * ) self ;
2623+ channelid * cidobj = channelid_CAST ( self ) ;
26202624 if (end != NULL ) {
26212625 PyObject * obj = NULL ;
26222626 int err = newchannelid (Py_TYPE (self ), cidobj -> cid , * (int * )end ,
@@ -2649,11 +2653,11 @@ static int _channelid_end_send = CHANNEL_SEND;
26492653static int _channelid_end_recv = CHANNEL_RECV ;
26502654
26512655static PyGetSetDef channelid_getsets [] = {
2652- {"end" , ( getter ) channelid_end , NULL ,
2656+ {"end" , channelid_end , NULL ,
26532657 PyDoc_STR ("'send', 'recv', or 'both'" )},
2654- {"send" , ( getter ) channelid_end , NULL ,
2658+ {"send" , channelid_end , NULL ,
26552659 PyDoc_STR ("the 'send' end of the channel" ), & _channelid_end_send },
2656- {"recv" , ( getter ) channelid_end , NULL ,
2660+ {"recv" , channelid_end , NULL ,
26572661 PyDoc_STR ("the 'recv' end of the channel" ), & _channelid_end_recv },
26582662 {NULL }
26592663};
@@ -2662,16 +2666,16 @@ PyDoc_STRVAR(channelid_doc,
26622666"A channel ID identifies a channel and may be used as an int." );
26632667
26642668static PyType_Slot channelid_typeslots [] = {
2665- {Py_tp_dealloc , ( destructor ) channelid_dealloc },
2669+ {Py_tp_dealloc , channelid_dealloc },
26662670 {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 },
26692673 {Py_tp_hash , channelid_hash },
26702674 {Py_tp_richcompare , channelid_richcompare },
26712675 {Py_tp_getset , channelid_getsets },
26722676 // 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 },
26752679 {0 , NULL },
26762680};
26772681
@@ -2904,10 +2908,10 @@ channelsmod_create(PyObject *self, PyObject *args, PyObject *kwds)
29042908 if (state == NULL ) {
29052909 return NULL ;
29062910 }
2907- PyObject * cidobj = NULL ;
2911+ channelid * cidobj = NULL ;
29082912 int err = newchannelid (state -> ChannelIDType , cid , 0 ,
29092913 & _globals .channels , 0 , 0 ,
2910- ( channelid * * ) & cidobj );
2914+ & cidobj );
29112915 if (handle_channel_error (err , self , cid )) {
29122916 assert (cidobj == NULL );
29132917 err = channel_destroy (& _globals .channels , cid );
@@ -2917,8 +2921,8 @@ channelsmod_create(PyObject *self, PyObject *args, PyObject *kwds)
29172921 return NULL ;
29182922 }
29192923 assert (cidobj != NULL );
2920- assert ((( channelid * ) cidobj ) -> channels != NULL );
2921- return cidobj ;
2924+ assert (cidobj -> channels != NULL );
2925+ return ( PyObject * ) cidobj ;
29222926}
29232927
29242928PyDoc_STRVAR (channelsmod_create_doc ,
@@ -3553,7 +3557,7 @@ module_traverse(PyObject *mod, visitproc visit, void *arg)
35533557{
35543558 module_state * state = get_module_state (mod );
35553559 assert (state != NULL );
3556- traverse_module_state (state , visit , arg );
3560+ ( void ) traverse_module_state (state , visit , arg );
35573561 return 0 ;
35583562}
35593563
@@ -3564,18 +3568,18 @@ module_clear(PyObject *mod)
35643568 assert (state != NULL );
35653569
35663570 // Now we clear the module state.
3567- clear_module_state (state );
3571+ ( void ) clear_module_state (state );
35683572 return 0 ;
35693573}
35703574
35713575static void
35723576module_free (void * mod )
35733577{
3574- module_state * state = get_module_state (mod );
3578+ module_state * state = get_module_state (( PyObject * ) mod );
35753579 assert (state != NULL );
35763580
35773581 // Now we clear the module state.
3578- clear_module_state (state );
3582+ ( void ) clear_module_state (state );
35793583
35803584 _globals_fini ();
35813585}
0 commit comments