[Python-checkins] CVS: python/dist/src/Modules linuxaudiodev.c,2.2,2.3
Fred L. Drake
python-dev@python.org
Fri, 7 Jul 2000 23:06:01 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv22913
Modified Files:
linuxaudiodev.c
Log Message:
Add method names to PyArg_ParseTuple() calls for better error messages.
Convert to four-space indents.
Index: linuxaudiodev.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/linuxaudiodev.c,v
retrieving revision 2.2
retrieving revision 2.3
diff -C2 -r2.2 -r2.3
*** linuxaudiodev.c 2000/05/03 23:44:32 2.2
--- linuxaudiodev.c 2000/07/08 06:05:58 2.3
***************
*** 33,54 ****
typedef struct {
! PyObject_HEAD;
! int x_fd; /* The open file */
! int x_icount; /* Input count */
! int x_ocount; /* Output count */
! uint32_t x_afmts; /* Supported audio formats */
} lad_t;
static struct {
! int a_bps;
! uint32_t a_fmt;
} audio_types[] = {
! { 8, AFMT_MU_LAW },
! { 8, AFMT_U8 },
! { 8, AFMT_S8 },
! { 16, AFMT_U16_BE },
! { 16, AFMT_U16_LE },
! { 16, AFMT_S16_BE },
! { 16, AFMT_S16_LE },
};
--- 33,54 ----
typedef struct {
! PyObject_HEAD;
! int x_fd; /* The open file */
! int x_icount; /* Input count */
! int x_ocount; /* Output count */
! uint32_t x_afmts; /* Supported audio formats */
} lad_t;
static struct {
! int a_bps;
! uint32_t a_fmt;
} audio_types[] = {
! { 8, AFMT_MU_LAW },
! { 8, AFMT_U8 },
! { 8, AFMT_S8 },
! { 16, AFMT_U16_BE },
! { 16, AFMT_U16_LE },
! { 16, AFMT_S16_BE },
! { 16, AFMT_S16_LE },
};
***************
*** 61,116 ****
newladobject(PyObject *arg)
{
! lad_t *xp;
! int fd, afmts, imode;
! char *mode;
! char *basedev;
! char *ctldev;
! char *opendev;
!
! /* Check arg for r/w/rw */
! if (!PyArg_ParseTuple(arg, "s", &mode)) return NULL;
! if (strcmp(mode, "r") == 0)
! imode = 0;
! else if (strcmp(mode, "w") == 0)
! imode = 1;
! else {
! PyErr_SetString(LinuxAudioError, "Mode should be one of 'r', or 'w'");
! return NULL;
! }
!
! /* Open the correct device. The base device name comes from the
! * AUDIODEV environment variable first, then /dev/audio. The
! * control device tacks "ctl" onto the base device name.
! */
! basedev = getenv("AUDIODEV");
! if (!basedev)
! basedev = "/dev/dsp";
!
! if ((fd = open(basedev, imode)) < 0) {
! PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev);
! return NULL;
! }
!
! if (imode) {
! if (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);
! return NULL;
! }
! xp->x_fd = fd;
! xp->x_icount = xp->x_ocount = 0;
! xp->x_afmts = afmts;
! return xp;
}
--- 61,111 ----
newladobject(PyObject *arg)
{
! lad_t *xp;
! int fd, afmts, imode;
! char *mode;
! char *basedev;
! char *ctldev;
! char *opendev;
!
! /* Check arg for r/w/rw */
! if (!PyArg_ParseTuple(arg, "s:open", &mode)) return NULL;
! if (strcmp(mode, "r") == 0)
! imode = 0;
! else if (strcmp(mode, "w") == 0)
! imode = 1;
! else {
! PyErr_SetString(LinuxAudioError, "Mode should be one of 'r', or 'w'");
! return NULL;
! }
!
! /* Open the correct device. The base device name comes from the
! * AUDIODEV environment variable first, then /dev/audio. The
! * control device tacks "ctl" onto the base device name.
! */
! basedev = getenv("AUDIODEV");
! if (!basedev)
! basedev = "/dev/dsp";
!
! if ((fd = open(basedev, imode)) < 0) {
! PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev);
! return NULL;
! }
! 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);
! return NULL;
! }
! xp->x_fd = fd;
! xp->x_icount = xp->x_ocount = 0;
! xp->x_afmts = afmts;
! return xp;
}
***************
*** 118,123 ****
lad_dealloc(lad_t *xp)
{
! close(xp->x_fd);
! PyObject_Del(xp);
}
--- 113,118 ----
lad_dealloc(lad_t *xp)
{
! close(xp->x_fd);
! PyObject_Del(xp);
}
***************
*** 125,149 ****
lad_read(lad_t *self, PyObject *args)
{
! int size, count;
! char *cp;
! PyObject *rv;
! if (!PyArg_ParseTuple(args, "i", &size)) return NULL;
! rv = PyString_FromStringAndSize(NULL, size);
! 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;
}
--- 120,144 ----
lad_read(lad_t *self, PyObject *args)
{
! int size, count;
! char *cp;
! PyObject *rv;
! if (!PyArg_ParseTuple(args, "i:read", &size))
! return NULL;
! rv = PyString_FromStringAndSize(NULL, size);
! 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;
}
***************
*** 151,170 ****
lad_write(lad_t *self, PyObject *args)
{
! char *cp;
! int rv, size;
! if (!PyArg_ParseTuple(args, "s#", &cp, &size)) return NULL;
! while (size > 0) {
! if ((rv = write(self->x_fd, cp, size)) < 0) {
! PyErr_SetFromErrno(LinuxAudioError);
! return NULL;
! }
! self->x_ocount += rv;
! size -= rv;
! cp += rv;
! }
! Py_INCREF(Py_None);
! return Py_None;
}
--- 146,165 ----
lad_write(lad_t *self, PyObject *args)
{
! char *cp;
! int rv, size;
! if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) return NULL;
! while (size > 0) {
! if ((rv = write(self->x_fd, cp, size)) < 0) {
! PyErr_SetFromErrno(LinuxAudioError);
! return NULL;
! }
! self->x_ocount += rv;
! size -= rv;
! cp += rv;
! }
! Py_INCREF(Py_None);
! return Py_None;
}
***************
*** 172,182 ****
lad_close(lad_t *self, PyObject *args)
{
! if (!PyArg_ParseTuple(args, "")) return NULL;
! if (self->x_fd >= 0) {
! close(self->x_fd);
! self->x_fd = -1;
! }
! Py_INCREF(Py_None);
! return Py_None;
}
--- 167,177 ----
lad_close(lad_t *self, PyObject *args)
{
! if (!PyArg_ParseTuple(args, ":close")) return NULL;
! if (self->x_fd >= 0) {
! close(self->x_fd);
! self->x_fd = -1;
! }
! Py_INCREF(Py_None);
! return Py_None;
}
***************
*** 184,189 ****
lad_fileno(lad_t *self, PyObject *args)
{
! if (!PyArg_ParseTuple(args, "")) return NULL;
! return PyInt_FromLong(self->x_fd);
}
--- 179,184 ----
lad_fileno(lad_t *self, PyObject *args)
{
! if (!PyArg_ParseTuple(args, ":fileno")) return NULL;
! return PyInt_FromLong(self->x_fd);
}
***************
*** 191,238 ****
lad_setparameters(lad_t *self, PyObject *args)
{
! int rate, ssize, nchannels, stereo, n, fmt;
! if (!PyArg_ParseTuple(args, "iiii", &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;
!
! if (n == sizeof(audio_types) / sizeof(audio_types[0]) ||
! audio_types[n].a_bps != ssize ||
! (self->x_afmts & audio_types[n].a_fmt) == 0) {
! 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;
}
--- 186,228 ----
lad_setparameters(lad_t *self, PyObject *args)
{
! int rate, ssize, nchannels, stereo, n, 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;
!
! if (n == sizeof(audio_types) / sizeof(audio_types[0]) ||
! audio_types[n].a_bps != ssize ||
! (self->x_afmts & audio_types[n].a_fmt) == 0) {
! 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;
}
***************
*** 240,296 ****
_ssize(lad_t *self, int *nchannels, int *ssize)
{
! int fmt;
! fmt = 0;
! if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
! return -errno;
!
! switch (fmt) {
! case AFMT_MU_LAW:
! case AFMT_A_LAW:
! case AFMT_U8:
! case AFMT_S8:
! *ssize = sizeof(char);
! break;
! case AFMT_S16_LE:
! case AFMT_S16_BE:
! case AFMT_U16_LE:
! case AFMT_U16_BE:
! *ssize = sizeof(short);
! break;
! case AFMT_MPEG:
! case AFMT_IMA_ADPCM:
! default:
! return -EOPNOTSUPP;
! }
!
! *nchannels = 0;
! if (ioctl(self->x_fd, SNDCTL_DSP_CHANNELS, nchannels) < 0)
! return -errno;
! return 0;
}
/* bufsize returns the size of the hardware audio buffer in number
! of samples */
static PyObject *
lad_bufsize(lad_t *self, PyObject *args)
{
! audio_buf_info ai;
! int nchannels, ssize;
!
! if (!PyArg_ParseTuple(args, "")) 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));
}
--- 230,283 ----
_ssize(lad_t *self, int *nchannels, int *ssize)
{
! int fmt;
! fmt = 0;
! if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
! return -errno;
!
! switch (fmt) {
! case AFMT_MU_LAW:
! case AFMT_A_LAW:
! case AFMT_U8:
! case AFMT_S8:
! *ssize = sizeof(char);
! break;
! case AFMT_S16_LE:
! case AFMT_S16_BE:
! case AFMT_U16_LE:
! case AFMT_U16_BE:
! *ssize = sizeof(short);
! break;
! case AFMT_MPEG:
! case AFMT_IMA_ADPCM:
! default:
! return -EOPNOTSUPP;
! }
! *nchannels = 0;
! if (ioctl(self->x_fd, SNDCTL_DSP_CHANNELS, nchannels) < 0)
! return -errno;
! return 0;
}
/* bufsize returns the size of the hardware audio buffer in number
! of samples */
static PyObject *
lad_bufsize(lad_t *self, PyObject *args)
{
! audio_buf_info ai;
! int nchannels, ssize;
! 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));
}
***************
*** 300,343 ****
lad_obufcount(lad_t *self, PyObject *args)
{
! audio_buf_info ai;
! int nchannels, ssize;
! if (!PyArg_ParseTuple(args, "")) 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));
}
/* obufcount returns the number of samples that can be played without
! blocking */
static PyObject *
lad_obuffree(lad_t *self, PyObject *args)
{
! audio_buf_info ai;
! int nchannels, ssize;
!
! if (!PyArg_ParseTuple(args, "")) 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));
}
--- 287,328 ----
lad_obufcount(lad_t *self, PyObject *args)
{
! audio_buf_info ai;
! int nchannels, ssize;
! 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));
}
/* obufcount returns the number of samples that can be played without
! blocking */
static PyObject *
lad_obuffree(lad_t *self, PyObject *args)
{
! audio_buf_info ai;
! int nchannels, ssize;
! 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));
}
***************
*** 346,371 ****
lad_flush(lad_t *self, PyObject *args)
{
! if (!PyArg_ParseTuple(args, "")) 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 },
! { NULL, NULL} /* sentinel */
};
--- 331,355 ----
lad_flush(lad_t *self, PyObject *args)
{
! 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, 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 */
};
***************
*** 373,392 ****
lad_getattr(lad_t *xp, char *name)
{
! return Py_FindMethod(lad_methods, (PyObject *)xp, name);
}
static PyTypeObject Ladtype = {
! PyObject_HEAD_INIT(&PyType_Type)
! 0, /*ob_size*/
! "linux_audio_device", /*tp_name*/
! sizeof(lad_t), /*tp_size*/
! 0, /*tp_itemsize*/
! /* methods */
! (destructor)lad_dealloc, /*tp_dealloc*/
! 0, /*tp_print*/
! (getattrfunc)lad_getattr, /*tp_getattr*/
! 0, /*tp_setattr*/
! 0, /*tp_compare*/
! 0, /*tp_repr*/
};
--- 357,376 ----
lad_getattr(lad_t *xp, char *name)
{
! return Py_FindMethod(lad_methods, (PyObject *)xp, name);
}
static PyTypeObject Ladtype = {
! PyObject_HEAD_INIT(&PyType_Type)
! 0, /*ob_size*/
! "linux_audio_device", /*tp_name*/
! sizeof(lad_t), /*tp_size*/
! 0, /*tp_itemsize*/
! /* methods */
! (destructor)lad_dealloc, /*tp_dealloc*/
! 0, /*tp_print*/
! (getattrfunc)lad_getattr, /*tp_getattr*/
! 0, /*tp_setattr*/
! 0, /*tp_compare*/
! 0, /*tp_repr*/
};
***************
*** 394,403 ****
ladopen(PyObject *self, PyObject *args)
{
! return (PyObject *)newladobject(args);
}
static PyMethodDef linuxaudiodev_methods[] = {
! { "open", ladopen, 1 },
! { 0, 0 },
};
--- 378,387 ----
ladopen(PyObject *self, PyObject *args)
{
! return (PyObject *)newladobject(args);
}
static PyMethodDef linuxaudiodev_methods[] = {
! { "open", ladopen, METH_VARARGS },
! { 0, 0 },
};
***************
*** 405,466 ****
ins(PyObject *d, char *symbol, long value)
{
! PyObject* v = PyInt_FromLong(value);
! if (!v || PyDict_SetItemString(d, symbol, v) < 0)
! return -1; /* triggers fatal error */
! Py_DECREF(v);
! return 0;
}
void
initlinuxaudiodev()
{
! PyObject *m, *d, *x;
! m = Py_InitModule("linuxaudiodev", linuxaudiodev_methods);
! d = PyModule_GetDict(m);
! LinuxAudioError = PyErr_NewException("linuxaudiodev.error", NULL, NULL);
! if (LinuxAudioError)
! PyDict_SetItemString(d, "error", LinuxAudioError);
!
! x = PyInt_FromLong((long) AFMT_MU_LAW);
! if (x == NULL || PyDict_SetItemString(d, "AFMT_MU_LAW", x) < 0)
! goto error;
! Py_DECREF(x);
!
! x = PyInt_FromLong((long) AFMT_U8);
! if (x == NULL || PyDict_SetItemString(d, "AFMT_U8", x) < 0)
! goto error;
! Py_DECREF(x);
!
! x = PyInt_FromLong((long) AFMT_S8);
! if (x == NULL || PyDict_SetItemString(d, "AFMT_S8", x) < 0)
! goto error;
! Py_DECREF(x);
!
! x = PyInt_FromLong((long) AFMT_U16_BE);
! if (x == NULL || PyDict_SetItemString(d, "AFMT_U16_BE", x) < 0)
! goto error;
! Py_DECREF(x);
!
! x = PyInt_FromLong((long) AFMT_U16_LE);
! if (x == NULL || PyDict_SetItemString(d, "AFMT_U16_LE", x) < 0)
! goto error;
! Py_DECREF(x);
!
! x = PyInt_FromLong((long) AFMT_S16_BE);
! if (x == NULL || PyDict_SetItemString(d, "AFMT_S16_BE", x) < 0)
! goto error;
! Py_DECREF(x);
!
! x = PyInt_FromLong((long) AFMT_S16_LE);
! if (x == NULL || PyDict_SetItemString(d, "AFMT_S16_LE", x) < 0)
! goto error;
! Py_DECREF(x);
!
! /* Check for errors */
! if (PyErr_Occurred()) {
! error:
! Py_FatalError("can't initialize module linuxaudiodev");
! }
}
--- 389,451 ----
ins(PyObject *d, char *symbol, long value)
{
! PyObject* v = PyInt_FromLong(value);
! if (!v || PyDict_SetItemString(d, symbol, v) < 0)
! return -1; /* triggers fatal error */
! Py_DECREF(v);
! return 0;
}
+
void
initlinuxaudiodev()
{
! PyObject *m, *d, *x;
! m = Py_InitModule("linuxaudiodev", linuxaudiodev_methods);
! d = PyModule_GetDict(m);
! LinuxAudioError = PyErr_NewException("linuxaudiodev.error", NULL, NULL);
! if (LinuxAudioError)
! PyDict_SetItemString(d, "error", LinuxAudioError);
!
! x = PyInt_FromLong((long) AFMT_MU_LAW);
! if (x == NULL || PyDict_SetItemString(d, "AFMT_MU_LAW", x) < 0)
! goto error;
! Py_DECREF(x);
!
! x = PyInt_FromLong((long) AFMT_U8);
! if (x == NULL || PyDict_SetItemString(d, "AFMT_U8", x) < 0)
! goto error;
! Py_DECREF(x);
!
! x = PyInt_FromLong((long) AFMT_S8);
! if (x == NULL || PyDict_SetItemString(d, "AFMT_S8", x) < 0)
! goto error;
! Py_DECREF(x);
!
! x = PyInt_FromLong((long) AFMT_U16_BE);
! if (x == NULL || PyDict_SetItemString(d, "AFMT_U16_BE", x) < 0)
! goto error;
! Py_DECREF(x);
!
! x = PyInt_FromLong((long) AFMT_U16_LE);
! if (x == NULL || PyDict_SetItemString(d, "AFMT_U16_LE", x) < 0)
! goto error;
! Py_DECREF(x);
!
! x = PyInt_FromLong((long) AFMT_S16_BE);
! if (x == NULL || PyDict_SetItemString(d, "AFMT_S16_BE", x) < 0)
! goto error;
! Py_DECREF(x);
!
! x = PyInt_FromLong((long) AFMT_S16_LE);
! if (x == NULL || PyDict_SetItemString(d, "AFMT_S16_LE", x) < 0)
! goto error;
! Py_DECREF(x);
!
! /* Check for errors */
! if (PyErr_Occurred()) {
! error:
! Py_FatalError("can't initialize module linuxaudiodev");
! }
}