【发布时间】:2014-04-14 06:32:05
【问题描述】:
我有这个防锈方法:
/* Define a python method on a given module */
pub fn method(data: *mut Struct_ppyData, module: ~str, method: ~str, callback: PyCFunction, flags: Method, help: ~str) {
let mbytes = module.to_c_str().with_mut_ref(|a: * mut c_char| { a });
let fbytes = method.to_c_str().with_mut_ref(|b: * mut c_char| { b });
let dbytes = help.to_c_str().with_mut_ref(|c: * mut c_char| { c });
println!("Incoming! {} {} {}\n", module, method, help);
println!("Invoking! {} {} {}\n", mbytes, fbytes, dbytes);
let cflags = flags as c_int;
unsafe {
ppy_method(data, mbytes, fbytes, callback, cflags, dbytes);
}
}
我得到的输出是:
Incoming! yyy xxx A callback.
Invoking! 0x7f85084077d0 0x7f85084077d0 0x7f85084077d0
什么?这也是 ffi c 调用所看到的:
Received a value
Pointer: 7f85084077d0
length: 11
--------> value: A callback.
Received a value
Pointer: 7f85084077d0
length: 11
--------> value: A callback.
Received a value
Pointer: 7f85084077d0
length: 11
--------> value: A callback.
为什么 mbytes、fbytes 和 dbytes 的值都一样? O_o
【问题讨论】:
标签: rust