@@ -1593,7 +1593,7 @@ mod decl {
1593
1593
let iterators = iterators. into_vec ( ) ;
1594
1594
PyItertoolsZipLongest {
1595
1595
iterators,
1596
- fillvalue,
1596
+ fillvalue : PyRwLock :: new ( fillvalue ) ,
1597
1597
}
1598
1598
. into_ref_with_type ( vm, cls)
1599
1599
. map ( Into :: into)
@@ -1605,11 +1605,31 @@ mod decl {
1605
1605
#[ derive( Debug , PyPayload ) ]
1606
1606
struct PyItertoolsZipLongest {
1607
1607
iterators : Vec < PyIter > ,
1608
- fillvalue : PyObjectRef ,
1608
+ fillvalue : PyRwLock < PyObjectRef > ,
1609
1609
}
1610
1610
1611
1611
#[ pyclass( with( IterNext , Constructor ) ) ]
1612
- impl PyItertoolsZipLongest { }
1612
+ impl PyItertoolsZipLongest {
1613
+ #[ pymethod( magic) ]
1614
+ fn reduce ( zelf : PyRef < Self > , vm : & VirtualMachine ) -> PyResult < PyTupleRef > {
1615
+ let args: Vec < PyObjectRef > = zelf
1616
+ . iterators
1617
+ . iter ( )
1618
+ . map ( |i| i. clone ( ) . to_pyobject ( vm) )
1619
+ . collect ( ) ;
1620
+ Ok ( vm. new_tuple ( (
1621
+ zelf. class ( ) . to_owned ( ) ,
1622
+ vm. new_tuple ( args) ,
1623
+ zelf. fillvalue . read ( ) . to_owned ( ) ,
1624
+ ) ) )
1625
+ }
1626
+
1627
+ #[ pymethod( magic) ]
1628
+ fn setstate ( zelf : PyRef < Self > , state : PyObjectRef , _vm : & VirtualMachine ) -> PyResult < ( ) > {
1629
+ * zelf. fillvalue . write ( ) = state;
1630
+ Ok ( ( ) )
1631
+ }
1632
+ }
1613
1633
impl IterNextIterable for PyItertoolsZipLongest { }
1614
1634
impl IterNext for PyItertoolsZipLongest {
1615
1635
fn next ( zelf : & Py < Self > , vm : & VirtualMachine ) -> PyResult < PyIterReturn > {
@@ -1627,7 +1647,7 @@ mod decl {
1627
1647
if numactive == 0 {
1628
1648
return Ok ( PyIterReturn :: StopIteration ( v) ) ;
1629
1649
}
1630
- zelf. fillvalue . clone ( )
1650
+ zelf. fillvalue . read ( ) . clone ( )
1631
1651
}
1632
1652
} ;
1633
1653
result. push ( next_obj) ;
0 commit comments