Store IDs in dc_array as u32

This changes dc_array_get_raw API
This commit is contained in:
Alexander Krotov
2019-08-14 14:00:10 +03:00
committed by holger krekel
parent 5b47409fb0
commit 29d4f6888d
3 changed files with 8 additions and 8 deletions

View File

@@ -387,7 +387,7 @@ char* dc_array_get_marker (const dc_array_t*, size_t index);
int dc_array_is_independent (const dc_array_t*, size_t index);
int dc_array_search_id (const dc_array_t*, uint32_t needle, size_t* indx);
const uintptr_t* dc_array_get_raw (const dc_array_t*);
const uint32_t* dc_array_get_raw (const dc_array_t*);
/**

View File

@@ -1171,7 +1171,7 @@ pub unsafe extern "C" fn dc_array_search_id(
}
#[no_mangle]
pub unsafe extern "C" fn dc_array_get_raw(array: *const dc_array_t) -> *const libc::size_t {
pub unsafe extern "C" fn dc_array_get_raw(array: *const dc_array_t) -> *const u32 {
assert!(!array.is_null());
dc_array::dc_array_get_raw(array)

View File

@@ -7,7 +7,7 @@ use crate::types::*;
#[allow(non_camel_case_types)]
pub enum dc_array_t {
Locations(Vec<dc_location>),
Uint(Vec<uintptr_t>),
Uint(Vec<u32>),
}
impl dc_array_t {
@@ -26,7 +26,7 @@ impl dc_array_t {
pub fn add_id(&mut self, item: uint32_t) {
if let Self::Uint(array) = self {
array.push(item as uintptr_t);
array.push(item);
} else {
panic!("Attempt to add id to array of other type");
}
@@ -105,7 +105,7 @@ impl dc_array_t {
}
}
pub fn search_id(&self, needle: uintptr_t) -> Option<usize> {
pub fn search_id(&self, needle: u32) -> Option<usize> {
if let Self::Uint(array) = self {
for (i, &u) in array.iter().enumerate() {
if u == needle {
@@ -129,7 +129,7 @@ impl dc_array_t {
impl From<Vec<u32>> for dc_array_t {
fn from(array: Vec<u32>) -> Self {
dc_array_t::Uint(array.iter().map(|&x| x as uintptr_t).collect())
dc_array_t::Uint(array)
}
}
@@ -235,7 +235,7 @@ pub unsafe fn dc_array_search_id(
) -> bool {
assert!(!array.is_null());
if let Some(i) = (*array).search_id(needle as uintptr_t) {
if let Some(i) = (*array).search_id(needle) {
if !ret_index.is_null() {
*ret_index = i
}
@@ -245,7 +245,7 @@ pub unsafe fn dc_array_search_id(
}
}
pub unsafe fn dc_array_get_raw(array: *const dc_array_t) -> *const uintptr_t {
pub unsafe fn dc_array_get_raw(array: *const dc_array_t) -> *const u32 {
assert!(!array.is_null());
if let dc_array_t::Uint(v) = &*array {