mirror of
https://github.com/python/cpython.git
synced 2025-09-27 18:59:43 +00:00
Add method names to PyArg_ParseTuple() calls for better error messages.
Convert to four-space indents.
This commit is contained in:
parent
5443c49fbb
commit
da940d8f8d
1 changed files with 281 additions and 296 deletions
|
@ -68,7 +68,7 @@ newladobject(PyObject *arg)
|
|||
char *opendev;
|
||||
|
||||
/* Check arg for r/w/rw */
|
||||
if (!PyArg_ParseTuple(arg, "s", &mode)) return NULL;
|
||||
if (!PyArg_ParseTuple(arg, "s:open", &mode)) return NULL;
|
||||
if (strcmp(mode, "r") == 0)
|
||||
imode = 0;
|
||||
else if (strcmp(mode, "w") == 0)
|
||||
|
@ -90,19 +90,14 @@ newladobject(PyObject *arg)
|
|||
PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (imode) {
|
||||
if (ioctl(fd, SNDCTL_DSP_NONBLOCK, NULL) < 0) {
|
||||
if (imode && ioctl(fd, SNDCTL_DSP_NONBLOCK, NULL) < 0) {
|
||||
PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (ioctl(fd, SNDCTL_DSP_GETFMTS, &afmts) < 0) {
|
||||
PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Create and initialize the object */
|
||||
if ((xp = PyObject_New(lad_t, &Ladtype)) == NULL) {
|
||||
close(fd);
|
||||
|
@ -128,21 +123,21 @@ lad_read(lad_t *self, PyObject *args)
|
|||
char *cp;
|
||||
PyObject *rv;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i", &size)) return NULL;
|
||||
if (!PyArg_ParseTuple(args, "i:read", &size))
|
||||
return NULL;
|
||||
rv = PyString_FromStringAndSize(NULL, size);
|
||||
if (rv == NULL) return NULL;
|
||||
if (rv == NULL)
|
||||
return NULL;
|
||||
|
||||
if (!(cp = PyString_AsString(rv))) {
|
||||
Py_DECREF(rv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((count = read(self->x_fd, cp, size)) < 0) {
|
||||
PyErr_SetFromErrno(LinuxAudioError);
|
||||
Py_DECREF(rv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
self->x_icount += count;
|
||||
return rv;
|
||||
}
|
||||
|
@ -153,7 +148,7 @@ lad_write(lad_t *self, PyObject *args)
|
|||
char *cp;
|
||||
int rv, size;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s#", &cp, &size)) return NULL;
|
||||
if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) return NULL;
|
||||
|
||||
while (size > 0) {
|
||||
if ((rv = write(self->x_fd, cp, size)) < 0) {
|
||||
|
@ -171,7 +166,7 @@ lad_write(lad_t *self, PyObject *args)
|
|||
static PyObject *
|
||||
lad_close(lad_t *self, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, "")) return NULL;
|
||||
if (!PyArg_ParseTuple(args, ":close")) return NULL;
|
||||
if (self->x_fd >= 0) {
|
||||
close(self->x_fd);
|
||||
self->x_fd = -1;
|
||||
|
@ -183,7 +178,7 @@ lad_close(lad_t *self, PyObject *args)
|
|||
static PyObject *
|
||||
lad_fileno(lad_t *self, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, "")) return NULL;
|
||||
if (!PyArg_ParseTuple(args, ":fileno")) return NULL;
|
||||
return PyInt_FromLong(self->x_fd);
|
||||
}
|
||||
|
||||
|
@ -192,30 +187,27 @@ lad_setparameters(lad_t *self, PyObject *args)
|
|||
{
|
||||
int rate, ssize, nchannels, stereo, n, fmt;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "iiii", &rate, &ssize, &nchannels, &fmt))
|
||||
if (!PyArg_ParseTuple(args, "iiii:setparameters",
|
||||
&rate, &ssize, &nchannels, &fmt))
|
||||
return NULL;
|
||||
|
||||
if (rate < 0 || ssize < 0 || (nchannels != 1 && nchannels != 2)) {
|
||||
PyErr_SetFromErrno(LinuxAudioError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ioctl(self->x_fd, SOUND_PCM_WRITE_RATE, &rate) < 0) {
|
||||
PyErr_SetFromErrno(LinuxAudioError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ioctl(self->x_fd, SNDCTL_DSP_SAMPLESIZE, &ssize) < 0) {
|
||||
PyErr_SetFromErrno(LinuxAudioError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
stereo = (nchannels == 1)? 0: (nchannels == 2)? 1: -1;
|
||||
if (ioctl(self->x_fd, SNDCTL_DSP_STEREO, &stereo) < 0) {
|
||||
PyErr_SetFromErrno(LinuxAudioError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (n = 0; n != sizeof(audio_types) / sizeof(audio_types[0]); n++)
|
||||
if (fmt == audio_types[n].a_fmt)
|
||||
break;
|
||||
|
@ -226,12 +218,10 @@ lad_setparameters(lad_t *self, PyObject *args)
|
|||
PyErr_SetFromErrno(LinuxAudioError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, &audio_types[n].a_fmt) < 0) {
|
||||
PyErr_SetFromErrno(LinuxAudioError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
@ -263,7 +253,6 @@ _ssize(lad_t *self, int *nchannels, int *ssize)
|
|||
default:
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
*nchannels = 0;
|
||||
if (ioctl(self->x_fd, SNDCTL_DSP_CHANNELS, nchannels) < 0)
|
||||
return -errno;
|
||||
|
@ -279,18 +268,16 @@ lad_bufsize(lad_t *self, PyObject *args)
|
|||
audio_buf_info ai;
|
||||
int nchannels, ssize;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "")) return NULL;
|
||||
if (!PyArg_ParseTuple(args, ":bufsize")) return NULL;
|
||||
|
||||
if (_ssize(self, &nchannels, &ssize) < 0) {
|
||||
PyErr_SetFromErrno(LinuxAudioError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
|
||||
PyErr_SetFromErrno(LinuxAudioError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return PyInt_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize));
|
||||
}
|
||||
|
||||
|
@ -302,18 +289,17 @@ lad_obufcount(lad_t *self, PyObject *args)
|
|||
audio_buf_info ai;
|
||||
int nchannels, ssize;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "")) return NULL;
|
||||
if (!PyArg_ParseTuple(args, ":obufcount"))
|
||||
return NULL;
|
||||
|
||||
if (_ssize(self, &nchannels, &ssize) < 0) {
|
||||
PyErr_SetFromErrno(LinuxAudioError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
|
||||
PyErr_SetFromErrno(LinuxAudioError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) /
|
||||
(ssize * nchannels));
|
||||
}
|
||||
|
@ -326,18 +312,17 @@ lad_obuffree(lad_t *self, PyObject *args)
|
|||
audio_buf_info ai;
|
||||
int nchannels, ssize;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "")) return NULL;
|
||||
if (!PyArg_ParseTuple(args, ":obuffree"))
|
||||
return NULL;
|
||||
|
||||
if (_ssize(self, &nchannels, &ssize) < 0) {
|
||||
PyErr_SetFromErrno(LinuxAudioError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
|
||||
PyErr_SetFromErrno(LinuxAudioError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return PyInt_FromLong(ai.bytes / (ssize * nchannels));
|
||||
}
|
||||
|
||||
|
@ -345,27 +330,26 @@ lad_obuffree(lad_t *self, PyObject *args)
|
|||
static PyObject *
|
||||
lad_flush(lad_t *self, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, "")) return NULL;
|
||||
if (!PyArg_ParseTuple(args, ":flush")) return NULL;
|
||||
|
||||
if (ioctl(self->x_fd, SNDCTL_DSP_SYNC, NULL) < 0) {
|
||||
PyErr_SetFromErrno(LinuxAudioError);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
static PyMethodDef lad_methods[] = {
|
||||
{ "read", (PyCFunction)lad_read, 1 },
|
||||
{ "write", (PyCFunction)lad_write, 1 },
|
||||
{ "setparameters", (PyCFunction)lad_setparameters, 1 },
|
||||
{ "bufsize", (PyCFunction)lad_bufsize, 1 },
|
||||
{ "obufcount", (PyCFunction)lad_obufcount, 1 },
|
||||
{ "obuffree", (PyCFunction)lad_obuffree, 1 },
|
||||
{ "flush", (PyCFunction)lad_flush, 1 },
|
||||
{ "close", (PyCFunction)lad_close, 1 },
|
||||
{ "fileno", (PyCFunction)lad_fileno, 1 },
|
||||
{ "read", (PyCFunction)lad_read, METH_VARARGS },
|
||||
{ "write", (PyCFunction)lad_write, METH_VARARGS },
|
||||
{ "setparameters", (PyCFunction)lad_setparameters, METH_VARARGS },
|
||||
{ "bufsize", (PyCFunction)lad_bufsize, METH_VARARGS },
|
||||
{ "obufcount", (PyCFunction)lad_obufcount, METH_VARARGS },
|
||||
{ "obuffree", (PyCFunction)lad_obuffree, METH_VARARGS },
|
||||
{ "flush", (PyCFunction)lad_flush, METH_VARARGS },
|
||||
{ "close", (PyCFunction)lad_close, METH_VARARGS },
|
||||
{ "fileno", (PyCFunction)lad_fileno, METH_VARARGS },
|
||||
{ NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
|
@ -397,7 +381,7 @@ ladopen(PyObject *self, PyObject *args)
|
|||
}
|
||||
|
||||
static PyMethodDef linuxaudiodev_methods[] = {
|
||||
{ "open", ladopen, 1 },
|
||||
{ "open", ladopen, METH_VARARGS },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
|
@ -411,6 +395,7 @@ ins(PyObject *d, char *symbol, long value)
|
|||
Py_DECREF(v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
initlinuxaudiodev()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue