From 84630d66e363f2193d4c2f19a836f169e3488c9e Mon Sep 17 00:00:00 2001 From: pca006132 Date: Thu, 16 Jul 2020 15:48:17 +0800 Subject: [PATCH] rpc: added `#[repr(C)]` for structs. --- src/runtime/src/rpc.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/runtime/src/rpc.rs b/src/runtime/src/rpc.rs index 9d3e118..a0653fa 100644 --- a/src/runtime/src/rpc.rs +++ b/src/runtime/src/rpc.rs @@ -73,6 +73,7 @@ async unsafe fn recv_value(stream: &TcpStream, tag: Tag<'async_recursion>, da Ok(()) } Tag::List(it) | Tag::Array(it) => { + #[repr(C)] struct List { elements: *mut (), length: u32 }; consume_value!(List, |ptr| { (*ptr).length = proto_async::read_i32(stream).await? as u32; @@ -174,6 +175,7 @@ unsafe fn send_value(writer: &mut W, tag: Tag, data: &mut *const ()) Ok(()) } Tag::Keyword(it) => { + #[repr(C)] struct Keyword<'a> { name: CSlice<'a, u8> }; consume_value!(Keyword, |ptr| { writer.write_string(str::from_utf8((*ptr).name.as_ref()).unwrap())?; @@ -185,6 +187,7 @@ unsafe fn send_value(writer: &mut W, tag: Tag, data: &mut *const ()) // to accurately advance data. } Tag::Object => { + #[repr(C)] struct Object { id: u32 }; consume_value!(*const Object, |ptr| writer.write_u32((**ptr).id))