From ad464c4779b54c07931b9d57b335db9bc4f9c1e9 Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Sun, 13 Feb 2022 03:33:43 +0000 Subject: [PATCH] use Uda instead of UDA --- integration-tests/src/bindings_tests/task.c | 2 +- lib/src/lib.rs | 2 +- lib/src/task.rs | 18 +++---- lib/src/uda.rs | 56 ++++++++++----------- lib/taskchampion.h | 34 ++++++------- 5 files changed, 56 insertions(+), 56 deletions(-) diff --git a/integration-tests/src/bindings_tests/task.c b/integration-tests/src/bindings_tests/task.c index 7f89ddc51..b2412f3c3 100644 --- a/integration-tests/src/bindings_tests/task.c +++ b/integration-tests/src/bindings_tests/task.c @@ -400,7 +400,7 @@ static void test_task_udas(void) { tc_task_to_mut(task, rep); TCString *value; - TCUDAList udas; + TCUdaList udas; TEST_ASSERT_NULL(tc_task_get_uda(task, tc_string_borrow("ns"), tc_string_borrow("u1"))); TEST_ASSERT_NULL(tc_task_get_legacy_uda(task, tc_string_borrow("leg1"))); diff --git a/lib/src/lib.rs b/lib/src/lib.rs index b6a8f2eec..39fab8534 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -29,7 +29,7 @@ pub(crate) mod types { pub(crate) use crate::status::TCStatus; pub(crate) use crate::string::{TCString, TCStringList}; pub(crate) use crate::task::{TCTask, TCTaskList}; - pub(crate) use crate::uda::{TCUDAList, TCUDA, UDA}; + pub(crate) use crate::uda::{TCUda, TCUdaList, Uda}; pub(crate) use crate::uuid::{TCUuid, TCUuidList}; pub(crate) use crate::workingset::TCWorkingSet; } diff --git a/lib/src/task.rs b/lib/src/task.rs index 5a7a446fc..1a4b66157 100644 --- a/lib/src/task.rs +++ b/lib/src/task.rs @@ -404,40 +404,40 @@ pub unsafe extern "C" fn tc_task_get_legacy_uda<'a>( /// /// Legacy UDAs are represented with an empty string in the ns field. #[no_mangle] -pub unsafe extern "C" fn tc_task_get_udas(task: *mut TCTask) -> TCUDAList { +pub unsafe extern "C" fn tc_task_get_udas(task: *mut TCTask) -> TCUdaList { wrap(task, |task| { - let vec: Vec = task + let vec: Vec = task .get_udas() .map(|((ns, key), value)| { - TCUDA::return_val(UDA { + TCUda::return_val(Uda { ns: Some(ns.into()), key: key.into(), value: value.into(), }) }) .collect(); - TCUDAList::return_val(vec) + TCUdaList::return_val(vec) }) } /// Get all UDAs for this task. /// -/// All TCUDAs in this list have a NULL ns field. The entire UDA key is +/// All TCUdas in this list have a NULL ns field. The entire UDA key is /// included in the key field. #[no_mangle] -pub unsafe extern "C" fn tc_task_get_legacy_udas(task: *mut TCTask) -> TCUDAList { +pub unsafe extern "C" fn tc_task_get_legacy_udas(task: *mut TCTask) -> TCUdaList { wrap(task, |task| { - let vec: Vec = task + let vec: Vec = task .get_legacy_udas() .map(|(key, value)| { - TCUDA::return_val(UDA { + TCUda::return_val(Uda { ns: None, key: key.into(), value: value.into(), }) }) .collect(); - TCUDAList::return_val(vec) + TCUdaList::return_val(vec) }) } diff --git a/lib/src/uda.rs b/lib/src/uda.rs index 4c0fe03f2..3712932ad 100644 --- a/lib/src/uda.rs +++ b/lib/src/uda.rs @@ -1,9 +1,9 @@ use crate::traits::*; use crate::types::*; -/// TCUDA contains the details of a UDA. +/// TCUda contains the details of a UDA. #[repr(C)] -pub struct TCUDA { +pub struct TCUda { /// Namespace of the UDA. For legacy UDAs, this is NULL. pub ns: *mut TCString<'static>, /// UDA key. Must not be NULL. @@ -12,17 +12,17 @@ pub struct TCUDA { pub value: *mut TCString<'static>, } -pub(crate) struct UDA { +pub(crate) struct Uda { pub ns: Option>, pub key: TCString<'static>, pub value: TCString<'static>, } -impl PassByValue for TCUDA { - type RustType = UDA; +impl PassByValue for TCUda { + type RustType = Uda; unsafe fn from_ctype(self) -> Self::RustType { - UDA { + Uda { ns: if self.ns.is_null() { None } else { @@ -42,8 +42,8 @@ impl PassByValue for TCUDA { } } - fn as_ctype(uda: UDA) -> Self { - TCUDA { + fn as_ctype(uda: Uda) -> Self { + TCUda { // SAFETY: caller assumes ownership of this value ns: if let Some(ns) = uda.ns { unsafe { ns.return_ptr() } @@ -58,9 +58,9 @@ impl PassByValue for TCUDA { } } -impl Default for TCUDA { +impl Default for TCUda { fn default() -> Self { - TCUDA { + TCUda { ns: std::ptr::null_mut(), key: std::ptr::null_mut(), value: std::ptr::null_mut(), @@ -68,27 +68,27 @@ impl Default for TCUDA { } } -/// TCUDAList represents a list of UDAs. +/// TCUdaList represents a list of UDAs. /// /// The content of this struct must be treated as read-only. #[repr(C)] -pub struct TCUDAList { +pub struct TCUdaList { /// number of UDAs in items len: libc::size_t, /// total size of items (internal use only) _capacity: libc::size_t, - /// array of UDAs. These remain owned by the TCUDAList instance and will be freed by - /// tc_uda_list_free. This pointer is never NULL for a valid TCUDAList. - items: *const TCUDA, + /// array of UDAs. These remain owned by the TCUdaList instance and will be freed by + /// tc_uda_list_free. This pointer is never NULL for a valid TCUdaList. + items: *const TCUda, } -impl CList for TCUDAList { - type Element = TCUDA; +impl CList for TCUdaList { + type Element = TCUda; unsafe fn from_raw_parts(items: *const Self::Element, len: usize, cap: usize) -> Self { - TCUDAList { + TCUdaList { len, _capacity: cap, items, @@ -100,25 +100,25 @@ impl CList for TCUDAList { } } -/// Free a TCUDA instance. The instance, and the TCStrings it contains, must not be used +/// Free a TCUda instance. The instance, and the TCStrings it contains, must not be used /// after this call. #[no_mangle] -pub unsafe extern "C" fn tc_uda_free(tcuda: *mut TCUDA) { +pub unsafe extern "C" fn tc_uda_free(tcuda: *mut TCUda) { debug_assert!(!tcuda.is_null()); // SAFETY: - // - *tcuda is a valid TCUDA (caller promises to treat it as read-only) - let uda = unsafe { TCUDA::take_val_from_arg(tcuda, TCUDA::default()) }; + // - *tcuda is a valid TCUda (caller promises to treat it as read-only) + let uda = unsafe { TCUda::take_val_from_arg(tcuda, TCUda::default()) }; drop(uda); } -/// Free a TCUDAList instance. The instance, and all TCUDAs it contains, must not be used after +/// Free a TCUdaList instance. The instance, and all TCUdas it contains, must not be used after /// this call. /// -/// When this call returns, the `items` pointer will be NULL, signalling an invalid TCUDAList. +/// When this call returns, the `items` pointer will be NULL, signalling an invalid TCUdaList. #[no_mangle] -pub unsafe extern "C" fn tc_uda_list_free(tcudas: *mut TCUDAList) { +pub unsafe extern "C" fn tc_uda_list_free(tcudas: *mut TCUdaList) { // SAFETY: - // - tcudas is not NULL and points to a valid TCUDAList (caller is not allowed to + // - tcudas is not NULL and points to a valid TCUdaList (caller is not allowed to // modify the list) // - caller promises not to use the value after return unsafe { drop_value_list(tcudas) } @@ -130,7 +130,7 @@ mod test { #[test] fn empty_list_has_non_null_pointer() { - let tcudas = TCUDAList::return_val(Vec::new()); + let tcudas = TCUdaList::return_val(Vec::new()); assert!(!tcudas.items.is_null()); assert_eq!(tcudas.len, 0); assert_eq!(tcudas._capacity, 0); @@ -138,7 +138,7 @@ mod test { #[test] fn free_sets_null_pointer() { - let mut tcudas = TCUDAList::return_val(Vec::new()); + let mut tcudas = TCUdaList::return_val(Vec::new()); // SAFETY: testing expected behavior unsafe { tc_uda_list_free(&mut tcudas) }; assert!(tcudas.items.is_null()); diff --git a/lib/taskchampion.h b/lib/taskchampion.h index bb41d4e5a..d5f787a88 100644 --- a/lib/taskchampion.h +++ b/lib/taskchampion.h @@ -268,9 +268,9 @@ typedef struct TCStringList { } TCStringList; /** - * TCUDA contains the details of a UDA. + * TCUda contains the details of a UDA. */ -typedef struct TCUDA { +typedef struct TCUda { /** * Namespace of the UDA. For legacy UDAs, this is NULL. */ @@ -283,14 +283,14 @@ typedef struct TCUDA { * Content of the UDA. Must not be NULL. */ struct TCString *value; -} TCUDA; +} TCUda; /** - * TCUDAList represents a list of UDAs. + * TCUdaList represents a list of UDAs. * * The content of this struct must be treated as read-only. */ -typedef struct TCUDAList { +typedef struct TCUdaList { /** * number of UDAs in items */ @@ -300,11 +300,11 @@ typedef struct TCUDAList { */ size_t _capacity; /** - * array of UDAs. These remain owned by the TCUDAList instance and will be freed by - * tc_uda_list_free. This pointer is never NULL for a valid TCUDAList. + * array of UDAs. These remain owned by the TCUdaList instance and will be freed by + * tc_uda_list_free. This pointer is never NULL for a valid TCUdaList. */ - const struct TCUDA *items; -} TCUDAList; + const struct TCUda *items; +} TCUdaList; #ifdef __cplusplus extern "C" { @@ -612,15 +612,15 @@ struct TCString *tc_task_get_legacy_uda(struct TCTask *task, struct TCString *ke * * Legacy UDAs are represented with an empty string in the ns field. */ -struct TCUDAList tc_task_get_udas(struct TCTask *task); +struct TCUdaList tc_task_get_udas(struct TCTask *task); /** * Get all UDAs for this task. * - * All TCUDAs in this list have a NULL ns field. The entire UDA key is + * All TCUdas in this list have a NULL ns field. The entire UDA key is * included in the key field. */ -struct TCUDAList tc_task_get_legacy_udas(struct TCTask *task); +struct TCUdaList tc_task_get_legacy_udas(struct TCTask *task); /** * Set a mutable task's status. @@ -735,18 +735,18 @@ void tc_task_free(struct TCTask *task); void tc_task_list_free(struct TCTaskList *tctasks); /** - * Free a TCUDA instance. The instance, and the TCStrings it contains, must not be used + * Free a TCUda instance. The instance, and the TCStrings it contains, must not be used * after this call. */ -void tc_uda_free(struct TCUDA *tcuda); +void tc_uda_free(struct TCUda *tcuda); /** - * Free a TCUDAList instance. The instance, and all TCUDAs it contains, must not be used after + * Free a TCUdaList instance. The instance, and all TCUdas it contains, must not be used after * this call. * - * When this call returns, the `items` pointer will be NULL, signalling an invalid TCUDAList. + * When this call returns, the `items` pointer will be NULL, signalling an invalid TCUdaList. */ -void tc_uda_list_free(struct TCUDAList *tcudas); +void tc_uda_list_free(struct TCUdaList *tcudas); /** * Create a new, randomly-generated UUID.