| 216 | } |
| 217 | |
| 218 | Result<int64_t> PyReadableFile::Read(int64_t nbytes, void* out) { |
| 219 | return SafeCallIntoPython([=]() -> Result<int64_t> { |
| 220 | OwnedRef bytes; |
| 221 | RETURN_NOT_OK(file_->Read(nbytes, bytes.ref())); |
| 222 | PyObject* bytes_obj = bytes.obj(); |
| 223 | ARROW_DCHECK(bytes_obj != NULL); |
| 224 | |
| 225 | Py_buffer py_buf; |
| 226 | if (!PyObject_GetBuffer(bytes_obj, &py_buf, PyBUF_ANY_CONTIGUOUS)) { |
| 227 | const uint8_t* data = reinterpret_cast<const uint8_t*>(py_buf.buf); |
| 228 | std::memcpy(out, data, py_buf.len); |
| 229 | int64_t len = py_buf.len; |
| 230 | PyBuffer_Release(&py_buf); |
| 231 | return len; |
| 232 | } else { |
| 233 | return Status::TypeError( |
| 234 | "Python file read() should have returned a bytes object or an object " |
| 235 | "supporting the buffer protocol, got '", |
| 236 | Py_TYPE(bytes_obj)->tp_name, "' (did you open the file in binary mode?)"); |
| 237 | } |
| 238 | }); |
| 239 | } |
| 240 | |
| 241 | Result<std::shared_ptr<Buffer>> PyReadableFile::Read(int64_t nbytes) { |
| 242 | return SafeCallIntoPython([=]() -> Result<std::shared_ptr<Buffer>> { |
nothing calls this directly
no test coverage detected