Skip to content

Commit

Permalink
Merge branch 'main' into davidpz/use-the-_symbolprovider_-and-_model_…
Browse files Browse the repository at this point in the history
…-directly-from-the-smithy-plugins
  • Loading branch information
david-perez committed Jun 15, 2022
2 parents f664633 + 04eeb4f commit f59b6e3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ references = ["aws-sdk-rust#547", "smithy-rs#1458"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "rcoh"

[[smithy-rs]]
message = """
Fix a potential bug with `ByteStream`'s implementation of `futures_core::stream::Stream` and add helpful error messages
for users on 32-bit systems that try to stream HTTP bodies larger than 4.29Gb.
"""
references = ["smithy-rs#1460"]
meta = { "breaking" = false, "tada" = false, "bug" = false }
author = "Velfi"

[[aws-sdk-rust]]
message = "Add `Debug` implementation to several types in `aws-config`"
references = ["smithy-rs#1421"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,16 @@ fun RustWriter.containerDocs(text: String, vararg args: Any): RustWriter {
* - Empty newlines are removed
*/
fun <T : AbstractCodeWriter<T>> T.docs(text: String, vararg args: Any, newlinePrefix: String = "/// "): T {
// Because writing docs relies on the newline prefix, ensure that there was a new line written
// before we write the docs
this.ensureNewline()
pushState()
setNewlinePrefix(newlinePrefix)
val cleaned = text.lines()
.joinToString("\n") {
// Rustdoc warns on tabs in documentation
it.trimStart().replace("\t", " ")
}
// Because writing docs relies on the newline prefix, ensure that there was a new line written
// before we write the docs
this.ensureNewline()
write(cleaned, *args)
popState()
return this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ class FluentClientGenerator(
Fluent builders are created through the [`Client`](crate::client::Client) by calling
one if its operation methods. After parameters are set using the builder methods,
the `send` method can be called to initiate the request.
""",
""".trim(),
newlinePrefix = "//! "
)
operations.forEach { operation ->
Expand Down
31 changes: 16 additions & 15 deletions rust-runtime/aws-smithy-http/src/byte_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,31 +546,32 @@ impl Inner<SdkBody> {
}
}

const SIZE_HINT_32_BIT_PANIC_MESSAGE: &str = r#"
You're running a 32-bit system and this stream's length is too large to be represented with a usize.
Please limit stream length to less than 4.294Gb or run this program on a 64-bit computer architecture.
"#;

impl<B> futures_core::stream::Stream for Inner<B>
where
B: http_body::Body,
B: http_body::Body<Data = Bytes>,
{
type Item = Result<Bytes, B::Error>;

fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
match self.project().body.poll_data(cx) {
Poll::Ready(Some(Ok(mut data))) => {
let len = data.chunk().len();
let bytes = data.copy_to_bytes(len);
Poll::Ready(Some(Ok(bytes)))
}
Poll::Ready(None) => Poll::Ready(None),
Poll::Ready(Some(Err(e))) => Poll::Ready(Some(Err(e))),
Poll::Pending => Poll::Pending,
}
self.project().body.poll_data(cx)
}

fn size_hint(&self) -> (usize, Option<usize>) {
let size_hint = http_body::Body::size_hint(&self.body);
(
size_hint.lower() as usize,
size_hint.upper().map(|u| u as usize),
)
let lower = size_hint.lower().try_into();
let upper = size_hint.upper().map(|u| u.try_into()).transpose();

match (lower, upper) {
(Ok(lower), Ok(upper)) => (lower, upper),
(Err(_), _) | (_, Err(_)) => {
panic!("{}", SIZE_HINT_32_BIT_PANIC_MESSAGE)
}
}
}
}

Expand Down

0 comments on commit f59b6e3

Please sign in to comment.