Skip to content

Docs: remove Safety notes from functions which are not unsafe; mark get_module_*_conf unsafe #130

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

Merged
merged 2 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions nginx-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ impl ngx_str_t {

/// Convert the nginx string to a string slice (`&str`).
///
/// # Safety
/// This function is marked as unsafe because it involves raw pointer manipulation.
/// It assumes that the underlying `data` pointer is valid and points to a valid UTF-8 encoded string.
///
/// # Panics
/// This function panics if the `ngx_str_t` is not valid UTF-8.
///
Expand Down
12 changes: 0 additions & 12 deletions src/core/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,12 @@ pub trait Buffer {
fn as_ngx_buf_mut(&mut self) -> *mut ngx_buf_t;

/// Returns the buffer contents as a byte slice.
///
/// # Safety
/// This function is marked as unsafe because it involves raw pointer manipulation.
fn as_bytes(&self) -> &[u8] {
let buf = self.as_ngx_buf();
unsafe { slice::from_raw_parts((*buf).pos, self.len()) }
}

/// Returns the length of the buffer contents.
///
/// # Safety
/// This function is marked as unsafe because it involves raw pointer manipulation.
fn len(&self) -> usize {
let buf = self.as_ngx_buf();
unsafe {
Expand Down Expand Up @@ -68,9 +62,6 @@ pub trait Buffer {
/// The `MutableBuffer` trait extends the `Buffer` trait and provides methods for working with a mutable buffer.
pub trait MutableBuffer: Buffer {
/// Returns a mutable reference to the buffer contents as a byte slice.
///
/// # Safety
/// This function is marked as unsafe because it involves raw pointer manipulation.
fn as_bytes_mut(&mut self) -> &mut [u8] {
let buf = self.as_ngx_buf_mut();
unsafe { slice::from_raw_parts_mut((*buf).pos, self.len()) }
Expand Down Expand Up @@ -105,9 +96,6 @@ impl Buffer for TemporaryBuffer {

impl MutableBuffer for TemporaryBuffer {
/// Returns a mutable reference to the buffer contents as a byte slice.
///
/// # Safety
/// This function is marked as unsafe because it involves raw pointer manipulation.
fn as_bytes_mut(&mut self) -> &mut [u8] {
unsafe { slice::from_raw_parts_mut((*self.0).pos, self.len()) }
}
Expand Down
3 changes: 0 additions & 3 deletions src/core/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ impl Pool {
/// Allocates memory for a value of a specified type and adds a cleanup handler to the memory pool.
///
/// Returns a typed pointer to the allocated memory if successful, or a null pointer if allocation or cleanup handler addition fails.
///
/// # Safety
/// This function is marked as unsafe because it involves raw pointer manipulation.
pub fn allocate<T>(&mut self, value: T) -> *mut T {
unsafe {
let p = self.alloc(mem::size_of::<T>()) as *mut T;
Expand Down
6 changes: 3 additions & 3 deletions src/http/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl Request {
///
/// # Safety
/// Caller must ensure that type `T` matches the configuration type for the specified module.
pub fn get_module_main_conf<T>(&self, module: &ngx_module_t) -> Option<&'static T> {
pub unsafe fn get_module_main_conf<T>(&self, module: &ngx_module_t) -> Option<&'static T> {
// SAFETY: main conf is either NULL or allocated with ngx_p(c)alloc and
// explicitly initialized by the module
unsafe {
Expand All @@ -174,7 +174,7 @@ impl Request {
///
/// # Safety
/// Caller must ensure that type `T` matches the configuration type for the specified module.
pub fn get_module_srv_conf<T>(&self, module: &ngx_module_t) -> Option<&'static T> {
pub unsafe fn get_module_srv_conf<T>(&self, module: &ngx_module_t) -> Option<&'static T> {
// SAFETY: server conf is either NULL or allocated with ngx_p(c)alloc and
// explicitly initialized by the module
unsafe {
Expand All @@ -189,7 +189,7 @@ impl Request {
///
/// # Safety
/// Caller must ensure that type `T` matches the configuration type for the specified module.
pub fn get_module_loc_conf<T>(&self, module: &ngx_module_t) -> Option<&'static T> {
pub unsafe fn get_module_loc_conf<T>(&self, module: &ngx_module_t) -> Option<&'static T> {
// SAFETY: location conf is either NULL or allocated with ngx_p(c)alloc and
// explicitly initialized by the module
unsafe {
Expand Down
Loading