Skip to content

Commit

Permalink
API-Rust.md: Use the addr_of_mut!() macro
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
  • Loading branch information
ac000 committed Jul 2, 2024
1 parent 2cf492f commit 4d4f1f2
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions API-Rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ static mut REQUEST_BUF: *mut u8 = null_mut();
*/ ... */
#[no_mangle]
pub extern "C" fn uwr_request_handler(addr: *mut u8) -> i32 {
let ctx: *mut luw_ctx_t = unsafe { &mut CTX };
let ctx: *mut luw_ctx_t = unsafe { addr_of_mut!(CTX) };

if unsafe { REQUEST_BUF.is_null() } {
uwr_init_ctx(ctx, addr, 0 /* Response offset */);
Expand All @@ -507,7 +507,7 @@ pub extern "C" fn uwr_request_handler(addr: *mut u8) -> i32 {
*/
uwr_set_req_buf(
ctx,
unsafe { &mut REQUEST_BUF },
unsafe { addr_of_mut!(REQUEST_BUF) },
LUW_SRB_APPEND | LUW_SRB_ALLOC | LUW_SRB_FULL_SIZE,
);
} else {
Expand Down Expand Up @@ -811,7 +811,7 @@ Example
```Rust
#[no_mangle]
pub extern "C" fn uwr_request_handler(addr: *mut u8) -> i32 {
let ctx: *mut luw_ctx_t = unsafe { &mut CTX };
let ctx: *mut luw_ctx_t = unsafe { addr_of_mut!(CTX) };
if unsafe { REQUEST_BUF.is_null() } {
uwr_init_ctx(ctx, addr, 0 /* Response offset */);
Expand All @@ -826,7 +826,7 @@ pub extern "C" fn uwr_request_handler(addr: *mut u8) -> i32 {
*/
uwr_set_req_buf(
ctx,
unsafe { &mut REQUEST_BUF },
unsafe { addr_of_mut!(REQUEST_BUF) },
LUW_SRB_APPEND | LUW_SRB_ALLOC | LUW_SRB_FULL_SIZE,
);
} else {
Expand Down Expand Up @@ -868,14 +868,18 @@ Example
```Rust
pub extern "C" fn uwr_request_handler(addr: *mut u8) -> i32 {
let ctx: *mut luw_ctx_t = unsafe { &mut CTX };
let ctx: *mut luw_ctx_t = unsafe { addr_of_mut!(CTX) };
let mut f;
let bytes_wrote: isize;
let mut total = unsafe { TOTAL_BYTES_WROTE };
if total == 0 {
uwr_init_ctx(ctx, addr, 0);
uwr_set_req_buf(ctx, unsafe { &mut REQUEST_BUF }, LUW_SRB_NONE);
uwr_set_req_buf(
ctx,
unsafe { addr_of_mut!(REQUEST_BUF) },
LUW_SRB_NONE
);
f = File::create("/var/tmp/large-file.dat").unwrap();
} else {
Expand Down

0 comments on commit 4d4f1f2

Please # to comment.