mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Resize pack_string with padding
This commit is contained in:
1 parent
7338bb701d
commit
bbb799f2c7
2 files changed
+14
-2
No files matched your search
@@ -56,3 +56,12 @@ class Indexable(object):
|
||||
|
||||
data = struct.pack('B', Indexable(65))
|
||||
assert data == bytes([65])
|
||||
|
||||
data = struct.pack('5s', b"test1")
|
||||
assert data == b"test1"
|
||||
|
||||
data = struct.pack('3s', b"test2")
|
||||
assert data == b"tes"
|
||||
|
||||
data = struct.pack('7s', b"test3")
|
||||
assert data == b"test3\0\0"
|
||||
@@ -338,8 +338,11 @@ fn pack_string(
|
||||
data: &mut dyn Write,
|
||||
length: usize,
|
||||
) -> PyResult<()> {
|
||||
let v = PyBytesRef::try_from_object(vm, arg.clone())?;
|
||||
match data.write_all(&v.get_value()[..length]) {
|
||||
let mut v = PyBytesRef::try_from_object(vm, arg.clone())?
|
||||
.get_value()
|
||||
.to_vec();
|
||||
v.resize(length, 0);
|
||||
match data.write_all(&v) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(e) => Err(new_struct_error(vm, format!("{:?}", e))),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user