1
0
Fork 0
forked from wry/wry

config: downgrade bincode to 1.3.3

This should not have any impact on existing configs since bincode claims
compatibility of the wire format between 1.3.3 and 2.0.0.
This commit is contained in:
Julian Orth 2024-02-16 14:02:45 +01:00
parent 6921531702
commit 615acd4847
22 changed files with 91 additions and 104 deletions

View file

@ -13,6 +13,7 @@ use {
unlink_on_drop::UnlinkOnDrop, xrd::xrd,
},
},
bincode::Options,
jay_config::{
_private::{
bincode_ops,
@ -175,8 +176,9 @@ impl ConfigProxy {
timers_by_name: Default::default(),
timers_by_id: Default::default(),
});
let init_msg =
bincode::encode_to_vec(&InitMessage::V1(V1InitMessage {}), bincode_ops()).unwrap();
let init_msg = bincode_ops()
.serialize(&InitMessage::V1(V1InitMessage {}))
.unwrap();
unsafe {
let client_data = (entry.init)(
Rc::into_raw(data.clone()) as _,

View file

@ -22,7 +22,7 @@ use {
},
xkbcommon::{XkbCommonError, XkbKeymap},
},
bincode::error::DecodeError,
bincode::Options,
jay_config::{
_private::{
bincode_ops,
@ -89,7 +89,7 @@ impl ConfigProxyHandler {
pub fn send(&self, msg: &ServerMessage) {
let mut buf = self.bufs.pop().unwrap_or_default();
buf.clear();
bincode::encode_into_std_write(msg, &mut buf, bincode_ops()).unwrap();
bincode_ops().serialize_into(&mut buf, msg).unwrap();
unsafe {
(self.handle_msg)(self.client_data.get(), buf.as_ptr(), buf.len());
}
@ -1097,11 +1097,10 @@ impl ConfigProxyHandler {
}
fn handle_request_(self: &Rc<Self>, msg: &[u8]) -> Result<(), CphError> {
let (request, _) =
match bincode::borrow_decode_from_slice::<ClientMessage, _>(msg, bincode_ops()) {
Ok(msg) => msg,
Err(e) => return Err(CphError::ParsingFailed(e)),
};
let request = match bincode_ops().deserialize::<ClientMessage>(msg) {
Ok(msg) => msg,
Err(e) => return Err(CphError::ParsingFailed(e)),
};
match request {
ClientMessage::Log {
level,
@ -1367,7 +1366,7 @@ enum CphError {
#[error("Sized element {0} is not known")]
UnknownSized(u32),
#[error("Could not parse the message")]
ParsingFailed(#[source] DecodeError),
ParsingFailed(#[source] bincode::Error),
#[error("Could not process a `{0}` request")]
FailedRequest(&'static str, #[source] Box<Self>),
#[error(transparent)]

View file

@ -17,12 +17,10 @@ use {
},
xwayland,
},
bincode::{
error::{DecodeError, EncodeError},
Decode, Encode,
},
bincode::Options,
jay_config::_private::bincode_ops,
log::Level,
serde::{Deserialize, Serialize},
std::{
cell::{Cell, RefCell},
env,
@ -65,9 +63,9 @@ pub enum ForkerError {
#[error("Could not write the next message")]
WriteFailed(#[source] BufFdError),
#[error("Could not decode the next message")]
DecodeFailed(#[source] DecodeError),
DecodeFailed(#[source] bincode::Error),
#[error("Could not encode the next message")]
EncodeFailed(#[source] EncodeError),
EncodeFailed(#[source] bincode::Error),
#[error("Could not fork")]
PidfdForkFailed,
}
@ -264,7 +262,7 @@ impl ForkerProxy {
}
}
#[derive(Encode, Decode)]
#[derive(Serialize, Deserialize)]
enum ServerMessage {
SetEnv {
var: Vec<u8>,
@ -281,7 +279,7 @@ enum ServerMessage {
},
}
#[derive(Encode, Decode)]
#[derive(Serialize, Deserialize)]
enum ForkerMessage {
Log {
level: usize,
@ -319,7 +317,7 @@ impl Forker {
level: log::Level::Error as _,
msg: format!("The ol' forker panicked: {}", pi),
};
let msg = bincode::encode_to_vec(msg, bincode_ops()).unwrap();
let msg = bincode_ops().serialize(&msg).unwrap();
let _ = Fd::new(socket).write_all(&msg);
})
});

View file

@ -1,5 +1,6 @@
use {
bincode::{Decode, Encode},
bincode::Options,
serde::{de::DeserializeOwned, Serialize},
std::{mem, rc::Rc},
};
@ -34,7 +35,7 @@ impl IoIn {
self.incoming.get_fd().ok()
}
pub async fn read_msg<T: Decode>(&mut self) -> Result<T, ForkerError> {
pub async fn read_msg<T: DeserializeOwned>(&mut self) -> Result<T, ForkerError> {
let mut len = 0usize;
if let Err(e) = self.incoming.read_full(&mut len).await {
return Err(ForkerError::ReadFailed(e));
@ -48,11 +49,9 @@ impl IoIn {
unsafe {
self.scratch.set_len(len);
}
let res = bincode::decode_from_slice::<T, _>(&self.scratch, bincode_ops());
match res {
Ok((msg, _)) => Ok(msg),
Err(e) => Err(ForkerError::DecodeFailed(e)),
}
bincode_ops()
.deserialize::<T>(&self.scratch)
.map_err(ForkerError::DecodeFailed)
}
}
@ -75,14 +74,13 @@ impl IoOut {
self.fds.push(fd);
}
pub async fn write_msg<T: Encode>(&mut self, msg: T) -> Result<(), ForkerError> {
pub async fn write_msg<T: Serialize>(&mut self, msg: T) -> Result<(), ForkerError> {
self.scratch.clear();
self.scratch.extend_from_slice(uapi::as_bytes(&0usize));
let res = bincode::encode_into_std_write(&msg, &mut self.scratch, bincode_ops());
let len = match res {
Ok(l) => l,
Err(e) => return Err(ForkerError::EncodeFailed(e)),
};
bincode_ops()
.serialize_into(&mut self.scratch, &msg)
.map_err(ForkerError::EncodeFailed)?;
let len = self.scratch.len() - mem::size_of_val(&0usize);
self.scratch[..mem::size_of_val(&len)].copy_from_slice(uapi::as_bytes(&len));
let mut buf = self.scratch.borrow();
match self

View file

@ -5,6 +5,7 @@ use {
it::test_error::{TestError, TestResult},
utils::{copyhashmap::CopyHashMap, stack::Stack},
},
bincode::Options,
isnt::std_1::primitive::IsntConstPtrExt,
jay_config::{
_private::{
@ -76,8 +77,8 @@ unsafe extern "C" fn unref(data: *const u8) {
unsafe extern "C" fn handle_msg(data: *const u8, msg: *const u8, size: usize) {
let tc = &*data.cast::<TestConfig>();
let msg = std::slice::from_raw_parts(msg, size);
let res = bincode::borrow_decode_from_slice::<ServerMessage, _>(msg, bincode_ops());
let (msg, _) = match res {
let res = bincode_ops().deserialize::<ServerMessage>(msg);
let msg = match res {
Ok(msg) => msg,
Err(e) => {
log::error!("could not deserialize message: {}", e);
@ -145,7 +146,7 @@ impl TestConfig {
_ => bail!("srv not set"),
};
let mut buf = vec![];
bincode::encode_into_std_write(msg, &mut buf, bincode_ops()).unwrap();
bincode_ops().serialize_into(&mut buf, msg).unwrap();
unsafe {
(srv.srv_handler)(srv.srv_data, buf.as_ptr(), buf.len());
}