bpo-37170: Fix the cast on error in PyLong_AsUnsignedLongLongMask() (… · python/cpython@dc24765 · GitHub
Skip to content

Commit dc24765

Browse files
ZackerySpytzvstinner
authored andcommitted
bpo-37170: Fix the cast on error in PyLong_AsUnsignedLongLongMask() (GH-13860)
1 parent f6713e8 commit dc24765

4 files changed

Lines changed: 29 additions & 4 deletions

File tree

Doc/c-api/long.rst

Lines changed: 4 additions & 2 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix the cast on error in :c:func:`PyLong_AsUnsignedLongLongMask()`.

Modules/_testcapimodule.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,26 @@ test_long_as_size_t(PyObject *self, PyObject *Py_UNUSED(ignored))
825825
return Py_None;
826826
}
827827

828+
static PyObject *
829+
test_long_as_unsigned_long_long_mask(PyObject *self,
830+
PyObject *Py_UNUSED(ignored))
831+
{
832+
unsigned long long res = PyLong_AsUnsignedLongLongMask(NULL);
833+
834+
if (res != (unsigned long long)-1 || !PyErr_Occurred()) {
835+
return raiseTestError("test_long_as_unsigned_long_long_mask",
836+
"PyLong_AsUnsignedLongLongMask(NULL) didn't "
837+
"complain");
838+
}
839+
if (!PyErr_ExceptionMatches(PyExc_SystemError)) {
840+
return raiseTestError("test_long_as_unsigned_long_long_mask",
841+
"PyLong_AsUnsignedLongLongMask(NULL) raised "
842+
"something other than SystemError");
843+
}
844+
PyErr_Clear();
845+
Py_RETURN_NONE;
846+
}
847+
828848
/* Test the PyLong_AsDouble API. At present this just tests that
829849
non-integer arguments are handled correctly.
830850
*/
@@ -5070,6 +5090,8 @@ static PyMethodDef TestMethods[] = {
50705090
{"test_long_and_overflow", test_long_and_overflow, METH_NOARGS},
50715091
{"test_long_as_double", test_long_as_double, METH_NOARGS},
50725092
{"test_long_as_size_t", test_long_as_size_t, METH_NOARGS},
5093+
{"test_long_as_unsigned_long_long_mask",
5094+
test_long_as_unsigned_long_long_mask, METH_NOARGS},
50735095
{"test_long_numbits", test_long_numbits, METH_NOARGS},
50745096
{"test_k_code", test_k_code, METH_NOARGS},
50755097
{"test_empty_argparse", test_empty_argparse, METH_NOARGS},

Objects/longobject.c

Lines changed: 2 additions & 2 deletions

0 commit comments

Comments
 (0)