@@ -21,6 +21,7 @@ use crate::rpc::pb::etcdserverpb::{
21
21
use crate :: rpc:: { get_prefix, KeyRange , KeyValue , ResponseHeader } ;
22
22
use crate :: vec:: VecExt ;
23
23
use http:: HeaderValue ;
24
+ use std:: mem:: ManuallyDrop ;
24
25
use std:: sync:: { Arc , RwLock } ;
25
26
use tonic:: { IntoRequest , Request } ;
26
27
@@ -469,7 +470,8 @@ impl GetResponse {
469
470
/// If `kvs` is set in the request, take the key-value pairs, leaving an empty vector in its place.
470
471
#[ inline]
471
472
pub fn take_kvs ( & mut self ) -> Vec < KeyValue > {
472
- unsafe { std:: mem:: transmute ( std:: mem:: take ( & mut self . 0 . kvs ) ) }
473
+ let kvs = ManuallyDrop :: new ( std:: mem:: take ( & mut self . 0 . kvs ) ) ;
474
+ unsafe { Vec :: from_raw_parts ( kvs. as_ptr ( ) as * mut KeyValue , kvs. len ( ) , kvs. capacity ( ) ) }
473
475
}
474
476
475
477
#[ inline]
@@ -619,7 +621,8 @@ impl DeleteResponse {
619
621
/// If `prev_kvs` is set in the request, take the previous key-value pairs, leaving an empty vector in its place.
620
622
#[ inline]
621
623
pub fn take_prev_kvs ( & mut self ) -> Vec < KeyValue > {
622
- unsafe { std:: mem:: transmute ( std:: mem:: take ( & mut self . 0 . prev_kvs ) ) }
624
+ let kvs = ManuallyDrop :: new ( std:: mem:: take ( & mut self . 0 . prev_kvs ) ) ;
625
+ unsafe { Vec :: from_raw_parts ( kvs. as_ptr ( ) as * mut KeyValue , kvs. len ( ) , kvs. capacity ( ) ) }
623
626
}
624
627
625
628
#[ inline]
@@ -866,7 +869,16 @@ impl Txn {
866
869
assert ! ( !self . c_else, "cannot call when after or_else" ) ;
867
870
868
871
self . c_when = true ;
869
- self . req . compare = unsafe { std:: mem:: transmute ( compares. into ( ) ) } ;
872
+
873
+ let compares = ManuallyDrop :: new ( compares. into ( ) ) ;
874
+ self . req . compare = unsafe {
875
+ Vec :: from_raw_parts (
876
+ compares. as_ptr ( ) as * mut PbCompare ,
877
+ compares. len ( ) ,
878
+ compares. capacity ( ) ,
879
+ )
880
+ } ;
881
+
870
882
self
871
883
}
872
884
0 commit comments