-
Notifications
You must be signed in to change notification settings - Fork 194
enforce no_std for some protocol/v2 crates
#1230
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
Changes from all commits
58c53c0
133f73e
433d9cb
76670d9
83d07c0
1a9012a
537a6ac
b4da137
8cd634b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # binary_sv2 | ||
|
|
||
| `binary_sv2` is a Rust `no_std` crate |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # binary_codec_sv2 | ||
|
|
||
| `binary_codec_sv2` is a Rust `no_std` crate |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,9 @@ | |
| //! Seq0255 <-> SEQ0_255[T] | ||
| //! Seq064K <-> SEQ0_64K[T] | ||
| //! ``` | ||
|
|
||
| #![cfg_attr(feature = "no_std", no_std)] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can now use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I asked about this in this comment. Current Look like you propose to remove it. It is also my preference.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also think we should enforce
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR looks good to me and is ready to go. We can enforce the
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree. Let's confirm in the dev meet before we approve. |
||
|
|
||
| #[cfg(not(feature = "no_std"))] | ||
| use std::io::{Error as E, ErrorKind}; | ||
|
|
||
|
|
@@ -35,6 +38,8 @@ pub use crate::codec::{ | |
| Fixed, GetSize, SizeHint, | ||
| }; | ||
|
|
||
| use alloc::vec::Vec; | ||
|
|
||
| #[allow(clippy::wrong_self_convention)] | ||
| pub fn to_bytes<T: Encodable + GetSize>(src: T) -> Result<Vec<u8>, Error> { | ||
| let mut result = vec![0_u8; src.get_size()]; | ||
|
|
@@ -281,7 +286,7 @@ impl From<&[u8]> for CVec { | |
| // the std lib) | ||
| let len = buffer.len(); | ||
| let ptr = buffer.as_mut_ptr(); | ||
| std::mem::forget(buffer); | ||
| core::mem::forget(buffer); | ||
|
|
||
| CVec { | ||
| data: ptr, | ||
|
|
@@ -296,7 +301,7 @@ impl From<&[u8]> for CVec { | |
| /// # Safety | ||
| #[no_mangle] | ||
| pub unsafe extern "C" fn cvec_from_buffer(data: *const u8, len: usize) -> CVec { | ||
| let input = std::slice::from_raw_parts(data, len); | ||
| let input = core::slice::from_raw_parts(data, len); | ||
|
|
||
| let mut buffer: Vec<u8> = vec![0; len]; | ||
| buffer.copy_from_slice(input); | ||
|
|
@@ -305,7 +310,7 @@ pub unsafe extern "C" fn cvec_from_buffer(data: *const u8, len: usize) -> CVec { | |
| // cause UB, but it may be unsound due to unclear (to me, at least) guarantees of the std lib) | ||
| let len = buffer.len(); | ||
| let ptr = buffer.as_mut_ptr(); | ||
| std::mem::forget(buffer); | ||
| core::mem::forget(buffer); | ||
|
|
||
| CVec { | ||
| data: ptr, | ||
|
|
@@ -360,7 +365,7 @@ impl<'a, const A: bool, const B: usize, const C: usize, const D: usize> | |
| let len = inner.len(); | ||
| let cap = inner.capacity(); | ||
| let ptr = inner.as_mut_ptr(); | ||
| std::mem::forget(inner); | ||
| core::mem::forget(inner); | ||
|
|
||
| (ptr, len, cap) | ||
| } | ||
|
|
@@ -371,7 +376,7 @@ impl<'a, const A: bool, const B: usize, const C: usize, const D: usize> | |
| let len = inner.len(); | ||
| let cap = inner.capacity(); | ||
| let ptr = inner.as_mut_ptr(); | ||
| std::mem::forget(inner); | ||
| core::mem::forget(inner); | ||
|
|
||
| (ptr, len, cap) | ||
| } | ||
|
|
@@ -393,7 +398,7 @@ pub unsafe extern "C" fn init_cvec2() -> CVec2 { | |
| // cause UB, but it may be unsound due to unclear (to me, at least) guarantees of the std lib) | ||
| let len = buffer.len(); | ||
| let ptr = buffer.as_mut_ptr(); | ||
| std::mem::forget(buffer); | ||
| core::mem::forget(buffer); | ||
|
|
||
| CVec2 { | ||
| data: ptr, | ||
|
|
@@ -412,7 +417,7 @@ pub unsafe extern "C" fn cvec2_push(cvec2: &mut CVec2, cvec: CVec) { | |
|
|
||
| let len = buffer.len(); | ||
| let ptr = buffer.as_mut_ptr(); | ||
| std::mem::forget(buffer); | ||
| core::mem::forget(buffer); | ||
|
|
||
| cvec2.data = ptr; | ||
| cvec2.len = len; | ||
|
|
@@ -428,7 +433,7 @@ impl<'a, T: Into<CVec>> From<Seq0255<'a, T>> for CVec2 { | |
| let len = v.len(); | ||
| let capacity = v.capacity(); | ||
| let data = v.as_mut_ptr(); | ||
| std::mem::forget(v); | ||
| core::mem::forget(v); | ||
| Self { | ||
| data, | ||
| len, | ||
|
|
@@ -445,7 +450,7 @@ impl<'a, T: Into<CVec>> From<Seq064K<'a, T>> for CVec2 { | |
| let len = v.len(); | ||
| let capacity = v.capacity(); | ||
| let data = v.as_mut_ptr(); | ||
| std::mem::forget(v); | ||
| core::mem::forget(v); | ||
| Self { | ||
| data, | ||
| len, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # derive_codec_sv2 | ||
|
|
||
| `derive_codec_sv2` is a Rust `no_std` crate |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # serde_sv2 | ||
|
|
||
| `serde_sv2` is a Rust `no_std` crate |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # framing_sv2 | ||
|
|
||
| `framing_sv2` is a Rust `no_std` crate |
Uh oh!
There was an error while loading. Please reload this page.