rkyv / rend Goto Github PK
View Code? Open in Web Editor NEWCross-platform, endian-aware primitives for Rust
License: MIT License
Cross-platform, endian-aware primitives for Rust
License: MIT License
Title says it all, how can I get a u32_be from a u16_be?
define_unaligned_nonzero
invokes impl_nonzero
, which implements bytecheck::CheckBytes
, it has a comment stating
// SAFETY: `value` points to a `Self`, which has the same size
// as a `$prim` and is at least as aligned as one. Note that the
// bit pattern for 0 is always the same regardless of
// endianness.
But unaligned types always have an alignment of 1 and $prim
(other than 8-bit ones) have different alignments. The actual implementation then casts the pointer and reads as if it were aligned, which goes kaboom in debug (sometimes) as it's UB.
I was trying to use rkyv
with unaligned
feature and ran into this.
Replace mem::transmute::<_, [u8; 4]>(char_{be,le}::new('๐'))
with u32::from('๐').to_{be,le}_bytes()
and the assert passes on riscv64. I don't have a sparc64 environment to test on.
From Debian buildd log: riscv64 sparc64
riscv64:
running 1 test
test tests::endian_representation ... FAILED
failures:
---- tests::endian_representation stdout ----
thread 'tests::endian_representation' panicked at 'assertion failed: `(left == right)`
left: `[0, 1, 243, 137]`,
right: `[0, 1, 243, 0]`', src/lib.rs:466:13
stack backtrace:
0: rust_begin_unwind
at /usr/src/rustc-1.59.0/library/std/src/panicking.rs:498:5
1: core::panicking::panic_fmt
at /usr/src/rustc-1.59.0/library/core/src/panicking.rs:116:14
2: core::panicking::assert_failed_inner
3: core::panicking::assert_failed
at /usr/src/rustc-1.59.0/library/core/src/panicking.rs:154:5
4: rend::tests::endian_representation
at /usr/share/cargo/registry/rend-0.3.6/src/lib.rs:466:13
5: rend::tests::endian_representation::{{closure}}
at /usr/share/cargo/registry/rend-0.3.6/src/lib.rs:351:5
6: core::ops::function::FnOnce::call_once
at /usr/src/rustc-1.59.0/library/core/src/ops/function.rs:227:5
7: core::ops::function::FnOnce::call_once
at /usr/src/rustc-1.59.0/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
failures:
tests::endian_representation
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.08s
error: test failed, to rerun pass '--lib'
sparc64:
running 1 test
test tests::endian_representation ... FAILED
failures:
---- tests::endian_representation stdout ----
thread 'tests::endian_representation' panicked at 'assertion failed: `(left == right)`
left: `[137, 243, 1, 0]`,
right: `[0, 243, 1, 0]`', src/lib.rs:470:13
stack backtrace:
0: rust_begin_unwind
at /usr/src/rustc-1.59.0/library/std/src/panicking.rs:498:5
1: core::panicking::panic_fmt
at /usr/src/rustc-1.59.0/library/core/src/panicking.rs:116:14
2: core::panicking::assert_failed_inner
3: core::panicking::assert_failed
at /usr/src/rustc-1.59.0/library/core/src/panicking.rs:154:5
4: rend::tests::endian_representation
at /usr/share/cargo/registry/rend-0.3.6/src/lib.rs:470:13
5: rend::tests::endian_representation::{{closure}}
at /usr/share/cargo/registry/rend-0.3.6/src/lib.rs:351:5
6: core::ops::function::FnOnce::call_once
at /usr/src/rustc-1.59.0/library/core/src/ops/function.rs:227:5
7: core::ops::function::FnOnce::call_once
at /usr/src/rustc-1.59.0/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
failures:
tests::endian_representation
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.02s
error: test failed, to rerun pass '--lib'
Having an std
feature is pretty useless if you never use it
Hi. Test failed on fedora koji. Latest version 0.3.1. The issue is the same on the two arch.
https://kojipkgs.fedoraproject.org//work/tasks/592/73360592/build.log
https://kojipkgs.fedoraproject.org//work/tasks/597/73360597/build.log
error[E0433]: failed to resolve: use of undeclared type AtomicU16_be
--> src/lib.rs:470:46
|
470 | mem::transmute::<, [u8; 2]>(AtomicU16_be::new(0x0102))
| ^^^^^^^^^^^^ use of undeclared type AtomicU16_be
error[E0433]: failed to resolve: use of undeclared type AtomicU16_le
--> src/lib.rs:474:46
|
474 | mem::transmute::<, [u8; 2]>(AtomicU16_le::new(0x0102))
| ^^^^^^^^^^^^ use of undeclared type AtomicU16_le
error[E0433]: failed to resolve: use of undeclared type AtomicU32_be
--> src/lib.rs:480:46
|
480 | mem::transmute::<, [u8; 4]>(AtomicU32_be::new(0x01020304))
| ^^^^^^^^^^^^ use of undeclared type AtomicU32_be
error[E0433]: failed to resolve: use of undeclared type AtomicU32_le
--> src/lib.rs:484:46
|
484 | mem::transmute::<, [u8; 4]>(AtomicU32_le::new(0x01020304))
| ^^^^^^^^^^^^ use of undeclared type AtomicU32_le
error[E0433]: failed to resolve: use of undeclared type AtomicU64_be
--> src/lib.rs:490:46
|
490 | mem::transmute::<, [u8; 8]>(AtomicU64_be::new(0x0102030405060708))
| ^^^^^^^^^^^^ use of undeclared type AtomicU64_be
error[E0433]: failed to resolve: use of undeclared type AtomicU64_le
--> src/lib.rs:494:46
|
494 | mem::transmute::<, [u8; 8]>(AtomicU64_le::new(0x0102030405060708))
| ^^^^^^^^^^^^ use of undeclared type AtomicU64_le
error: aborting due to 6 previous errors
While adding rkyv support to glam, the question came up of how to handle SIMD-optimized types. There are a few pieces here:
f32_le
and i64_be
.i32_be
on a little-endian machine) may have negative performance impacts and should be carefully benchmarked.With those in mind, let's take a look at the following:
type Vec2_le = XY<f32_le>
and type Vec2_be = XY<f32_be>
?With the concrete goals:
When running build on this crate with
โ rkyv git:(master) โ cargo --version
cargo 1.63.0 (fd9c4297c 2022-07-01)
โ rkyv git:(master) โ rustc --version
rustc 1.63.0 (4b91a6ea7 2022-08-08)
โ rkyv git:(master) โ
I'm getting
error: cross-crate traits with a default impl, like `Sync`, should not be specialized
--> /Users/dev/rend/src/impl_struct.rs:396:9
|
396 | unsafe impl Sync for $endian<$ne> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
::: /Users/dev/rend/src/lib.rs:338:1
|
338 | / impl_endian!(
339 | | @atomic AtomicU64 = u64,
340 | | AtomicU64_ne = "`NativeEndian<AtomicU64>`",
341 | | AtomicU64_le = "`LittleEndian<AtomicU64>`",
342 | | AtomicU64_be = "`BigEndian<AtomicU64>`"
343 | | );
| |_- in this macro invocation
|
= warning: this will change its meaning in a future release!
= note: for more information, see issue #93367 <https://github.com/rust-lang/rust/issues/93367>
= note: `AtomicU64` is not a generic parameter
note: try using the same sequence of generic parameters as the struct definition
--> /Users/dev/rend/src/lib.rs:110:1
|
110 | / pub struct BigEndian<T> {
111 | | value: T,
112 | | }
| |_^
= note: this error originates in the macro `impl_struct` (in Nightly builds, run with -Z macro-backtrace for more info)
error: could not compile `rend` due to 36 previous errors
would love to hear if you have thoughts why?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.