aboutsummaryrefslogtreecommitdiff
path: root/Lib/python/pybuffer.i
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/python/pybuffer.i')
-rw-r--r--Lib/python/pybuffer.i108
1 files changed, 95 insertions, 13 deletions
diff --git a/Lib/python/pybuffer.i b/Lib/python/pybuffer.i
index 577eb69c8..9ebc36a8c 100644
--- a/Lib/python/pybuffer.i
+++ b/Lib/python/pybuffer.i
@@ -12,18 +12,43 @@
* }
*/
+/* Note that in Py_LIMITED_API case we have no choice, but to use deprecated
+ * functions, as they provides the only way to access buffer data with limited
+ * API, which doesn't include Py_buffer definition. We also disable the
+ * warnings about doing this because they're not useful in our case.
+ */
+
%define %pybuffer_mutable_binary(TYPEMAP, SIZE)
%typemap(in) (TYPEMAP, SIZE) {
int res; Py_ssize_t size = 0; void *buf = 0;
+%#ifndef Py_LIMITED_API
Py_buffer view;
res = PyObject_GetBuffer($input, &view, PyBUF_WRITABLE);
- size = view.len;
- buf = view.buf;
- PyBuffer_Release(&view);
+%#else
+ %#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+ %#pragma GCC diagnostic push
+ %#pragma GCC diagnostic ignored "-Wdeprecated"
+ %#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+ %#elif defined(_MSC_VER)
+ %#pragma warning(push)
+ %#pragma warning(disable: 4996)
+ %#endif
+ res = PyObject_AsWriteBuffer($input, &buf, &size);
+ %#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+ %#pragma GCC diagnostic pop
+ %#elif defined(_MSC_VER)
+ %#pragma warning(pop)
+ %#endif
+%#endif
if (res < 0) {
PyErr_Clear();
%argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
}
+%#ifndef Py_LIMITED_API
+ size = view.len;
+ buf = view.buf;
+ PyBuffer_Release(&view);
+%#endif
$1 = ($1_ltype) buf;
$2 = ($2_ltype) (size/sizeof($*1_type));
}
@@ -45,14 +70,34 @@
%define %pybuffer_mutable_string(TYPEMAP)
%typemap(in) (TYPEMAP) {
int res; void *buf = 0;
+%#ifndef Py_LIMITED_API
Py_buffer view;
res = PyObject_GetBuffer($input, &view, PyBUF_WRITABLE);
- buf = view.buf;
- PyBuffer_Release(&view);
+%#else
+ %#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+ %#pragma GCC diagnostic push
+ %#pragma GCC diagnostic ignored "-Wdeprecated"
+ %#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+ %#elif defined(_MSC_VER)
+ %#pragma warning(push)
+ %#pragma warning(disable: 4996)
+ %#endif
+ Py_ssize_t size;
+ res = PyObject_AsWriteBuffer($input, &buf, &size);
+ %#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+ %#pragma GCC diagnostic pop
+ %#elif defined(_MSC_VER)
+ %#pragma warning(pop)
+ %#endif
+%#endif
if (res < 0) {
PyErr_Clear();
%argument_fail(res, "(TYPEMAP)", $symname, $argnum);
}
+%#ifndef Py_LIMITED_API
+ buf = view.buf;
+ PyBuffer_Release(&view);
+%#endif
$1 = ($1_ltype) buf;
}
%enddef
@@ -74,15 +119,34 @@
%define %pybuffer_binary(TYPEMAP, SIZE)
%typemap(in) (TYPEMAP, SIZE) {
int res; Py_ssize_t size = 0; const void *buf = 0;
+%#ifndef Py_LIMITED_API
Py_buffer view;
res = PyObject_GetBuffer($input, &view, PyBUF_CONTIG_RO);
- size = view.len;
- buf = view.buf;
- PyBuffer_Release(&view);
+%#else
+ %#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+ %#pragma GCC diagnostic push
+ %#pragma GCC diagnostic ignored "-Wdeprecated"
+ %#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+ %#elif defined(_MSC_VER)
+ %#pragma warning(push)
+ %#pragma warning(disable: 4996)
+ %#endif
+ res = PyObject_AsReadBuffer($input, &buf, &size);
+ %#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+ %#pragma GCC diagnostic pop
+ %#elif defined(_MSC_VER)
+ %#pragma warning(pop)
+ %#endif
+%#endif
if (res < 0) {
PyErr_Clear();
%argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
}
+%#ifndef Py_LIMITED_API
+ size = view.len;
+ buf = view.buf;
+ PyBuffer_Release(&view);
+%#endif
$1 = ($1_ltype) buf;
$2 = ($2_ltype) (size / sizeof($*1_type));
}
@@ -106,16 +170,34 @@
%define %pybuffer_string(TYPEMAP)
%typemap(in) (TYPEMAP) {
int res; const void *buf = 0;
+%#ifndef Py_LIMITED_API
Py_buffer view;
res = PyObject_GetBuffer($input, &view, PyBUF_CONTIG_RO);
- buf = view.buf;
- PyBuffer_Release(&view);
+%#else
+ %#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+ %#pragma GCC diagnostic push
+ %#pragma GCC diagnostic ignored "-Wdeprecated"
+ %#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+ %#elif defined(_MSC_VER)
+ %#pragma warning(push)
+ %#pragma warning(disable: 4996)
+ %#endif
+ Py_ssize_t size;
+ res = PyObject_AsReadBuffer($input, &buf, &size);
+ %#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+ %#pragma GCC diagnostic pop
+ %#elif defined(_MSC_VER)
+ %#pragma warning(pop)
+ %#endif
+%#endif
if (res < 0) {
+ PyErr_Clear();
%argument_fail(res, "(TYPEMAP)", $symname, $argnum);
}
+%#ifndef Py_LIMITED_API
+ buf = view.buf;
+ PyBuffer_Release(&view);
+%#endif
$1 = ($1_ltype) buf;
}
%enddef
-
-
-