Skip to content

Commit f4e8486

Browse files
committed
fix: remove unnecessary #[no_mangle] attributes
`#[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
1 parent 28d5f2c commit f4e8486

File tree

7 files changed

+5
-31
lines changed

7 files changed

+5
-31
lines changed

examples/async.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ impl Default for ModuleConfig {
5454
}
5555
}
5656

57-
#[no_mangle]
5857
static mut ngx_http_async_commands: [ngx_command_t; 2] = [
5958
ngx_command_t {
6059
name: ngx_string!("async"),
@@ -67,7 +66,6 @@ static mut ngx_http_async_commands: [ngx_command_t; 2] = [
6766
ngx_null_command!(),
6867
];
6968

70-
#[no_mangle]
7169
static ngx_http_async_module_ctx: ngx_http_module_t = ngx_http_module_t {
7270
preconfiguration: Some(Module::preconfiguration),
7371
postconfiguration: Some(Module::postconfiguration),
@@ -84,8 +82,8 @@ static ngx_http_async_module_ctx: ngx_http_module_t = ngx_http_module_t {
8482
#[cfg(feature = "export-modules")]
8583
ngx::ngx_modules!(ngx_http_async_module);
8684

87-
#[no_mangle]
8885
#[used]
86+
#[cfg_attr(not(feature = "export-modules"), no_mangle)]
8987
pub static mut ngx_http_async_module: ngx_module_t = ngx_module_t {
9088
ctx_index: ngx_uint_t::MAX,
9189
index: ngx_uint_t::MAX,
@@ -235,7 +233,6 @@ http_request_handler!(async_access_handler, |request: &mut http::Request| {
235233
core::Status::NGX_DONE
236234
});
237235

238-
#[no_mangle]
239236
extern "C" fn ngx_http_async_commands_set_enable(
240237
cf: *mut ngx_conf_t,
241238
_cmd: *mut ngx_command_t,

examples/awssig.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ struct ModuleConfig {
4242
s3_endpoint: String,
4343
}
4444

45-
#[no_mangle]
4645
static mut ngx_http_awssigv4_commands: [ngx_command_t; 6] = [
4746
ngx_command_t {
4847
name: ngx_string!("awssigv4"),
@@ -87,7 +86,6 @@ static mut ngx_http_awssigv4_commands: [ngx_command_t; 6] = [
8786
ngx_null_command!(),
8887
];
8988

90-
#[no_mangle]
9189
static ngx_http_awssigv4_module_ctx: ngx_http_module_t = ngx_http_module_t {
9290
preconfiguration: Some(Module::preconfiguration),
9391
postconfiguration: Some(Module::postconfiguration),
@@ -104,8 +102,8 @@ static ngx_http_awssigv4_module_ctx: ngx_http_module_t = ngx_http_module_t {
104102
#[cfg(feature = "export-modules")]
105103
ngx::ngx_modules!(ngx_http_awssigv4_module);
106104

107-
#[no_mangle]
108105
#[used]
106+
#[cfg_attr(not(feature = "export-modules"), no_mangle)]
109107
pub static mut ngx_http_awssigv4_module: ngx_module_t = ngx_module_t {
110108
ctx_index: ngx_uint_t::MAX,
111109
index: ngx_uint_t::MAX,
@@ -187,7 +185,6 @@ impl Merge for ModuleConfig {
187185
}
188186
}
189187

190-
#[no_mangle]
191188
extern "C" fn ngx_http_awssigv4_commands_set_enable(
192189
cf: *mut ngx_conf_t,
193190
_cmd: *mut ngx_command_t,
@@ -211,7 +208,6 @@ extern "C" fn ngx_http_awssigv4_commands_set_enable(
211208
std::ptr::null_mut()
212209
}
213210

214-
#[no_mangle]
215211
extern "C" fn ngx_http_awssigv4_commands_set_access_key(
216212
cf: *mut ngx_conf_t,
217213
_cmd: *mut ngx_command_t,
@@ -226,7 +222,6 @@ extern "C" fn ngx_http_awssigv4_commands_set_access_key(
226222
std::ptr::null_mut()
227223
}
228224

229-
#[no_mangle]
230225
extern "C" fn ngx_http_awssigv4_commands_set_secret_key(
231226
cf: *mut ngx_conf_t,
232227
_cmd: *mut ngx_command_t,
@@ -241,7 +236,6 @@ extern "C" fn ngx_http_awssigv4_commands_set_secret_key(
241236
std::ptr::null_mut()
242237
}
243238

244-
#[no_mangle]
245239
extern "C" fn ngx_http_awssigv4_commands_set_s3_bucket(
246240
cf: *mut ngx_conf_t,
247241
_cmd: *mut ngx_command_t,
@@ -259,7 +253,6 @@ extern "C" fn ngx_http_awssigv4_commands_set_s3_bucket(
259253
std::ptr::null_mut()
260254
}
261255

262-
#[no_mangle]
263256
extern "C" fn ngx_http_awssigv4_commands_set_s3_endpoint(
264257
cf: *mut ngx_conf_t,
265258
_cmd: *mut ngx_command_t,

examples/curl.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ struct ModuleConfig {
3636
enable: bool,
3737
}
3838

39-
#[no_mangle]
4039
static mut ngx_http_curl_commands: [ngx_command_t; 2] = [
4140
ngx_command_t {
4241
name: ngx_string!("curl"),
@@ -49,7 +48,6 @@ static mut ngx_http_curl_commands: [ngx_command_t; 2] = [
4948
ngx_null_command!(),
5049
];
5150

52-
#[no_mangle]
5351
static ngx_http_curl_module_ctx: ngx_http_module_t = ngx_http_module_t {
5452
preconfiguration: Some(Module::preconfiguration),
5553
postconfiguration: Some(Module::postconfiguration),
@@ -66,8 +64,8 @@ static ngx_http_curl_module_ctx: ngx_http_module_t = ngx_http_module_t {
6664
#[cfg(feature = "export-modules")]
6765
ngx::ngx_modules!(ngx_http_curl_module);
6866

69-
#[no_mangle]
7067
#[used]
68+
#[cfg_attr(not(feature = "export-modules"), no_mangle)]
7169
pub static mut ngx_http_curl_module: ngx_module_t = ngx_module_t {
7270
ctx_index: ngx_uint_t::MAX,
7371
index: ngx_uint_t::MAX,
@@ -129,7 +127,6 @@ http_request_handler!(curl_access_handler, |request: &mut http::Request| {
129127
}
130128
});
131129

132-
#[no_mangle]
133130
extern "C" fn ngx_http_curl_commands_set_enable(
134131
cf: *mut ngx_conf_t,
135132
_cmd: *mut ngx_command_t,

examples/httporigdst.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ impl NgxHttpOrigDstCtx {
7676
}
7777
}
7878

79-
#[no_mangle]
8079
static ngx_http_orig_dst_module_ctx: ngx_http_module_t = ngx_http_module_t {
8180
preconfiguration: Some(Module::preconfiguration),
8281
postconfiguration: Some(Module::postconfiguration),
@@ -93,8 +92,8 @@ static ngx_http_orig_dst_module_ctx: ngx_http_module_t = ngx_http_module_t {
9392
#[cfg(feature = "export-modules")]
9493
ngx::ngx_modules!(ngx_http_orig_dst_module);
9594

96-
#[no_mangle]
9795
#[used]
96+
#[cfg_attr(not(feature = "export-modules"), no_mangle)]
9897
pub static mut ngx_http_orig_dst_module: ngx_module_t = ngx_module_t {
9998
ctx_index: ngx_uint_t::MAX,
10099
index: ngx_uint_t::MAX,
@@ -125,7 +124,6 @@ pub static mut ngx_http_orig_dst_module: ngx_module_t = ngx_module_t {
125124
spare_hook7: 0,
126125
};
127126

128-
#[no_mangle]
129127
static mut ngx_http_orig_dst_vars: [ngx_http_variable_t; 3] = [
130128
// ngx_str_t name
131129
// ngx_http_set_variable_pt set_handler

examples/upstream.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ impl Default for UpstreamPeerData {
7676
}
7777
}
7878

79-
#[no_mangle]
8079
static ngx_http_upstream_custom_ctx: ngx_http_module_t = ngx_http_module_t {
8180
preconfiguration: Some(Module::preconfiguration),
8281
postconfiguration: Some(Module::postconfiguration),
@@ -88,7 +87,6 @@ static ngx_http_upstream_custom_ctx: ngx_http_module_t = ngx_http_module_t {
8887
merge_loc_conf: Some(Module::merge_loc_conf),
8988
};
9089

91-
#[no_mangle]
9290
static mut ngx_http_upstream_custom_commands: [ngx_command_t; 2] = [
9391
ngx_command_t {
9492
name: ngx_string!("custom"),
@@ -106,8 +104,8 @@ static mut ngx_http_upstream_custom_commands: [ngx_command_t; 2] = [
106104
#[cfg(feature = "export-modules")]
107105
ngx::ngx_modules!(ngx_http_upstream_custom_module);
108106

109-
#[no_mangle]
110107
#[used]
108+
#[cfg_attr(not(feature = "export-modules"), no_mangle)]
111109
pub static mut ngx_http_upstream_custom_module: ngx_module_t = ngx_module_t {
112110
ctx_index: ngx_uint_t::MAX,
113111
index: ngx_uint_t::MAX,
@@ -191,7 +189,6 @@ http_upstream_init_peer_pt!(
191189
// ngx_http_usptream_get_custom_peer
192190
// For demonstration purposes, use the original get callback, but log this callback proxies through
193191
// to the original.
194-
#[no_mangle]
195192
unsafe extern "C" fn ngx_http_upstream_get_custom_peer(pc: *mut ngx_peer_connection_t, data: *mut c_void) -> ngx_int_t {
196193
let hcpd: *mut UpstreamPeerData = unsafe { mem::transmute(data) };
197194

@@ -217,7 +214,6 @@ unsafe extern "C" fn ngx_http_upstream_get_custom_peer(pc: *mut ngx_peer_connect
217214
// ngx_http_upstream_free_custom_peer
218215
// For demonstration purposes, use the original free callback, but log this callback proxies
219216
// through to the original.
220-
#[no_mangle]
221217
unsafe extern "C" fn ngx_http_upstream_free_custom_peer(
222218
pc: *mut ngx_peer_connection_t,
223219
data: *mut c_void,
@@ -237,7 +233,6 @@ unsafe extern "C" fn ngx_http_upstream_free_custom_peer(
237233
// ngx_http_upstream_init_custom
238234
// The module's custom `peer.init_upstream` callback.
239235
// The original callback is saved in our SrvConfig data and reset to this module's `peer.init`.
240-
#[no_mangle]
241236
unsafe extern "C" fn ngx_http_upstream_init_custom(
242237
cf: *mut ngx_conf_t,
243238
us: *mut ngx_http_upstream_srv_conf_t,
@@ -282,7 +277,6 @@ unsafe extern "C" fn ngx_http_upstream_init_custom(
282277
// ngx_http_upstream_commands_set_custom
283278
// Entry point for the module, if this command is set our custom upstreams take effect.
284279
// The original upstream initializer function is saved and replaced with this module's initializer.
285-
#[no_mangle]
286280
unsafe extern "C" fn ngx_http_upstream_commands_set_custom(
287281
cf: *mut ngx_conf_t,
288282
cmd: *mut ngx_command_t,

src/http/request.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use crate::ngx_null_string;
1414
#[macro_export]
1515
macro_rules! http_request_handler {
1616
( $name: ident, $handler: expr ) => {
17-
#[no_mangle]
1817
extern "C" fn $name(r: *mut $crate::ffi::ngx_http_request_t) -> $crate::ffi::ngx_int_t {
1918
let status: $crate::core::Status =
2019
$handler(unsafe { &mut $crate::http::Request::from_ngx_http_request(r) });
@@ -29,7 +28,6 @@ macro_rules! http_request_handler {
2928
#[macro_export]
3029
macro_rules! http_subrequest_handler {
3130
( $name: ident, $handler: expr ) => {
32-
#[no_mangle]
3331
unsafe extern "C" fn $name(
3432
r: *mut $crate::ffi::ngx_http_request_t,
3533
data: *mut ::std::ffi::c_void,
@@ -48,7 +46,6 @@ macro_rules! http_subrequest_handler {
4846
#[macro_export]
4947
macro_rules! http_variable_set {
5048
( $name: ident, $handler: expr ) => {
51-
#[no_mangle]
5249
unsafe extern "C" fn $name(
5350
r: *mut $crate::ffi::ngx_http_request_t,
5451
v: *mut $crate::ffi::ngx_variable_value_t,
@@ -72,7 +69,6 @@ macro_rules! http_variable_set {
7269
#[macro_export]
7370
macro_rules! http_variable_get {
7471
( $name: ident, $handler: expr ) => {
75-
#[no_mangle]
7672
unsafe extern "C" fn $name(
7773
r: *mut $crate::ffi::ngx_http_request_t,
7874
v: *mut $crate::ffi::ngx_variable_value_t,

src/http/upstream.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#[macro_export]
1313
macro_rules! http_upstream_init_peer_pt {
1414
( $name: ident, $handler: expr ) => {
15-
#[no_mangle]
1615
extern "C" fn $name(
1716
r: *mut $crate::ffi::ngx_http_request_t,
1817
us: *mut $crate::ffi::ngx_http_upstream_srv_conf_t,

0 commit comments

Comments
 (0)