1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-26 09:47:58 +00:00

use PyMemoryView_FromMemory (py 3.3+)

This commit is contained in:
Thomas Waldmann 2015-12-15 01:00:28 +01:00
parent ef00f5d12d
commit 8e13d315bb

View file

@ -186,19 +186,6 @@ chunker_fill(Chunker *c)
return 1; return 1;
} }
static PyObject *
PyBuffer_FromMemory(void *data, Py_ssize_t len)
{
Py_buffer buffer;
PyObject *mv;
PyBuffer_FillInfo(&buffer, NULL, data, len, 1, PyBUF_CONTIG_RO);
mv = PyMemoryView_FromBuffer(&buffer);
PyBuffer_Release(&buffer);
return mv;
}
static PyObject * static PyObject *
chunker_process(Chunker *c) chunker_process(Chunker *c)
{ {
@ -221,7 +208,7 @@ chunker_process(Chunker *c)
c->done = 1; c->done = 1;
if(c->remaining) { if(c->remaining) {
c->bytes_yielded += c->remaining; c->bytes_yielded += c->remaining;
return PyBuffer_FromMemory(c->data + c->position, c->remaining); return PyMemoryView_FromMemory(c->data + c->position, c->remaining, PyBUF_READ);
} }
else { else {
if(c->bytes_read == c->bytes_yielded) if(c->bytes_read == c->bytes_yielded)
@ -253,5 +240,5 @@ chunker_process(Chunker *c)
c->last = c->position; c->last = c->position;
n = c->last - old_last; n = c->last - old_last;
c->bytes_yielded += n; c->bytes_yielded += n;
return PyBuffer_FromMemory(c->data + old_last, n); return PyMemoryView_FromMemory(c->data + old_last, n, PyBUF_READ);
} }