Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Do not explicitly check against INT64_MAX.
  • Loading branch information
ericsnowcurrently committed Feb 3, 2018
commit aac9485031de7b9c2ee78d13d4a3d9d1fa8e6ec6
6 changes: 3 additions & 3 deletions Lib/test/test__xxsubinterpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,12 +763,12 @@ def __int__(self):
self.assertEqual(int(cid), 10)

def test_bad_id(self):
ids = [-1, 2**64, "spam"]
for cid in ids:
for cid in [-1, 'spam']:
with self.subTest(cid):
with self.assertRaises(ValueError):
interpreters._channel_id(cid)

with self.assertRaises(OverflowError):
interpreters._channel_id(2**64)
with self.assertRaises(TypeError):
interpreters._channel_id(object())

Expand Down
15 changes: 6 additions & 9 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,20 @@ _coerce_id(PyObject *id)
}
return -1;
}
long long cid = PyLong_AsLongLong(id);
int64_t cid = PyLong_AsLongLong(id);
Py_DECREF(id);
if (cid == -1 && PyErr_Occurred() != NULL) {
PyErr_SetString(PyExc_ValueError,
"'id' must be a non-negative int");
if (!PyErr_ExceptionMatches(PyExc_OverflowError)) {
PyErr_SetString(PyExc_ValueError,
"'id' must be a non-negative int");
}
return -1;
}
if (cid < 0) {
PyErr_SetString(PyExc_ValueError,
"'id' must be a non-negative int");
return -1;
}
if (cid > INT64_MAX) {
PyErr_SetString(PyExc_ValueError,
"'id' too large (must be 64-bit int)");
return -1;
}
return cid;
}

Expand Down Expand Up @@ -1231,7 +1228,7 @@ channelid_richcompare(PyObject *self, PyObject *other, int op)
if (othercid == -1 && PyErr_Occurred() != NULL) {
return NULL;
}
if (othercid < 0 || othercid > INT64_MAX) {
if (othercid < 0) {
equal = 0;
}
else {
Expand Down