summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrew Clayton <a.clayton@nginx.com>2023-09-05 15:26:37 +0100
committerAndrew Clayton <a.clayton@nginx.com>2023-09-05 15:26:37 +0100
commit6764e6e8ac3f1223536c35d7daef0755df144643 (patch)
tree009d04dc5f5541d9befe06ce4e806f184e7dd457
parentd81bc9290edc8d1eb59ced024499359ccd4da77a (diff)
downloadunit-wasm-6764e6e8ac3f1223536c35d7daef0755df144643.tar.gz
unit-wasm-6764e6e8ac3f1223536c35d7daef0755df144643.tar.bz2
examples/rust: Slightly simplify hello-world
There is no need in this case to declare REQUEST_BUF as a global variable. Declaring it local to uwr_request_handler() lets us get rid of the unsafe code blocks. Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
-rw-r--r--examples/rust/hello-world/src/lib.rs7
1 files changed, 3 insertions, 4 deletions
diff --git a/examples/rust/hello-world/src/lib.rs b/examples/rust/hello-world/src/lib.rs
index 9be1abd..a06bb4a 100644
--- a/examples/rust/hello-world/src/lib.rs
+++ b/examples/rust/hello-world/src/lib.rs
@@ -8,14 +8,13 @@
use unit_wasm::rusty::*;
-static mut REQUEST_BUF: *mut u8 = std::ptr::null_mut();
-
#[no_mangle]
pub extern "C" fn uwr_request_handler(addr: *mut u8) -> i32 {
let ctx = &mut UWR_CTX_INITIALIZER();
+ let mut request_buf: *mut u8 = std::ptr::null_mut();
uwr_init_ctx(ctx, addr, 4096);
- uwr_set_req_buf(ctx, unsafe { &mut REQUEST_BUF }, LUW_SRB_ALLOC);
+ uwr_set_req_buf(ctx, &mut request_buf, LUW_SRB_ALLOC);
uwr_write_str!(
ctx,
@@ -35,7 +34,7 @@ pub extern "C" fn uwr_request_handler(addr: *mut u8) -> i32 {
uwr_http_send_response(ctx);
uwr_http_response_end();
- uwr_free(unsafe { REQUEST_BUF });
+ uwr_free(request_buf);
return 0;
}