From 6a38fc82f46c06580fb7b6fac5ff54dcab6b24ad Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Sun, 20 Nov 2022 18:35:08 +0000 Subject: [PATCH] Deps: Update Ringbuf, Serde-Aux, Simd-Json, Typemap --- Cargo.toml | 8 ++++---- src/input/adapters/async_adapter.rs | 8 ++++---- src/ws.rs | 7 ++++++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1737cec..39f2b73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,13 +27,13 @@ parking_lot = { optional = true, version = "0.12" } pin-project = "1" rand = { optional = true, version = "0.8" } reqwest = { default-features = false, features = ["stream"], optional = true, version = "0.11" } -ringbuf = { optional = true, version = "0.2" } +ringbuf = { optional = true, version = "0.3" } rubato = { optional = true, version = "0.12" } rusty_pool = { optional = true, version = "0.7" } serde = { version = "1", features = ["derive"] } -serde-aux = { default-features = false, optional = true, version = "3"} +serde-aux = { optional = true, version = "4"} serde_json = "1" -simd-json = { features = ["serde_impl"], optional = true, version = "0.6.0" } +simd-json = { features = ["serde_impl"], optional = true, version = "0.7.0" } socket2 = { optional = true, version = "0.4" } streamcatcher = { optional = true, version = "1" } tokio = { default-features = false, optional = true, version = "1.0" } @@ -43,7 +43,7 @@ tracing = { version = "0.1", features = ["log"] } tracing-futures = "0.2" twilight-gateway = { default-features = false, optional = true, version = "0.14.0" } twilight-model = { default-features = false, optional = true, version = "0.14.0" } -typemap_rev = { optional = true, version = "0.1" } +typemap_rev = { optional = true, version = "0.2" } url = { optional = true, version = "2" } uuid = { features = ["v4"], optional = true, version = "1" } xsalsa20poly1305 = { features = ["std"], optional = true, version = "0.9" } diff --git a/src/input/adapters/async_adapter.rs b/src/input/adapters/async_adapter.rs index 54d3dfb..8388470 100644 --- a/src/input/adapters/async_adapter.rs +++ b/src/input/adapters/async_adapter.rs @@ -25,7 +25,7 @@ use tokio::{ }; struct AsyncAdapterSink { - bytes_in: Producer, + bytes_in: HeapProducer, req_rx: Receiver, resp_tx: Sender, stream: Box, @@ -135,7 +135,7 @@ impl AsyncAdapterSink { /// pass along seek requests needed. This allows for passing bytes from exclusively `AsyncRead` /// streams (e.g., hyper HTTP sessions) to Songbird. pub struct AsyncAdapterStream { - bytes_out: Consumer, + bytes_out: HeapConsumer, can_seek: bool, // Note: this is Atomic just to work around the need for // check_messages to take &self rather than &mut. @@ -150,7 +150,7 @@ impl AsyncAdapterStream { /// between the async and sync halves. #[must_use] pub fn new(stream: Box, buf_len: usize) -> AsyncAdapterStream { - let (bytes_in, bytes_out) = RingBuffer::new(buf_len).split(); + let (bytes_in, bytes_out) = SharedRb::new(buf_len).split(); let (resp_tx, resp_rx) = flume::unbounded(); let (req_tx, req_rx) = flume::unbounded(); let can_seek = stream.is_seekable(); @@ -264,7 +264,7 @@ impl Seek for AsyncAdapterStream { _ => unreachable!(), } - self.bytes_out.discard(self.bytes_out.capacity()); + self.bytes_out.skip(self.bytes_out.capacity()); let _ = self.req_tx.send(AdapterRequest::SeekCleared); diff --git a/src/ws.rs b/src/ws.rs index a71cf55..5201dcd 100644 --- a/src/ws.rs +++ b/src/ws.rs @@ -89,10 +89,15 @@ impl From for Error { } #[inline] +#[allow(unused_unsafe)] pub(crate) fn convert_ws_message(message: Option) -> Result> { Ok(match message { + // SAFETY: + // simd-json::serde::from_str may leave an &mut str in a non-UTF state on failure. + // The below is safe as we have taken ownership of the inner `String`, and don't + // access it as a `str`/`String` or return it if failure occurs. Some(Message::Text(mut payload)) => - crate::json::from_str(payload.as_mut_str()).map(Some)?, + unsafe { crate::json::from_str(payload.as_mut_str()) }.map(Some)?, Some(Message::Binary(bytes)) => { return Err(Error::UnexpectedBinaryMessage(bytes)); },