Merge branch 'PyBuffer_Release-pybuffer'

* PyBuffer_Release-pybuffer:
  Add tests.
  Fix the error handling for the PyObject_GetBuffer() calls in pybuffer.i
This commit is contained in:
William S Fulton 2020-10-07 22:37:17 +01:00
commit 4d5f4bcd33
2 changed files with 35 additions and 13 deletions

View file

@ -44,3 +44,27 @@ else:
buf3 = bytearray(b"hello")
python_pybuffer.title1(buf3)
check(buf3 == b"Hello")
try:
python_pybuffer.func1(1)
raise RuntimeError, "should throw TypeError"
except TypeError, e:
check("(char *buf1, int len)" in str(e))
try:
python_pybuffer.func2(1)
raise RuntimeError, "should throw TypeError"
except TypeError, e:
check("(char *buf2)" in str(e))
try:
python_pybuffer.func3(1)
raise RuntimeError, "should throw TypeError"
except TypeError, e:
check("(const char *buf3, int len)" in str(e))
try:
python_pybuffer.func4(1)
raise RuntimeError, "should throw TypeError"
except TypeError, e:
check("(const char *buf4)" in str(e))

View file

@ -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