Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2ccea17

Browse files
committed
Any call to marshal.dumps() with the new optional argument 'version' just
immediately segfaults, due to a typo! This was obviously never tested... Added a test for it, and also fixed the documentation.
1 parent f964154 commit 2ccea17

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

Doc/lib/libmarshal.tex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ \section{\module{marshal} ---
6262

6363
The module defines these functions:
6464

65-
\begin{funcdesc}{dump}{value, file}
65+
\begin{funcdesc}{dump}{value, file\optional{, version}}
6666
Write the value on the open file. The value must be a supported
6767
type. The file must be an open file object such as
6868
\code{sys.stdout} or returned by \function{open()} or
@@ -75,7 +75,7 @@ \section{\module{marshal} ---
7575
read back by \function{load()}.
7676

7777
\versionadded[The \var{version} argument indicates the data
78-
format that \code{dumps} should use.]{2.4}
78+
format that \code{dump} should use (see below)]{2.4}
7979
\end{funcdesc}
8080

8181
\begin{funcdesc}{load}{file}
@@ -96,7 +96,7 @@ \section{\module{marshal} ---
9696
contains an object that has) an unsupported type.
9797

9898
\versionadded[The \var{version} argument indicates the data
99-
format that \code{dumps} should use.]{2.4}
99+
format that \code{dumps} should use (see below)]{2.4}
100100
\end{funcdesc}
101101

102102
\begin{funcdesc}{loads}{string}

Lib/test/test_marshal.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ def test_patch_873224(self):
180180
self.assertRaises(Exception, marshal.loads, 'f')
181181
self.assertRaises(Exception, marshal.loads, marshal.dumps(5L)[:-1])
182182

183+
def test_version_argument(self):
184+
# Python 2.4.0 crashes for any call to marshal.dumps(x, y)
185+
self.assertEquals(marshal.loads(marshal.dumps(5, 0)), 5)
186+
self.assertEquals(marshal.loads(marshal.dumps(5, 1)), 5)
187+
183188
def test_main():
184189
test_support.run_unittest(IntTestCase,
185190
FloatTestCase,

Python/marshal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ marshal_dumps(PyObject *self, PyObject *args)
893893
{
894894
PyObject *x;
895895
int version = Py_MARSHAL_VERSION;
896-
if (!PyArg_ParseTuple(args, "O|i:dumps", &x, version))
896+
if (!PyArg_ParseTuple(args, "O|i:dumps", &x, &version))
897897
return NULL;
898898
return PyMarshal_WriteObjectToString(x, version);
899899
}

0 commit comments

Comments
 (0)