marshal.version

This commit is contained in:
Jeong YunWon committed 2022-08-07 04:15:21 +09:00
1 parent b32493d2cf
commit ec9fa505e3
2 files changed
+17 -21

No files matched your search

+1 -17
View File
@@ -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)
+16 -4
View File
@@ -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<PyBytes> {
fn dumps(
value: PyObjectRef,
_version: OptionalArg<i32>,
vm: &VirtualMachine,
) -> PyResult<PyBytes> {
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<i32>,
vm: &VirtualMachine,
) -> PyResult<()> {
let dumped = dumps(value, version, vm)?;
vm.call_method(&f, "write", (dumped,))?;
Ok(())
}