-
-
Save fitzgen/6703b6b96aef0c2e8177fe40cb8862bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IncludeUsedRval { | |
mutable bool usedRval_; | |
protected: | |
void clearUsedRval() { usedRval_ = false; } | |
// No virtual methods | |
}; | |
class CallArgsBase : public IncludeUsedRval { | |
protected: | |
void* argv_; | |
unsigned argc_; | |
bool constructing_; | |
// No virtual methods | |
}; | |
class CallArgs : public CallArgsBase { | |
// No members, no virtual methods | |
public: | |
static CallArgs create(unsigned argc, void* vp) { | |
CallArgs args; | |
args.clearUsedRval(); | |
args.argc_ = argc; | |
args.argv_ = vp; | |
args.constructing_ = false; | |
return args; | |
} | |
}; | |
static_assert(sizeof(CallArgs) <= 4 * 64, "not larger than 4 eightbytes"); | |
extern "C" { | |
CallArgs | |
CreateCallArgsFromVp(unsigned argc, void* vp) | |
{ | |
return CallArgs::create(argc, vp); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ g++ -c -o c_dumb.o -g -O0 c_dumb.cpp | |
$ rustc --crate-type bin -g -C opt-level=0 -o dumb dumb.rs -C link-args=c_dumb.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* automatically generated by rust-bindgen */ | |
#[repr(C)] | |
#[derive(Debug, Copy)] | |
pub struct IncludeUsedRval { | |
pub usedRval_: bool, | |
} | |
impl ::std::clone::Clone for IncludeUsedRval { | |
fn clone(&self) -> Self { *self } | |
} | |
#[test] | |
fn bindgen_test_layout_IncludeUsedRval() { | |
assert_eq!(::std::mem::size_of::<IncludeUsedRval>() , 1usize); | |
assert_eq!(::std::mem::align_of::<IncludeUsedRval>() , 1usize); | |
} | |
#[repr(C)] | |
#[derive(Debug, Copy)] | |
pub struct CallArgsBase { | |
pub _base: IncludeUsedRval, | |
pub argv_: *mut ::std::os::raw::c_void, | |
pub argc_: ::std::os::raw::c_uint, | |
pub constructing_: bool, | |
} | |
impl ::std::clone::Clone for CallArgsBase { | |
fn clone(&self) -> Self { *self } | |
} | |
#[test] | |
fn bindgen_test_layout_CallArgsBase() { | |
assert_eq!(::std::mem::size_of::<CallArgsBase>() , 24usize); | |
assert_eq!(::std::mem::align_of::<CallArgsBase>() , 8usize); | |
} | |
#[repr(C)] | |
#[derive(Debug, Copy)] | |
pub struct CallArgs { | |
pub _base: CallArgsBase, | |
} | |
impl ::std::clone::Clone for CallArgs { | |
fn clone(&self) -> Self { *self } | |
} | |
#[test] | |
fn bindgen_test_layout_CallArgs() { | |
assert_eq!(::std::mem::size_of::<CallArgs>() , 24usize); | |
assert_eq!(::std::mem::align_of::<CallArgs>() , 8usize); | |
} | |
extern "C" { | |
pub fn CreateCallArgsFromVp(argc: ::std::os::raw::c_uint, | |
vp: *mut ::std::os::raw::c_void) -> CallArgs; | |
} | |
///////////////////////////////////////////////////////////////// | |
fn main() { | |
unsafe { | |
let call_args = CreateCallArgsFromVp(1, 0xfeedface as _); | |
println!("call_args = {:#?}", call_args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment