Skip to content
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

fix: remove unnecessary #[no_mangle] attributes #114

Merged
merged 2 commits into from
Jan 1, 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
14 changes: 6 additions & 8 deletions examples/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ impl Default for ModuleConfig {
}
}

#[no_mangle]
static mut ngx_http_async_commands: [ngx_command_t; 2] = [
static mut NGX_HTTP_ASYNC_COMMANDS: [ngx_command_t; 2] = [
ngx_command_t {
name: ngx_string!("async"),
type_: (NGX_HTTP_LOC_CONF | NGX_CONF_TAKE1) as ngx_uint_t,
Expand All @@ -67,8 +66,7 @@ static mut ngx_http_async_commands: [ngx_command_t; 2] = [
ngx_null_command!(),
];

#[no_mangle]
static ngx_http_async_module_ctx: ngx_http_module_t = ngx_http_module_t {
static NGX_HTTP_ASYNC_MODULE_CTX: ngx_http_module_t = ngx_http_module_t {
preconfiguration: Some(Module::preconfiguration),
postconfiguration: Some(Module::postconfiguration),
create_main_conf: Some(Module::create_main_conf),
Expand All @@ -84,8 +82,9 @@ static ngx_http_async_module_ctx: ngx_http_module_t = ngx_http_module_t {
#[cfg(feature = "export-modules")]
ngx::ngx_modules!(ngx_http_async_module);

#[no_mangle]
#[used]
#[allow(non_upper_case_globals)]
#[cfg_attr(not(feature = "export-modules"), no_mangle)]
pub static mut ngx_http_async_module: ngx_module_t = ngx_module_t {
ctx_index: ngx_uint_t::MAX,
index: ngx_uint_t::MAX,
Expand All @@ -95,8 +94,8 @@ pub static mut ngx_http_async_module: ngx_module_t = ngx_module_t {
version: nginx_version as ngx_uint_t,
signature: NGX_RS_MODULE_SIGNATURE.as_ptr() as *const c_char,

ctx: &ngx_http_async_module_ctx as *const _ as *mut _,
commands: unsafe { &ngx_http_async_commands[0] as *const _ as *mut _ },
ctx: &NGX_HTTP_ASYNC_MODULE_CTX as *const _ as *mut _,
commands: unsafe { &NGX_HTTP_ASYNC_COMMANDS[0] as *const _ as *mut _ },
type_: NGX_HTTP_MODULE as ngx_uint_t,

init_master: None,
Expand Down Expand Up @@ -235,7 +234,6 @@ http_request_handler!(async_access_handler, |request: &mut http::Request| {
core::Status::NGX_DONE
});

#[no_mangle]
extern "C" fn ngx_http_async_commands_set_enable(
cf: *mut ngx_conf_t,
_cmd: *mut ngx_command_t,
Expand Down
18 changes: 6 additions & 12 deletions examples/awssig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ struct ModuleConfig {
s3_endpoint: String,
}

#[no_mangle]
static mut ngx_http_awssigv4_commands: [ngx_command_t; 6] = [
static mut NGX_HTTP_AWSSIGV4_COMMANDS: [ngx_command_t; 6] = [
ngx_command_t {
name: ngx_string!("awssigv4"),
type_: (NGX_HTTP_LOC_CONF | NGX_HTTP_SRV_CONF | NGX_CONF_TAKE1) as ngx_uint_t,
Expand Down Expand Up @@ -87,8 +86,7 @@ static mut ngx_http_awssigv4_commands: [ngx_command_t; 6] = [
ngx_null_command!(),
];

#[no_mangle]
static ngx_http_awssigv4_module_ctx: ngx_http_module_t = ngx_http_module_t {
static NGX_HTTP_AWSSIGV4_MODULE_CTX: ngx_http_module_t = ngx_http_module_t {
preconfiguration: Some(Module::preconfiguration),
postconfiguration: Some(Module::postconfiguration),
create_main_conf: Some(Module::create_main_conf),
Expand All @@ -104,8 +102,9 @@ static ngx_http_awssigv4_module_ctx: ngx_http_module_t = ngx_http_module_t {
#[cfg(feature = "export-modules")]
ngx::ngx_modules!(ngx_http_awssigv4_module);

#[no_mangle]
#[used]
#[allow(non_upper_case_globals)]
#[cfg_attr(not(feature = "export-modules"), no_mangle)]
pub static mut ngx_http_awssigv4_module: ngx_module_t = ngx_module_t {
ctx_index: ngx_uint_t::MAX,
index: ngx_uint_t::MAX,
Expand All @@ -115,8 +114,8 @@ pub static mut ngx_http_awssigv4_module: ngx_module_t = ngx_module_t {
version: nginx_version as ngx_uint_t,
signature: NGX_RS_MODULE_SIGNATURE.as_ptr() as *const c_char,

ctx: &ngx_http_awssigv4_module_ctx as *const _ as *mut _,
commands: unsafe { &ngx_http_awssigv4_commands[0] as *const _ as *mut _ },
ctx: &NGX_HTTP_AWSSIGV4_MODULE_CTX as *const _ as *mut _,
commands: unsafe { &NGX_HTTP_AWSSIGV4_COMMANDS[0] as *const _ as *mut _ },
type_: NGX_HTTP_MODULE as ngx_uint_t,

init_master: None,
Expand Down Expand Up @@ -187,7 +186,6 @@ impl Merge for ModuleConfig {
}
}

#[no_mangle]
extern "C" fn ngx_http_awssigv4_commands_set_enable(
cf: *mut ngx_conf_t,
_cmd: *mut ngx_command_t,
Expand All @@ -211,7 +209,6 @@ extern "C" fn ngx_http_awssigv4_commands_set_enable(
std::ptr::null_mut()
}

#[no_mangle]
extern "C" fn ngx_http_awssigv4_commands_set_access_key(
cf: *mut ngx_conf_t,
_cmd: *mut ngx_command_t,
Expand All @@ -226,7 +223,6 @@ extern "C" fn ngx_http_awssigv4_commands_set_access_key(
std::ptr::null_mut()
}

#[no_mangle]
extern "C" fn ngx_http_awssigv4_commands_set_secret_key(
cf: *mut ngx_conf_t,
_cmd: *mut ngx_command_t,
Expand All @@ -241,7 +237,6 @@ extern "C" fn ngx_http_awssigv4_commands_set_secret_key(
std::ptr::null_mut()
}

#[no_mangle]
extern "C" fn ngx_http_awssigv4_commands_set_s3_bucket(
cf: *mut ngx_conf_t,
_cmd: *mut ngx_command_t,
Expand All @@ -259,7 +254,6 @@ extern "C" fn ngx_http_awssigv4_commands_set_s3_bucket(
std::ptr::null_mut()
}

#[no_mangle]
extern "C" fn ngx_http_awssigv4_commands_set_s3_endpoint(
cf: *mut ngx_conf_t,
_cmd: *mut ngx_command_t,
Expand Down
14 changes: 6 additions & 8 deletions examples/curl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ struct ModuleConfig {
enable: bool,
}

#[no_mangle]
static mut ngx_http_curl_commands: [ngx_command_t; 2] = [
static mut NGX_HTTP_CURL_COMMANDS: [ngx_command_t; 2] = [
ngx_command_t {
name: ngx_string!("curl"),
type_: (NGX_HTTP_LOC_CONF | NGX_CONF_TAKE1) as ngx_uint_t,
Expand All @@ -49,8 +48,7 @@ static mut ngx_http_curl_commands: [ngx_command_t; 2] = [
ngx_null_command!(),
];

#[no_mangle]
static ngx_http_curl_module_ctx: ngx_http_module_t = ngx_http_module_t {
static NGX_HTTP_CURL_MODULE_CTX: ngx_http_module_t = ngx_http_module_t {
preconfiguration: Some(Module::preconfiguration),
postconfiguration: Some(Module::postconfiguration),
create_main_conf: Some(Module::create_main_conf),
Expand All @@ -66,8 +64,9 @@ static ngx_http_curl_module_ctx: ngx_http_module_t = ngx_http_module_t {
#[cfg(feature = "export-modules")]
ngx::ngx_modules!(ngx_http_curl_module);

#[no_mangle]
#[used]
#[allow(non_upper_case_globals)]
#[cfg_attr(not(feature = "export-modules"), no_mangle)]
pub static mut ngx_http_curl_module: ngx_module_t = ngx_module_t {
ctx_index: ngx_uint_t::MAX,
index: ngx_uint_t::MAX,
Expand All @@ -77,8 +76,8 @@ pub static mut ngx_http_curl_module: ngx_module_t = ngx_module_t {
version: nginx_version as ngx_uint_t,
signature: NGX_RS_MODULE_SIGNATURE.as_ptr() as *const c_char,

ctx: &ngx_http_curl_module_ctx as *const _ as *mut _,
commands: unsafe { &ngx_http_curl_commands[0] as *const _ as *mut _ },
ctx: &NGX_HTTP_CURL_MODULE_CTX as *const _ as *mut _,
commands: unsafe { &NGX_HTTP_CURL_COMMANDS[0] as *const _ as *mut _ },
type_: NGX_HTTP_MODULE as ngx_uint_t,

init_master: None,
Expand Down Expand Up @@ -129,7 +128,6 @@ http_request_handler!(curl_access_handler, |request: &mut http::Request| {
}
});

#[no_mangle]
extern "C" fn ngx_http_curl_commands_set_enable(
cf: *mut ngx_conf_t,
_cmd: *mut ngx_command_t,
Expand Down
13 changes: 6 additions & 7 deletions examples/httporigdst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ impl NgxHttpOrigDstCtx {
}
}

#[no_mangle]
static ngx_http_orig_dst_module_ctx: ngx_http_module_t = ngx_http_module_t {
static NGX_HTTP_ORIG_DST_MODULE_CTX: ngx_http_module_t = ngx_http_module_t {
preconfiguration: Some(Module::preconfiguration),
postconfiguration: Some(Module::postconfiguration),
create_main_conf: Some(Module::create_main_conf),
Expand All @@ -93,8 +92,9 @@ static ngx_http_orig_dst_module_ctx: ngx_http_module_t = ngx_http_module_t {
#[cfg(feature = "export-modules")]
ngx::ngx_modules!(ngx_http_orig_dst_module);

#[no_mangle]
#[used]
#[allow(non_upper_case_globals)]
#[cfg_attr(not(feature = "export-modules"), no_mangle)]
pub static mut ngx_http_orig_dst_module: ngx_module_t = ngx_module_t {
ctx_index: ngx_uint_t::MAX,
index: ngx_uint_t::MAX,
Expand All @@ -103,7 +103,7 @@ pub static mut ngx_http_orig_dst_module: ngx_module_t = ngx_module_t {
spare1: 0,
version: nginx_version as ngx_uint_t,
signature: NGX_RS_MODULE_SIGNATURE.as_ptr() as *const c_char,
ctx: &ngx_http_orig_dst_module_ctx as *const _ as *mut _,
ctx: &NGX_HTTP_ORIG_DST_MODULE_CTX as *const _ as *mut _,
commands: std::ptr::null_mut(),
type_: NGX_HTTP_MODULE as ngx_uint_t,

Expand All @@ -125,8 +125,7 @@ pub static mut ngx_http_orig_dst_module: ngx_module_t = ngx_module_t {
spare_hook7: 0,
};

#[no_mangle]
static mut ngx_http_orig_dst_vars: [ngx_http_variable_t; 3] = [
static mut NGX_HTTP_ORIG_DST_VARS: [ngx_http_variable_t; 3] = [
// ngx_str_t name
// ngx_http_set_variable_pt set_handler
// ngx_http_get_variable_pt get_handler
Expand Down Expand Up @@ -299,7 +298,7 @@ impl HTTPModule for Module {

// static ngx_int_t ngx_http_orig_dst_add_variables(ngx_conf_t *cf)
unsafe extern "C" fn preconfiguration(cf: *mut ngx_conf_t) -> ngx_int_t {
for mut v in ngx_http_orig_dst_vars {
for mut v in NGX_HTTP_ORIG_DST_VARS {
if v.name.len == 0 {
break;
}
Expand Down
17 changes: 6 additions & 11 deletions examples/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ impl Default for UpstreamPeerData {
}
}

#[no_mangle]
static ngx_http_upstream_custom_ctx: ngx_http_module_t = ngx_http_module_t {
static NGX_HTTP_UPSTREAM_CUSTOM_CTX: ngx_http_module_t = ngx_http_module_t {
preconfiguration: Some(Module::preconfiguration),
postconfiguration: Some(Module::postconfiguration),
create_main_conf: Some(Module::create_main_conf),
Expand All @@ -88,8 +87,7 @@ static ngx_http_upstream_custom_ctx: ngx_http_module_t = ngx_http_module_t {
merge_loc_conf: Some(Module::merge_loc_conf),
};

#[no_mangle]
static mut ngx_http_upstream_custom_commands: [ngx_command_t; 2] = [
static mut NGX_HTTP_UPSTREAM_CUSTOM_COMMANDS: [ngx_command_t; 2] = [
ngx_command_t {
name: ngx_string!("custom"),
type_: (NGX_HTTP_UPS_CONF | NGX_CONF_NOARGS | NGX_CONF_TAKE1) as ngx_uint_t,
Expand All @@ -106,8 +104,9 @@ static mut ngx_http_upstream_custom_commands: [ngx_command_t; 2] = [
#[cfg(feature = "export-modules")]
ngx::ngx_modules!(ngx_http_upstream_custom_module);

#[no_mangle]
#[used]
#[allow(non_upper_case_globals)]
#[cfg_attr(not(feature = "export-modules"), no_mangle)]
pub static mut ngx_http_upstream_custom_module: ngx_module_t = ngx_module_t {
ctx_index: ngx_uint_t::MAX,
index: ngx_uint_t::MAX,
Expand All @@ -117,8 +116,8 @@ pub static mut ngx_http_upstream_custom_module: ngx_module_t = ngx_module_t {
version: nginx_version as ngx_uint_t,
signature: NGX_RS_MODULE_SIGNATURE.as_ptr() as *const c_char,

ctx: &ngx_http_upstream_custom_ctx as *const _ as *mut _,
commands: unsafe { &ngx_http_upstream_custom_commands[0] as *const _ as *mut _ },
ctx: &NGX_HTTP_UPSTREAM_CUSTOM_CTX as *const _ as *mut _,
commands: unsafe { &NGX_HTTP_UPSTREAM_CUSTOM_COMMANDS[0] as *const _ as *mut _ },
type_: NGX_HTTP_MODULE as ngx_uint_t,

init_master: None,
Expand Down Expand Up @@ -191,7 +190,6 @@ http_upstream_init_peer_pt!(
// ngx_http_usptream_get_custom_peer
// For demonstration purposes, use the original get callback, but log this callback proxies through
// to the original.
#[no_mangle]
unsafe extern "C" fn ngx_http_upstream_get_custom_peer(pc: *mut ngx_peer_connection_t, data: *mut c_void) -> ngx_int_t {
let hcpd: *mut UpstreamPeerData = unsafe { mem::transmute(data) };

Expand All @@ -217,7 +215,6 @@ unsafe extern "C" fn ngx_http_upstream_get_custom_peer(pc: *mut ngx_peer_connect
// ngx_http_upstream_free_custom_peer
// For demonstration purposes, use the original free callback, but log this callback proxies
// through to the original.
#[no_mangle]
unsafe extern "C" fn ngx_http_upstream_free_custom_peer(
pc: *mut ngx_peer_connection_t,
data: *mut c_void,
Expand All @@ -237,7 +234,6 @@ unsafe extern "C" fn ngx_http_upstream_free_custom_peer(
// ngx_http_upstream_init_custom
// The module's custom `peer.init_upstream` callback.
// The original callback is saved in our SrvConfig data and reset to this module's `peer.init`.
#[no_mangle]
unsafe extern "C" fn ngx_http_upstream_init_custom(
cf: *mut ngx_conf_t,
us: *mut ngx_http_upstream_srv_conf_t,
Expand Down Expand Up @@ -282,7 +278,6 @@ unsafe extern "C" fn ngx_http_upstream_init_custom(
// ngx_http_upstream_commands_set_custom
// Entry point for the module, if this command is set our custom upstreams take effect.
// The original upstream initializer function is saved and replaced with this module's initializer.
#[no_mangle]
unsafe extern "C" fn ngx_http_upstream_commands_set_custom(
cf: *mut ngx_conf_t,
cmd: *mut ngx_command_t,
Expand Down
4 changes: 0 additions & 4 deletions src/http/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::ngx_null_string;
#[macro_export]
macro_rules! http_request_handler {
( $name: ident, $handler: expr ) => {
#[no_mangle]
extern "C" fn $name(r: *mut $crate::ffi::ngx_http_request_t) -> $crate::ffi::ngx_int_t {
let status: $crate::core::Status =
$handler(unsafe { &mut $crate::http::Request::from_ngx_http_request(r) });
Expand All @@ -29,7 +28,6 @@ macro_rules! http_request_handler {
#[macro_export]
macro_rules! http_subrequest_handler {
( $name: ident, $handler: expr ) => {
#[no_mangle]
unsafe extern "C" fn $name(
r: *mut $crate::ffi::ngx_http_request_t,
data: *mut ::std::ffi::c_void,
Expand All @@ -48,7 +46,6 @@ macro_rules! http_subrequest_handler {
#[macro_export]
macro_rules! http_variable_set {
( $name: ident, $handler: expr ) => {
#[no_mangle]
unsafe extern "C" fn $name(
r: *mut $crate::ffi::ngx_http_request_t,
v: *mut $crate::ffi::ngx_variable_value_t,
Expand All @@ -72,7 +69,6 @@ macro_rules! http_variable_set {
#[macro_export]
macro_rules! http_variable_get {
( $name: ident, $handler: expr ) => {
#[no_mangle]
unsafe extern "C" fn $name(
r: *mut $crate::ffi::ngx_http_request_t,
v: *mut $crate::ffi::ngx_variable_value_t,
Expand Down
1 change: 0 additions & 1 deletion src/http/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#[macro_export]
macro_rules! http_upstream_init_peer_pt {
( $name: ident, $handler: expr ) => {
#[no_mangle]
extern "C" fn $name(
r: *mut $crate::ffi::ngx_http_request_t,
us: *mut $crate::ffi::ngx_http_upstream_srv_conf_t,
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,21 @@ pub mod log;
macro_rules! ngx_modules {
($( $mod:ident ),+) => {
#[no_mangle]
#[allow(non_upper_case_globals)]
pub static mut ngx_modules: [*const $crate::ffi::ngx_module_t; $crate::count!($( $mod, )+) + 1] = [
$( unsafe { &$mod } as *const $crate::ffi::ngx_module_t, )+
::std::ptr::null()
];

#[no_mangle]
#[allow(non_upper_case_globals)]
pub static mut ngx_module_names: [*const ::std::ffi::c_char; $crate::count!($( $mod, )+) + 1] = [
$( concat!(stringify!($mod), "\0").as_ptr() as *const ::std::ffi::c_char, )+
::std::ptr::null()
];

#[no_mangle]
#[allow(non_upper_case_globals)]
pub static mut ngx_module_order: [*const ::std::ffi::c_char; 1] = [
::std::ptr::null()
];
Expand Down
Loading