chore: checkpoint before Python removal

This commit is contained in:
2026-03-26 22:33:59 +00:00
parent 683cec9307
commit e568ddf82a
29972 changed files with 11269302 additions and 2 deletions

45
vendor/tokio/tests/support/io_vec.rs vendored Normal file
View File

@@ -0,0 +1,45 @@
use std::io::IoSlice;
use std::ops::Deref;
use std::slice;
pub struct IoBufs<'a, 'b>(&'b mut [IoSlice<'a>]);
impl<'a, 'b> IoBufs<'a, 'b> {
pub fn new(slices: &'b mut [IoSlice<'a>]) -> Self {
IoBufs(slices)
}
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
pub fn advance(mut self, n: usize) -> IoBufs<'a, 'b> {
let mut to_remove = 0;
let mut remaining_len = n;
for slice in self.0.iter() {
if remaining_len < slice.len() {
break;
} else {
remaining_len -= slice.len();
to_remove += 1;
}
}
self.0 = self.0.split_at_mut(to_remove).1;
if let Some(slice) = self.0.first_mut() {
let tail = &slice[remaining_len..];
// Safety: recasts slice to the original lifetime
let tail = unsafe { slice::from_raw_parts(tail.as_ptr(), tail.len()) };
*slice = IoSlice::new(tail);
} else if remaining_len != 0 {
panic!("advance past the end of the slice vector");
}
self
}
}
impl<'a, 'b> Deref for IoBufs<'a, 'b> {
type Target = [IoSlice<'a>];
fn deref(&self) -> &[IoSlice<'a>] {
self.0
}
}

View File

@@ -0,0 +1,26 @@
/// Can create buffers of arbitrary lifetime.
/// Frees created buffers when dropped.
///
/// This struct is of course unsafe and the fact that
/// it must outlive the created slices has to be ensured by
/// the programmer.
///
/// Used at certain test scenarios as a safer version of
/// Vec::leak, to satisfy the address sanitizer.
pub struct LeakedBuffers {
leaked_vecs: Vec<Box<[u8]>>,
}
impl LeakedBuffers {
pub fn new() -> Self {
Self {
leaked_vecs: vec![],
}
}
pub unsafe fn create<'a>(&mut self, size: usize) -> &'a mut [u8] {
let new_mem = vec![0u8; size].into_boxed_slice();
self.leaked_vecs.push(new_mem);
let new_mem = self.leaked_vecs.last_mut().unwrap();
std::slice::from_raw_parts_mut(new_mem.as_mut_ptr(), new_mem.len())
}
}

View File

@@ -0,0 +1,42 @@
#![allow(dead_code)]
use std::pin::Pin;
use std::task::{Context, Poll};
use tokio::sync::mpsc::{self, Receiver, Sender, UnboundedReceiver, UnboundedSender};
use tokio_stream::Stream;
struct UnboundedStream<T> {
recv: UnboundedReceiver<T>,
}
impl<T> Stream for UnboundedStream<T> {
type Item = T;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<T>> {
Pin::into_inner(self).recv.poll_recv(cx)
}
}
pub fn unbounded_channel_stream<T: Unpin>() -> (UnboundedSender<T>, impl Stream<Item = T>) {
let (tx, rx) = mpsc::unbounded_channel();
let stream = UnboundedStream { recv: rx };
(tx, stream)
}
struct BoundedStream<T> {
recv: Receiver<T>,
}
impl<T> Stream for BoundedStream<T> {
type Item = T;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<T>> {
Pin::into_inner(self).recv.poll_recv(cx)
}
}
pub fn channel_stream<T: Unpin>(size: usize) -> (Sender<T>, impl Stream<Item = T>) {
let (tx, rx) = mpsc::channel(size);
let stream = BoundedStream { recv: rx };
(tx, stream)
}

34
vendor/tokio/tests/support/panic.rs vendored Normal file
View File

@@ -0,0 +1,34 @@
use std::panic;
use std::sync::{Arc, Mutex};
pub fn test_panic<Func: FnOnce() + panic::UnwindSafe>(func: Func) -> Option<String> {
static PANIC_MUTEX: Mutex<()> = Mutex::new(());
{
let _guard = PANIC_MUTEX.lock();
let panic_file: Arc<Mutex<Option<String>>> = Arc::new(Mutex::new(None));
let prev_hook = panic::take_hook();
{
let panic_file = panic_file.clone();
panic::set_hook(Box::new(move |panic_info| {
let panic_location = panic_info.location().unwrap();
panic_file
.lock()
.unwrap()
.clone_from(&Some(panic_location.file().to_string()));
}));
}
let result = panic::catch_unwind(func);
// Return to the previously set panic hook (maybe default) so that we get nice error
// messages in the tests.
panic::set_hook(prev_hook);
if result.is_err() {
panic_file.lock().unwrap().clone()
} else {
None
}
}
}

15
vendor/tokio/tests/support/signal.rs vendored Normal file
View File

@@ -0,0 +1,15 @@
pub fn send_signal(signal: libc::c_int) {
use libc::{getpid, kill};
unsafe {
let pid = getpid();
assert_eq!(
kill(pid, signal),
0,
"kill(pid = {}, {}) failed with error: {}",
pid,
signal,
std::io::Error::last_os_error(),
);
}
}