@@ -1000,11 +1000,11 @@ _channels_lookup(_channels *channels, int64_t id, PyThread_type_lock *pmutex)
10001000
10011001 _channelref * ref = _channelref_find (channels -> head , id , NULL );
10021002 if (ref == NULL ) {
1003- PyErr_Format (ChannelNotFoundError , "channel %lld not found" , id );
1003+ PyErr_Format (ChannelNotFoundError , "channel %" PRId64 " not found" , id );
10041004 goto done ;
10051005 }
10061006 if (ref -> chan == NULL || !ref -> chan -> open ) {
1007- PyErr_Format (ChannelClosedError , "channel %lld closed" , id );
1007+ PyErr_Format (ChannelClosedError , "channel %" PRId64 " closed" , id );
10081008 goto done ;
10091009 }
10101010
@@ -1064,16 +1064,16 @@ _channels_close(_channels *channels, int64_t cid, _PyChannelState **pchan,
10641064
10651065 _channelref * ref = _channelref_find (channels -> head , cid , NULL );
10661066 if (ref == NULL ) {
1067- PyErr_Format (ChannelNotFoundError , "channel %lld not found" , cid );
1067+ PyErr_Format (ChannelNotFoundError , "channel %" PRId64 " not found" , cid );
10681068 goto done ;
10691069 }
10701070
10711071 if (ref -> chan == NULL ) {
1072- PyErr_Format (ChannelClosedError , "channel %lld closed" , cid );
1072+ PyErr_Format (ChannelClosedError , "channel %" PRId64 " closed" , cid );
10731073 goto done ;
10741074 }
10751075 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 );
10771077 goto done ;
10781078 }
10791079 else {
@@ -1082,7 +1082,7 @@ _channels_close(_channels *channels, int64_t cid, _PyChannelState **pchan,
10821082 PyErr_ExceptionMatches (ChannelNotEmptyError )) {
10831083 if (ref -> chan -> closing != NULL ) {
10841084 PyErr_Format (ChannelClosedError ,
1085- "channel %lld closed" , cid );
1085+ "channel %" PRId64 " closed" , cid );
10861086 goto done ;
10871087 }
10881088 // Mark the channel as closing and return. The channel
@@ -1144,7 +1144,7 @@ _channels_remove(_channels *channels, int64_t id, _PyChannelState **pchan)
11441144 _channelref * prev = NULL ;
11451145 _channelref * ref = _channelref_find (channels -> head , id , & prev );
11461146 if (ref == NULL ) {
1147- PyErr_Format (ChannelNotFoundError , "channel %lld not found" , id );
1147+ PyErr_Format (ChannelNotFoundError , "channel %" PRId64 " not found" , id );
11481148 goto done ;
11491149 }
11501150
@@ -1164,7 +1164,7 @@ _channels_add_id_object(_channels *channels, int64_t id)
11641164
11651165 _channelref * ref = _channelref_find (channels -> head , id , NULL );
11661166 if (ref == NULL ) {
1167- PyErr_Format (ChannelNotFoundError , "channel %lld not found" , id );
1167+ PyErr_Format (ChannelNotFoundError , "channel %" PRId64 " not found" , id );
11681168 goto done ;
11691169 }
11701170 ref -> objcount += 1 ;
@@ -1328,7 +1328,7 @@ _channel_send(_channels *channels, int64_t id, PyObject *obj)
13281328 // Past this point we are responsible for releasing the mutex.
13291329
13301330 if (chan -> closing != NULL ) {
1331- PyErr_Format (ChannelClosedError , "channel %lld closed" , id );
1331+ PyErr_Format (ChannelClosedError , "channel %" PRId64 " closed" , id );
13321332 PyThread_release_lock (mutex );
13331333 return -1 ;
13341334 }
@@ -1377,7 +1377,7 @@ _channel_recv(_channels *channels, int64_t id)
13771377 PyThread_release_lock (mutex );
13781378 if (data == NULL ) {
13791379 if (!PyErr_Occurred ()) {
1380- PyErr_Format (ChannelEmptyError , "channel %lld is empty" , id );
1380+ PyErr_Format (ChannelEmptyError , "channel %" PRId64 " is empty" , id );
13811381 }
13821382 return NULL ;
13831383 }
@@ -1527,13 +1527,13 @@ channelid_repr(PyObject *self)
15271527 channelid * cid = (channelid * )self ;
15281528 const char * fmt ;
15291529 if (cid -> end == CHANNEL_SEND ) {
1530- fmt = "%s(%lld , send=True)" ;
1530+ fmt = "%s(%" PRId64 " , send=True)" ;
15311531 }
15321532 else if (cid -> end == CHANNEL_RECV ) {
1533- fmt = "%s(%lld , recv=True)" ;
1533+ fmt = "%s(%" PRId64 " , recv=True)" ;
15341534 }
15351535 else {
1536- fmt = "%s(%lld )" ;
1536+ fmt = "%s(%" PRId64 " )" ;
15371537 }
15381538 return PyUnicode_FromFormat (fmt , name , cid -> id );
15391539}
@@ -1542,7 +1542,7 @@ static PyObject *
15421542channelid_str (PyObject * self )
15431543{
15441544 channelid * cid = (channelid * )self ;
1545- return PyUnicode_FromFormat ("%lld " , cid -> id );
1545+ return PyUnicode_FromFormat ("%" PRId64 " " , cid -> id );
15461546}
15471547
15481548PyObject *
@@ -1652,6 +1652,32 @@ channelid_richcompare(PyObject *self, PyObject *other, int op)
16521652 Py_RETURN_FALSE ;
16531653}
16541654
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+
16551681struct _channelid_xid {
16561682 int64_t id ;
16571683 int end ;
@@ -1673,31 +1699,13 @@ _channelid_from_xid(_PyCrossInterpreterData *data)
16731699 }
16741700
16751701 /* 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 );
16921703 if (chan == NULL ) {
1693- goto error ;
1704+ PyErr_Clear ();
1705+ return cid ;
16941706 }
16951707 Py_DECREF (cid );
16961708 return chan ;
1697-
1698- error :
1699- PyErr_Clear ();
1700- return cid ;
17011709}
17021710
17031711static int
@@ -2048,14 +2056,14 @@ interpid_repr(PyObject *self)
20482056 PyTypeObject * type = Py_TYPE (self );
20492057 const char * name = _PyType_Name (type );
20502058 interpid * id = (interpid * )self ;
2051- return PyUnicode_FromFormat ("%s(%lld )" , name , id -> id );
2059+ return PyUnicode_FromFormat ("%s(%" PRId64 " )" , name , id -> id );
20522060}
20532061
20542062static PyObject *
20552063interpid_str (PyObject * self )
20562064{
20572065 interpid * id = (interpid * )self ;
2058- return PyUnicode_FromFormat ("%lld " , id -> id );
2066+ return PyUnicode_FromFormat ("%" PRId64 " " , id -> id );
20592067}
20602068
20612069PyObject *
0 commit comments