Commit ec0add58 authored by Mark Florisson's avatar Mark Florisson

Decref capsules & fix py3 numpy test output

parent 1d00d8ad
...@@ -107,7 +107,7 @@ typedef struct { ...@@ -107,7 +107,7 @@ typedef struct {
/////////////// GetAndReleaseBuffer /////////////// /////////////// GetAndReleaseBuffer ///////////////
#if PY_MAJOR_VERSION < 3 #if PY_MAJOR_VERSION < 3
static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
PyObject *getbuffer_cobj = NULL; PyObject *getbuffer_cobj;
#if PY_VERSION_HEX >= 0x02060000 #if PY_VERSION_HEX >= 0x02060000
if (PyObject_CheckBuffer(obj)) return PyObject_GetBuffer(obj, view, flags); if (PyObject_CheckBuffer(obj)) return PyObject_GetBuffer(obj, view, flags);
...@@ -130,6 +130,7 @@ static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { ...@@ -130,6 +130,7 @@ static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
#else #else
func = (getbufferproc) PyCObject_AsVoidPtr(getbuffer_cobj); func = (getbufferproc) PyCObject_AsVoidPtr(getbuffer_cobj);
#endif #endif
Py_DECREF(getbuffer_cobj);
if (!func) if (!func)
goto fail; goto fail;
...@@ -144,13 +145,13 @@ static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) { ...@@ -144,13 +145,13 @@ static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
#if PY_VERSION_HEX < 0x02060000 #if PY_VERSION_HEX < 0x02060000
fail: fail:
#endif #endif
Py_XDECREF(getbuffer_cobj);
return -1; return -1;
} }
static void __Pyx_ReleaseBuffer(Py_buffer *view) { static void __Pyx_ReleaseBuffer(Py_buffer *view) {
PyObject* obj = view->obj; PyObject *obj = view->obj;
PyObject *releasebuffer_cobj = NULL; PyObject *releasebuffer_cobj;
if (!obj) return; if (!obj) return;
...@@ -179,6 +180,8 @@ static void __Pyx_ReleaseBuffer(Py_buffer *view) { ...@@ -179,6 +180,8 @@ static void __Pyx_ReleaseBuffer(Py_buffer *view) {
func = (releasebufferproc) PyCObject_AsVoidPtr(releasebuffer_cobj); func = (releasebufferproc) PyCObject_AsVoidPtr(releasebuffer_cobj);
#endif #endif
Py_DECREF(releasebuffer_cobj);
if (!func) if (!func)
goto fail; goto fail;
...@@ -197,7 +200,6 @@ fail: ...@@ -197,7 +200,6 @@ fail:
PyErr_WriteUnraisable(obj); PyErr_WriteUnraisable(obj);
nofail: nofail:
Py_XDECREF(releasebuffer_cobj);
Py_DECREF(obj); Py_DECREF(obj);
view->obj = NULL; view->obj = NULL;
} }
......
...@@ -176,12 +176,23 @@ try: ...@@ -176,12 +176,23 @@ try:
ValueError: Buffer dtype mismatch, expected 'int' but got 'float' in 'DoubleInt.y' ValueError: Buffer dtype mismatch, expected 'int' but got 'float' in 'DoubleInt.y'
>>> print(test_packed_align(np.zeros((1,), dtype=np.dtype('b,i', align=False)))) >>> print(test_packed_align(np.zeros((1,), dtype=np.dtype('b,i', align=False))))
array([(22, 23)], [(22, 23)]
dtype=[('f0', '|i1'), ('f1', '!i4')])
>>> print(test_unpacked_align(np.zeros((1,), dtype=np.dtype('b,i', align=True))))
The output changed in Python 3:
>> print(test_unpacked_align(np.zeros((1,), dtype=np.dtype('b,i', align=True))))
array([(22, 23)], array([(22, 23)],
dtype=[('f0', '|i1'), ('', '|V3'), ('f1', '!i4')]) dtype=[('f0', '|i1'), ('', '|V3'), ('f1', '!i4')])
->
array([(22, 23)],
dtype={'names':['f0','f1'], 'formats':['i1','!i4'], 'offsets':[0,4], 'itemsize':8, 'aligned':True})
>>> print(test_unpacked_align(np.zeros((1,), dtype=np.dtype('b,i', align=True))))
[(22, 23)]
>>> print(test_packed_align(np.zeros((1,), dtype=np.dtype('b,i', align=True)))) #doctest: +ELLIPSIS >>> print(test_packed_align(np.zeros((1,), dtype=np.dtype('b,i', align=True)))) #doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... ...
...@@ -444,12 +455,13 @@ cdef packed struct PartiallyPackedStruct2: ...@@ -444,12 +455,13 @@ cdef packed struct PartiallyPackedStruct2:
def test_packed_align(np.ndarray[PackedStruct] arr): def test_packed_align(np.ndarray[PackedStruct] arr):
arr[0].a = 22 arr[0].a = 22
arr[0].b = 23 arr[0].b = 23
return repr(arr).replace('<', '!').replace('>', '!') return list(arr)
def test_unpacked_align(np.ndarray[UnpackedStruct] arr): def test_unpacked_align(np.ndarray[UnpackedStruct] arr):
arr[0].a = 22 arr[0].a = 22
arr[0].b = 23 arr[0].b = 23
return repr(arr).replace('<', '!').replace('>', '!') # return repr(arr).replace('<', '!').replace('>', '!')
return list(arr)
def test_partially_packed_align(np.ndarray[PartiallyPackedStruct] arr): def test_partially_packed_align(np.ndarray[PartiallyPackedStruct] arr):
arr[0].a = 22 arr[0].a = 22
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment