Skip to content

Miscellaneous fixes #163

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 4 commits into from
Jun 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
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
needs: rust-version
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust-version:
- ${{ needs.rust-version.outputs.version }}
Expand Down
2 changes: 1 addition & 1 deletion examples/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ extern "C" fn ngx_http_async_commands_set_enable(
}
};

std::ptr::null_mut()
ngx::core::NGX_CONF_OK
}

fn ngx_http_async_runtime() -> &'static Runtime {
Expand Down
13 changes: 7 additions & 6 deletions examples/awssig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ extern "C" fn ngx_http_awssigv4_commands_set_enable(
}
};

std::ptr::null_mut()
ngx::core::NGX_CONF_OK
}

extern "C" fn ngx_http_awssigv4_commands_set_access_key(
Expand All @@ -202,7 +202,7 @@ extern "C" fn ngx_http_awssigv4_commands_set_access_key(
conf.access_key = (*args.add(1)).to_string();
};

std::ptr::null_mut()
ngx::core::NGX_CONF_OK
}

extern "C" fn ngx_http_awssigv4_commands_set_secret_key(
Expand All @@ -216,7 +216,7 @@ extern "C" fn ngx_http_awssigv4_commands_set_secret_key(
conf.secret_key = (*args.add(1)).to_string();
};

std::ptr::null_mut()
ngx::core::NGX_CONF_OK
}

extern "C" fn ngx_http_awssigv4_commands_set_s3_bucket(
Expand All @@ -230,10 +230,11 @@ extern "C" fn ngx_http_awssigv4_commands_set_s3_bucket(
conf.s3_bucket = (*args.add(1)).to_string();
if conf.s3_bucket.len() == 1 {
println!("Validation failed");
return ngx::core::NGX_CONF_ERROR as _;
return ngx::core::NGX_CONF_ERROR;
}
};
std::ptr::null_mut()

ngx::core::NGX_CONF_OK
}

extern "C" fn ngx_http_awssigv4_commands_set_s3_endpoint(
Expand All @@ -247,7 +248,7 @@ extern "C" fn ngx_http_awssigv4_commands_set_s3_endpoint(
conf.s3_endpoint = (*args.add(1)).to_string();
};

std::ptr::null_mut()
ngx::core::NGX_CONF_OK
}

http_request_handler!(awssigv4_header_handler, |request: &mut Request| {
Expand Down
2 changes: 1 addition & 1 deletion examples/curl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,5 @@ extern "C" fn ngx_http_curl_commands_set_enable(
}
};

std::ptr::null_mut()
ngx::core::NGX_CONF_OK
}
6 changes: 3 additions & 3 deletions examples/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ unsafe extern "C" fn ngx_http_upstream_commands_set_custom(
value[1],
&(*cmd).name
);
return usize::MAX as *mut c_char;
return ngx::core::NGX_CONF_ERROR;
}
ccf.max = n as u32;
}
Expand All @@ -298,8 +298,8 @@ unsafe extern "C" fn ngx_http_upstream_commands_set_custom(
uscf.peer.init_upstream = Some(ngx_http_upstream_init_custom);

ngx_log_debug_mask!(DebugMask::Http, cf.log, "CUSTOM UPSTREAM end module init");
// NGX_CONF_OK
std::ptr::null_mut()

ngx::core::NGX_CONF_OK
}

// The upstream module.
Expand Down
15 changes: 7 additions & 8 deletions nginx-sys/build/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ fn generate_binding(nginx: &NginxSource) {
// Bindings will not compile on Linux without block listing this item
// It is worth investigating why this is
.blocklist_item("IPPORT_RESERVED")
// will be restored later in build.rs
.blocklist_item("NGX_ALIGNMENT")
.generate_cstr(true)
// The input header we would like to generate bindings for.
.header("build/wrapper.h")
Expand Down Expand Up @@ -339,22 +341,19 @@ pub fn print_cargo_metadata<T: AsRef<Path>>(includes: &[T]) -> Result<(), Box<dy

// A quoted list of all recognized features to be passed to rustc-check-cfg.
let values = NGX_CONF_FEATURES.join("\",\"");
println!("cargo::metadata=features_check=\"{}\"", values);
println!(
"cargo::rustc-check-cfg=cfg(ngx_feature, values(\"{}\"))",
values
);
println!("cargo::metadata=features_check=\"{values}\"");
println!("cargo::rustc-check-cfg=cfg(ngx_feature, values(\"{values}\"))");

// A list of features enabled in the nginx build we're using
println!("cargo::metadata=features={}", ngx_features.join(","));
for feature in ngx_features {
println!("cargo::rustc-cfg=ngx_feature=\"{}\"", feature);
println!("cargo::rustc-cfg=ngx_feature=\"{feature}\"");
}

// A quoted list of all recognized operating systems to be passed to rustc-check-cfg.
let values = NGX_CONF_OS.join("\",\"");
println!("cargo::metadata=os_check=\"{}\"", values);
println!("cargo::rustc-check-cfg=cfg(ngx_os, values(\"{}\"))", values);
println!("cargo::metadata=os_check=\"{values}\"");
println!("cargo::rustc-check-cfg=cfg(ngx_os, values(\"{values}\"))");
// Current detected operating system
println!("cargo::metadata=os={ngx_os}");
println!("cargo::rustc-cfg=ngx_os=\"{ngx_os}\"");
Expand Down
4 changes: 4 additions & 0 deletions nginx-sys/build/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

const char *NGX_RS_MODULE_SIGNATURE = NGX_MODULE_SIGNATURE;

// NGX_ALIGNMENT could be defined as a constant or an expression, with the
// latter being unsupported by bindgen.
const size_t NGX_RS_ALIGNMENT = NGX_ALIGNMENT;

// `--prefix=` results in not emitting the declaration
#ifndef NGX_PREFIX
#define NGX_PREFIX ""
Expand Down
8 changes: 8 additions & 0 deletions nginx-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ pub use queue::*;
#[cfg(ngx_feature = "stream")]
pub use stream::*;

/// Default alignment for pool allocations.
pub const NGX_ALIGNMENT: usize = NGX_RS_ALIGNMENT;

// Check if the allocations made with ngx_palloc are properly aligned.
// If the check fails, objects allocated from `ngx_pool` can violate Rust pointer alignment
// requirements.
const _: () = assert!(core::mem::align_of::<ngx_str_t>() <= NGX_ALIGNMENT);

impl ngx_command_t {
/// Creates a new empty [`ngx_command_t`] instance.
///
Expand Down
9 changes: 6 additions & 3 deletions src/core/status.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use core::ffi::c_char;
use core::fmt;
use core::ptr;

use crate::ffi::*;

Expand Down Expand Up @@ -62,6 +64,7 @@ ngx_codes! {
(NGX_ABORT);
}

/// NGX_CONF_ERROR - An error occurred while parsing and validating configuration.
pub const NGX_CONF_ERROR: *const () = -1isize as *const ();
// pub const CONF_OK: Status = Status(NGX_CONF_OK as ngx_int_t);
/// An error occurred while parsing and validating configuration.
pub const NGX_CONF_ERROR: *mut c_char = ptr::null_mut::<c_char>().wrapping_offset(-1);
/// Configuration handler succeeded.
pub const NGX_CONF_OK: *mut c_char = ptr::null_mut();
2 changes: 1 addition & 1 deletion src/core/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl NgxStr {
///
/// See [`String::from_utf8_lossy`].
#[cfg(feature = "alloc")]
pub fn to_string_lossy(&self) -> Cow<str> {
pub fn to_string_lossy(&self) -> Cow<'_, str> {
String::from_utf8_lossy(self.as_bytes())
}

Expand Down
6 changes: 3 additions & 3 deletions src/http/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,13 @@ impl Request {

/// Iterate over headers_in
/// each header item is (&str, &str) (borrowed)
pub fn headers_in_iterator(&self) -> NgxListIterator {
pub fn headers_in_iterator(&self) -> NgxListIterator<'_> {
unsafe { list_iterator(&self.0.headers_in.headers) }
}

/// Iterate over headers_out
/// each header item is (&str, &str) (borrowed)
pub fn headers_out_iterator(&self) -> NgxListIterator {
pub fn headers_out_iterator(&self) -> NgxListIterator<'_> {
unsafe { list_iterator(&self.0.headers_out.headers) }
}
}
Expand Down Expand Up @@ -448,7 +448,7 @@ impl<'a> From<&'a ngx_list_part_t> for ListPart<'a> {
/// # Safety
///
/// The caller has provided a valid [`ngx_str_t`] which can be dereferenced validly.
pub unsafe fn list_iterator(list: &ngx_list_t) -> NgxListIterator {
pub unsafe fn list_iterator(list: &ngx_list_t) -> NgxListIterator<'_> {
NgxListIterator {
part: Some((&list.part).into()),
i: 0,
Expand Down
Loading