158 | | return numeric_cast<T>( |
159 | | PyLong_Check(intermediate) |
160 | | ? PyLong_AsUnsignedLong(intermediate) |
161 | | : PyInt_AS_LONG(intermediate)); |
| 158 | if (PyLong_Check(intermediate)) { |
| 159 | unsigned long result = PyLong_AsUnsignedLong(intermediate); |
| 160 | if (PyErr_Occurred()) |
| 161 | throw_error_already_set(); |
| 162 | return numeric_cast<T>(result); |
| 163 | } else { |
| 164 | long result = PyInt_AS_LONG(intermediate); |
| 165 | if (PyErr_Occurred()) |
| 166 | throw_error_already_set(); |
| 167 | if (result < 0) { |
| 168 | PyErr_SetString(PyExc_ValueError, "argument must not be negative"); |
| 169 | throw_error_already_set(); |
| 170 | } |
| 171 | return numeric_cast<T>(result); |
| 172 | } |