| 376 | } |
| 377 | |
| 378 | void write(const char* data, size_t n) override { |
| 379 | nb::gil_scoped_acquire gil; |
| 380 | |
| 381 | nb::object memview = nb::steal<nb::object>( |
| 382 | PyMemoryView_FromMemory(const_cast<char*>(data), n, PyBUF_READ)); |
| 383 | if (!memview.is_valid()) { |
| 384 | throw std::runtime_error("[load] Failed to create memoryview for write"); |
| 385 | } |
| 386 | nb::object bytes_written = write_func_(memview); |
| 387 | |
| 388 | if (bytes_written.is_none() || nb::cast<size_t>(bytes_written) < n) { |
| 389 | throw std::runtime_error("[load] Failed to write to python stream"); |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | std::string label() const override { |
| 394 | return "python file object"; |
no outgoing calls