diff --git a/src/contact.rs b/src/contact.rs index 8ab3073b7..de86f3041 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -478,7 +478,7 @@ impl<'a> Contact<'a> { .unwrap_or_default(); let mut add_self = false; - let mut ret = dc_array_t::new(100); + let mut ret = Vec::new(); if (listflags & DC_GCL_VERIFIED_ONLY) > 0 || query.is_some() { let s3str_like_cmd = format!( @@ -509,7 +509,7 @@ impl<'a> Contact<'a> { |row| row.get::<_, i32>(0), |ids| { for id in ids { - ret.add_id(id? as u32); + ret.push(id? as u32); } Ok(()) }, @@ -537,7 +537,7 @@ impl<'a> Contact<'a> { |row| row.get::<_, i32>(0), |ids| { for id in ids { - ret.add_id(id? as u32); + ret.push(id? as u32); } Ok(()) } @@ -545,10 +545,10 @@ impl<'a> Contact<'a> { } if 0 != listflags & DC_GCL_ADD_SELF as u32 && add_self { - ret.add_id(DC_CONTACT_ID_SELF as u32); + ret.push(DC_CONTACT_ID_SELF as u32); } - Ok(ret.into_raw()) + Ok(dc_array_t::from(ret).into_raw()) } pub fn get_blocked_cnt(context: &Context) -> usize { @@ -572,13 +572,13 @@ impl<'a> Contact<'a> { params![DC_CONTACT_ID_LAST_SPECIAL as i32], |row| row.get::<_, i32>(0), |ids| { - let mut ret = dc_array_t::new(100); + let mut ret = Vec::new(); for id in ids { - ret.add_id(id? as u32); + ret.push(id? as u32); } - Ok(ret.into_raw()) + Ok(dc_array_t::from(ret).into_raw()) }, ) .unwrap_or_else(|_| std::ptr::null_mut()) diff --git a/src/context.rs b/src/context.rs index a645bd7b2..2f9ca8e49 100644 --- a/src/context.rs +++ b/src/context.rs @@ -496,13 +496,12 @@ pub fn dc_get_fresh_msgs(context: &Context) -> *mut dc_array_t { &[10, 9, if 0 != show_deaddrop { 2 } else { 0 }], |row| row.get(0), |rows| { - let mut ret = dc_array_t::new(128); - + let mut ret = Vec::new(); for row in rows { - let id = row?; - ret.add_id(id); + let id: u32 = row?; + ret.push(id); } - Ok(ret.into_raw()) + Ok(dc_array_t::from(ret).into_raw()) }, ) .unwrap() @@ -536,7 +535,7 @@ pub fn dc_search_msgs( AND ct.blocked=0 AND (m.txt LIKE ? OR ct.name LIKE ?) ORDER BY m.timestamp DESC,m.id DESC;" }; - let mut ret = dc_array_t::new(100); + let mut ret = Vec::new(); let success = context .sql @@ -546,7 +545,7 @@ pub fn dc_search_msgs( |row| row.get::<_, i32>(0), |rows| { for id in rows { - ret.add_id(id? as u32); + ret.push(id? as u32); } Ok(()) }, @@ -554,7 +553,7 @@ pub fn dc_search_msgs( .is_ok(); if success { - return ret.into_raw(); + return dc_array_t::from(ret).into_raw(); } std::ptr::null_mut() diff --git a/src/dc_array.rs b/src/dc_array.rs index a83ab860f..435173349 100644 --- a/src/dc_array.rs +++ b/src/dc_array.rs @@ -147,6 +147,12 @@ impl dc_array_t { } } +impl From> for dc_array_t { + fn from(array: Vec) -> Self { + dc_array_t::Uint(array.iter().map(|&x| x as uintptr_t).collect()) + } +} + impl From> for dc_array_t { fn from(array: Vec) -> Self { dc_array_t::Locations(array) diff --git a/src/dc_chat.rs b/src/dc_chat.rs index edb98022e..8f6d1a5dd 100644 --- a/src/dc_chat.rs +++ b/src/dc_chat.rs @@ -1072,7 +1072,7 @@ pub fn dc_get_chat_msgs( flags: uint32_t, marker1before: uint32_t, ) -> *mut dc_array_t { - let mut ret = dc_array_t::new(512); + let mut ret = Vec::new(); let mut last_day = 0; let cnv_to_local = dc_gm2local_offset(); @@ -1082,17 +1082,17 @@ pub fn dc_get_chat_msgs( for row in rows { let (curr_id, ts) = row?; if curr_id as u32 == marker1before { - ret.add_id(1); + ret.push(DC_MSG_ID_MARKER1 as u32); } if 0 != flags & 0x1 { let curr_local_timestamp = ts + cnv_to_local; let curr_day = (curr_local_timestamp / 86400) as libc::c_int; if curr_day != last_day { - ret.add_id(9); + ret.push(DC_MSG_ID_LAST_SPECIAL as u32); last_day = curr_day; } } - ret.add_id(curr_id as u32); + ret.push(curr_id as u32); } Ok(()) }; @@ -1140,7 +1140,7 @@ pub fn dc_get_chat_msgs( }; if success.is_ok() { - ret.into_raw() + dc_array_t::from(ret).into_raw() } else { 0 as *mut dc_array_t } @@ -1253,11 +1253,11 @@ pub fn dc_get_chat_media( ], |row| row.get::<_, i32>(0), |ids| { - let mut ret = dc_array_t::new(100); + let mut ret = Vec::new(); for id in ids { - ret.add_id(id? as u32); + ret.push(id? as u32); } - Ok(ret.into_raw()) + Ok(dc_array_t::from(ret).into_raw()) } ).unwrap_or_else(|_| std::ptr::null_mut()) } @@ -1426,13 +1426,13 @@ pub fn dc_get_chat_contacts(context: &Context, chat_id: u32) -> *mut dc_array_t params![chat_id as i32], |row| row.get::<_, i32>(0), |ids| { - let mut ret = dc_array_t::new(100); + let mut ret = Vec::new(); for id in ids { - ret.add_id(id? as u32); + ret.push(id? as u32); } - Ok(ret.into_raw()) + Ok(dc_array_t::from(ret).into_raw()) }, ) .unwrap_or_else(|_| std::ptr::null_mut())