Rename b as buf in several places.

Because it's easy to confuse with `bridge`.
This commit is contained in:
Nicholas Nethercote 2022-05-19 09:03:26 +10:00
parent c2c505737f
commit f5c9c1215c
2 changed files with 30 additions and 30 deletions

View File

@ -254,17 +254,17 @@ macro_rules! define_client_side {
$(impl $name {
$(pub(crate) fn $method($($arg: $arg_ty),*) $(-> $ret_ty)* {
Bridge::with(|bridge| {
let mut b = bridge.cached_buffer.take();
let mut buf = bridge.cached_buffer.take();
b.clear();
api_tags::Method::$name(api_tags::$name::$method).encode(&mut b, &mut ());
reverse_encode!(b; $($arg),*);
buf.clear();
api_tags::Method::$name(api_tags::$name::$method).encode(&mut buf, &mut ());
reverse_encode!(buf; $($arg),*);
b = bridge.dispatch.call(b);
buf = bridge.dispatch.call(buf);
let r = Result::<_, PanicMessage>::decode(&mut &b[..], &mut ());
let r = Result::<_, PanicMessage>::decode(&mut &buf[..], &mut ());
bridge.cached_buffer = b;
bridge.cached_buffer = buf;
r.unwrap_or_else(|e| panic::resume_unwind(e.into()))
})
@ -383,20 +383,20 @@ fn run_client<A: for<'a, 's> DecodeMut<'a, 's, ()>, R: Encode<()>>(
f: impl FnOnce(A) -> R,
) -> Buffer {
// The initial `cached_buffer` contains the input.
let mut b = bridge.cached_buffer.take();
let mut buf = bridge.cached_buffer.take();
panic::catch_unwind(panic::AssertUnwindSafe(|| {
bridge.enter(|| {
let reader = &mut &b[..];
let reader = &mut &buf[..];
let input = A::decode(reader, &mut ());
// Put the `cached_buffer` back in the `Bridge`, for requests.
Bridge::with(|bridge| bridge.cached_buffer = b.take());
Bridge::with(|bridge| bridge.cached_buffer = buf.take());
let output = f(input);
// Take the `cached_buffer` back out, for the output value.
b = Bridge::with(|bridge| bridge.cached_buffer.take());
buf = Bridge::with(|bridge| bridge.cached_buffer.take());
// HACK(eddyb) Separate encoding a success value (`Ok(output)`)
// from encoding a panic (`Err(e: PanicMessage)`) to avoid
@ -407,16 +407,16 @@ fn run_client<A: for<'a, 's> DecodeMut<'a, 's, ()>, R: Encode<()>>(
// this is defensively trying to avoid any accidental panicking
// reaching the `extern "C"` (which should `abort` but might not
// at the moment, so this is also potentially preventing UB).
b.clear();
Ok::<_, ()>(output).encode(&mut b, &mut ());
buf.clear();
Ok::<_, ()>(output).encode(&mut buf, &mut ());
})
}))
.map_err(PanicMessage::from)
.unwrap_or_else(|e| {
b.clear();
Err::<(), _>(e).encode(&mut b, &mut ());
buf.clear();
Err::<(), _>(e).encode(&mut buf, &mut ());
});
b
buf
}
impl Client<fn(crate::TokenStream) -> crate::TokenStream> {

View File

@ -80,15 +80,15 @@ macro_rules! define_dispatcher_impl {
pub trait DispatcherTrait {
// HACK(eddyb) these are here to allow `Self::$name` to work below.
$(type $name;)*
fn dispatch(&mut self, b: Buffer) -> Buffer;
fn dispatch(&mut self, buf: Buffer) -> Buffer;
}
impl<S: Server> DispatcherTrait for Dispatcher<MarkedTypes<S>> {
$(type $name = <MarkedTypes<S> as Types>::$name;)*
fn dispatch(&mut self, mut b: Buffer) -> Buffer {
fn dispatch(&mut self, mut buf: Buffer) -> Buffer {
let Dispatcher { handle_store, server } = self;
let mut reader = &b[..];
let mut reader = &buf[..];
match api_tags::Method::decode(&mut reader, &mut ()) {
$(api_tags::Method::$name(m) => match m {
$(api_tags::$name::$method => {
@ -107,12 +107,12 @@ fn dispatch(&mut self, mut b: Buffer) -> Buffer {
.map_err(PanicMessage::from)
};
b.clear();
r.encode(&mut b, handle_store);
buf.clear();
r.encode(&mut buf, handle_store);
})*
}),*
}
b
buf
}
}
}
@ -141,7 +141,7 @@ fn run_bridge_and_client<D: Copy + Send + 'static>(
client_data: D,
force_show_panics: bool,
) -> Buffer {
let mut dispatch = |b| dispatcher.dispatch(b);
let mut dispatch = |buf| dispatcher.dispatch(buf);
run_client(
Bridge {
@ -175,8 +175,8 @@ fn run_bridge_and_client<D: Copy + Send + 'static>(
let (res_tx, res_rx) = channel();
let join_handle = thread::spawn(move || {
let mut dispatch = |b| {
req_tx.send(b).unwrap();
let mut dispatch = |buf| {
req_tx.send(buf).unwrap();
res_rx.recv().unwrap()
};
@ -283,18 +283,18 @@ fn run_server<
let mut dispatcher =
Dispatcher { handle_store: HandleStore::new(handle_counters), server: MarkedTypes(server) };
let mut b = Buffer::new();
input.encode(&mut b, &mut dispatcher.handle_store);
let mut buf = Buffer::new();
input.encode(&mut buf, &mut dispatcher.handle_store);
b = strategy.run_bridge_and_client(
buf = strategy.run_bridge_and_client(
&mut dispatcher,
b,
buf,
run_client,
client_data,
force_show_panics,
);
Result::decode(&mut &b[..], &mut dispatcher.handle_store)
Result::decode(&mut &buf[..], &mut dispatcher.handle_store)
}
impl client::Client<fn(crate::TokenStream) -> crate::TokenStream> {