| 194 | // Extract C signed int from Python object |
| 195 | template <typename Int, enable_if_t<std::is_signed<Int>::value, Int> = 0> |
| 196 | Status CIntFromPythonImpl(PyObject* obj, Int* out, const std::string& overflow_message) { |
| 197 | static_assert(sizeof(Int) <= sizeof(long long), // NOLINT |
| 198 | "integer type larger than long long"); |
| 199 | |
| 200 | OwnedRef ref; |
| 201 | if (!PyLong_Check(obj)) { |
| 202 | ARROW_ASSIGN_OR_RAISE(ref, PyObjectToPyInt(obj)); |
| 203 | obj = ref.obj(); |
| 204 | } |
| 205 | |
| 206 | if (sizeof(Int) > sizeof(long)) { // NOLINT |
| 207 | const auto value = PyLong_AsLongLong(obj); |
| 208 | if (ARROW_PREDICT_FALSE(value == -1)) { |
| 209 | RETURN_IF_PYERROR(); |
| 210 | } |
| 211 | if (ARROW_PREDICT_FALSE(value < std::numeric_limits<Int>::min() || |
| 212 | value > std::numeric_limits<Int>::max())) { |
| 213 | return IntegerOverflowStatus(obj, overflow_message); |
| 214 | } |
| 215 | *out = static_cast<Int>(value); |
| 216 | } else { |
| 217 | const auto value = PyLong_AsLong(obj); |
| 218 | if (ARROW_PREDICT_FALSE(value == -1)) { |
| 219 | RETURN_IF_PYERROR(); |
| 220 | } |
| 221 | if (ARROW_PREDICT_FALSE(value < std::numeric_limits<Int>::min() || |
| 222 | value > std::numeric_limits<Int>::max())) { |
| 223 | return IntegerOverflowStatus(obj, overflow_message); |
| 224 | } |
| 225 | *out = static_cast<Int>(value); |
| 226 | } |
| 227 | return Status::OK(); |
| 228 | } |
| 229 | |
| 230 | // Extract C unsigned int from Python object |
| 231 | template <typename Int, enable_if_t<std::is_unsigned<Int>::value, Int> = 0> |
no test coverage detected