Skip to content

Commit 1c68087

Browse files
committed
Fix struct pack and unpack
1 parent 197ef9c commit 1c68087

3 files changed

Lines changed: 308 additions & 122 deletions

File tree

vm/src/obj/objbytes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl PyBytes {
109109
}
110110

111111
#[pymethod(name = "__len__")]
112-
fn len(&self) -> usize {
112+
pub(crate) fn len(&self) -> usize {
113113
self.inner.len()
114114
}
115115

vm/src/stdlib/math.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ use statrs::function::erf::{erf, erfc};
77
use statrs::function::gamma::{gamma, ln_gamma};
88

99
use num_bigint::BigInt;
10-
use num_traits::cast::ToPrimitive;
1110
use num_traits::{One, Zero};
1211

1312
use crate::function::OptionalArg;
1413
use crate::obj::objfloat::{self, IntoPyFloat, PyFloatRef};
15-
use crate::obj::objint::PyIntRef;
14+
use crate::obj::objint::{self, PyIntRef};
1615
use crate::obj::objtype;
17-
use crate::pyobject::{PyObjectRef, PyResult, TypeProtocol};
16+
use crate::pyobject::{Either, PyObjectRef, PyResult, TypeProtocol};
1817
use crate::vm::VirtualMachine;
1918

2019
#[cfg(not(target_arch = "wasm32"))]
@@ -261,8 +260,16 @@ fn math_frexp(value: IntoPyFloat) -> (f64, i32) {
261260
}
262261
}
263262

264-
fn math_ldexp(value: PyFloatRef, i: PyIntRef) -> f64 {
265-
value.to_f64() * (2_f64).powf(i.as_bigint().to_f64().unwrap())
263+
fn math_ldexp(
264+
value: Either<PyFloatRef, PyIntRef>,
265+
i: PyIntRef,
266+
vm: &VirtualMachine,
267+
) -> PyResult<f64> {
268+
let value = match value {
269+
Either::A(f) => f.to_f64(),
270+
Either::B(z) => objint::try_float(z.as_bigint(), vm)?,
271+
};
272+
Ok(value * (2_f64).powf(objint::try_float(i.as_bigint(), vm)?))
266273
}
267274

268275
fn math_gcd(a: PyIntRef, b: PyIntRef) -> BigInt {

0 commit comments

Comments
 (0)