mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
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.
This commit is contained in:
parent
f964154b8c
commit
2ccea17856
3 changed files with 9 additions and 4 deletions
|
@ -62,7 +62,7 @@ operating on strings.
|
||||||
|
|
||||||
The module defines these functions:
|
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
|
Write the value on the open file. The value must be a supported
|
||||||
type. The file must be an open file object such as
|
type. The file must be an open file object such as
|
||||||
\code{sys.stdout} or returned by \function{open()} or
|
\code{sys.stdout} or returned by \function{open()} or
|
||||||
|
@ -75,7 +75,7 @@ The module defines these functions:
|
||||||
read back by \function{load()}.
|
read back by \function{load()}.
|
||||||
|
|
||||||
\versionadded[The \var{version} argument indicates the data
|
\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}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{load}{file}
|
\begin{funcdesc}{load}{file}
|
||||||
|
@ -96,7 +96,7 @@ The module defines these functions:
|
||||||
contains an object that has) an unsupported type.
|
contains an object that has) an unsupported type.
|
||||||
|
|
||||||
\versionadded[The \var{version} argument indicates the data
|
\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}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{loads}{string}
|
\begin{funcdesc}{loads}{string}
|
||||||
|
|
|
@ -180,6 +180,11 @@ class BugsTestCase(unittest.TestCase):
|
||||||
self.assertRaises(Exception, marshal.loads, 'f')
|
self.assertRaises(Exception, marshal.loads, 'f')
|
||||||
self.assertRaises(Exception, marshal.loads, marshal.dumps(5L)[:-1])
|
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():
|
def test_main():
|
||||||
test_support.run_unittest(IntTestCase,
|
test_support.run_unittest(IntTestCase,
|
||||||
FloatTestCase,
|
FloatTestCase,
|
||||||
|
|
|
@ -893,7 +893,7 @@ marshal_dumps(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *x;
|
PyObject *x;
|
||||||
int version = Py_MARSHAL_VERSION;
|
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 NULL;
|
||||||
return PyMarshal_WriteObjectToString(x, version);
|
return PyMarshal_WriteObjectToString(x, version);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue