@@ -22,24 +22,29 @@ _coerce_id(PyObject *id)
22
22
id = PyNumber_Long (id );
23
23
if (id == NULL ) {
24
24
if (PyErr_ExceptionMatches (PyExc_TypeError )) {
25
- PyErr_SetString (PyExc_TypeError , "'id' must be a non-negative int" );
25
+ PyErr_SetString (PyExc_TypeError ,
26
+ "'id' must be a non-negative int" );
26
27
}
27
28
else {
28
- PyErr_SetString (PyExc_ValueError , "'id' must be a non-negative int" );
29
+ PyErr_SetString (PyExc_ValueError ,
30
+ "'id' must be a non-negative int" );
29
31
}
30
32
return -1 ;
31
33
}
32
34
long long cid = PyLong_AsLongLong (id );
33
35
if (cid == -1 && PyErr_Occurred () != NULL ) {
34
- PyErr_SetString (PyExc_ValueError , "'id' must be a non-negative int" );
36
+ PyErr_SetString (PyExc_ValueError ,
37
+ "'id' must be a non-negative int" );
35
38
return -1 ;
36
39
}
37
40
if (cid < 0 ) {
38
- PyErr_SetString (PyExc_ValueError , "'id' must be a non-negative int" );
41
+ PyErr_SetString (PyExc_ValueError ,
42
+ "'id' must be a non-negative int" );
39
43
return -1 ;
40
44
}
41
45
if (cid > INT64_MAX ) {
42
- PyErr_SetString (PyExc_ValueError , "'id' too large (must be 64-bit int)" );
46
+ PyErr_SetString (PyExc_ValueError ,
47
+ "'id' too large (must be 64-bit int)" );
43
48
return -1 ;
44
49
}
45
50
return cid ;
@@ -212,8 +217,8 @@ channel_exceptions_init(PyObject *ns)
212
217
}
213
218
214
219
// An operation tried to use a channel that doesn't exist.
215
- ChannelNotFoundError = PyErr_NewException ("_xxsubinterpreters.ChannelNotFoundError" ,
216
- ChannelError , NULL );
220
+ ChannelNotFoundError = PyErr_NewException (
221
+ "_xxsubinterpreters.ChannelNotFoundError" , ChannelError , NULL );
217
222
if (ChannelNotFoundError == NULL ) {
218
223
return -1 ;
219
224
}
@@ -222,8 +227,8 @@ channel_exceptions_init(PyObject *ns)
222
227
}
223
228
224
229
// An operation tried to use a closed channel.
225
- ChannelClosedError = PyErr_NewException ("_xxsubinterpreters.ChannelClosedError" ,
226
- ChannelError , NULL );
230
+ ChannelClosedError = PyErr_NewException (
231
+ "_xxsubinterpreters.ChannelClosedError" , ChannelError , NULL );
227
232
if (ChannelClosedError == NULL ) {
228
233
return -1 ;
229
234
}
@@ -232,8 +237,8 @@ channel_exceptions_init(PyObject *ns)
232
237
}
233
238
234
239
// An operation tried to pop from an empty channel.
235
- ChannelEmptyError = PyErr_NewException ("_xxsubinterpreters.ChannelEmptyError" ,
236
- ChannelError , NULL );
240
+ ChannelEmptyError = PyErr_NewException (
241
+ "_xxsubinterpreters.ChannelEmptyError" , ChannelError , NULL );
237
242
if (ChannelEmptyError == NULL ) {
238
243
return -1 ;
239
244
}
@@ -333,7 +338,8 @@ _channel_new(void)
333
338
chan -> mutex = PyThread_allocate_lock ();
334
339
if (chan -> mutex == NULL ) {
335
340
PyMem_Free (chan );
336
- PyErr_SetString (ChannelError , "can't initialize mutex for new channel" );
341
+ PyErr_SetString (ChannelError ,
342
+ "can't initialize mutex for new channel" );
337
343
return NULL ;
338
344
}
339
345
@@ -352,7 +358,8 @@ _channel_new(void)
352
358
}
353
359
354
360
static _channelend *
355
- _channel_add_end (_PyChannelState * chan , _channelend * prev , int64_t interp , int send )
361
+ _channel_add_end (_PyChannelState * chan , _channelend * prev , int64_t interp ,
362
+ int send )
356
363
{
357
364
_channelend * end = _channelend_new (interp );
358
365
if (end == NULL ) {
@@ -388,7 +395,8 @@ _channel_associate_end(_PyChannelState *chan, int64_t interp, int send)
388
395
}
389
396
390
397
_channelend * prev ;
391
- _channelend * end = _channelend_find (send ? chan -> send : chan -> recv , interp , & prev );
398
+ _channelend * end = _channelend_find (send ? chan -> send : chan -> recv ,
399
+ interp , & prev );
392
400
if (end != NULL ) {
393
401
if (!end -> open ) {
394
402
PyErr_SetString (ChannelClosedError , "channel already closed" );
@@ -494,7 +502,8 @@ _channel_close_all(_PyChannelState *chan)
494
502
}
495
503
496
504
static int
497
- _channel_add (_PyChannelState * chan , int64_t interp , _PyCrossInterpreterData * data )
505
+ _channel_add (_PyChannelState * chan , int64_t interp ,
506
+ _PyCrossInterpreterData * data )
498
507
{
499
508
int res = -1 ;
500
509
@@ -632,7 +641,8 @@ _channels_init(_channels *channels)
632
641
channels -> mutex = PyThread_allocate_lock ();
633
642
if (channels -> mutex == NULL ) {
634
643
PyMem_Free (channels );
635
- PyErr_SetString (ChannelError , "can't initialize mutex for channel management" );
644
+ PyErr_SetString (ChannelError ,
645
+ "can't initialize mutex for channel management" );
636
646
return -1 ;
637
647
}
638
648
}
@@ -752,7 +762,8 @@ _channels_close(_channels *channels, int64_t cid, _PyChannelState **pchan)
752
762
}
753
763
754
764
static void
755
- _channels_remove_ref (_channels * channels , _channelref * ref , _channelref * prev , _PyChannelState * * pchan )
765
+ _channels_remove_ref (_channels * channels , _channelref * ref , _channelref * prev ,
766
+ _PyChannelState * * pchan )
756
767
{
757
768
if (ref == channels -> head ) {
758
769
channels -> head = ref -> next ;
@@ -906,7 +917,7 @@ _channel_send(_channels *channels, int64_t id, PyObject *obj)
906
917
// Past this point we are responsible for releasing the mutex.
907
918
908
919
// Convert the object to cross-interpreter data.
909
- _PyCrossInterpreterData * data = PyMem_Malloc ( sizeof ( _PyCrossInterpreterData ) );
920
+ _PyCrossInterpreterData * data = PyMem_NEW ( _PyCrossInterpreterData , 1 );
910
921
if (data == NULL ) {
911
922
PyThread_release_lock (mutex );
912
923
return -1 ;
@@ -1005,7 +1016,8 @@ typedef struct channelid {
1005
1016
} channelid ;
1006
1017
1007
1018
static channelid *
1008
- newchannelid (PyTypeObject * cls , int64_t cid , int end , _channels * channels , int force )
1019
+ newchannelid (PyTypeObject * cls , int64_t cid , int end , _channels * channels ,
1020
+ int force )
1009
1021
{
1010
1022
channelid * self = PyObject_New (channelid , cls );
1011
1023
if (self == NULL ) {
@@ -1038,7 +1050,8 @@ channelid_new(PyTypeObject *cls, PyObject *args, PyObject *kwds)
1038
1050
int send = -1 ;
1039
1051
int recv = -1 ;
1040
1052
int force = 0 ;
1041
- if (!PyArg_ParseTupleAndKeywords (args , kwds , "O|$ppp:ChannelID.__init__" , kwlist ,
1053
+ if (!PyArg_ParseTupleAndKeywords (args , kwds ,
1054
+ "O|$ppp:ChannelID.__init__" , kwlist ,
1042
1055
& id , & send , & recv , & force ))
1043
1056
return NULL ;
1044
1057
@@ -1056,7 +1069,8 @@ channelid_new(PyTypeObject *cls, PyObject *args, PyObject *kwds)
1056
1069
1057
1070
// Handle "send" and "recv".
1058
1071
if (send == 0 && recv == 0 ) {
1059
- PyErr_SetString (PyExc_ValueError , "'send' and 'recv' cannot both be False" );
1072
+ PyErr_SetString (PyExc_ValueError ,
1073
+ "'send' and 'recv' cannot both be False" );
1060
1074
return NULL ;
1061
1075
}
1062
1076
int end = 0 ;
@@ -1205,7 +1219,8 @@ static PyObject *
1205
1219
_channelid_from_xid (_PyCrossInterpreterData * data )
1206
1220
{
1207
1221
struct _channelid_xid * xid = (struct _channelid_xid * )data -> data ;
1208
- return (PyObject * )newchannelid (& ChannelIDtype , xid -> id , xid -> end , _global_channels (), 0 );
1222
+ return (PyObject * )newchannelid (& ChannelIDtype , xid -> id , xid ->end ,
1223
+ _global_channels (), 0 );
1209
1224
}
1210
1225
1211
1226
static int
@@ -1231,7 +1246,8 @@ channelid_end(PyObject *self, void *end)
1231
1246
int force = 1 ;
1232
1247
channelid * cid = (channelid * )self ;
1233
1248
if (end != NULL ) {
1234
- return (PyObject * )newchannelid (Py_TYPE (self ), cid -> id , * (int * )end , cid -> channels , force );
1249
+ return (PyObject * )newchannelid (Py_TYPE (self ), cid -> id , * (int * )end ,
1250
+ cid -> channels , force );
1235
1251
}
1236
1252
1237
1253
if (cid -> end == CHANNEL_SEND ) {
@@ -1736,7 +1752,8 @@ channel_create(PyObject *self)
1736
1752
if (cid < 0 ) {
1737
1753
return NULL ;
1738
1754
}
1739
- PyObject * id = (PyObject * )newchannelid (& ChannelIDtype , cid , 0 , & _globals .channels , 0 );
1755
+ PyObject * id = (PyObject * )newchannelid (& ChannelIDtype , cid , 0 ,
1756
+ & _globals .channels , 0 );
1740
1757
if (id == NULL ) {
1741
1758
if (_channel_destroy (& _globals .channels , cid ) != 0 ) {
1742
1759
// XXX issue a warning?
@@ -1793,7 +1810,8 @@ channel_list_all(PyObject *self)
1793
1810
return NULL ;
1794
1811
}
1795
1812
for (int64_t i = 0 ; i < count ; cids ++ , i ++ ) {
1796
- PyObject * id = (PyObject * )newchannelid (& ChannelIDtype , * cids , 0 , & _globals .channels , 0 );
1813
+ PyObject * id = (PyObject * )newchannelid (& ChannelIDtype , * cids , 0 ,
1814
+ & _globals .channels , 0 );
1797
1815
if (id == NULL ) {
1798
1816
Py_DECREF (ids );
1799
1817
ids = NULL ;
@@ -1886,7 +1904,8 @@ channel_drop_interpreter(PyObject *self, PyObject *args, PyObject *kwds)
1886
1904
PyObject * id ;
1887
1905
int send = -1 ;
1888
1906
int recv = -1 ;
1889
- if (!PyArg_ParseTupleAndKeywords (args , kwds , "O|$pp:channel_drop_interpreter" , kwlist ,
1907
+ if (!PyArg_ParseTupleAndKeywords (args , kwds ,
1908
+ "O|$pp:channel_drop_interpreter" , kwlist ,
1890
1909
& id , & send , & recv ))
1891
1910
return NULL ;
1892
1911
0 commit comments