diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py index 95a0100c0..6b6c36732 100644 --- a/Lib/test/test_marshal.py +++ b/Lib/test/test_marshal.py @@ -64,8 +64,6 @@ class IntTestCase(unittest.TestCase, HelperMixin): self.helper(b) class FloatTestCase(unittest.TestCase, HelperMixin): - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_floats(self): # Test a few floats small = 1e-25 @@ -200,14 +198,11 @@ class BugsTestCase(unittest.TestCase): self.assertRaises(Exception, marshal.loads, b'f') self.assertRaises(Exception, marshal.loads, marshal.dumps(2**65)[:-1]) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_version_argument(self): # Python 2.4.0 crashes for any call to marshal.dumps(x, y) self.assertEqual(marshal.loads(marshal.dumps(5, 0)), 5) self.assertEqual(marshal.loads(marshal.dumps(5, 1)), 5) - @unittest.skip("TODO: RUSTPYTHON; panic") def test_fuzz(self): # simple test that it's at least not *totally* trivial to # crash from bad marshal data @@ -505,8 +500,7 @@ class InstancingTestCase(unittest.TestCase, HelperMixin): self.helper(code) self.helper3(code) - # TODO: RUSTPYTHON - @unittest.expectedFailure + @unittest.skip("TODO: RUSTPYTHON") def testRecursion(self): obj = 1.2345 d = {"hello": obj, "goodbye": obj, obj: "hello"} @@ -525,23 +519,15 @@ class CompatibilityTestCase(unittest.TestCase): data = marshal.dumps(code, version) marshal.loads(data) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test0To3(self): self._test(0) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test1To3(self): self._test(1) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test2To3(self): self._test(2) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test3To3(self): self._test(3) @@ -558,8 +544,6 @@ class InterningTestCase(unittest.TestCase, HelperMixin): s2 = sys.intern(s) self.assertEqual(id(s2), id(s)) - # TODO: RUSTPYTHON - @unittest.expectedFailure def testNoIntern(self): s = marshal.loads(marshal.dumps(self.strobj, 2)) self.assertEqual(s, self.strobj) diff --git a/vm/src/stdlib/marshal.rs b/vm/src/stdlib/marshal.rs index 4b24384c9..21d575e3b 100644 --- a/vm/src/stdlib/marshal.rs +++ b/vm/src/stdlib/marshal.rs @@ -9,7 +9,7 @@ mod decl { }, bytecode, convert::ToPyObject, - function::ArgBytesLike, + function::{ArgBytesLike, OptionalArg}, object::AsObject, protocol::PyBuffer, PyObjectRef, PyResult, TryFromObject, VirtualMachine, @@ -84,6 +84,9 @@ mod decl { } } + #[pyattr(name = "version")] + const VERSION: u32 = 4; + fn too_short_error(vm: &VirtualMachine) -> PyBaseExceptionRef { vm.new_exception_msg( vm.ctx.exceptions.eof_error.to_owned(), @@ -201,15 +204,24 @@ mod decl { } #[pyfunction] - fn dumps(value: PyObjectRef, vm: &VirtualMachine) -> PyResult { + fn dumps( + value: PyObjectRef, + _version: OptionalArg, + vm: &VirtualMachine, + ) -> PyResult { let mut buf = Vec::new(); dump_obj(&mut buf, value, vm)?; Ok(PyBytes::from(buf)) } #[pyfunction] - fn dump(value: PyObjectRef, f: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> { - let dumped = dumps(value, vm)?; + fn dump( + value: PyObjectRef, + f: PyObjectRef, + version: OptionalArg, + vm: &VirtualMachine, + ) -> PyResult<()> { + let dumped = dumps(value, version, vm)?; vm.call_method(&f, "write", (dumped,))?; Ok(()) }