Be explicit about the interface being "C".

master
Jos van den Oever 2017-08-08 20:38:42 +02:00
parent 6b22802ec6
commit 81b9aa29e5
2 changed files with 17 additions and 13 deletions

View File

@ -1,4 +1,4 @@
use libc::{c_int}; use libc::c_int;
use types::*; use types::*;
use testinterface::*; use testinterface::*;
@ -7,7 +7,7 @@ pub struct Test {
username: String, username: String,
age: c_int, age: c_int,
active: bool, active: bool,
misc: Variant misc: Variant,
} }
impl TestTrait for Test { impl TestTrait for Test {
@ -17,13 +17,15 @@ impl TestTrait for Test {
username: String::new(), username: String::new(),
age: 0, age: 0,
active: true, active: true,
misc: Variant::None misc: Variant::None,
} }
} }
fn emit(&self) -> &TestEmitter { fn emit(&self) -> &TestEmitter {
&self.emit &self.emit
} }
fn get_username(&self) -> String { self.username.clone() } fn get_username(&self) -> String {
self.username.clone()
}
fn set_username(&mut self, value: String) { fn set_username(&mut self, value: String) {
self.username = value; self.username = value;
self.emit.username_changed(); self.emit.username_changed();
@ -38,7 +40,9 @@ impl TestTrait for Test {
self.active = value; self.active = value;
self.emit.active_changed(); self.emit.active_changed();
} }
fn get_misc(&self) -> Variant { Variant::None } fn get_misc(&self) -> Variant {
Variant::None
}
fn set_misc(&mut self, value: Variant) { fn set_misc(&mut self, value: Variant) {
self.misc = value; self.misc = value;
self.emit.misc_changed(); self.emit.misc_changed();

View File

@ -379,7 +379,7 @@ pub struct %1Emitter {
qobject: Arc<Mutex<*const %1QObject>>, qobject: Arc<Mutex<*const %1QObject>>,
)").arg(o.name); )").arg(o.name);
for (const Property& p: o.properties) { for (const Property& p: o.properties) {
r << QString(" %2_changed: fn (*const %1QObject),\n") r << QString(" %2_changed: fn(*const %1QObject),\n")
.arg(o.name, p.name.toLower()); .arg(o.name, p.name.toLower());
} }
r << QString(R"(} r << QString(R"(}
@ -419,9 +419,9 @@ pub trait %1Trait {
r << QString(R"(} r << QString(R"(}
#[no_mangle] #[no_mangle]
pub extern fn %2_new(qobject: *const %1QObject)").arg(o.name, lcname); pub extern "C" fn %2_new(qobject: *const %1QObject)").arg(o.name, lcname);
for (const Property& p: o.properties) { for (const Property& p: o.properties) {
r << QString(",\n %2_changed: fn (*const %1QObject)") r << QString(",\n %2_changed: fn(*const %1QObject)")
.arg(o.name, p.name.toLower()); .arg(o.name, p.name.toLower());
} }
r << QString(R"() -> *mut %1 { r << QString(R"() -> *mut %1 {
@ -437,7 +437,7 @@ pub extern fn %2_new(qobject: *const %1QObject)").arg(o.name, lcname);
} }
#[no_mangle] #[no_mangle]
pub unsafe extern fn %2_free(ptr: *mut %1) { pub unsafe extern "C" fn %2_free(ptr: *mut %1) {
Box::from_raw(ptr).emit().clear(); Box::from_raw(ptr).emit().clear();
} }
)").arg(o.name, lcname); )").arg(o.name, lcname);
@ -447,7 +447,7 @@ pub unsafe extern fn %2_free(ptr: *mut %1) {
if (p.type.startsWith("Q")) { if (p.type.startsWith("Q")) {
r << QString(R"( r << QString(R"(
#[no_mangle] #[no_mangle]
pub unsafe extern fn %2_get(ptr: *const %1, p: *mut c_void, set: fn (*mut c_void, %4)) { pub unsafe extern "C" fn %2_get(ptr: *const %1, p: *mut c_void, set: fn (*mut c_void, %4)) {
let data = (&*ptr).get_%3(); let data = (&*ptr).get_%3();
set(p, %4::from(&data)); set(p, %4::from(&data));
} }
@ -456,7 +456,7 @@ pub unsafe extern fn %2_get(ptr: *const %1, p: *mut c_void, set: fn (*mut c_void
const QString type = p.type == "QString" ? "QStringIn" : p.type; const QString type = p.type == "QString" ? "QStringIn" : p.type;
r << QString(R"( r << QString(R"(
#[no_mangle] #[no_mangle]
pub unsafe extern fn %2_set(ptr: *mut %1, v: %4) { pub unsafe extern "C" fn %2_set(ptr: *mut %1, v: %4) {
(&mut *ptr).set_%3(v.convert()); (&mut *ptr).set_%3(v.convert());
} }
)").arg(o.name, base, p.name.toLower(), type); )").arg(o.name, base, p.name.toLower(), type);
@ -464,14 +464,14 @@ pub unsafe extern fn %2_set(ptr: *mut %1, v: %4) {
} else { } else {
r << QString(R"( r << QString(R"(
#[no_mangle] #[no_mangle]
pub unsafe extern fn %2_get(ptr: *const %1) -> %4 { pub unsafe extern "C" fn %2_get(ptr: *const %1) -> %4 {
(&*ptr).get_%3() (&*ptr).get_%3()
} }
)").arg(o.name, base, p.name.toLower(), rustType(p)); )").arg(o.name, base, p.name.toLower(), rustType(p));
if (p.write) { if (p.write) {
r << QString(R"( r << QString(R"(
#[no_mangle] #[no_mangle]
pub unsafe extern fn %2_set(ptr: *mut %1, v: %4) { pub unsafe extern "C" fn %2_set(ptr: *mut %1, v: %4) {
(&mut *ptr).set_%3(v); (&mut *ptr).set_%3(v);
} }
)").arg(o.name, base, p.name.toLower(), rustType(p)); )").arg(o.name, base, p.name.toLower(), rustType(p));