Rename b
as buf
in several places.
Because it's easy to confuse with `bridge`.
This commit is contained in:
parent
c2c505737f
commit
f5c9c1215c
2 changed files with 30 additions and 30 deletions
|
@ -254,17 +254,17 @@ macro_rules! define_client_side {
|
||||||
$(impl $name {
|
$(impl $name {
|
||||||
$(pub(crate) fn $method($($arg: $arg_ty),*) $(-> $ret_ty)* {
|
$(pub(crate) fn $method($($arg: $arg_ty),*) $(-> $ret_ty)* {
|
||||||
Bridge::with(|bridge| {
|
Bridge::with(|bridge| {
|
||||||
let mut b = bridge.cached_buffer.take();
|
let mut buf = bridge.cached_buffer.take();
|
||||||
|
|
||||||
b.clear();
|
buf.clear();
|
||||||
api_tags::Method::$name(api_tags::$name::$method).encode(&mut b, &mut ());
|
api_tags::Method::$name(api_tags::$name::$method).encode(&mut buf, &mut ());
|
||||||
reverse_encode!(b; $($arg),*);
|
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()))
|
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,
|
f: impl FnOnce(A) -> R,
|
||||||
) -> Buffer {
|
) -> Buffer {
|
||||||
// The initial `cached_buffer` contains the input.
|
// 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(|| {
|
panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||||
bridge.enter(|| {
|
bridge.enter(|| {
|
||||||
let reader = &mut &b[..];
|
let reader = &mut &buf[..];
|
||||||
let input = A::decode(reader, &mut ());
|
let input = A::decode(reader, &mut ());
|
||||||
|
|
||||||
// Put the `cached_buffer` back in the `Bridge`, for requests.
|
// 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);
|
let output = f(input);
|
||||||
|
|
||||||
// Take the `cached_buffer` back out, for the output value.
|
// 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)`)
|
// HACK(eddyb) Separate encoding a success value (`Ok(output)`)
|
||||||
// from encoding a panic (`Err(e: PanicMessage)`) to avoid
|
// 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
|
// this is defensively trying to avoid any accidental panicking
|
||||||
// reaching the `extern "C"` (which should `abort` but might not
|
// reaching the `extern "C"` (which should `abort` but might not
|
||||||
// at the moment, so this is also potentially preventing UB).
|
// at the moment, so this is also potentially preventing UB).
|
||||||
b.clear();
|
buf.clear();
|
||||||
Ok::<_, ()>(output).encode(&mut b, &mut ());
|
Ok::<_, ()>(output).encode(&mut buf, &mut ());
|
||||||
})
|
})
|
||||||
}))
|
}))
|
||||||
.map_err(PanicMessage::from)
|
.map_err(PanicMessage::from)
|
||||||
.unwrap_or_else(|e| {
|
.unwrap_or_else(|e| {
|
||||||
b.clear();
|
buf.clear();
|
||||||
Err::<(), _>(e).encode(&mut b, &mut ());
|
Err::<(), _>(e).encode(&mut buf, &mut ());
|
||||||
});
|
});
|
||||||
b
|
buf
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Client<fn(crate::TokenStream) -> crate::TokenStream> {
|
impl Client<fn(crate::TokenStream) -> crate::TokenStream> {
|
||||||
|
|
|
@ -80,15 +80,15 @@ macro_rules! define_dispatcher_impl {
|
||||||
pub trait DispatcherTrait {
|
pub trait DispatcherTrait {
|
||||||
// HACK(eddyb) these are here to allow `Self::$name` to work below.
|
// HACK(eddyb) these are here to allow `Self::$name` to work below.
|
||||||
$(type $name;)*
|
$(type $name;)*
|
||||||
fn dispatch(&mut self, b: Buffer) -> Buffer;
|
fn dispatch(&mut self, buf: Buffer) -> Buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: Server> DispatcherTrait for Dispatcher<MarkedTypes<S>> {
|
impl<S: Server> DispatcherTrait for Dispatcher<MarkedTypes<S>> {
|
||||||
$(type $name = <MarkedTypes<S> as Types>::$name;)*
|
$(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 Dispatcher { handle_store, server } = self;
|
||||||
|
|
||||||
let mut reader = &b[..];
|
let mut reader = &buf[..];
|
||||||
match api_tags::Method::decode(&mut reader, &mut ()) {
|
match api_tags::Method::decode(&mut reader, &mut ()) {
|
||||||
$(api_tags::Method::$name(m) => match m {
|
$(api_tags::Method::$name(m) => match m {
|
||||||
$(api_tags::$name::$method => {
|
$(api_tags::$name::$method => {
|
||||||
|
@ -107,12 +107,12 @@ macro_rules! define_dispatcher_impl {
|
||||||
.map_err(PanicMessage::from)
|
.map_err(PanicMessage::from)
|
||||||
};
|
};
|
||||||
|
|
||||||
b.clear();
|
buf.clear();
|
||||||
r.encode(&mut b, handle_store);
|
r.encode(&mut buf, handle_store);
|
||||||
})*
|
})*
|
||||||
}),*
|
}),*
|
||||||
}
|
}
|
||||||
b
|
buf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ impl ExecutionStrategy for SameThread {
|
||||||
client_data: D,
|
client_data: D,
|
||||||
force_show_panics: bool,
|
force_show_panics: bool,
|
||||||
) -> Buffer {
|
) -> Buffer {
|
||||||
let mut dispatch = |b| dispatcher.dispatch(b);
|
let mut dispatch = |buf| dispatcher.dispatch(buf);
|
||||||
|
|
||||||
run_client(
|
run_client(
|
||||||
Bridge {
|
Bridge {
|
||||||
|
@ -175,8 +175,8 @@ impl ExecutionStrategy for CrossThread1 {
|
||||||
let (res_tx, res_rx) = channel();
|
let (res_tx, res_rx) = channel();
|
||||||
|
|
||||||
let join_handle = thread::spawn(move || {
|
let join_handle = thread::spawn(move || {
|
||||||
let mut dispatch = |b| {
|
let mut dispatch = |buf| {
|
||||||
req_tx.send(b).unwrap();
|
req_tx.send(buf).unwrap();
|
||||||
res_rx.recv().unwrap()
|
res_rx.recv().unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -283,18 +283,18 @@ fn run_server<
|
||||||
let mut dispatcher =
|
let mut dispatcher =
|
||||||
Dispatcher { handle_store: HandleStore::new(handle_counters), server: MarkedTypes(server) };
|
Dispatcher { handle_store: HandleStore::new(handle_counters), server: MarkedTypes(server) };
|
||||||
|
|
||||||
let mut b = Buffer::new();
|
let mut buf = Buffer::new();
|
||||||
input.encode(&mut b, &mut dispatcher.handle_store);
|
input.encode(&mut buf, &mut dispatcher.handle_store);
|
||||||
|
|
||||||
b = strategy.run_bridge_and_client(
|
buf = strategy.run_bridge_and_client(
|
||||||
&mut dispatcher,
|
&mut dispatcher,
|
||||||
b,
|
buf,
|
||||||
run_client,
|
run_client,
|
||||||
client_data,
|
client_data,
|
||||||
force_show_panics,
|
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> {
|
impl client::Client<fn(crate::TokenStream) -> crate::TokenStream> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue