summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatus Valo <matusvalo@gmail.com>2017-09-10 12:11:47 -0700
committerMatus Valo <matusvalo@gmail.com>2017-09-10 12:11:47 -0700
commita6dee4ff3a5e515ff421a6802c828dc51bb85d30 (patch)
treef262e35ff03fa17757fee4b1248de114619d47cc
parent6c99d6cab01a26d71f9da79fe876420bc54507ce (diff)
downloadlibrabbitmq-a6dee4ff3a5e515ff421a6802c828dc51bb85d30.tar.gz
Use memoryviews instead of old style buffers
-rw-r--r--Modules/_librabbitmq/connection.c6
-rw-r--r--Modules/_librabbitmq/connection.h15
2 files changed, 17 insertions, 4 deletions
diff --git a/Modules/_librabbitmq/connection.c b/Modules/_librabbitmq/connection.c
index 34648f9..927b7e3 100644
--- a/Modules/_librabbitmq/connection.c
+++ b/Modules/_librabbitmq/connection.c
@@ -1392,16 +1392,14 @@ PyRabbitMQ_recv(PyRabbitMQ_Connection *self, PyObject *p,
buf = PyBytes_AsString(payload);
if (!buf)
goto finally;
- view = PyBuffer_FromObject(payload, 0,
- (Py_ssize_t)body_target);
+ view = PyMemoryView_FromObject(payload);
}
else {
if (p) {
payload = PySTRING_FROM_AMQBYTES(
frame.payload.body_fragment);
} else {
- view = PyBuffer_FromMemory(bufp,
- (Py_ssize_t)frame.payload.body_fragment.len);
+ view = buffer_toMemoryView(bufp, (Py_ssize_t)frame.payload.body_fragment.len);
}
break;
}
diff --git a/Modules/_librabbitmq/connection.h b/Modules/_librabbitmq/connection.h
index d9a00f6..972b781 100644
--- a/Modules/_librabbitmq/connection.h
+++ b/Modules/_librabbitmq/connection.h
@@ -45,6 +45,21 @@
# endif
#endif
+
+_PYRMQ_INLINE PyObject*
+buffer_toMemoryView(char *buf, Py_ssize_t buf_len) {
+ PyObject *view;
+#if PY_MAJOR_VERSION == 2
+ PyObject *pybuffer;
+ pybuffer = PyBuffer_FromMemory(buf, buf_len);
+ view = PyMemoryView_FromObject(pybuffer);
+ Py_XDECREF(pybuffer);
+#else
+ view = PyMemoryView_FromMemory(buf, buf_len, PyBUF_READ);
+#endif
+ return view;
+}
+
#define PyDICT_SETNONE_DECREF(dict, key) \
do { \
PyDict_SetItem(dict, key, Py_None); \