Skip to content

Commit 23c6a13

Browse files
JRRudy1davidhewitt
authored andcommitted
Updated the private array::clone_elements function to require a GIL token and call the py_clone method instead of Clone.
Updated usages accordingly, which is trivial since the GIL is already held everywhere it is called.
1 parent 3d84909 commit 23c6a13

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/array.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ impl<T: Element> PyArray<T, Ix1> {
10661066
unsafe {
10671067
let array = PyArray::new_bound(py, [slice.len()], false);
10681068
let mut data_ptr = array.data();
1069-
clone_elements(slice, &mut data_ptr);
1069+
clone_elements(py, slice, &mut data_ptr);
10701070
array
10711071
}
10721072
}
@@ -1180,7 +1180,7 @@ impl<T: Element> PyArray<T, Ix2> {
11801180
cold();
11811181
return Err(FromVecError::new(v.len(), len2));
11821182
}
1183-
clone_elements(v, &mut data_ptr);
1183+
clone_elements(py, v, &mut data_ptr);
11841184
}
11851185
Ok(array)
11861186
}
@@ -1245,7 +1245,7 @@ impl<T: Element> PyArray<T, Ix3> {
12451245
cold();
12461246
return Err(FromVecError::new(v.len(), len3));
12471247
}
1248-
clone_elements(v, &mut data_ptr);
1248+
clone_elements(py, v, &mut data_ptr);
12491249
}
12501250
}
12511251
Ok(array)
@@ -1466,13 +1466,13 @@ impl<T: Element + AsPrimitive<f64>> PyArray<T, Ix1> {
14661466
}
14671467
}
14681468

1469-
unsafe fn clone_elements<T: Element>(elems: &[T], data_ptr: &mut *mut T) {
1469+
unsafe fn clone_elements<T: Element>(py: Python<'_>, elems: &[T], data_ptr: &mut *mut T) {
14701470
if T::IS_COPY {
14711471
ptr::copy_nonoverlapping(elems.as_ptr(), *data_ptr, elems.len());
14721472
*data_ptr = data_ptr.add(elems.len());
14731473
} else {
14741474
for elem in elems {
1475-
data_ptr.write(elem.clone());
1475+
data_ptr.write(elem.py_clone(py));
14761476
*data_ptr = data_ptr.add(1);
14771477
}
14781478
}

0 commit comments

Comments
 (0)