From 772dfd5dcb0e59459a8ff4924ff5cb2383b7c5d3 Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Sun, 7 Jun 2020 17:47:11 -0600 Subject: [PATCH] Fix the error handling for the PyObject_GetBuffer() calls in pybuffer.i Closes #1640. --- Lib/python/pybuffer.i | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/Lib/python/pybuffer.i b/Lib/python/pybuffer.i index 577eb69c8..2fdaa6d6e 100644 --- a/Lib/python/pybuffer.i +++ b/Lib/python/pybuffer.i @@ -17,13 +17,13 @@ int res; Py_ssize_t size = 0; void *buf = 0; Py_buffer view; res = PyObject_GetBuffer($input, &view, PyBUF_WRITABLE); - size = view.len; - buf = view.buf; - PyBuffer_Release(&view); if (res < 0) { PyErr_Clear(); %argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum); } + size = view.len; + buf = view.buf; + PyBuffer_Release(&view); $1 = ($1_ltype) buf; $2 = ($2_ltype) (size/sizeof($*1_type)); } @@ -47,12 +47,12 @@ int res; void *buf = 0; Py_buffer view; res = PyObject_GetBuffer($input, &view, PyBUF_WRITABLE); - buf = view.buf; - PyBuffer_Release(&view); if (res < 0) { PyErr_Clear(); %argument_fail(res, "(TYPEMAP)", $symname, $argnum); } + buf = view.buf; + PyBuffer_Release(&view); $1 = ($1_ltype) buf; } %enddef @@ -76,13 +76,13 @@ int res; Py_ssize_t size = 0; const void *buf = 0; Py_buffer view; res = PyObject_GetBuffer($input, &view, PyBUF_CONTIG_RO); - size = view.len; - buf = view.buf; - PyBuffer_Release(&view); if (res < 0) { PyErr_Clear(); %argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum); } + size = view.len; + buf = view.buf; + PyBuffer_Release(&view); $1 = ($1_ltype) buf; $2 = ($2_ltype) (size / sizeof($*1_type)); } @@ -108,14 +108,12 @@ int res; const void *buf = 0; Py_buffer view; res = PyObject_GetBuffer($input, &view, PyBUF_CONTIG_RO); - buf = view.buf; - PyBuffer_Release(&view); if (res < 0) { + PyErr_Clear(); %argument_fail(res, "(TYPEMAP)", $symname, $argnum); } + buf = view.buf; + PyBuffer_Release(&view); $1 = ($1_ltype) buf; } %enddef - - -