Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conversion from Bytes to Vec<u8> #547

Merged
merged 27 commits into from Jul 13, 2022

Conversation

NobodyXu
Copy link
Contributor

@NobodyXu NobodyXu commented May 1, 2022

Fixed #427

This PR adds conversion for Bytes, which is parallel to #543, which adds conversion for BytesMut.

This PR supersedes #151

Signed-off-by: Jiahao XU Jiahao_XU@outlook.com

@NobodyXu NobodyXu force-pushed the feature/into-vec-for-bytes branch from 6a81b68 to 37b4146 Compare July 6, 2022 03:07
@NobodyXu
Copy link
Contributor Author

NobodyXu commented Jul 6, 2022

CI/miri failed due to strict provenance being enabled and the bytes codebase uses integer-pointer conversions and vice versa.

I also run miri locally with strict provenance and it succeeded with warning on integer-pointer cast.

This PR itself does not add any integer-pointer conversion, so it should not block this PR from being merged.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Add new function `dealloc_shared` and call it instead of setting the
underlying `Vec` contained in `Shared` to an empty Vec then
`release_shared`.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Instead of reborrowing it as mutable reference, modify the first borrow
to be mutable reference.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Call `release_shared` if `kind == KIND_ARC` and the shared is not
unique.

Also fixed reborrowing as mutable reference issue in
`bytes_mut::shared_to_vec`.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
in `test_bytes.rs`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
instead of `&mut Shared` to avoid breaking stack borrow rules.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
As it is only used by `promotable_to_vec`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
run_tests.sh Outdated Show resolved Hide resolved
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
src/bytes.rs Outdated Show resolved Hide resolved
src/bytes.rs Outdated Show resolved Hide resolved
NobodyXu and others added 3 commits July 12, 2022 00:19
Co-authored-by: Alice Ryhl <aliceryhl@google.com>
Co-authored-by: Alice Ryhl <aliceryhl@google.com>
just to be explicit

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Just to be explicit

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
src/bytes.rs Outdated Show resolved Hide resolved
src/bytes_mut.rs Outdated Show resolved Hide resolved
until `is_unique()` returns `true`.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
To set the `ref_cnt` to `0` using `Ordering::AcqRel` if it is unique.
Otherwise, it is equivalent to a `Ordering::Relaxed` load.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
@NobodyXu NobodyXu requested a review from Darksonn July 13, 2022 03:14
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Darksonn Darksonn merged commit cd188cb into tokio-rs:master Jul 13, 2022
@NobodyXu NobodyXu deleted the feature/into-vec-for-bytes branch July 13, 2022 07:04
lelongg pushed a commit to lelongg/bytes that referenced this pull request Jan 9, 2023
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Co-authored-by: Alice Ryhl <aliceryhl@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Conversion from Bytes to Vec<u8>?
2 participants