From f81c4eec90d0d9e1a159047acc70eb0726ea7f69 Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Sat, 12 Feb 2022 15:20:46 +0000 Subject: [PATCH] rename array to list in rust types --- lib/src/annotation.rs | 6 +++--- lib/src/replica.rs | 2 +- lib/src/string.rs | 6 +++--- lib/src/task.rs | 6 +++--- lib/src/traits.rs | 48 +++++++++++++++++++++---------------------- lib/src/uuid.rs | 6 +++--- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/lib/src/annotation.rs b/lib/src/annotation.rs index 22a81653d..558f0d8c4 100644 --- a/lib/src/annotation.rs +++ b/lib/src/annotation.rs @@ -62,7 +62,7 @@ pub struct TCAnnotationList { items: *const TCAnnotation, } -impl CArray for TCAnnotationList { +impl CList for TCAnnotationList { type Element = TCAnnotation; unsafe fn from_raw_parts(items: *const Self::Element, len: usize, cap: usize) -> Self { @@ -99,7 +99,7 @@ pub unsafe extern "C" fn tc_annotation_list_free(tcanns: *mut TCAnnotationList) // - tcanns is not NULL and points to a valid TCAnnotationList (caller is not allowed to // modify the list) // - caller promises not to use the value after return - unsafe { drop_value_array(tcanns) } + unsafe { drop_value_list(tcanns) } } #[cfg(test)] @@ -107,7 +107,7 @@ mod test { use super::*; #[test] - fn empty_array_has_non_null_pointer() { + fn empty_list_has_non_null_pointer() { let tcanns = TCAnnotationList::return_val(Vec::new()); assert!(!tcanns.items.is_null()); assert_eq!(tcanns.len, 0); diff --git a/lib/src/replica.rs b/lib/src/replica.rs index b946efb34..99f07639d 100644 --- a/lib/src/replica.rs +++ b/lib/src/replica.rs @@ -139,7 +139,7 @@ pub unsafe extern "C" fn tc_replica_all_tasks(rep: *mut TCReplica) -> TCTaskList rep, |rep| { // note that the Replica API returns a hashmap here, but we discard - // the keys and return a simple array. The task UUIDs are available + // the keys and return a simple list. The task UUIDs are available // from task.get_uuid(), so information is not lost. let tasks: Vec<_> = rep .all_tasks()? diff --git a/lib/src/string.rs b/lib/src/string.rs index c02bdb1e6..af40714d9 100644 --- a/lib/src/string.rs +++ b/lib/src/string.rs @@ -154,7 +154,7 @@ pub struct TCStringList { items: *const NonNull>, } -impl CArray for TCStringList { +impl CList for TCStringList { type Element = NonNull>; unsafe fn from_raw_parts(items: *const Self::Element, len: usize, cap: usize) -> Self { @@ -325,7 +325,7 @@ pub unsafe extern "C" fn tc_string_list_free(tcstrings: *mut TCStringList) { // - tcstrings is not NULL and points to a valid TCStringList (caller is not allowed to // modify the list) // - caller promises not to use the value after return - unsafe { drop_pointer_array(tcstrings) }; + unsafe { drop_pointer_list(tcstrings) }; } #[cfg(test)] @@ -334,7 +334,7 @@ mod test { use pretty_assertions::assert_eq; #[test] - fn empty_array_has_non_null_pointer() { + fn empty_list_has_non_null_pointer() { let tcstrings = TCStringList::return_val(Vec::new()); assert!(!tcstrings.items.is_null()); assert_eq!(tcstrings.len, 0); diff --git a/lib/src/task.rs b/lib/src/task.rs index 87a64493d..390386e93 100644 --- a/lib/src/task.rs +++ b/lib/src/task.rs @@ -172,7 +172,7 @@ pub struct TCTaskList { items: *const NonNull, } -impl CArray for TCTaskList { +impl CList for TCTaskList { type Element = NonNull; unsafe fn from_raw_parts(items: *const Self::Element, len: usize, cap: usize) -> Self { @@ -590,7 +590,7 @@ pub unsafe extern "C" fn tc_task_list_free(tctasks: *mut TCTaskList) { // - tctasks is not NULL and points to a valid TCTaskList (caller is not allowed to // modify the list) // - caller promises not to use the value after return - unsafe { drop_pointer_array(tctasks) }; + unsafe { drop_pointer_list(tctasks) }; } #[cfg(test)] @@ -598,7 +598,7 @@ mod test { use super::*; #[test] - fn empty_array_has_non_null_pointer() { + fn empty_list_has_non_null_pointer() { let tctasks = TCTaskList::return_val(Vec::new()); assert!(!tctasks.items.is_null()); assert_eq!(tctasks.len, 0); diff --git a/lib/src/traits.rs b/lib/src/traits.rs index fea6ddbca..6a4ad2735 100644 --- a/lib/src/traits.rs +++ b/lib/src/traits.rs @@ -148,14 +148,14 @@ pub(crate) trait PassByPointer: Sized { } } -/// Support for C arrays of objects referenced by value. +/// Support for C lists of objects referenced by value. /// /// The underlying C type should have three fields, containing items, length, and capacity. The /// required trait functions just fetch and set these fields. The PassByValue trait will be /// implemented automatically, converting between the C type and `Vec`. For most cases, /// it is only necessary to implement `tc_.._free` that first calls -/// `PassByValue::take_from_arg(arg, CArray::null_value())` to take the existing value and -/// replace it with the null value; then one of hte `drop_.._array(..)` functions to drop the resulting +/// `PassByValue::take_from_arg(arg, CList::null_value())` to take the existing value and +/// replace it with the null value; then one of hte `drop_.._list(..)` functions to drop the resulting /// vector and all of the objects it points to. /// /// This can be used for objects referenced by pointer, too, with an Element type of `NonNull` @@ -165,11 +165,11 @@ pub(crate) trait PassByPointer: Sized { /// The C type must be documented as read-only. None of the fields may be modified, nor anything /// in the `items` array. /// -/// This class guarantees that the items pointer is non-NULL for any valid array (even when len=0). -pub(crate) trait CArray: Sized { +/// This class guarantees that the items pointer is non-NULL for any valid list (even when len=0). +pub(crate) trait CList: Sized { type Element; - /// Create a new CArray from the given items, len, and capacity. + /// Create a new CList from the given items, len, and capacity. /// /// # Safety /// @@ -191,26 +191,26 @@ pub(crate) trait CArray: Sized { } } -/// Given a CArray containing pass-by-value values, drop all of the values and -/// the array. +/// Given a CList containing pass-by-value values, drop all of the values and +/// the list. /// /// This is a convenience function for `tc_.._list_free` functions. /// /// # Safety /// -/// - Array must be non-NULL and point to a valid CA instance +/// - List must be non-NULL and point to a valid CL instance /// - The caller must not use the value array points to after this function, as /// it has been freed. It will be replaced with the null value. -pub(crate) unsafe fn drop_value_array(array: *mut CA) +pub(crate) unsafe fn drop_value_list(list: *mut CL) where - CA: CArray, + CL: CList, T: PassByValue, { - debug_assert!(!array.is_null()); + debug_assert!(!list.is_null()); // SAFETY: - // - *array is a valid CA (caller promises to treat it as read-only) - let mut vec = unsafe { CA::take_from_arg(array, CA::null_value()) }; + // - *list is a valid CL (caller promises to treat it as read-only) + let mut vec = unsafe { CL::take_from_arg(list, CL::null_value()) }; // first, drop each of the elements in turn for e in vec.drain(..) { @@ -223,24 +223,24 @@ where drop(vec); } -/// Given a CArray containing NonNull pointers, drop all of the pointed-to values and the array. +/// Given a CList containing NonNull pointers, drop all of the pointed-to values and the list. /// /// This is a convenience function for `tc_.._list_free` functions. /// /// # Safety /// -/// - Array must be non-NULL and point to a valid CA instance +/// - List must be non-NULL and point to a valid CL instance /// - The caller must not use the value array points to after this function, as /// it has been freed. It will be replaced with the null value. -pub(crate) unsafe fn drop_pointer_array(array: *mut CA) +pub(crate) unsafe fn drop_pointer_list(list: *mut CL) where - CA: CArray>, + CL: CList>, T: PassByPointer, { - debug_assert!(!array.is_null()); + debug_assert!(!list.is_null()); // SAFETY: - // - *array is a valid CA (caller promises to treat it as read-only) - let mut vec = unsafe { CA::take_from_arg(array, CA::null_value()) }; + // - *list is a valid CL (caller promises to treat it as read-only) + let mut vec = unsafe { CL::take_from_arg(list, CL::null_value()) }; // first, drop each of the elements in turn for e in vec.drain(..) { @@ -255,7 +255,7 @@ where impl PassByValue for A where - A: CArray, + A: CList, { type RustType = Vec; @@ -263,9 +263,9 @@ where let (items, len, cap) = self.into_raw_parts(); debug_assert!(!items.is_null()); // SAFETY: - // - CArray::from_raw_parts requires that items, len, and cap be valid for + // - CList::from_raw_parts requires that items, len, and cap be valid for // Vec::from_raw_parts if not NULL, and they are not NULL (as promised by caller) - // - CArray::into_raw_parts returns precisely the values passed to from_raw_parts. + // - CList::into_raw_parts returns precisely the values passed to from_raw_parts. // - those parts are passed to Vec::from_raw_parts here. unsafe { Vec::from_raw_parts(items as *mut _, len, cap) } } diff --git a/lib/src/uuid.rs b/lib/src/uuid.rs index 56311152b..8a26e4d11 100644 --- a/lib/src/uuid.rs +++ b/lib/src/uuid.rs @@ -56,7 +56,7 @@ pub struct TCUuidList { items: *const TCUuid, } -impl CArray for TCUuidList { +impl CList for TCUuidList { type Element = TCUuid; unsafe fn from_raw_parts(items: *const Self::Element, len: usize, cap: usize) -> Self { @@ -134,7 +134,7 @@ pub unsafe extern "C" fn tc_uuid_list_free(tcuuids: *mut TCUuidList) { // - tcuuids is not NULL and points to a valid TCUuidList (caller is not allowed to // modify the list) // - caller promises not to use the value after return - unsafe { drop_value_array(tcuuids) }; + unsafe { drop_value_list(tcuuids) }; } #[cfg(test)] @@ -142,7 +142,7 @@ mod test { use super::*; #[test] - fn empty_array_has_non_null_pointer() { + fn empty_list_has_non_null_pointer() { let tcuuids = TCUuidList::return_val(Vec::new()); assert!(!tcuuids.items.is_null()); assert_eq!(tcuuids.len, 0);