glib: varianttype can actually be NULL
@@ -226,17 +226,25 @@ impl SetValue for VariantTy {
impl SetValueOptional for VariantTy {
unsafe fn set_value_optional(value: &mut Value, this: Option<&Self>) {
- gobject_ffi::g_value_set_boxed(value.to_glib_none_mut().0, this.to_glib_none().0 as glib_ffi::gpointer)
+ use std::ptr;
+ let p = match this{
+ Some(ref t) => t.to_glib_none().0 as glib_ffi::gpointer,
+ None => ptr::null()
+ };
+ gobject_ffi::g_value_set_boxed(value.to_glib_none_mut().0, p)
}
}
impl<'a> FromValueOptional<'a> for &'a VariantTy {
unsafe fn from_value_optional(value: &'a Value) -> Option<Self> {
let cvty = gobject_ffi::g_value_get_boxed(value.to_glib_none().0) as *mut glib_ffi::GVariantType;
- assert!(!cvty.is_null());
+ if cvty.is_null() {
+ None
+ } else {
Some(VariantTy::from_ptr(cvty))
}
}
+}
impl StaticType for VariantType {
fn static_type() -> Type {
@@ -250,11 +258,16 @@ impl SetValue for VariantType {
}
}
-// impl SetValueOptional for VariantType {
-// unsafe fn set_value_optional(value: &mut Value, this: Option<&Self>) {
-// gobject_ffi::g_value_set_boxed(value.to_glib_none_mut().0, this.to_glib_none().0 as glib_ffi::gpointer)
-// }
-// }
+impl SetValueOptional for VariantType {
+ unsafe fn set_value_optional(value: &mut Value, this: Option<&Self>) {
+ use std::ptr;
+ let p = match this{
+ Some(ref t) => t.to_glib_none().0 as glib_ffi::gpointer,
+ None => ptr::null()
+ };
+ gobject_ffi::g_value_set_boxed(value.to_glib_none_mut().0, p)
+ }
+}
impl<'a> FromValueOptional<'a> for VariantType {
unsafe fn from_value_optional(value: &'a Value) -> Option<Self> {
@@ -412,6 +425,9 @@ mod tests {
let tyv2 = ty1.to_value();
let ty4 = tyv2.get::<VariantType>().unwrap();
assert_eq!(ty3, ty4);
+
+ assert_eq!(VariantTy::static_type(), VariantTy::static_type());
+
}
}
