Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make KeyFile get_boolean and has_key return bool #320

Merged
merged 1 commit into from Apr 19, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+25 −16
Diff settings

Always

Just for now

Copy path View file
@@ -330,6 +330,14 @@ status = "generate"
name = "set_integer_list"
#wrong array type
ignore = true
[[object.function]]
name = "get_boolean"
#boolean return value needs to be returned
ignore = true
[[object.function]]
name = "has_key"
#boolean return value needs to be returned
ignore = true

[[object]]
name = "GLib.MainContext"
Copy path View file
@@ -32,14 +32,6 @@ impl KeyFile {
}
}

pub fn get_boolean(&self, group_name: &str, key: &str) -> Result<(), Error> {
unsafe {
let mut error = ptr::null_mut();
let _ = ffi::g_key_file_get_boolean(self.to_glib_none().0, group_name.to_glib_none().0, key.to_glib_none().0, &mut error);
if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) }
}
}

//pub fn get_boolean_list(&self, group_name: &str, key: &str) -> Result</*Unimplemented*/CArray TypeId { ns_id: 0, id: 1 }, Error> {
// unsafe { TODO: call ffi::g_key_file_get_boolean_list() }
//}
@@ -179,14 +171,6 @@ impl KeyFile {
}
}

pub fn has_key(&self, group_name: &str, key: &str) -> Result<(), Error> {
unsafe {
let mut error = ptr::null_mut();
let _ = ffi::g_key_file_has_key(self.to_glib_none().0, group_name.to_glib_none().0, key.to_glib_none().0, &mut error);
if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) }
}
}

#[cfg(any(feature = "v2_50", feature = "dox"))]
pub fn load_from_bytes(&self, bytes: &Bytes, flags: KeyFileFlags) -> Result<(), Error> {
unsafe {
Copy path View file
@@ -70,4 +70,21 @@ impl KeyFile {
from_glib_full(ret)
}
}

pub fn get_boolean(&self, group_name: &str, key: &str) -> Result<bool, Error> {
unsafe {
let mut error = ptr::null_mut();
let ret = ffi::g_key_file_get_boolean(self.to_glib_none().0, group_name.to_glib_none().0, key.to_glib_none().0, &mut error);
if error.is_null() { Ok(from_glib(ret)) } else { Err(from_glib_full(error)) }

This comment has been minimized.

Copy link
@EPashkin

EPashkin Apr 19, 2018

Member

As I understand from gtk-rs/gir#580 this function better use g_key_file_get_value internally?

This comment has been minimized.

Copy link
@EPashkin

EPashkin Apr 19, 2018

Member

Or this if need 3th case if g_key_file_get_boolean return false and error = null for false value

This comment has been minimized.

Copy link
@bvinc

bvinc Apr 19, 2018

Author Contributor

I'm not sure what you mean. The problem that I'm fixing is that GIR assumed that the gboolean return value from g_key_file_get_boolean was redundant and useless, and so it generated a function that dropped the gboolean return value and returned Result<(), Error> instead. This is an OK assumption because it's often the right thing to do for functions that throw and also return gboolean.

But in this particular case, the gboolean return value is exactly what we want to return back to the caller.

The &mut error parameter is still important and still needs to be checked.

It looks good to me.

This comment has been minimized.

Copy link
@EPashkin

EPashkin Apr 19, 2018

Member

Oops, I missed that if condition changed.
No problem for me now.

}
}

pub fn has_key(&self, group_name: &str, key: &str) -> Result<bool, Error> {
unsafe {
let mut error = ptr::null_mut();
let ret = ffi::g_key_file_has_key(self.to_glib_none().0, group_name.to_glib_none().0, key.to_glib_none().0, &mut error);
if error.is_null() { Ok(from_glib(ret)) } else { Err(from_glib_full(error)) }
}
}

}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.