[xiph-cvs] cvs commit: vorbis-python/src pyvorbiscodec.c pyvorbisfile.c pyvorbisfile.h pyvorbisinfo.c vorbismodule.c

Andrew Catham Master of Python andrew at xiph.org
Sun Feb 17 17:16:36 PST 2002



andrew      02/02/17 17:16:35

  Modified:    .        ChangeLog
               src      pyvorbiscodec.c pyvorbisfile.c pyvorbisfile.h
                        pyvorbisinfo.c vorbismodule.c
  Log:
  2002-02-17  Andrew H. Chatham <andrew.chatham at duke.edu>
          * pyvorbisfile.c: (py_ov_open): Fixed fd leak pointed out by
          Harald Meland. Also correctly incref file objects passed in to
          keep them open.
  
          * vorbismodule.c, pyvorbisfile.c, pyvorbiscodec.c, pyvorbisinfo.c:
          Set the ob_types in the init method instead of statically, as
          MSVC complains.

Revision  Changes    Path
1.12      +9 -0      vorbis-python/ChangeLog

Index: ChangeLog
===================================================================
RCS file: /usr/local/cvsroot/vorbis-python/ChangeLog,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ChangeLog	2002/01/28 05:00:36	1.11
+++ ChangeLog	2002/02/18 01:16:34	1.12
@@ -1,3 +1,12 @@
+2002-02-17  Andrew H. Chatham <andrew.chatham at duke.edu>
+	* pyvorbisfile.c: (py_ov_open): Fixed fd leak pointed out by
+	Harald Meland. Also correctly incref file objects passed in to
+	keep them open.
+
+	* vorbismodule.c, pyvorbisfile.c, pyvorbiscodec.c, pyvorbisinfo.c:
+	Set the ob_types in the init method instead of statically, as 
+	MSVC complains.
+
 2002-01-27  Andrew H. Chatham <andrew.chatham at duke.edu>
         * pyvorbisinfo.c (del_comment): Set parent to NULL after decref
         

<p><p>1.6       +2 -2      vorbis-python/src/pyvorbiscodec.c

Index: pyvorbiscodec.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-python/src/pyvorbiscodec.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- pyvorbiscodec.c	2002/01/27 11:14:19	1.5
+++ pyvorbiscodec.c	2002/02/18 01:16:34	1.6
@@ -35,7 +35,7 @@
 char py_dsp_doc[] = "";
 
 PyTypeObject py_dsp_type = {
-  PyObject_HEAD_INIT(&PyType_Type)
+  PyObject_HEAD_INIT(NULL)
   0,
   "VorbisDSPState",
   sizeof(py_dsp),
@@ -405,7 +405,7 @@
 char py_block_doc[] = "";
 
 PyTypeObject py_block_type = {
-  PyObject_HEAD_INIT(&PyType_Type)
+  PyObject_HEAD_INIT(NULL)
   0,
   "VorbisBlock",
   sizeof(py_block),

<p><p>1.5       +32 -20    vorbis-python/src/pyvorbisfile.c

Index: pyvorbisfile.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-python/src/pyvorbisfile.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- pyvorbisfile.c	2001/08/31 02:04:28	1.4
+++ pyvorbisfile.c	2002/02/18 01:16:34	1.5
@@ -8,9 +8,9 @@
 #include "pyvorbisinfo.h"
 
 /*  
-   *********************************************************
-                        VorbisFile Object methods 
-   *********************************************************
+*********************************************************
+VorbisFile Object methods 
+*********************************************************
 */
 
 char py_vorbisfile_doc[] = "";
@@ -37,21 +37,21 @@
 FDEF(ov_bitrate) "Returns the bitrate of this VorbisFile.";
 
 FDEF(ov_serialnumber) \
-"x.serialnumber(link):\n\n\
+     "x.serialnumber(link):\n\n\
 Returns the serialnumber of this VorbisFile. What's link do?";
 
 FDEF(ov_bitrate_instant) \
-"Returns the bitrate_instant value for this VorbisFile.";
+     "Returns the bitrate_instant value for this VorbisFile.";
 
-FDEF(ov_raw_total) "x.raw_total(i):\n\n\
+     FDEF(ov_raw_total) "x.raw_total(i):\n\n\
 Returns the raw_total value for this VorbisFile. What's i?";
 
 FDEF(ov_pcm_total) \
-"x.pcm_total(i):\n\n\
+     "x.pcm_total(i):\n\n\
 Returns the pcm_total value for this VorbisFile. What's i?";
 
 FDEF(ov_time_total) \
-"x.time_total(i):\n\n\
+     "x.time_total(i):\n\n\
 Returns the time_total value for this VorbisFile. What's i?";
 
 FDEF(ov_raw_seek) "x.raw_seek(pos):\n\nSeeks to raw position pos.";
@@ -65,7 +65,7 @@
 FDEF(ov_info) "Return an info object for this file";
 
 FDEF(ov_comment) \
-"Returns a dictionary of lists for the comments in this file.\n\
+     "Returns a dictionary of lists for the comments in this file.\n\
 All values are stored in uppercase, since values should be case-insensitive.";
 
 static PyObject *py_ov_file_getattr(PyObject *, char *name);
@@ -80,7 +80,7 @@
 The most useful method for a VorbisFile object is \"read\".";
 
 PyTypeObject py_vorbisfile_type = {
-  PyObject_HEAD_INIT(&PyType_Type)
+  PyObject_HEAD_INIT(NULL)
   0,
   "VorbisFile",
   sizeof(py_vorbisfile),
@@ -176,6 +176,9 @@
   if (PY_VORBISFILE(self))
     ov_clear(PY_VORBISFILE(self));
 
+  /* If file was opened from a file object, decref it, so it can close */
+  Py_XDECREF(((py_vorbisfile *) self)->py_file);
+
   PyMem_DEL(self);
 }
 
@@ -194,6 +197,7 @@
   if (PyArg_ParseTuple(args, "s|sl", &fname, &initial, &ibytes)) {
 
     file = fopen(fname, "r");
+    fobject = NULL;
 
     if (file == NULL) {
       snprintf(errmsg, MSG_SIZE, "Could not open file: %s", fname);
@@ -202,9 +206,10 @@
     }
 
   } else if (PyArg_ParseTuple(args, "O!|sl", &PyFile_Type, &fobject,
-			      &initial, &ibytes)) {
+                              &initial, &ibytes)) {
     PyErr_Clear(); /* clear first failure */
 
+    fname = NULL;
     file = PyFile_AsFile(fobject);
 
     if (file == NULL) 
@@ -212,16 +217,23 @@
 
   } else {
     PyErr_SetString(PyExc_TypeError, 
-		    "Argument 1 is not a filename or file object");
+                    "Argument 1 is not a filename or file object");
     return NULL;
   }
 
   self->ovf = (OggVorbis_File*) malloc(sizeof(OggVorbis_File));
+  self->py_file = fobject;
+  Py_XINCREF(fobject); /* Prevent the file from being closed */
   
   retval = ov_open(file, self->ovf, initial, ibytes);
+
+  if (retval < 0) {
+    if (fname != NULL)
+      fclose(file);
+    Py_XDECREF(self->py_file);
 
-  if (retval < 0)
     return v_error_from_code(retval, "Error opening file: ");
+  }
 
   Py_INCREF(Py_None);
   return Py_None;
@@ -250,7 +262,7 @@
   sgned = 1;
 
   if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|llll", read_kwlist,
-				   &length, &bigendianp, &word, &sgned))
+                                   &length, &bigendianp, &word, &sgned))
     return NULL;
 
   buffobj = PyBuffer_New(length);
@@ -265,14 +277,14 @@
   Py_DECREF(tuple);
 
   Py_BEGIN_ALLOW_THREADS
-  retval = ov_read(ov_self->ovf, buff, length, 
-		   bigendianp, word, sgned, &bitstream);
+    retval = ov_read(ov_self->ovf, buff, length, 
+                     bigendianp, word, sgned, &bitstream);
   Py_END_ALLOW_THREADS
 
-  if (retval < 0) {
-    Py_DECREF(buffobj);
-    return v_error_from_code(retval, "Error reading file: ");
-  }
+    if (retval < 0) {
+      Py_DECREF(buffobj);
+      return v_error_from_code(retval, "Error reading file: ");
+    }
 
   retobj = Py_BuildValue("Oii", buffobj, retval, bitstream);
   Py_DECREF(buffobj);

<p><p>1.4       +2 -0      vorbis-python/src/pyvorbisfile.h

Index: pyvorbisfile.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-python/src/pyvorbisfile.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- pyvorbisfile.h	2001/06/01 20:54:46	1.3
+++ pyvorbisfile.h	2002/02/18 01:16:34	1.4
@@ -7,9 +7,11 @@
 typedef struct {
   PyObject_HEAD
   OggVorbis_File *ovf;
+  PyObject *py_file;
 } py_vorbisfile;
 
 #define PY_VORBISFILE(x) (((py_vorbisfile *)x)->ovf)
+#define PY_VORBISFILEOBJECT(x) (((py_vorbisfile *)x)->py_file)
 extern PyTypeObject py_vorbisfile_type;
 
 #endif /* __PYVORBIS_FILE_H__ */

<p><p>1.8       +2 -2      vorbis-python/src/pyvorbisinfo.c

Index: pyvorbisinfo.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-python/src/pyvorbisinfo.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- pyvorbisinfo.c	2002/01/28 05:00:36	1.7
+++ pyvorbisinfo.c	2002/02/18 01:16:34	1.8
@@ -37,7 +37,7 @@
 Information is stored as attributes.";
 
 PyTypeObject py_vinfo_type = {
-  PyObject_HEAD_INIT(&PyType_Type)
+  PyObject_HEAD_INIT(NULL)
   0,
   "VorbisInfo",
   sizeof(py_vinfo),
@@ -285,7 +285,7 @@
 in value().";
 
 PyTypeObject py_vcomment_type = {
-  PyObject_HEAD_INIT(&PyType_Type)
+  PyObject_HEAD_INIT(NULL)
   0,
   "VorbisComment",
   sizeof(py_vcomment),

<p><p>1.2       +6 -0      vorbis-python/src/vorbismodule.c

Index: vorbismodule.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-python/src/vorbismodule.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- vorbismodule.c	2001/02/06 03:20:48	1.1
+++ vorbismodule.c	2002/02/18 01:16:34	1.2
@@ -78,6 +78,12 @@
 {
   PyObject *module, *dict;
 
+  py_dsp_type.ob_type = &PyType_Type;
+  py_block_type.ob_type = &PyType_Type;
+  py_vorbisfile_type.ob_type = &PyType_Type;
+  py_vinfo_type.ob_type = &PyType_Type;
+  py_vcomment_type.ob_type = &PyType_Type;
+
   module = Py_InitModule("ogg.vorbis", Vorbis_methods);
   dict = PyModule_GetDict(module);
   

<p><p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list