Update pybuffer.i library to use new-style Python buffer C API.
Removed old API altogether as Python 2.7 is now the minimum version supported and it supports the new-style buffer API.
This commit is contained in:
parent
33f3dbb005
commit
4313c2c168
4 changed files with 18 additions and 33 deletions
|
|
@ -15,16 +15,12 @@
|
|||
%define %pybuffer_mutable_binary(TYPEMAP, SIZE)
|
||||
%typemap(in) (TYPEMAP, SIZE) {
|
||||
int res; Py_ssize_t size = 0; void *buf = 0;
|
||||
%#if PY_VERSION_HEX < 0x03000000
|
||||
res = PyObject_AsWriteBuffer($input, &buf, &size);
|
||||
%#else
|
||||
Py_buffer view;
|
||||
res = PyObject_GetBuffer($input, &view, PyBUF_WRITABLE);
|
||||
size = view.len;
|
||||
buf = view.buf;
|
||||
PyBuffer_Release(&view);
|
||||
%#endif
|
||||
if (res<0) {
|
||||
if (res < 0) {
|
||||
PyErr_Clear();
|
||||
%argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
|
||||
}
|
||||
|
|
@ -33,7 +29,7 @@
|
|||
}
|
||||
%enddef
|
||||
|
||||
/* %pybuffer_mutable_string(TYPEMAP, SIZE)
|
||||
/* %pybuffer_mutable_string(TYPEMAP)
|
||||
*
|
||||
* Macro for functions accept mutable zero terminated string pointer.
|
||||
* This can be used for both input and output. For example:
|
||||
|
|
@ -48,19 +44,14 @@
|
|||
|
||||
%define %pybuffer_mutable_string(TYPEMAP)
|
||||
%typemap(in) (TYPEMAP) {
|
||||
int res; Py_ssize_t size = 0; void *buf = 0;
|
||||
%#if PY_VERSION_HEX < 0x03000000
|
||||
res = PyObject_AsWriteBuffer($input, &buf, &size);
|
||||
%#else
|
||||
int res; void *buf = 0;
|
||||
Py_buffer view;
|
||||
res = PyObject_GetBuffer($input, &view, PyBUF_WRITABLE);
|
||||
size = view.len;
|
||||
buf = view.buf;
|
||||
PyBuffer_Release(&view);
|
||||
%#endif
|
||||
if (res<0) {
|
||||
if (res < 0) {
|
||||
PyErr_Clear();
|
||||
%argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
|
||||
%argument_fail(res, "(TYPEMAP)", $symname, $argnum);
|
||||
}
|
||||
$1 = ($1_ltype) buf;
|
||||
}
|
||||
|
|
@ -83,16 +74,12 @@
|
|||
%define %pybuffer_binary(TYPEMAP, SIZE)
|
||||
%typemap(in) (TYPEMAP, SIZE) {
|
||||
int res; Py_ssize_t size = 0; const void *buf = 0;
|
||||
%#if PY_VERSION_HEX < 0x03000000
|
||||
res = PyObject_AsReadBuffer($input, &buf, &size);
|
||||
%#else
|
||||
Py_buffer view;
|
||||
res = PyObject_GetBuffer($input, &view, PyBUF_CONTIG_RO);
|
||||
size = view.len;
|
||||
buf = view.buf;
|
||||
PyBuffer_Release(&view);
|
||||
%#endif
|
||||
if (res<0) {
|
||||
if (res < 0) {
|
||||
PyErr_Clear();
|
||||
%argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
|
||||
}
|
||||
|
|
@ -101,7 +88,7 @@
|
|||
}
|
||||
%enddef
|
||||
|
||||
/* %pybuffer_string(TYPEMAP, SIZE)
|
||||
/* %pybuffer_string(TYPEMAP)
|
||||
*
|
||||
* Macro for functions accept read only zero terminated string pointer.
|
||||
* This can be used for input. For example:
|
||||
|
|
@ -118,18 +105,13 @@
|
|||
|
||||
%define %pybuffer_string(TYPEMAP)
|
||||
%typemap(in) (TYPEMAP) {
|
||||
int res; Py_ssize_t size = 0; const void *buf = 0;
|
||||
%#if PY_VERSION_HEX < 0x03000000
|
||||
res = PyObject_AsReadBuffer($input, &buf, &size);
|
||||
%#else
|
||||
int res; const void *buf = 0;
|
||||
Py_buffer view;
|
||||
res = PyObject_GetBuffer($input, &view, PyBUF_CONTIG_RO);
|
||||
size = view.len;
|
||||
buf = view.buf;
|
||||
PyBuffer_Release(&view);
|
||||
%#endif
|
||||
if (res<0) {
|
||||
%argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
|
||||
if (res < 0) {
|
||||
%argument_fail(res, "(TYPEMAP)", $symname, $argnum);
|
||||
}
|
||||
$1 = ($1_ltype) buf;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue