From e796a4c4386b7b3af074d91de0eb6e344783dd61 Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Tue, 23 Jul 2019 00:11:00 +0300 Subject: [PATCH] Move dc_array_add_{uint,id} implementations into dc_array_t --- src/dc_array.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/dc_array.rs b/src/dc_array.rs index a9a8b6967..93e5dbe7f 100644 --- a/src/dc_array.rs +++ b/src/dc_array.rs @@ -22,6 +22,14 @@ impl dc_array_t { pub fn as_ptr(self) -> *mut Self { Box::into_raw(Box::new(self)) } + + pub fn add_uint(&mut self, item: uintptr_t) { + self.array.push(item); + } + + pub fn add_id(&mut self, item: uint32_t) { + self.add_uint(item as uintptr_t); + } } /** @@ -57,14 +65,15 @@ pub unsafe fn dc_array_free_ptr(array: *mut dc_array_t) { } pub unsafe fn dc_array_add_uint(array: *mut dc_array_t, item: uintptr_t) { - if array.is_null() { - return; + if !array.is_null() { + (*array).add_uint(item); } - (*array).array.push(item); } pub unsafe fn dc_array_add_id(array: *mut dc_array_t, item: uint32_t) { - dc_array_add_uint(array, item as uintptr_t); + if !array.is_null() { + (*array).add_id(item); + } } pub unsafe fn dc_array_add_ptr(array: *mut dc_array_t, item: *mut libc::c_void) {