MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/Imath / getbuffer

Function getbuffer

src/python/PyImath/PyImathBufferProtocol.cpp:227–293  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

225
226template <class ArrayT>
227int
228getbuffer (PyObject *obj, Py_buffer *view, int flags)
229{
230 if (view == nullptr)
231 {
232 PyErr_SetString (PyExc_ValueError, "Buffer view is NULL");
233 return -1;
234 }
235
236 if ((flags & PyBUF_F_CONTIGUOUS) == PyBUF_F_CONTIGUOUS)
237 {
238 PyErr_SetString (PyExc_ValueError, "FORTRAN order not supported");
239 return -1;
240 }
241
242 boost::python::extract<ArrayT> eObj (obj);
243 if (!eObj.check())
244 {
245 PyErr_SetString (PyExc_ValueError, "Cannot extract FixedArray");
246 return -1;
247 }
248 ArrayT array = eObj();
249
250 if (array.isMaskedReference())
251 {
252 PyErr_SetString (PyExc_ValueError, "Buffer protocol does not support masked references");
253 return -1;
254 }
255
256 BufferAPI<ArrayT> *api = nullptr;
257 bool writableBuffer = ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE);
258 if (writableBuffer && !array.writable())
259 api = new CopyBufferAPI<ArrayT> (array);
260 else
261 api = new SharedBufferAPI<ArrayT> (array);
262
263 view->internal = api;
264 view->buf = api->buffer();
265 view->len = api->numBytes();
266 view->readonly = api->readOnly();
267 view->itemsize = api->atomicSize();
268 view->suboffsets = nullptr;
269
270 view->format = ((flags & PyBUF_FORMAT) == PyBUF_FORMAT)
271 ? PyFormat<typename ArrayT::BaseType>()
272 : nullptr;
273
274 view->strides = ((flags & PyBUF_STRIDES) == PyBUF_STRIDES)
275 ? api->stride
276 : nullptr;
277
278 if ((flags & PyBUF_ND) == PyBUF_ND)
279 {
280 view->ndim = api->dimensions;
281 view->shape = api->shape;
282 }
283 else
284 {

Callers

nothing calls this directly

Calls 6

atomicSizeMethod · 0.80
isMaskedReferenceMethod · 0.45
writableMethod · 0.45
bufferMethod · 0.45
numBytesMethod · 0.45
readOnlyMethod · 0.45

Tested by

no test coverage detected