@@ -24,11 +24,14 @@ pub struct PyInt {
24
24
pub type PyIntRef = PyRef < PyInt > ;
25
25
26
26
impl PyInt {
27
- pub fn new < T : ToBigInt > ( i : T ) -> Self {
28
- PyInt {
29
- // TODO: this .clone()s a BigInt, which is not what we want.
30
- value : i. to_bigint ( ) . unwrap ( ) ,
31
- }
27
+ pub fn new < T : Into < BigInt > > ( i : T ) -> Self {
28
+ PyInt { value : i. into ( ) }
29
+ }
30
+ }
31
+
32
+ impl IntoPyObject for BigInt {
33
+ fn into_pyobject ( self , ctx : & PyContext ) -> PyResult {
34
+ Ok ( ctx. new_int ( self ) )
32
35
}
33
36
}
34
37
@@ -315,8 +318,8 @@ impl PyIntRef {
315
318
}
316
319
}
317
320
318
- fn neg ( self , vm : & mut VirtualMachine ) -> PyObjectRef {
319
- vm . ctx . new_int ( -( & self . value ) )
321
+ fn neg ( self , _vm : & mut VirtualMachine ) -> BigInt {
322
+ -( & self . value )
320
323
}
321
324
322
325
fn hash ( self , _vm : & mut VirtualMachine ) -> u64 {
@@ -325,8 +328,8 @@ impl PyIntRef {
325
328
hasher. finish ( )
326
329
}
327
330
328
- fn abs ( self , vm : & mut VirtualMachine ) -> PyObjectRef {
329
- vm . ctx . new_int ( self . value . abs ( ) )
331
+ fn abs ( self , _vm : & mut VirtualMachine ) -> BigInt {
332
+ self . value . abs ( )
330
333
}
331
334
332
335
fn round ( self , _precision : OptionalArg < PyObjectRef > , _vm : & mut VirtualMachine ) -> Self {
@@ -337,8 +340,8 @@ impl PyIntRef {
337
340
self . value . to_f64 ( ) . unwrap ( )
338
341
}
339
342
340
- fn invert ( self , vm : & mut VirtualMachine ) -> PyObjectRef {
341
- vm . ctx . new_int ( !( & self . value ) )
343
+ fn invert ( self , _vm : & mut VirtualMachine ) -> BigInt {
344
+ !( & self . value )
342
345
}
343
346
344
347
fn repr ( self , _vm : & mut VirtualMachine ) -> String {
0 commit comments