From 88a81f57372ab4f35f13caef94d3a4a356952066 Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Tue, 13 Aug 2019 18:44:00 +0300 Subject: [PATCH] Return Vec from get_all_blocked And never return nullptr from dc_get_blocked_contacts. --- deltachat-ffi/src/lib.rs | 2 +- src/contact.rs | 16 +++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index e98abaebe..823e2a6be 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -837,7 +837,7 @@ pub unsafe extern "C" fn dc_get_blocked_contacts( assert!(!context.is_null()); let context = &*context; - Contact::get_all_blocked(context) + dc_array_t::from(Contact::get_all_blocked(context)).into_raw() } #[no_mangle] diff --git a/src/contact.rs b/src/contact.rs index b0e210098..0891449ef 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -7,7 +7,6 @@ use crate::aheader::EncryptPreference; use crate::config::Config; use crate::constants::*; use crate::context::Context; -use crate::dc_array::*; use crate::dc_e2ee::*; use crate::dc_loginparam::*; use crate::dc_tools::*; @@ -564,24 +563,19 @@ impl<'a> Contact<'a> { } /// Get blocked contacts. - pub fn get_all_blocked(context: &Context) -> *mut dc_array_t { + pub fn get_all_blocked(context: &Context) -> Vec { context .sql .query_map( "SELECT id FROM contacts WHERE id>? AND blocked!=0 ORDER BY LOWER(name||addr),id;", params![DC_CONTACT_ID_LAST_SPECIAL as i32], - |row| row.get::<_, i32>(0), + |row| row.get::<_, u32>(0), |ids| { - let mut ret = Vec::new(); - - for id in ids { - ret.push(id? as u32); - } - - Ok(dc_array_t::from(ret).into_raw()) + ids.collect::, _>>() + .map_err(Into::into) }, ) - .unwrap_or_else(|_| std::ptr::null_mut()) + .unwrap_or_default() } /// Returns a textual summary of the encryption state for the contact.