Skip to content

Commit

Permalink
fix: remove unnecessary #[no_mangle] attributes
Browse files Browse the repository at this point in the history
`#[no_mangle]` is only necessary for the symbols that are exported by
**name**. That is, exported module lists for the `cdylib` build and
individual `ngx_module_t` globals for the `staticlib`.

`extern "C"` ABI specification is sufficient for all the remaining
symbols that we pass to the NGINX C code by address.

Fixes: #102
  • Loading branch information
bavshin-f5 committed Jan 1, 2025
1 parent 28d5f2c commit f4e8486
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 31 deletions.
5 changes: 1 addition & 4 deletions examples/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ impl Default for ModuleConfig {
}
}

#[no_mangle]
static mut ngx_http_async_commands: [ngx_command_t; 2] = [
ngx_command_t {
name: ngx_string!("async"),
Expand All @@ -67,7 +66,6 @@ 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 {
preconfiguration: Some(Module::preconfiguration),
postconfiguration: Some(Module::postconfiguration),
Expand All @@ -84,8 +82,8 @@ 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]
#[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 Down Expand Up @@ -235,7 +233,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
9 changes: 1 addition & 8 deletions examples/awssig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ struct ModuleConfig {
s3_endpoint: String,
}

#[no_mangle]
static mut ngx_http_awssigv4_commands: [ngx_command_t; 6] = [
ngx_command_t {
name: ngx_string!("awssigv4"),
Expand Down Expand Up @@ -87,7 +86,6 @@ 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 {
preconfiguration: Some(Module::preconfiguration),
postconfiguration: Some(Module::postconfiguration),
Expand All @@ -104,8 +102,8 @@ 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]
#[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 Down Expand Up @@ -187,7 +185,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 +208,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 +222,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 +236,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 +253,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
5 changes: 1 addition & 4 deletions examples/curl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ struct ModuleConfig {
enable: bool,
}

#[no_mangle]
static mut ngx_http_curl_commands: [ngx_command_t; 2] = [
ngx_command_t {
name: ngx_string!("curl"),
Expand All @@ -49,7 +48,6 @@ 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 {
preconfiguration: Some(Module::preconfiguration),
postconfiguration: Some(Module::postconfiguration),
Expand All @@ -66,8 +64,8 @@ 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]
#[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 Down Expand Up @@ -129,7 +127,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
4 changes: 1 addition & 3 deletions examples/httporigdst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ impl NgxHttpOrigDstCtx {
}
}

#[no_mangle]
static ngx_http_orig_dst_module_ctx: ngx_http_module_t = ngx_http_module_t {
preconfiguration: Some(Module::preconfiguration),
postconfiguration: Some(Module::postconfiguration),
Expand All @@ -93,8 +92,8 @@ 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]
#[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 Down Expand Up @@ -125,7 +124,6 @@ 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] = [
// ngx_str_t name
// ngx_http_set_variable_pt set_handler
Expand Down
8 changes: 1 addition & 7 deletions examples/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ impl Default for UpstreamPeerData {
}
}

#[no_mangle]
static ngx_http_upstream_custom_ctx: ngx_http_module_t = ngx_http_module_t {
preconfiguration: Some(Module::preconfiguration),
postconfiguration: Some(Module::postconfiguration),
Expand All @@ -88,7 +87,6 @@ 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] = [
ngx_command_t {
name: ngx_string!("custom"),
Expand All @@ -106,8 +104,8 @@ 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]
#[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 Down Expand Up @@ -191,7 +189,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 +214,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 +233,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 +277,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

0 comments on commit f4e8486

Please sign in to comment.