MCPcopy Create free account
hub / github.com/apache/arrow / CIntFromPythonImpl

Function CIntFromPythonImpl

python/pyarrow/src/arrow/python/helpers.cc:197–229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

CIntFromPythonFunction · 0.85

Calls 4

PyObjectToPyIntFunction · 0.85
IntegerOverflowStatusFunction · 0.85
ARROW_ASSIGN_OR_RAISEFunction · 0.50
OKFunction · 0.50

Tested by

no test coverage detected