Skip to content

Commit b8377d0

Browse files
JyJyJcrdekobon
authored andcommitted
fix: replace borrow() by &*addr_of!()
1 parent f708d0d commit b8377d0

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

examples/async.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ use ngx::ffi::{
77
use ngx::http::MergeConfigError;
88
use ngx::{core, core::Status, http, http::HTTPModule};
99
use ngx::{http_request_handler, ngx_log_debug_http, ngx_modules, ngx_null_command, ngx_string};
10-
use std::borrow::Borrow;
1110
use std::os::raw::{c_char, c_void};
12-
use std::ptr::addr_of_mut;
11+
use std::ptr::{addr_of, addr_of_mut};
1312
use std::sync::atomic::AtomicBool;
1413
use std::sync::Arc;
1514
use std::time::Instant;
@@ -23,7 +22,7 @@ impl http::HTTPModule for Module {
2322
type LocConf = ModuleConfig;
2423

2524
unsafe extern "C" fn postconfiguration(cf: *mut ngx_conf_t) -> ngx_int_t {
26-
let cmcf = http::ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module.borrow());
25+
let cmcf = http::ngx_http_conf_get_module_main_conf(cf, &*addr_of!(ngx_http_core_module));
2726

2827
let h = ngx_array_push(&mut (*cmcf).phases[ngx_http_phases_NGX_HTTP_ACCESS_PHASE as usize].handlers)
2928
as *mut ngx_http_handler_pt;
@@ -164,7 +163,7 @@ unsafe fn post_event(event: *mut ngx_event_t, queue: *mut ngx_queue_s) {
164163
}
165164

166165
http_request_handler!(async_access_handler, |request: &mut http::Request| {
167-
let co = unsafe { request.get_module_loc_conf::<ModuleConfig>(ngx_http_async_module.borrow()) };
166+
let co = unsafe { request.get_module_loc_conf::<ModuleConfig>(&*addr_of!(ngx_http_async_module)) };
168167
let co = co.expect("module config is none");
169168
if !co.enable {
170169
return core::Status::NGX_DECLINED;

examples/awssig.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use ngx::ffi::{
77
};
88
use ngx::{core, core::Status, http::*};
99
use ngx::{http_request_handler, ngx_log_debug_http, ngx_modules, ngx_null_command, ngx_string};
10-
use std::borrow::Borrow;
1110
use std::os::raw::{c_char, c_void};
11+
use std::ptr::addr_of;
1212

1313
struct Module;
1414

@@ -18,7 +18,7 @@ impl HTTPModule for Module {
1818
type LocConf = ModuleConfig;
1919

2020
unsafe extern "C" fn postconfiguration(cf: *mut ngx_conf_t) -> ngx_int_t {
21-
let cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module.borrow());
21+
let cmcf = ngx_http_conf_get_module_main_conf(cf, &*addr_of!(ngx_http_core_module));
2222

2323
let h = ngx_array_push(&mut (*cmcf).phases[ngx_http_phases_NGX_HTTP_PRECONTENT_PHASE as usize].handlers)
2424
as *mut ngx_http_handler_pt;
@@ -270,7 +270,7 @@ extern "C" fn ngx_http_awssigv4_commands_set_s3_endpoint(
270270

271271
http_request_handler!(awssigv4_header_handler, |request: &mut Request| {
272272
// get Module Config from request
273-
let conf = unsafe { request.get_module_loc_conf::<ModuleConfig>(ngx_http_awssigv4_module.borrow()) };
273+
let conf = unsafe { request.get_module_loc_conf::<ModuleConfig>(&*addr_of!(ngx_http_awssigv4_module)) };
274274
let conf = conf.unwrap();
275275
ngx_log_debug_http!(request, "AWS signature V4 module {}", {
276276
if conf.enable {

examples/curl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use ngx::ffi::{
77
use ngx::http::MergeConfigError;
88
use ngx::{core, core::Status, http, http::HTTPModule};
99
use ngx::{http_request_handler, ngx_log_debug_http, ngx_modules, ngx_null_command, ngx_string};
10-
use std::borrow::Borrow;
1110
use std::os::raw::{c_char, c_void};
11+
use std::ptr::addr_of;
1212

1313
struct Module;
1414

@@ -18,7 +18,7 @@ impl http::HTTPModule for Module {
1818
type LocConf = ModuleConfig;
1919

2020
unsafe extern "C" fn postconfiguration(cf: *mut ngx_conf_t) -> ngx_int_t {
21-
let cmcf = http::ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module.borrow());
21+
let cmcf = http::ngx_http_conf_get_module_main_conf(cf, &*addr_of!(ngx_http_core_module));
2222

2323
let h = ngx_array_push(&mut (*cmcf).phases[ngx_http_phases_NGX_HTTP_ACCESS_PHASE as usize].handlers)
2424
as *mut ngx_http_handler_pt;
@@ -105,7 +105,7 @@ impl http::Merge for ModuleConfig {
105105
}
106106

107107
http_request_handler!(curl_access_handler, |request: &mut http::Request| {
108-
let co = unsafe { request.get_module_loc_conf::<ModuleConfig>(ngx_http_curl_module.borrow()) };
108+
let co = unsafe { request.get_module_loc_conf::<ModuleConfig>(&*addr_of!(ngx_http_curl_module)) };
109109
let co = co.expect("module config is none");
110110

111111
ngx_log_debug_http!(request, "curl module enabled: {}", co.enable);

examples/upstream.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ use ngx::{
2525
ngx_log_debug_http, ngx_log_debug_mask, ngx_modules, ngx_null_command, ngx_string,
2626
};
2727
use std::{
28-
borrow::Borrow,
2928
mem,
3029
os::raw::{c_char, c_void},
30+
ptr::addr_of,
3131
slice,
3232
};
3333

@@ -153,7 +153,7 @@ http_upstream_init_peer_pt!(
153153
}
154154

155155
let maybe_conf: Option<*const SrvConfig> =
156-
unsafe { ngx_http_conf_upstream_srv_conf_immutable(us, ngx_http_upstream_custom_module.borrow()) };
156+
unsafe { ngx_http_conf_upstream_srv_conf_immutable(us, &*addr_of!(ngx_http_upstream_custom_module)) };
157157
if maybe_conf.is_none() {
158158
return Status::NGX_ERROR;
159159
}
@@ -245,7 +245,7 @@ unsafe extern "C" fn ngx_http_upstream_init_custom(
245245
ngx_log_debug_mask!(DebugMask::Http, (*cf).log, "CUSTOM UPSTREAM peer init_upstream");
246246

247247
let maybe_conf: Option<*mut SrvConfig> =
248-
ngx_http_conf_upstream_srv_conf_mutable(us, ngx_http_upstream_custom_module.borrow());
248+
ngx_http_conf_upstream_srv_conf_mutable(us, &*addr_of!(ngx_http_upstream_custom_module));
249249
if maybe_conf.is_none() {
250250
ngx_conf_log_error(
251251
NGX_LOG_EMERG as usize,
@@ -310,7 +310,8 @@ unsafe extern "C" fn ngx_http_upstream_commands_set_custom(
310310
}
311311

312312
let uscf: *mut ngx_http_upstream_srv_conf_t =
313-
ngx_http_conf_get_module_srv_conf(cf, ngx_http_upstream_module.borrow()) as *mut ngx_http_upstream_srv_conf_t;
313+
ngx_http_conf_get_module_srv_conf(cf, &*addr_of!(ngx_http_upstream_module))
314+
as *mut ngx_http_upstream_srv_conf_t;
314315

315316
ccf.original_init_upstream = if (*uscf).peer.init_upstream.is_some() {
316317
(*uscf).peer.init_upstream

0 commit comments

Comments
 (0)