File tree Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Original file line number Diff line number Diff line change 1- e862c01aadb2d029864f7bb256cf6c85bbb5d7e4
1+ 12307b3b08edee543a78fb9d4a837fbd6d6ac0fa
Original file line number Diff line number Diff line change 1+ trait Empty { }
2+
3+ #[ repr( transparent) ]
4+ pub struct FunnyPointer ( dyn Empty ) ;
5+
6+ #[ repr( C ) ]
7+ pub struct Meta {
8+ drop_fn : fn ( & mut ( ) ) ,
9+ size : usize ,
10+ align : usize ,
11+ }
12+
13+ impl Meta {
14+ pub fn new ( ) -> Self {
15+ Meta {
16+ drop_fn : |_| { } ,
17+ size : 0 ,
18+ align : 1 ,
19+ }
20+ }
21+ }
22+
23+ #[ repr( C ) ]
24+ pub struct FatPointer {
25+ pub data : * const ( ) ,
26+ pub vtable : * const ( ) ,
27+ }
28+
29+ impl FunnyPointer {
30+ pub unsafe fn from_data_ptr ( data : & String , ptr : * const Meta ) -> & Self {
31+ let obj = FatPointer {
32+ data : data as * const _ as * const ( ) ,
33+ vtable : ptr as * const _ as * const ( ) ,
34+ } ;
35+ let obj = std:: mem:: transmute :: < FatPointer , * mut FunnyPointer > ( obj) ; //~ ERROR invalid drop fn in vtable
36+ & * obj
37+ }
38+ }
39+
40+ fn main ( ) {
41+ unsafe {
42+ let meta = Meta :: new ( ) ;
43+ let hello = "hello" . to_string ( ) ;
44+ let _raw: & FunnyPointer = FunnyPointer :: from_data_ptr ( & hello, & meta as * const _ ) ;
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments