@@ -1000,11 +1000,11 @@ _channels_lookup(_channels *channels, int64_t id, PyThread_type_lock *pmutex)
1000
1000
1001
1001
_channelref * ref = _channelref_find (channels -> head , id , NULL );
1002
1002
if (ref == NULL ) {
1003
- PyErr_Format (ChannelNotFoundError , "channel %lld not found" , id );
1003
+ PyErr_Format (ChannelNotFoundError , "channel %" PRId64 " not found" , id );
1004
1004
goto done ;
1005
1005
}
1006
1006
if (ref -> chan == NULL || !ref -> chan -> open ) {
1007
- PyErr_Format (ChannelClosedError , "channel %lld closed" , id );
1007
+ PyErr_Format (ChannelClosedError , "channel %" PRId64 " closed" , id );
1008
1008
goto done ;
1009
1009
}
1010
1010
@@ -1064,16 +1064,16 @@ _channels_close(_channels *channels, int64_t cid, _PyChannelState **pchan,
1064
1064
1065
1065
_channelref * ref = _channelref_find (channels -> head , cid , NULL );
1066
1066
if (ref == NULL ) {
1067
- PyErr_Format (ChannelNotFoundError , "channel %lld not found" , cid );
1067
+ PyErr_Format (ChannelNotFoundError , "channel %" PRId64 " not found" , cid );
1068
1068
goto done ;
1069
1069
}
1070
1070
1071
1071
if (ref -> chan == NULL ) {
1072
- PyErr_Format (ChannelClosedError , "channel %lld closed" , cid );
1072
+ PyErr_Format (ChannelClosedError , "channel %" PRId64 " closed" , cid );
1073
1073
goto done ;
1074
1074
}
1075
1075
else if (!force && end == CHANNEL_SEND && ref -> chan -> closing != NULL ) {
1076
- PyErr_Format (ChannelClosedError , "channel %lld closed" , cid );
1076
+ PyErr_Format (ChannelClosedError , "channel %" PRId64 " closed" , cid );
1077
1077
goto done ;
1078
1078
}
1079
1079
else {
@@ -1082,7 +1082,7 @@ _channels_close(_channels *channels, int64_t cid, _PyChannelState **pchan,
1082
1082
PyErr_ExceptionMatches (ChannelNotEmptyError )) {
1083
1083
if (ref -> chan -> closing != NULL ) {
1084
1084
PyErr_Format (ChannelClosedError ,
1085
- "channel %lld closed" , cid );
1085
+ "channel %" PRId64 " closed" , cid );
1086
1086
goto done ;
1087
1087
}
1088
1088
// Mark the channel as closing and return. The channel
@@ -1144,7 +1144,7 @@ _channels_remove(_channels *channels, int64_t id, _PyChannelState **pchan)
1144
1144
_channelref * prev = NULL ;
1145
1145
_channelref * ref = _channelref_find (channels -> head , id , & prev );
1146
1146
if (ref == NULL ) {
1147
- PyErr_Format (ChannelNotFoundError , "channel %lld not found" , id );
1147
+ PyErr_Format (ChannelNotFoundError , "channel %" PRId64 " not found" , id );
1148
1148
goto done ;
1149
1149
}
1150
1150
@@ -1164,7 +1164,7 @@ _channels_add_id_object(_channels *channels, int64_t id)
1164
1164
1165
1165
_channelref * ref = _channelref_find (channels -> head , id , NULL );
1166
1166
if (ref == NULL ) {
1167
- PyErr_Format (ChannelNotFoundError , "channel %lld not found" , id );
1167
+ PyErr_Format (ChannelNotFoundError , "channel %" PRId64 " not found" , id );
1168
1168
goto done ;
1169
1169
}
1170
1170
ref -> objcount += 1 ;
@@ -1328,7 +1328,7 @@ _channel_send(_channels *channels, int64_t id, PyObject *obj)
1328
1328
// Past this point we are responsible for releasing the mutex.
1329
1329
1330
1330
if (chan -> closing != NULL ) {
1331
- PyErr_Format (ChannelClosedError , "channel %lld closed" , id );
1331
+ PyErr_Format (ChannelClosedError , "channel %" PRId64 " closed" , id );
1332
1332
PyThread_release_lock (mutex );
1333
1333
return -1 ;
1334
1334
}
@@ -1377,7 +1377,7 @@ _channel_recv(_channels *channels, int64_t id)
1377
1377
PyThread_release_lock (mutex );
1378
1378
if (data == NULL ) {
1379
1379
if (!PyErr_Occurred ()) {
1380
- PyErr_Format (ChannelEmptyError , "channel %lld is empty" , id );
1380
+ PyErr_Format (ChannelEmptyError , "channel %" PRId64 " is empty" , id );
1381
1381
}
1382
1382
return NULL ;
1383
1383
}
@@ -1527,13 +1527,13 @@ channelid_repr(PyObject *self)
1527
1527
channelid * cid = (channelid * )self ;
1528
1528
const char * fmt ;
1529
1529
if (cid -> end == CHANNEL_SEND ) {
1530
- fmt = "%s(%lld , send=True)" ;
1530
+ fmt = "%s(%" PRId64 " , send=True)" ;
1531
1531
}
1532
1532
else if (cid -> end == CHANNEL_RECV ) {
1533
- fmt = "%s(%lld , recv=True)" ;
1533
+ fmt = "%s(%" PRId64 " , recv=True)" ;
1534
1534
}
1535
1535
else {
1536
- fmt = "%s(%lld )" ;
1536
+ fmt = "%s(%" PRId64 " )" ;
1537
1537
}
1538
1538
return PyUnicode_FromFormat (fmt , name , cid -> id );
1539
1539
}
@@ -1542,7 +1542,7 @@ static PyObject *
1542
1542
channelid_str (PyObject * self )
1543
1543
{
1544
1544
channelid * cid = (channelid * )self ;
1545
- return PyUnicode_FromFormat ("%lld " , cid -> id );
1545
+ return PyUnicode_FromFormat ("%" PRId64 " " , cid -> id );
1546
1546
}
1547
1547
1548
1548
PyObject *
@@ -1652,6 +1652,32 @@ channelid_richcompare(PyObject *self, PyObject *other, int op)
1652
1652
Py_RETURN_FALSE ;
1653
1653
}
1654
1654
1655
+ static PyObject *
1656
+ _channel_from_cid (PyObject * cid , int end )
1657
+ {
1658
+ PyObject * highlevel = PyImport_ImportModule ("interpreters" );
1659
+ if (highlevel == NULL ) {
1660
+ PyErr_Clear ();
1661
+ highlevel = PyImport_ImportModule ("test.support.interpreters" );
1662
+ if (highlevel == NULL ) {
1663
+ return NULL ;
1664
+ }
1665
+ }
1666
+ const char * clsname = (end == CHANNEL_RECV ) ? "RecvChannel" :
1667
+ "SendChannel" ;
1668
+ PyObject * cls = PyObject_GetAttrString (highlevel , clsname );
1669
+ Py_DECREF (highlevel );
1670
+ if (cls == NULL ) {
1671
+ return NULL ;
1672
+ }
1673
+ PyObject * chan = PyObject_CallFunctionObjArgs (cls , cid , NULL );
1674
+ Py_DECREF (cls );
1675
+ if (chan == NULL ) {
1676
+ return NULL ;
1677
+ }
1678
+ return chan ;
1679
+ }
1680
+
1655
1681
struct _channelid_xid {
1656
1682
int64_t id ;
1657
1683
int end ;
@@ -1673,31 +1699,13 @@ _channelid_from_xid(_PyCrossInterpreterData *data)
1673
1699
}
1674
1700
1675
1701
/* Try returning a high-level channel end but fall back to the ID. */
1676
- PyObject * highlevel = PyImport_ImportModule ("interpreters" );
1677
- if (highlevel == NULL ) {
1678
- PyErr_Clear ();
1679
- highlevel = PyImport_ImportModule ("test.support.interpreters" );
1680
- if (highlevel == NULL ) {
1681
- goto error ;
1682
- }
1683
- }
1684
- const char * clsname = (xid -> end == CHANNEL_RECV ) ? "RecvChannel" :
1685
- "SendChannel" ;
1686
- PyObject * cls = PyObject_GetAttrString (highlevel , clsname );
1687
- Py_DECREF (highlevel );
1688
- if (cls == NULL ) {
1689
- goto error ;
1690
- }
1691
- PyObject * chan = PyObject_CallFunctionObjArgs (cls , cid , NULL );
1702
+ PyObject * chan = _channel_from_cid (cid , xid -> end );
1692
1703
if (chan == NULL ) {
1693
- goto error ;
1704
+ PyErr_Clear ();
1705
+ return cid ;
1694
1706
}
1695
1707
Py_DECREF (cid );
1696
1708
return chan ;
1697
-
1698
- error :
1699
- PyErr_Clear ();
1700
- return cid ;
1701
1709
}
1702
1710
1703
1711
static int
@@ -2048,14 +2056,14 @@ interpid_repr(PyObject *self)
2048
2056
PyTypeObject * type = Py_TYPE (self );
2049
2057
const char * name = _PyType_Name (type );
2050
2058
interpid * id = (interpid * )self ;
2051
- return PyUnicode_FromFormat ("%s(%lld )" , name , id -> id );
2059
+ return PyUnicode_FromFormat ("%s(%" PRId64 " )" , name , id -> id );
2052
2060
}
2053
2061
2054
2062
static PyObject *
2055
2063
interpid_str (PyObject * self )
2056
2064
{
2057
2065
interpid * id = (interpid * )self ;
2058
- return PyUnicode_FromFormat ("%lld " , id -> id );
2066
+ return PyUnicode_FromFormat ("%" PRId64 " " , id -> id );
2059
2067
}
2060
2068
2061
2069
PyObject *
0 commit comments