bpo-33724: Use the right format code for int64_t in subinterpreters c… · python/cpython@6854e80

@@ -33,35 +33,35 @@ _get_current(void)

3333

}

34343535

static int64_t

36-

_coerce_id(PyObject *id)

36+

_coerce_id(PyObject *orig)

3737

{

38-

id = PyNumber_Long(id);

39-

if (id == NULL) {

38+

PyObject *pyid = PyNumber_Long(orig);

39+

if (pyid == NULL) {

4040

if (PyErr_ExceptionMatches(PyExc_TypeError)) {

41-

PyErr_SetString(PyExc_TypeError,

42-

"'id' must be a non-negative int");

41+

PyErr_Format(PyExc_TypeError,

42+

"'id' must be a non-negative int, got %R", orig);

4343

}

4444

else {

45-

PyErr_SetString(PyExc_ValueError,

46-

"'id' must be a non-negative int");

45+

PyErr_Format(PyExc_ValueError,

46+

"'id' must be a non-negative int, got %R", orig);

4747

}

4848

return -1;

4949

}

50-

int64_t cid = PyLong_AsLongLong(id);

51-

Py_DECREF(id);

52-

if (cid == -1 && PyErr_Occurred() != NULL) {

50+

int64_t id = PyLong_AsLongLong(pyid);

51+

Py_DECREF(pyid);

52+

if (id == -1 && PyErr_Occurred() != NULL) {

5353

if (!PyErr_ExceptionMatches(PyExc_OverflowError)) {

54-

PyErr_SetString(PyExc_ValueError,

55-

"'id' must be a non-negative int");

54+

PyErr_Format(PyExc_ValueError,

55+

"'id' must be a non-negative int, got %R", orig);

5656

}

5757

return -1;

5858

}

59-

if (cid < 0) {

60-

PyErr_SetString(PyExc_ValueError,

61-

"'id' must be a non-negative int");

59+

if (id < 0) {

60+

PyErr_Format(PyExc_ValueError,

61+

"'id' must be a non-negative int, got %R", orig);

6262

return -1;

6363

}

64-

return cid;

64+

return id;

6565

}

66666767

@@ -1000,11 +1000,11 @@ _channels_lookup(_channels *channels, int64_t id, PyThread_type_lock *pmutex)

1000100010011001

_channelref *ref = _channelref_find(channels->head, id, NULL);

10021002

if (ref == NULL) {

1003-

PyErr_Format(ChannelNotFoundError, "channel %d not found", id);

1003+

PyErr_Format(ChannelNotFoundError, "channel %lld not found", id);

10041004

goto done;

10051005

}

10061006

if (ref->chan == NULL || !ref->chan->open) {

1007-

PyErr_Format(ChannelClosedError, "channel %d closed", id);

1007+

PyErr_Format(ChannelClosedError, "channel %lld closed", id);

10081008

goto done;

10091009

}

10101010

@@ -1064,24 +1064,25 @@ _channels_close(_channels *channels, int64_t cid, _PyChannelState **pchan,

1064106410651065

_channelref *ref = _channelref_find(channels->head, cid, NULL);

10661066

if (ref == NULL) {

1067-

PyErr_Format(ChannelNotFoundError, "channel %d not found", cid);

1067+

PyErr_Format(ChannelNotFoundError, "channel %lld not found", cid);

10681068

goto done;

10691069

}

1070107010711071

if (ref->chan == NULL) {

1072-

PyErr_Format(ChannelClosedError, "channel %d closed", cid);

1072+

PyErr_Format(ChannelClosedError, "channel %lld closed", cid);

10731073

goto done;

10741074

}

10751075

else if (!force && end == CHANNEL_SEND && ref->chan->closing != NULL) {

1076-

PyErr_Format(ChannelClosedError, "channel %d closed", cid);

1076+

PyErr_Format(ChannelClosedError, "channel %lld closed", cid);

10771077

goto done;

10781078

}

10791079

else {

10801080

if (_channel_close_all(ref->chan, end, force) != 0) {

10811081

if (end == CHANNEL_SEND &&

10821082

PyErr_ExceptionMatches(ChannelNotEmptyError)) {

10831083

if (ref->chan->closing != NULL) {

1084-

PyErr_Format(ChannelClosedError, "channel %d closed", cid);

1084+

PyErr_Format(ChannelClosedError,

1085+

"channel %lld closed", cid);

10851086

goto done;

10861087

}

10871088

// Mark the channel as closing and return. The channel

@@ -1143,7 +1144,7 @@ _channels_remove(_channels *channels, int64_t id, _PyChannelState **pchan)

11431144

_channelref *prev = NULL;

11441145

_channelref *ref = _channelref_find(channels->head, id, &prev);

11451146

if (ref == NULL) {

1146-

PyErr_Format(ChannelNotFoundError, "channel %d not found", id);

1147+

PyErr_Format(ChannelNotFoundError, "channel %lld not found", id);

11471148

goto done;

11481149

}

11491150

@@ -1163,7 +1164,7 @@ _channels_add_id_object(_channels *channels, int64_t id)

1163116411641165

_channelref *ref = _channelref_find(channels->head, id, NULL);

11651166

if (ref == NULL) {

1166-

PyErr_Format(ChannelNotFoundError, "channel %d not found", id);

1167+

PyErr_Format(ChannelNotFoundError, "channel %lld not found", id);

11671168

goto done;

11681169

}

11691170

ref->objcount += 1;

@@ -1327,7 +1328,7 @@ _channel_send(_channels *channels, int64_t id, PyObject *obj)

13271328

// Past this point we are responsible for releasing the mutex.

1328132913291330

if (chan->closing != NULL) {

1330-

PyErr_Format(ChannelClosedError, "channel %d closed", id);

1331+

PyErr_Format(ChannelClosedError, "channel %lld closed", id);

13311332

PyThread_release_lock(mutex);

13321333

return -1;

13331334

}

@@ -1376,7 +1377,7 @@ _channel_recv(_channels *channels, int64_t id)

13761377

PyThread_release_lock(mutex);

13771378

if (data == NULL) {

13781379

if (!PyErr_Occurred()) {

1379-

PyErr_Format(ChannelEmptyError, "channel %d is empty", id);

1380+

PyErr_Format(ChannelEmptyError, "channel %lld is empty", id);

13801381

}

13811382

return NULL;

13821383

}

@@ -1526,13 +1527,13 @@ channelid_repr(PyObject *self)

15261527

channelid *cid = (channelid *)self;

15271528

const char *fmt;

15281529

if (cid->end == CHANNEL_SEND) {

1529-

fmt = "%s(%d, send=True)";

1530+

fmt = "%s(%lld, send=True)";

15301531

}

15311532

else if (cid->end == CHANNEL_RECV) {

1532-

fmt = "%s(%d, recv=True)";

1533+

fmt = "%s(%lld, recv=True)";

15331534

}

15341535

else {

1535-

fmt = "%s(%d)";

1536+

fmt = "%s(%lld)";

15361537

}

15371538

return PyUnicode_FromFormat(fmt, name, cid->id);

15381539

}

@@ -1541,7 +1542,7 @@ static PyObject *

15411542

channelid_str(PyObject *self)

15421543

{

15431544

channelid *cid = (channelid *)self;

1544-

return PyUnicode_FromFormat("%d", cid->id);

1545+

return PyUnicode_FromFormat("%lld", cid->id);

15451546

}

1546154715471548

PyObject *

@@ -2046,14 +2047,14 @@ interpid_repr(PyObject *self)

20462047

PyTypeObject *type = Py_TYPE(self);

20472048

const char *name = _PyType_Name(type);

20482049

interpid *id = (interpid *)self;

2049-

return PyUnicode_FromFormat("%s(%d)", name, id->id);

2050+

return PyUnicode_FromFormat("%s(%lld)", name, id->id);

20502051

}

2051205220522053

static PyObject *

20532054

interpid_str(PyObject *self)

20542055

{

20552056

interpid *id = (interpid *)self;

2056-

return PyUnicode_FromFormat("%d", id->id);

2057+

return PyUnicode_FromFormat("%lld", id->id);

20572058

}

2058205920592060

PyObject *