Any call to marshal.dumps() with the new optional argument 'version' just
authorArmin Rigo <arigo@tunes.org>
Mon, 20 Dec 2004 12:25:57 +0000 (12:25 +0000)
committerArmin Rigo <arigo@tunes.org>
Mon, 20 Dec 2004 12:25:57 +0000 (12:25 +0000)
immediately segfaults, due to a typo!  This was obviously never tested...
Added a test for it, and also fixed the documentation.

Doc/lib/libmarshal.tex
Lib/test/test_marshal.py
Python/marshal.c

index 53ca6688562846abf8f64b6b098b75755c1716e9..d3dd83534721a458fa157810d5c12d2aaef85807 100644 (file)
@@ -62,7 +62,7 @@ operating on strings.
 
 The module defines these functions:
 
-\begin{funcdesc}{dump}{value, file}
+\begin{funcdesc}{dump}{value, file\optional{, version}}
   Write the value on the open file.  The value must be a supported
   type.  The file must be an open file object such as
   \code{sys.stdout} or returned by \function{open()} or
@@ -75,7 +75,7 @@ The module defines these functions:
   read back by \function{load()}.
 
   \versionadded[The \var{version} argument indicates the data
-  format that \code{dumps} should use.]{2.4}
+  format that \code{dump} should use (see below)]{2.4}
 \end{funcdesc}
 
 \begin{funcdesc}{load}{file}
@@ -96,7 +96,7 @@ The module defines these functions:
   contains an object that has) an unsupported type.
 
   \versionadded[The \var{version} argument indicates the data
-  format that \code{dumps} should use.]{2.4}
+  format that \code{dumps} should use (see below)]{2.4}
 \end{funcdesc}
 
 \begin{funcdesc}{loads}{string}
index eb0752178844e47ea07d9207229d2651d1270bda..5c1a3f3c6d27d333f90dfb8dcc0ce8b690e1a68e 100644 (file)
@@ -180,6 +180,11 @@ class BugsTestCase(unittest.TestCase):
         self.assertRaises(Exception, marshal.loads, 'f')
         self.assertRaises(Exception, marshal.loads, marshal.dumps(5L)[:-1])
 
+    def test_version_argument(self):
+        # Python 2.4.0 crashes for any call to marshal.dumps(x, y)
+        self.assertEquals(marshal.loads(marshal.dumps(5, 0)), 5)
+        self.assertEquals(marshal.loads(marshal.dumps(5, 1)), 5)
+
 def test_main():
     test_support.run_unittest(IntTestCase,
                               FloatTestCase,
index 590e1ca3911faa4ddc4f16d6cc483be2d0010f92..0ab0597d321bbb59b62bdc1e5b81a1bc93f82ce9 100644 (file)
@@ -893,7 +893,7 @@ marshal_dumps(PyObject *self, PyObject *args)
 {
        PyObject *x;
        int version = Py_MARSHAL_VERSION;
-       if (!PyArg_ParseTuple(args, "O|i:dumps", &x, version))
+       if (!PyArg_ParseTuple(args, "O|i:dumps", &x, &version))
                return NULL;
        return PyMarshal_WriteObjectToString(x, version);
 }