Index: libs/python/src/converter/builtin_converters.cpp =================================================================== --- libs/python/src/converter/builtin_converters.cpp (revision 53980) +++ libs/python/src/converter/builtin_converters.cpp (working copy) @@ -155,10 +155,21 @@ { static T extract(PyObject* intermediate) { - return numeric_cast( - PyLong_Check(intermediate) - ? PyLong_AsUnsignedLong(intermediate) - : PyInt_AS_LONG(intermediate)); + if (PyLong_Check(intermediate)) { + unsigned long result = PyLong_AsUnsignedLong(intermediate); + if (PyErr_Occurred()) + throw_error_already_set(); + return numeric_cast(result); + } else { + long result = PyInt_AS_LONG(intermediate); + if (PyErr_Occurred()) + throw_error_already_set(); + if (result < 0) { + PyErr_SetString(PyExc_ValueError, "argument must not be negative"); + throw_error_already_set(); + } + return numeric_cast(result); + } } };