\rst Creates ``memoryview`` from static memory. This method is meant for providing a ``memoryview`` for C/C++ buffer not managed by Python. The caller is responsible for managing the lifetime of ``mem``, which MUST outlive the memoryview constructed here. See also: Python C API documentation for `PyMemoryView_FromBuffer`_. .. _PyMemoryView_FromMem
| 2489 | https://docs.python.org/c-api/memoryview.html#c.PyMemoryView_FromMemory |
| 2490 | \endrst */ |
| 2491 | static memoryview from_memory(void *mem, ssize_t size, bool readonly = false) { |
| 2492 | PyObject *ptr = PyMemoryView_FromMemory( |
| 2493 | reinterpret_cast<char *>(mem), size, (readonly) ? PyBUF_READ : PyBUF_WRITE); |
| 2494 | if (!ptr) { |
| 2495 | pybind11_fail("Could not allocate memoryview object!"); |
| 2496 | } |
| 2497 | return memoryview(object(ptr, stolen_t{})); |
| 2498 | } |
| 2499 | |
| 2500 | static memoryview from_memory(const void *mem, ssize_t size) { |
| 2501 | return memoryview::from_memory(const_cast<void *>(mem), size, true); |
nothing calls this directly
no test coverage detected