Skip to content

bpo-33724: Use the right format code for int64_t in subinterpreters code. #7330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 33 additions & 32 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,35 @@ _get_current(void)
}

static int64_t
_coerce_id(PyObject *id)
_coerce_id(PyObject *orig)
{
id = PyNumber_Long(id);
if (id == NULL) {
PyObject *pyid = PyNumber_Long(orig);
if (pyid == NULL) {
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
PyErr_SetString(PyExc_TypeError,
"'id' must be a non-negative int");
PyErr_Format(PyExc_TypeError,
"'id' must be a non-negative int, got %R", orig);
}
else {
PyErr_SetString(PyExc_ValueError,
"'id' must be a non-negative int");
PyErr_Format(PyExc_ValueError,
"'id' must be a non-negative int, got %R", orig);
}
return -1;
}
int64_t cid = PyLong_AsLongLong(id);
Py_DECREF(id);
if (cid == -1 && PyErr_Occurred() != NULL) {
int64_t id = PyLong_AsLongLong(pyid);
Py_DECREF(pyid);
if (id == -1 && PyErr_Occurred() != NULL) {
if (!PyErr_ExceptionMatches(PyExc_OverflowError)) {
PyErr_SetString(PyExc_ValueError,
"'id' must be a non-negative int");
PyErr_Format(PyExc_ValueError,
"'id' must be a non-negative int, got %R", orig);
}
return -1;
}
if (cid < 0) {
PyErr_SetString(PyExc_ValueError,
"'id' must be a non-negative int");
if (id < 0) {
PyErr_Format(PyExc_ValueError,
"'id' must be a non-negative int, got %R", orig);
return -1;
}
return cid;
return id;
}


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

_channelref *ref = _channelref_find(channels->head, id, NULL);
if (ref == NULL) {
PyErr_Format(ChannelNotFoundError, "channel %d not found", id);
PyErr_Format(ChannelNotFoundError, "channel %lld not found", id);
goto done;
}
if (ref->chan == NULL || !ref->chan->open) {
PyErr_Format(ChannelClosedError, "channel %d closed", id);
PyErr_Format(ChannelClosedError, "channel %lld closed", id);
goto done;
}

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

_channelref *ref = _channelref_find(channels->head, cid, NULL);
if (ref == NULL) {
PyErr_Format(ChannelNotFoundError, "channel %d not found", cid);
PyErr_Format(ChannelNotFoundError, "channel %lld not found", cid);
goto done;
}

if (ref->chan == NULL) {
PyErr_Format(ChannelClosedError, "channel %d closed", cid);
PyErr_Format(ChannelClosedError, "channel %lld closed", cid);
goto done;
}
else if (!force && end == CHANNEL_SEND && ref->chan->closing != NULL) {
PyErr_Format(ChannelClosedError, "channel %d closed", cid);
PyErr_Format(ChannelClosedError, "channel %lld closed", cid);
goto done;
}
else {
if (_channel_close_all(ref->chan, end, force) != 0) {
if (end == CHANNEL_SEND &&
PyErr_ExceptionMatches(ChannelNotEmptyError)) {
if (ref->chan->closing != NULL) {
PyErr_Format(ChannelClosedError, "channel %d closed", cid);
PyErr_Format(ChannelClosedError,
"channel %lld closed", cid);
goto done;
}
// Mark the channel as closing and return. The channel
Expand Down Expand Up @@ -1143,7 +1144,7 @@ _channels_remove(_channels *channels, int64_t id, _PyChannelState **pchan)
_channelref *prev = NULL;
_channelref *ref = _channelref_find(channels->head, id, &prev);
if (ref == NULL) {
PyErr_Format(ChannelNotFoundError, "channel %d not found", id);
PyErr_Format(ChannelNotFoundError, "channel %lld not found", id);
goto done;
}

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

_channelref *ref = _channelref_find(channels->head, id, NULL);
if (ref == NULL) {
PyErr_Format(ChannelNotFoundError, "channel %d not found", id);
PyErr_Format(ChannelNotFoundError, "channel %lld not found", id);
goto done;
}
ref->objcount += 1;
Expand Down Expand Up @@ -1327,7 +1328,7 @@ _channel_send(_channels *channels, int64_t id, PyObject *obj)
// Past this point we are responsible for releasing the mutex.

if (chan->closing != NULL) {
PyErr_Format(ChannelClosedError, "channel %d closed", id);
PyErr_Format(ChannelClosedError, "channel %lld closed", id);
PyThread_release_lock(mutex);
return -1;
}
Expand Down Expand Up @@ -1376,7 +1377,7 @@ _channel_recv(_channels *channels, int64_t id)
PyThread_release_lock(mutex);
if (data == NULL) {
if (!PyErr_Occurred()) {
PyErr_Format(ChannelEmptyError, "channel %d is empty", id);
PyErr_Format(ChannelEmptyError, "channel %lld is empty", id);
}
return NULL;
}
Expand Down Expand Up @@ -1526,13 +1527,13 @@ channelid_repr(PyObject *self)
channelid *cid = (channelid *)self;
const char *fmt;
if (cid->end == CHANNEL_SEND) {
fmt = "%s(%d, send=True)";
fmt = "%s(%lld, send=True)";
}
else if (cid->end == CHANNEL_RECV) {
fmt = "%s(%d, recv=True)";
fmt = "%s(%lld, recv=True)";
}
else {
fmt = "%s(%d)";
fmt = "%s(%lld)";
}
return PyUnicode_FromFormat(fmt, name, cid->id);
}
Expand All @@ -1541,7 +1542,7 @@ static PyObject *
channelid_str(PyObject *self)
{
channelid *cid = (channelid *)self;
return PyUnicode_FromFormat("%d", cid->id);
return PyUnicode_FromFormat("%lld", cid->id);
}

PyObject *
Expand Down Expand Up @@ -2046,14 +2047,14 @@ interpid_repr(PyObject *self)
PyTypeObject *type = Py_TYPE(self);
const char *name = _PyType_Name(type);
interpid *id = (interpid *)self;
return PyUnicode_FromFormat("%s(%d)", name, id->id);
return PyUnicode_FromFormat("%s(%lld)", name, id->id);
}

static PyObject *
interpid_str(PyObject *self)
{
interpid *id = (interpid *)self;
return PyUnicode_FromFormat("%d", id->id);
return PyUnicode_FromFormat("%lld", id->id);
}

PyObject *
Expand Down