[librsvg/wip/subclass: 2/3] Fix compilation of GEnum registration code
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/wip/subclass: 2/3] Fix compilation of GEnum registration code
- Date: Thu, 14 Feb 2019 16:09:55 +0000 (UTC)
commit f3fd9607a0c6a3e331f980baea8b886982ae3f5b
Author: Sebastian Dröge <sebastian centricular com>
Date: Wed Feb 13 22:22:37 2019 +0200
Fix compilation of GEnum registration code
And fix some compiler warnings while at it.
rsvg_internals/src/c_api.rs | 32 ++++++++++++++++++++------------
1 file changed, 20 insertions(+), 12 deletions(-)
---
diff --git a/rsvg_internals/src/c_api.rs b/rsvg_internals/src/c_api.rs
index d2af7786..89744805 100644
--- a/rsvg_internals/src/c_api.rs
+++ b/rsvg_internals/src/c_api.rs
@@ -306,29 +306,37 @@ pub unsafe extern "C" fn rsvg_handle_rust_get_type() -> glib_sys::GType {
#[no_mangle]
pub unsafe extern "C" fn rsvg_rust_error_get_type() -> glib_sys::GType {
static ONCE: Once = Once::new();
- static mut etype: glib_sys::GType = gobject_sys::G_TYPE_INVALID;
-
- static values: [GEnumValue; 2] = [
- GEnumValue {
+ static mut ETYPE: glib_sys::GType = gobject_sys::G_TYPE_INVALID;
+
+ // We have to store the GEnumValue in a static variable but
+ // that requires it to be Sync. It is not Sync by default
+ // because it contains pointers, so we have define a custom
+ // wrapper type here on which we can implement Sync.
+ #[repr(C)]
+ struct GEnumValueWrapper(GEnumValue);
+ unsafe impl Sync for GEnumValueWrapper {}
+
+ static VALUES: [GEnumValueWrapper; 2] = [
+ GEnumValueWrapper(GEnumValue {
value: RSVG_ERROR_FAILED,
- value_name: b"RSVG_ERROR_FAILED\0" as *const u8 as *const i8,
- value_nick: b"failed\0" as *const u8 as *const i8,
- },
- GEnumValue {
+ value_name: b"RSVG_ERROR_FAILED\0" as *const u8 as *const _,
+ value_nick: b"failed\0" as *const u8 as *const _,
+ }),
+ GEnumValueWrapper(GEnumValue {
value: 0,
value_name: 0 as *const _,
value_nick: 0 as *const _,
- },
+ }),
];
ONCE.call_once(|| {
- etype = gobject_sys::g_enum_register_static(
+ ETYPE = gobject_sys::g_enum_register_static(
b"RsvgError\0" as *const u8 as *const _,
- &values as *const _,
+ &VALUES as *const GEnumValueWrapper as *const GEnumValue,
);
});
- etype
+ ETYPE
}
#[no_mangle]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]