From 2bdaea58ed0ffb543b812d729f412154e619088c Mon Sep 17 00:00:00 2001 From: Datong Sun Date: Tue, 22 Aug 2023 07:31:52 -0700 Subject: [PATCH] refactor(lib): make Rust module compile-able under stable Rust Implementation based on the Rust standard library implementation for `vec_into_raw_parts`. --- lib/ngx-wasm-rs/lib/backtrace/src/c_api.rs | 21 ++++++++++++--------- lib/ngx-wasm-rs/lib/backtrace/src/lib.rs | 1 - lib/ngx-wasm-rs/lib/wat/src/lib.rs | 8 ++++---- rust-toolchain | 2 +- util/test.sh | 1 - 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/ngx-wasm-rs/lib/backtrace/src/c_api.rs b/lib/ngx-wasm-rs/lib/backtrace/src/c_api.rs index 4f26f45be..812d3b03e 100644 --- a/lib/ngx-wasm-rs/lib/backtrace/src/c_api.rs +++ b/lib/ngx-wasm-rs/lib/backtrace/src/c_api.rs @@ -39,9 +39,10 @@ impl Drop for ngx_wasm_backtrace_name_table_t { fn vec_into_wasm_byte_vec_t(bv: *mut wasm_byte_vec_t, v: Vec) { unsafe { - let (ptr, len, _cap) = v.into_raw_parts(); - (*bv).size = len; - (*bv).data = ptr; + // FIXME Update this when vec_into_raw_parts is stabilized + let mut v = mem::ManuallyDrop::new(v); + (*bv).size = v.len(); + (*bv).data = v.as_mut_ptr(); } } @@ -63,22 +64,24 @@ pub unsafe extern "C" fn ngx_wasm_backtrace_get_name_table( let mut names = Vec::::with_capacity(table.len()); for (idx, name) in table.drain(..) { - let (bytes, len, _cap) = name.into_raw_parts(); + // FIXME Update this when vec_into_raw_parts is stabilized + let mut name = mem::ManuallyDrop::new(name); let name_t = ngx_wasm_backtrace_name_t { idx, name: Box::new(wasm_byte_vec_t { - size: len, - data: bytes, + size: name.len(), + data: name.as_mut_ptr(), }), }; names.push(name_t); } - let (bytes, len, _cap) = names.into_raw_parts(); + // FIXME Update this when vec_into_raw_parts is stabilized + let mut names = mem::ManuallyDrop::new(names); Some(Box::new(ngx_wasm_backtrace_name_table_t { - size: len, - table: bytes, + size: names.len(), + table: names.as_mut_ptr(), })) } else { None diff --git a/lib/ngx-wasm-rs/lib/backtrace/src/lib.rs b/lib/ngx-wasm-rs/lib/backtrace/src/lib.rs index e692a8848..9cb0a85c9 100644 --- a/lib/ngx-wasm-rs/lib/backtrace/src/lib.rs +++ b/lib/ngx-wasm-rs/lib/backtrace/src/lib.rs @@ -1,3 +1,2 @@ -#![feature(vec_into_raw_parts)] pub(crate) mod backtrace; pub mod c_api; diff --git a/lib/ngx-wasm-rs/lib/wat/src/lib.rs b/lib/ngx-wasm-rs/lib/wat/src/lib.rs index 460f9e123..c4e3577d9 100644 --- a/lib/ngx-wasm-rs/lib/wat/src/lib.rs +++ b/lib/ngx-wasm-rs/lib/wat/src/lib.rs @@ -1,4 +1,3 @@ -#![feature(vec_into_raw_parts)] use ngx_wasm_c_api::*; use regex::Regex; use std::mem; @@ -26,9 +25,10 @@ fn extract_message(err: &str) -> Option { fn vec_into_wasm_byte_vec_t(bv: *mut wasm_byte_vec_t, v: Vec) -> () { unsafe { - let (ptr, len, _cap) = v.into_raw_parts(); - (*bv).size = len; - (*bv).data = ptr; + // FIXME Update this when vec_into_raw_parts is stabilized + let v = mem::ManuallyDrop::new(v); + (*bv).size = v.len(); + (*bv).data = v.as_mut_ptr(); } } diff --git a/rust-toolchain b/rust-toolchain index bf867e0ae..2bf5ad044 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly +stable diff --git a/util/test.sh b/util/test.sh index 8712672ff..fa9c4b400 100755 --- a/util/test.sh +++ b/util/test.sh @@ -108,7 +108,6 @@ eval cargo build \ "${args[@]}" \ --target wasm32-wasi \ --out-dir $DIR_TESTS_LIB_WASM \ - -Z unstable-options if [ $(uname -s) = Linux ]; then export TEST_NGINX_EVENT_TYPE=epoll