2586f655bb
First, replace all usages in files in-place. I used my editor for this. If someone wants to add a one-liner that'd be fun. Then, update directory and file names: ``` # Run twice for nested directories find . -type d -print0 | xargs -0 rename s/puffin/uv/g find . -type d -print0 | xargs -0 rename s/puffin/uv/g # Update files find . -type f -print0 | xargs -0 rename s/puffin/uv/g ``` Then add all the files again ``` # Add all the files again git add crates git add python/uv # This one needs a force-add git add -f crates/uv-trampoline ```
59 lines
1.8 KiB
Rust
59 lines
1.8 KiB
Rust
use core::mem::size_of;
|
|
|
|
pub trait SizeOf {
|
|
fn size_of(&self) -> u32;
|
|
}
|
|
|
|
impl<T: Sized> SizeOf for T {
|
|
fn size_of(&self) -> u32 {
|
|
size_of::<T>() as u32
|
|
}
|
|
}
|
|
|
|
// Check result of win32 API call that returns BOOL
|
|
#[macro_export]
|
|
macro_rules! check {
|
|
($e:expr) => {
|
|
if $e == 0 {
|
|
use windows_sys::Win32::{
|
|
Foundation::*,
|
|
System::{
|
|
Diagnostics::Debug::{
|
|
FormatMessageA, FORMAT_MESSAGE_ALLOCATE_BUFFER, FORMAT_MESSAGE_FROM_SYSTEM,
|
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
},
|
|
}
|
|
};
|
|
let err = GetLastError();
|
|
let mut msg_ptr: *mut u8 = core::ptr::null_mut();
|
|
let size = FormatMessageA(
|
|
FORMAT_MESSAGE_ALLOCATE_BUFFER
|
|
| FORMAT_MESSAGE_FROM_SYSTEM
|
|
| FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
null(),
|
|
err,
|
|
0,
|
|
// Weird calling convention: this argument is typed as *mut u16,
|
|
// but if you pass FORMAT_MESSAGE_ALLOCATE_BUFFER then you have to
|
|
// *actually* pass in a *mut *mut u16 and just lie about the type.
|
|
// Getting Rust to do this requires some convincing.
|
|
core::ptr::addr_of_mut!(msg_ptr) as *mut _ as _,
|
|
0,
|
|
core::ptr::null(),
|
|
);
|
|
let msg = core::slice::from_raw_parts(msg_ptr, size as usize);
|
|
let msg = core::str::from_utf8_unchecked(msg);
|
|
$crate::eprintln!("Error: {} (from {})", msg, stringify!($e));
|
|
ExitProcess(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
// CStr literal: c!("...")
|
|
#[macro_export]
|
|
macro_rules! c {
|
|
($s:literal) => {
|
|
core::ffi::CStr::from_bytes_with_nul_unchecked(concat!($s, "\0").as_bytes())
|
|
};
|
|
}
|