[Python-checkins] python/dist/src/Modules ossaudiodev.c, 1.35.4.1, 1.35.4.2

gward at users.sourceforge.net gward at users.sourceforge.net
Wed Mar 9 01:55:21 CET 2005


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24519/Modules

Modified Files:
      Tag: release24-maint
	ossaudiodev.c 
Log Message:
SF #818006: revert addition of 'closed', 'mode', and 'name' attributes
to oss_audio_device objects.


Index: ossaudiodev.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/ossaudiodev.c,v
retrieving revision 1.35.4.1
retrieving revision 1.35.4.2
diff -u -d -r1.35.4.1 -r1.35.4.2
--- ossaudiodev.c	7 Mar 2005 01:32:02 -0000	1.35.4.1
+++ ossaudiodev.c	9 Mar 2005 00:55:18 -0000	1.35.4.2
@@ -46,12 +46,11 @@
 
 typedef struct {
     PyObject_HEAD;
-    char    *devicename;              /* name of the device file */
-    int      fd;                      /* file descriptor */
-    int      mode;                    /* file mode (O_RDONLY, etc.) */
-    int      icount;                  /* input count */
-    int      ocount;                  /* output count */
-    uint32_t afmts;                   /* audio formats supported by hardware */
+    int      fd;                      /* The open file */
+    int      mode;                    /* file mode */
+    int      icount;                  /* Input count */
+    int      ocount;                  /* Output count */
+    uint32_t afmts;                   /* Audio formats supported by hardware */
 } oss_audio_t;
 
 typedef struct {
@@ -75,7 +74,7 @@
 {
     oss_audio_t *self;
     int fd, afmts, imode;
-    char *devicename = NULL;
+    char *basedev = NULL;
     char *mode = NULL;
 
     /* Two ways to call open():
@@ -83,11 +82,11 @@
          open(mode)         (for backwards compatibility)
        because the *first* argument is optional, parsing args is
        a wee bit tricky. */
-    if (!PyArg_ParseTuple(arg, "s|s:open", &devicename, &mode))
+    if (!PyArg_ParseTuple(arg, "s|s:open", &basedev, &mode))
        return NULL;
     if (mode == NULL) {                 /* only one arg supplied */
-       mode = devicename;
-       devicename = NULL;
+       mode = basedev;
+       basedev = NULL;
     }
 
     if (strcmp(mode, "r") == 0)
@@ -103,18 +102,18 @@
 
     /* Open the correct device: either the 'device' argument,
        or the AUDIODEV environment variable, or "/dev/dsp". */
-    if (devicename == NULL) {              /* called with one arg */
-       devicename = getenv("AUDIODEV");
-       if (devicename == NULL)             /* $AUDIODEV not set */
-          devicename = "/dev/dsp";
+    if (basedev == NULL) {              /* called with one arg */
+       basedev = getenv("AUDIODEV");
+       if (basedev == NULL)             /* $AUDIODEV not set */
+          basedev = "/dev/dsp";
     }
 
     /* Open with O_NONBLOCK to avoid hanging on devices that only allow
        one open at a time.  This does *not* affect later I/O; OSS
        provides a special ioctl() for non-blocking read/write, which is
        exposed via oss_nonblock() below. */
-    if ((fd = open(devicename, imode|O_NONBLOCK)) == -1) {
-        PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
+    if ((fd = open(basedev, imode|O_NONBLOCK)) == -1) {
+        PyErr_SetFromErrnoWithFilename(PyExc_IOError, basedev);
         return NULL;
     }
 
@@ -122,12 +121,12 @@
        expected write() semantics. */
     if (fcntl(fd, F_SETFL, 0) == -1) {
         close(fd);
-        PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
+        PyErr_SetFromErrnoWithFilename(PyExc_IOError, basedev);
         return NULL;
     }
 
     if (ioctl(fd, SNDCTL_DSP_GETFMTS, &afmts) == -1) {
-        PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
+        PyErr_SetFromErrnoWithFilename(PyExc_IOError, basedev);
         return NULL;
     }
     /* Create and initialize the object */
@@ -135,7 +134,6 @@
         close(fd);
         return NULL;
     }
-    self->devicename = devicename;
     self->fd = fd;
     self->mode = imode;
     self->icount = self->ocount = 0;
@@ -160,22 +158,22 @@
 static oss_mixer_t *
 newossmixerobject(PyObject *arg)
 {
-    char *devicename = NULL;
+    char *basedev = NULL;
     int fd;
     oss_mixer_t *self;
 
-    if (!PyArg_ParseTuple(arg, "|s", &devicename)) {
+    if (!PyArg_ParseTuple(arg, "|s", &basedev)) {
         return NULL;
     }
 
-    if (devicename == NULL) {
-        devicename = getenv("MIXERDEV");
-        if (devicename == NULL)            /* MIXERDEV not set */
-            devicename = "/dev/mixer";
+    if (basedev == NULL) {
+        basedev = getenv("MIXERDEV");
+        if (basedev == NULL)            /* MIXERDEV not set */
+            basedev = "/dev/mixer";
     }
 
-    if ((fd = open(devicename, O_RDWR)) == -1) {
-        PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
+    if ((fd = open(basedev, O_RDWR)) == -1) {
+        PyErr_SetFromErrnoWithFilename(PyExc_IOError, basedev);
         return NULL;
     }
 
@@ -829,33 +827,7 @@
 static PyObject *
 oss_getattr(oss_audio_t *self, char *name)
 {
-    PyObject * rval = NULL;
-    if (strcmp(name, "closed") == 0) {
-        rval = (self->fd == -1) ? Py_True : Py_False;
-        Py_INCREF(rval);
-    }
-    else if (strcmp(name, "name") == 0) {
-        rval = PyString_FromString(self->devicename);
-    }
-    else if (strcmp(name, "mode") == 0) {
-        /* No need for a "default" in this switch: from newossobject(),
-           self->mode can only be one of these three values. */
-        switch(self->mode) {
-            case O_RDONLY:
-                rval = PyString_FromString("r");
-                break;
-            case O_RDWR:
-                rval = PyString_FromString("rw");
-                break;
-            case O_WRONLY:
-                rval = PyString_FromString("w");
-                break;
-        }
-    }
-    else {
-        rval = Py_FindMethod(oss_methods, (PyObject *)self, name);
-    }
-    return rval;
+    return Py_FindMethod(oss_methods, (PyObject *)self, name);
 }
 
 static PyObject *



More information about the Python-checkins mailing list