| 290 | // Int support |
| 291 | |
| 292 | const char* ConvertOneInt64(PyObject* v, int64* out) { |
| 293 | #if PY_MAJOR_VERSION < 3 |
| 294 | if (TF_PREDICT_TRUE(PyInt_Check(v))) { |
| 295 | *out = PyInt_AS_LONG(v); |
| 296 | return nullptr; |
| 297 | } |
| 298 | #endif |
| 299 | if (TF_PREDICT_TRUE(PyLong_Check(v) || IsPyDimension(v))) { |
| 300 | int overflow = 0; |
| 301 | // Have to use LongLong for 64 bits, since long is 32 bits on Windows. |
| 302 | *out = PyLong_AsLongLongAndOverflow(v, &overflow); |
| 303 | if (TF_PREDICT_FALSE(overflow)) return ErrorOutOfRange; |
| 304 | return nullptr; |
| 305 | } |
| 306 | if (PyIsInstance(v, &PyIntegerArrType_Type)) { // NumPy integers |
| 307 | #if PY_MAJOR_VERSION < 3 |
| 308 | Safe_PyObjectPtr as_int = make_safe(PyNumber_Int(v)); |
| 309 | #else |
| 310 | Safe_PyObjectPtr as_int = make_safe(PyNumber_Long(v)); |
| 311 | #endif |
| 312 | return ConvertOneInt64(as_int.get(), out); |
| 313 | } |
| 314 | if (IsPyFloat(v)) return ErrorFoundFloat; |
| 315 | return ErrorMixedTypes; |
| 316 | } |
| 317 | |
| 318 | DEFINE_HELPER(ConvertInt64, int64, DT_INT64, ConvertOneInt64); |
| 319 |
nothing calls this directly
no test coverage detected