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:
commit
4d5f4bcd33
2 changed files with 35 additions and 13 deletions
|
|
@ -44,3 +44,27 @@ else:
|
||||||
buf3 = bytearray(b"hello")
|
buf3 = bytearray(b"hello")
|
||||||
python_pybuffer.title1(buf3)
|
python_pybuffer.title1(buf3)
|
||||||
check(buf3 == b"Hello")
|
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))
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,13 @@
|
||||||
int res; Py_ssize_t size = 0; void *buf = 0;
|
int res; Py_ssize_t size = 0; void *buf = 0;
|
||||||
Py_buffer view;
|
Py_buffer view;
|
||||||
res = PyObject_GetBuffer($input, &view, PyBUF_WRITABLE);
|
res = PyObject_GetBuffer($input, &view, PyBUF_WRITABLE);
|
||||||
size = view.len;
|
|
||||||
buf = view.buf;
|
|
||||||
PyBuffer_Release(&view);
|
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
%argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
|
%argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
|
||||||
}
|
}
|
||||||
|
size = view.len;
|
||||||
|
buf = view.buf;
|
||||||
|
PyBuffer_Release(&view);
|
||||||
$1 = ($1_ltype) buf;
|
$1 = ($1_ltype) buf;
|
||||||
$2 = ($2_ltype) (size/sizeof($*1_type));
|
$2 = ($2_ltype) (size/sizeof($*1_type));
|
||||||
}
|
}
|
||||||
|
|
@ -47,12 +47,12 @@
|
||||||
int res; void *buf = 0;
|
int res; void *buf = 0;
|
||||||
Py_buffer view;
|
Py_buffer view;
|
||||||
res = PyObject_GetBuffer($input, &view, PyBUF_WRITABLE);
|
res = PyObject_GetBuffer($input, &view, PyBUF_WRITABLE);
|
||||||
buf = view.buf;
|
|
||||||
PyBuffer_Release(&view);
|
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
%argument_fail(res, "(TYPEMAP)", $symname, $argnum);
|
%argument_fail(res, "(TYPEMAP)", $symname, $argnum);
|
||||||
}
|
}
|
||||||
|
buf = view.buf;
|
||||||
|
PyBuffer_Release(&view);
|
||||||
$1 = ($1_ltype) buf;
|
$1 = ($1_ltype) buf;
|
||||||
}
|
}
|
||||||
%enddef
|
%enddef
|
||||||
|
|
@ -76,13 +76,13 @@
|
||||||
int res; Py_ssize_t size = 0; const void *buf = 0;
|
int res; Py_ssize_t size = 0; const void *buf = 0;
|
||||||
Py_buffer view;
|
Py_buffer view;
|
||||||
res = PyObject_GetBuffer($input, &view, PyBUF_CONTIG_RO);
|
res = PyObject_GetBuffer($input, &view, PyBUF_CONTIG_RO);
|
||||||
size = view.len;
|
|
||||||
buf = view.buf;
|
|
||||||
PyBuffer_Release(&view);
|
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
%argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
|
%argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
|
||||||
}
|
}
|
||||||
|
size = view.len;
|
||||||
|
buf = view.buf;
|
||||||
|
PyBuffer_Release(&view);
|
||||||
$1 = ($1_ltype) buf;
|
$1 = ($1_ltype) buf;
|
||||||
$2 = ($2_ltype) (size / sizeof($*1_type));
|
$2 = ($2_ltype) (size / sizeof($*1_type));
|
||||||
}
|
}
|
||||||
|
|
@ -108,14 +108,12 @@
|
||||||
int res; const void *buf = 0;
|
int res; const void *buf = 0;
|
||||||
Py_buffer view;
|
Py_buffer view;
|
||||||
res = PyObject_GetBuffer($input, &view, PyBUF_CONTIG_RO);
|
res = PyObject_GetBuffer($input, &view, PyBUF_CONTIG_RO);
|
||||||
buf = view.buf;
|
|
||||||
PyBuffer_Release(&view);
|
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
|
PyErr_Clear();
|
||||||
%argument_fail(res, "(TYPEMAP)", $symname, $argnum);
|
%argument_fail(res, "(TYPEMAP)", $symname, $argnum);
|
||||||
}
|
}
|
||||||
|
buf = view.buf;
|
||||||
|
PyBuffer_Release(&view);
|
||||||
$1 = ($1_ltype) buf;
|
$1 = ($1_ltype) buf;
|
||||||
}
|
}
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue