seanmonstar / httparse

A push parser for the HTTP 1.x protocol in Rust.
https://docs.rs/httparse
Apache License 2.0
567 stars 111 forks source link

mark match_uri_vectored/match_header_value_vectored function as unsafe #135

Closed kitcatier closed 1 year ago

kitcatier commented 1 year ago

https://github.com/seanmonstar/httparse/blob/fbb0bdde72a9b571ded779fdc3544d8a39c812fc/src/simd/mod.rs#L78-L87 hello, if a function's entire body is unsafe, the function is itself unsafe and should be marked appropriately. Marking them unsafe also means that callers must make sure they know what they're doing.

seanmonstar commented 1 year ago

I believe the point there is that they are unsafe if you call them on the wrong CPU architecture. But the #[cfg] attributes on the module above make it so those calls only happen if it is compiled for the right CPU. So, that is why they can be considered safe. Sound right @AaronO?

AaronO commented 1 year ago

I believe the point there is that they are unsafe if you call them on the wrong CPU architecture. But the #[cfg] attributes on the module above make it so those calls only happen if it is compiled for the right CPU. So, that is why they can be considered safe. Sound right @AaronO?

Yes this is 100% safe as per the SAFETY: comments. Functions marked with #[target_feature(...)] must be unsafe on x86/x64/aarch64 because you're codegening specialized instructions, but it's perfectly safe to call those functions once you've asserted (at compiletime or runtime) that those instructions are supported on the host CPU.