Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

More overlapped implementation #5748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
More overlapped implementation
  • Loading branch information
arihant2math committed Apr 27, 2025
commit ad8caa3317924548ae609f584ae4019ccb76400e
56 changes: 56 additions & 0 deletions 56 stdlib/src/overlapped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ mod _overlapped {
}
}

unsafe fn u64_to_handle(raw_ptr_value: u64) -> HANDLE {
raw_ptr_value as HANDLE
}

#[pyfunction]
fn CreateIoCompletionPort(
handle: isize,
Expand Down Expand Up @@ -354,4 +358,56 @@ mod _overlapped {
]);
Ok(value.into())
}

#[pyfunction]
fn CreateEvent(
event_attributes: PyObjectRef,
manual_reset: bool,
initial_state: bool,
name: Option<String>,
vm: &VirtualMachine,
) -> PyResult<isize> {
if !vm.is_none(&event_attributes) {
return Err(vm.new_value_error("EventAttributes must be None".to_owned()));
}

let name = match name {
Some(name) => {
let name = widestring::WideCString::from_str(&name).unwrap();
name.as_ptr()
}
None => std::ptr::null(),
};
let event = unsafe {
windows_sys::Win32::System::Threading::CreateEventW(
std::ptr::null(),
manual_reset as _,
initial_state as _,
name,
) as isize
};
if event == NULL {
return Err(errno_err(vm));
}
Ok(event)
}

#[pyfunction]
fn SetEvent(handle: u64, vm: &VirtualMachine) -> PyResult<()> {
let ret = unsafe { windows_sys::Win32::System::Threading::SetEvent(u64_to_handle(handle)) };
if ret == 0 {
return Err(errno_err(vm));
}
Ok(())
}

#[pyfunction]
fn ResetEvent(handle: u64, vm: &VirtualMachine) -> PyResult<()> {
let ret =
unsafe { windows_sys::Win32::System::Threading::ResetEvent(u64_to_handle(handle)) };
if ret == 0 {
return Err(errno_err(vm));
}
Ok(())
}
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.