10000 Remove the outdated getbuffer/releasebuffer implementations for the N… · cython/cython@b794997 · GitHub
[go: up one dir, main page]

Skip to content

Commit b794997

Browse files
committed
Remove the outdated getbuffer/releasebuffer implementations for the NumPy 'ndarray' since there are probably no NumPy installations out there anymore that do not support the buffer protocol themselves and are still worth supporting.
See numpy/numpy#12284 (comment) See GH-3573
1 parent 4d6939f commit b794997

File tree

1 file changed

+0
-91
lines changed

1 file changed

+0
-91
lines changed

Cython/Includes/numpy/__init__.pxd

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -281,97 +281,6 @@ cdef extern from "numpy/arrayobject.h":
281281
"""
282282
return PyArray_BYTES(self)
283283

284-
285-
# Note: This syntax (function definition in pxd files) is an
286-
# experimental exception made for __getbuffer__ and __releasebuffer__
287-
# -- the details of this may change.
288-
def __getbuffer__(ndarray self, Py_buffer* info, int flags):
289-
# This implementation of getbuffer is geared towards Cython
290-
# requirements, and does not yet fulfill the PEP.
291-
# In particular strided access is always provided regardless
292-
# of flags
293-
294-
cdef int i, ndim
295-
cdef int endian_detector = 1
296-
cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
297-
298-
ndim = PyArray_NDIM(self)
299-
300-
if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
301-
and not PyArray_CHKFLAGS(self, NPY_ARRAY_C_CONTIGUOUS)):
302-
raise ValueError(u"ndarray is not C contiguous")
303-
304-
if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
305-
and not PyArray_CHKFLAGS(self, NPY_ARRAY_F_CONTIGUOUS)):
306-
raise ValueError(u"ndarray is not Fortran contiguous")
307-
308-
info.buf = PyArray_DATA(self)
309-
info.ndim = ndim
310-
if sizeof(npy_intp) != sizeof(Py_ssize_t):
311-
# Allocate new buffer for strides and shape info.
312-
# This is allocated as one block, strides first.
313-
info.strides = <Py_ssize_t*>PyObject_Malloc(sizeof(Py_ssize_t) * 2 * <size_t>ndim)
314-
info.shape = info.strides + ndim
315-
for i in range(ndim):
316-
info.strides[i] = PyArray_STRIDES(self)[i]
317-
info.shape[i] = PyArray_DIMS(self)[i]
318-
else:
319-
info.strides = <Py_ssize_t*>PyArray_STRIDES(self)
320-
info.shape = <Py_ssize_t*>PyArray_DIMS(self)
321-
info.suboffsets = NULL
322-
info.itemsize = PyArray_ITEMSIZE(self)
323-
info.readonly = not PyArray_ISWRITEABLE(self)
324-
325-
cdef int t
326-
cdef char* f = NULL
327-
cdef dtype descr = <dtype>PyArray_DESCR(self)
328-
cdef int offset
329-
330-
info.obj = self
331-
332-
if not PyDataType_HASFIELDS(descr):
333-
t = descr.type_num
334-
if ((descr.byteorder == c'>' and little_endian) or
335-
(descr.byteorder == c'<' and not little_endian)):
336-
raise ValueError(u"Non-native byte order not supported")
337-
if t == NPY_BYTE: f = "b"
338-
elif t == NPY_UBYTE: f = "B"
339-
elif t == NPY_SHORT: f = "h"
340-
elif t == NPY_USHORT: f = "H"
341-
elif t == NPY_INT: f = "i"
342-
elif t == NPY_UINT: f = "I"
343-
elif t == NPY_LONG: f = "l"
344-
elif t == NPY_ULONG: f = "L"
345-
elif t == NPY_LONGLONG: f = "q"
346-
elif t == NPY_ULONGLONG: f = "Q"
347-
elif t == NPY_FLOAT: f = "f"
348-
elif t == NPY_DOUBLE: f = "d"
349-
elif t == NPY_LONGDOUBLE: f = "g"
350-
elif t == NPY_CFLOAT: f = "Zf"
351-
elif t == NPY_CDOUBLE: f = "Zd"
352-
elif t == NPY_CLONGDOUBLE: f = "Zg"
353-
elif t == NPY_OBJECT: f = "O"
354-
else:
355-
raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
356-
info.format = f
357-
return
358-
else:
359-
info.format = <char*>PyObject_Malloc(_buffer_format_string_len)
360-
info.format[0] = c'^' # Native data types, manual alignment
361-
offset = 0
362-
f = _util_dtypestring(descr, info.format + 1,
363-
info.format + _buffer_format_string_len,
364-
&offset)
365-
f[0] = c'\0' # Terminate format string
366-
367-
def __releasebuffer__(ndarray self, Py_buffer* info):
368-
if PyArray_HASFIELDS(self):
369-
PyObject_Free(info.format)
370-
if sizeof(npy_intp) != sizeof(Py_ssize_t):
371-
PyObject_Free(info.strides)
372-
# info.shape was stored after info.strides in the same block
373-
374-
375284
ctypedef unsigned char npy_bool
376285

377286
ctypedef signed char npy_byte

0 commit comments

Comments
 (0)
0