Skip to content

Commit ec9fa50

Browse files
committed
marshal.version
1 parent b32493d commit ec9fa50

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

Lib/test/test_marshal.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ def test_bool(self):
6464
self.helper(b)
6565

6666
class FloatTestCase(unittest.TestCase, HelperMixin):
67-
# TODO: RUSTPYTHON
68-
@unittest.expectedFailure
6967
def test_floats(self):
7068
# Test a few floats
7169
small = 1e-25
@@ -200,14 +198,11 @@ def test_patch_873224(self):
200198
self.assertRaises(Exception, marshal.loads, b'f')
201199
self.assertRaises(Exception, marshal.loads, marshal.dumps(2**65)[:-1])
202200

203-
# TODO: RUSTPYTHON
204-
@unittest.expectedFailure
205201
def test_version_argument(self):
206202
# Python 2.4.0 crashes for any call to marshal.dumps(x, y)
207203
self.assertEqual(marshal.loads(marshal.dumps(5, 0)), 5)
208204
self.assertEqual(marshal.loads(marshal.dumps(5, 1)), 5)
209205

210-
@unittest.skip("TODO: RUSTPYTHON; panic")
211206
def test_fuzz(self):
212207
# simple test that it's at least not *totally* trivial to
213208
# crash from bad marshal data
@@ -505,8 +500,7 @@ def testModule(self):
505500
self.helper(code)
506501
self.helper3(code)
507502

508-
# TODO: RUSTPYTHON
509-
@unittest.expectedFailure
503+
@unittest.skip("TODO: RUSTPYTHON")
510504
def testRecursion(self):
511505
obj = 1.2345
512506
d = {"hello": obj, "goodbye": obj, obj: "hello"}
@@ -525,23 +519,15 @@ def _test(self, version):
525519
data = marshal.dumps(code, version)
526520
marshal.loads(data)
527521

528-
# TODO: RUSTPYTHON
529-
@unittest.expectedFailure
530522
def test0To3(self):
531523
self._test(0)
532524

533-
# TODO: RUSTPYTHON
534-
@unittest.expectedFailure
535525
def test1To3(self):
536526
self._test(1)
537527

538-
# TODO: RUSTPYTHON
539-
@unittest.expectedFailure
540528
def test2To3(self):
541529
self._test(2)
542530

543-
# TODO: RUSTPYTHON
544-
@unittest.expectedFailure
545531
def test3To3(self):
546532
self._test(3)
547533

@@ -558,8 +544,6 @@ def testIntern(self):
558544
s2 = sys.intern(s)
559545
self.assertEqual(id(s2), id(s))
560546

561-
# TODO: RUSTPYTHON
562-
@unittest.expectedFailure
563547
def testNoIntern(self):
564548
s = marshal.loads(marshal.dumps(self.strobj, 2))
565549
self.assertEqual(s, self.strobj)

vm/src/stdlib/marshal.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod decl {
99
},
1010
bytecode,
1111
convert::ToPyObject,
12-
function::ArgBytesLike,
12+
function::{ArgBytesLike, OptionalArg},
1313
object::AsObject,
1414
protocol::PyBuffer,
1515
PyObjectRef, PyResult, TryFromObject, VirtualMachine,
@@ -84,6 +84,9 @@ mod decl {
8484
}
8585
}
8686

87+
#[pyattr(name = "version")]
88+
const VERSION: u32 = 4;
89+
8790
fn too_short_error(vm: &VirtualMachine) -> PyBaseExceptionRef {
8891
vm.new_exception_msg(
8992
vm.ctx.exceptions.eof_error.to_owned(),
@@ -201,15 +204,24 @@ mod decl {
201204
}
202205

203206
#[pyfunction]
204-
fn dumps(value: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyBytes> {
207+
fn dumps(
208+
value: PyObjectRef,
209+
_version: OptionalArg<i32>,
210+
vm: &VirtualMachine,
211+
) -> PyResult<PyBytes> {
205212
let mut buf = Vec::new();
206213
dump_obj(&mut buf, value, vm)?;
207214
Ok(PyBytes::from(buf))
208215
}
209216

210217
#[pyfunction]
211-
fn dump(value: PyObjectRef, f: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
212-
let dumped = dumps(value, vm)?;
218+
fn dump(
219+
value: PyObjectRef,
220+
f: PyObjectRef,
221+
version: OptionalArg<i32>,
222+
vm: &VirtualMachine,
223+
) -> PyResult<()> {
224+
let dumped = dumps(value, version, vm)?;
213225
vm.call_method(&f, "write", (dumped,))?;
214226
Ok(())
215227
}

0 commit comments

Comments
 (0)