File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -67,9 +67,16 @@ mod _random {
6767 }
6868
6969 #[ pymethod]
70- fn getrandbits ( & self , k : isize , vm : & VirtualMachine ) -> PyResult < BigInt > {
70+ fn getrandbits ( & self , k : PyObjectRef , vm : & VirtualMachine ) -> PyResult < BigInt > {
71+ let k_int = k. try_index ( vm) ?;
72+ let k_bigint = k_int. as_bigint ( ) ;
73+ if k_bigint. is_negative ( ) {
74+ return Err ( vm. new_value_error ( "number of bits must be non-negative" ) ) ;
75+ }
76+ let k: isize = k_int
77+ . try_to_primitive ( vm)
78+ . map_err ( |_| vm. new_overflow_error ( "getrandbits: number of bits too large" ) ) ?;
7179 match k {
72- ..0 => Err ( vm. new_value_error ( "number of bits must be non-negative" ) ) ,
7380 0 => Ok ( BigInt :: zero ( ) ) ,
7481 mut k => {
7582 let mut rng = self . rng . lock ( ) ;
Original file line number Diff line number Diff line change @@ -297,7 +297,7 @@ mod decl {
297297 struct PyRepeatNewArgs {
298298 object : PyObjectRef ,
299299 #[ pyarg( any, optional) ]
300- times : OptionalArg < PyIntRef > ,
300+ times : OptionalArg < PyObjectRef > ,
301301 }
302302
303303 impl Constructor for PyItertoolsRepeat {
@@ -309,7 +309,8 @@ mod decl {
309309 vm : & VirtualMachine ,
310310 ) -> PyResult < Self > {
311311 let times = match times. into_option ( ) {
312- Some ( int) => {
312+ Some ( obj) => {
313+ let int = obj. try_index ( vm) ?;
313314 let val: isize = int. try_to_primitive ( vm) ?;
314315 // times always >= 0.
315316 Some ( PyRwLock :: new ( val. to_usize ( ) . unwrap_or ( 0 ) ) )
You can’t perform that action at this time.
0 commit comments