MCPcopy Index your code
hub / github.com/RustPython/RustPython / del

Method del

crates/stdlib/src/overlapped.rs:1525–1584  ·  view source on GitHub ↗
(zelf: &Py<Self>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

1523
1524 impl Destructor for Overlapped {
1525 fn del(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<()> {
1526 use windows_sys::Win32::Foundation::{
1527 ERROR_NOT_FOUND, ERROR_OPERATION_ABORTED, ERROR_SUCCESS,
1528 };
1529 use windows_sys::Win32::System::IO::{CancelIoEx, GetOverlappedResult};
1530
1531 let mut inner = zelf.inner.lock();
1532 let olderr = unsafe { GetLastError() };
1533
1534 // Cancel pending I/O and wait for completion
1535 if !HasOverlappedIoCompleted(&inner.overlapped)
1536 && !matches!(inner.data, OverlappedData::NotStarted)
1537 {
1538 let cancelled = unsafe { CancelIoEx(inner.handle, &inner.overlapped) } != 0;
1539 let mut transferred: u32 = 0;
1540 let ret = unsafe {
1541 GetOverlappedResult(
1542 inner.handle,
1543 &inner.overlapped,
1544 &mut transferred,
1545 if cancelled { 1 } else { 0 },
1546 )
1547 };
1548
1549 let err = if ret != 0 {
1550 ERROR_SUCCESS
1551 } else {
1552 unsafe { GetLastError() }
1553 };
1554 match err {
1555 ERROR_SUCCESS | ERROR_NOT_FOUND | ERROR_OPERATION_ABORTED => {}
1556 _ => {
1557 let msg = format!(
1558 "{:?} still has pending operation at deallocation, the process may crash",
1559 zelf
1560 );
1561 let exc = vm.new_runtime_error(msg);
1562 let err_msg = Some(format!(
1563 "Exception ignored while deallocating overlapped operation {:?}",
1564 zelf
1565 ));
1566 let obj: PyObjectRef = zelf.to_owned().into();
1567 vm.run_unraisable(exc, err_msg, obj);
1568 }
1569 }
1570 }
1571
1572 // Close the event handle
1573 if !inner.overlapped.hEvent.is_null() {
1574 unsafe {
1575 Foundation::CloseHandle(inner.overlapped.hEvent);
1576 }
1577 inner.overlapped.hEvent = core::ptr::null_mut();
1578 }
1579
1580 // Restore last error
1581 unsafe { Foundation::SetLastError(olderr) };
1582

Callers

nothing calls this directly

Calls 7

HasOverlappedIoCompletedFunction · 0.85
CloseHandleFunction · 0.85
run_unraisableMethod · 0.80
GetLastErrorFunction · 0.50
SomeClass · 0.50
lockMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected