Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(157850)

Unified Diff: Modules/ossaudiodev.c

Issue 23001: Accept mutable bytes-like objects
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
--- a/Modules/ossaudiodev.c Wed Mar 18 21:36:23 2015 -0500
+++ b/Modules/ossaudiodev.c Thu Mar 19 13:16:44 2015 +0200
@@ -430,20 +430,21 @@ oss_read(oss_audio_t *self, PyObject *ar
static PyObject *
oss_write(oss_audio_t *self, PyObject *args)
{
- char *cp;
- int rv, size;
+ Py_buffer data;
+ int rv;
if (!_is_fd_valid(self->fd))
return NULL;
- if (!PyArg_ParseTuple(args, "y#:write", &cp, &size)) {
+ if (!PyArg_ParseTuple(args, "y*:write", &data)) {
return NULL;
}
Py_BEGIN_ALLOW_THREADS
- rv = write(self->fd, cp, size);
+ rv = write(self->fd, data.buf, data.len);
Py_END_ALLOW_THREADS
+ PyBuffer_Release(&data);
if (rv == -1) {
return PyErr_SetFromErrno(PyExc_IOError);
} else {
@@ -455,8 +456,10 @@ oss_write(oss_audio_t *self, PyObject *a
static PyObject *
oss_writeall(oss_audio_t *self, PyObject *args)
{
- char *cp;
- int rv, size;
+ Py_buffer data;
+ const char *cp;
+ Py_ssize_t size;
+ int rv;
fd_set write_set_fds;
int select_rv;
@@ -470,41 +473,49 @@ oss_writeall(oss_audio_t *self, PyObject
if (!_is_fd_valid(self->fd))
return NULL;
- if (!PyArg_ParseTuple(args, "y#:write", &cp, &size))
+ if (!PyArg_ParseTuple(args, "y*:writeall", &data))
return NULL;
if (!_PyIsSelectable_fd(self->fd)) {
PyErr_SetString(PyExc_ValueError,
"file descriptor out of range for select");
+ PyBuffer_Release(&data);
return NULL;
}
/* use select to wait for audio device to be available */
FD_ZERO(&write_set_fds);
FD_SET(self->fd, &write_set_fds);
+ cp = (const char *)data.buf;
+ size = data.len;
while (size > 0) {
Py_BEGIN_ALLOW_THREADS
select_rv = select(self->fd+1, NULL, &write_set_fds, NULL, NULL);
Py_END_ALLOW_THREADS
assert(select_rv != 0); /* no timeout, can't expire */
- if (select_rv == -1)
+ if (select_rv == -1) {
+ PyBuffer_Release(&data);
return PyErr_SetFromErrno(PyExc_IOError);
+ }
Py_BEGIN_ALLOW_THREADS
- rv = write(self->fd, cp, size);
+ rv = write(self->fd, cp, Py_MIN(size, INT_MAX));
Py_END_ALLOW_THREADS
if (rv == -1) {
if (errno == EAGAIN) { /* buffer is full, try again */
errno = 0;
continue;
- } else /* it's a real error */
+ } else { /* it's a real error */
+ PyBuffer_Release(&data);
return PyErr_SetFromErrno(PyExc_IOError);
+ }
} else { /* wrote rv bytes */
self->ocount += rv;
size -= rv;
cp += rv;
}
}
+ PyBuffer_Release(&data);
Py_INCREF(Py_None);
return Py_None;
}
« Modules/fcntlmodule.c ('K') | « Modules/mmapmodule.c ('k') | Modules/socketmodule.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+