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

Function CIntFromPythonImpl

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

Source from the content-addressed store, hash-verified

194// Extract C signed int from Python object
195template <typename Int, enable_if_t<std::is_signed<Int>::value, Int> = 0>
196Status 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
231template <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