News for hackers. Stuff that matters.
Re:Zlib-rs is faster than C by bangaladore on Monday March 17, 2025 @12:51PM (#43390437)
Quoted from your link

> Safe Rust: memory safe, no undefined behavior possible. Unsafe Rust: can trigger undefined behavior if preconditions are violated.

So Unsafe Rust from a UB perspective is no different than C/C++. If preconditions are violated, UB can occur, affecting anywhere in the program. Its unclear how the compiler could check anything about preconditions in a block explicitly used to say that the developer is the one upholding the preconditions.

Re:Zlib-rs is faster than C by randomNumber7 on Monday March 17, 2025 @05:08PM (#43392757)
The rust compiler was written by chuck norris.
Re:Zlib-rs is faster than C by j-krieger on Tuesday March 18, 2025 @06:52AM (#43397883)
> So Unsafe Rust from a UB perspective is no different than C/C++. If preconditions are violated, UB can occur

Only if you actively disable panics being triggered if unsafe preconditions are triggered. In most code, the program will crash instead. Enabling default panic on up violation in production code was done last year, IIRC.

> Its unclear how the compiler could check anything about preconditions

It can't. This is done at runtime, by default and without manually needed programmer interaction.

You can see an example of this in the `ptr`module, here: https://doc.rust-lang.org/beta/src/core/ptr/mod.rs.html#1071

Some are only enabled for `debug_assert` (which is enabled by default), see `ptr::read`, here: https://doc.rust-lang.org/beta/src/core/ptr/mod.rs.html#1370

Re:Zlib-rs is faster than C by bangaladore on Tuesday March 18, 2025 @02:05PM (#43402637)
These seem to be beta features. But in any case it seems like its just doing some number of asserts to validate some preconditions.

However, even at runtime it can't do anything to say if (excuse the C pseudocode) *(uint32_t*)0x1C00 = 0xFE is a valid memory operations. On some systems, in some cases it might be.

Re:Zlib-rs is faster than C by j-krieger on Wednesday March 19, 2025 @06:16AM (#43410104)
> These seem to be beta features

What? Where did you get that impression?

> But in any case it seems like its just doing some number of asserts to validate some preconditions

Yeah, like C code normally would, just in the STD in this case.

Re:Zlib-rs is faster than C by bangaladore on Monday March 24, 2025 @04:25PM (#43465052)
> What? Where did you get that impression?

https://doc.rust-lang.org/beta/

> Yeah, like C code normally would, just in the STD in this case.

Yes, in that manual checks are still needed. My point is unsafe code in rust is nowhere near safe and cannot be considered as safe without extensive analysis, no matter the language features used.