mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
rename TCStrings to TCStringList
This commit is contained in:
parent
8caf442e3f
commit
28a4599a6a
6 changed files with 43 additions and 40 deletions
|
@ -312,7 +312,7 @@ static void test_task_get_tags(void) {
|
|||
|
||||
TEST_ASSERT_EQUAL(TC_RESULT_OK, tc_task_add_tag(task, tc_string_borrow("next")));
|
||||
|
||||
TCStrings tags = tc_task_get_tags(task);
|
||||
TCStringList tags = tc_task_get_tags(task);
|
||||
|
||||
int found_pending = false, found_next = false;
|
||||
for (size_t i = 0; i < tags.len; i++) {
|
||||
|
@ -326,7 +326,7 @@ static void test_task_get_tags(void) {
|
|||
TEST_ASSERT_TRUE(found_pending);
|
||||
TEST_ASSERT_TRUE(found_next);
|
||||
|
||||
tc_strings_free(&tags);
|
||||
tc_string_list_free(&tags);
|
||||
TEST_ASSERT_NULL(tags.items);
|
||||
|
||||
tc_task_free(task);
|
||||
|
|
|
@ -10,6 +10,6 @@ pub mod replica;
|
|||
pub mod result;
|
||||
pub mod status;
|
||||
pub mod string;
|
||||
pub mod strings;
|
||||
pub mod stringlist;
|
||||
pub mod task;
|
||||
pub mod uuid;
|
||||
|
|
|
@ -31,9 +31,9 @@ use std::str::Utf8Error;
|
|||
///
|
||||
/// Unless specified otherwise, TaskChampion functions take ownership of a `*TCString` when it is
|
||||
/// given as a function argument, and the pointer is invalid when the function returns. Callers
|
||||
/// must not use or free TCStrings after passing them to such API functions.
|
||||
/// must not use or free TCStringList after passing them to such API functions.
|
||||
///
|
||||
/// TCStrings are not threadsafe.
|
||||
/// TCString is not threadsafe.
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub enum TCString<'a> {
|
||||
CString(CString),
|
||||
|
|
|
@ -2,28 +2,28 @@ use crate::string::TCString;
|
|||
use crate::traits::*;
|
||||
use std::ptr::NonNull;
|
||||
|
||||
/// TCStrings represents a list of strings.
|
||||
/// TCStringList represents a list of strings.
|
||||
///
|
||||
/// The content of this struct must be treated as read-only.
|
||||
#[repr(C)]
|
||||
pub struct TCStrings {
|
||||
pub struct TCStringList {
|
||||
/// number of strings in items
|
||||
len: libc::size_t,
|
||||
|
||||
/// total size of items (internal use only)
|
||||
_capacity: libc::size_t,
|
||||
|
||||
/// TCStrings representing each string. these remain owned by the TCStrings instance and will
|
||||
/// be freed by tc_strings_free. This pointer is never NULL for a valid TCStrings, and the
|
||||
/// *TCStrings at indexes 0..len-1 are not NULL.
|
||||
/// TCStringList representing each string. these remain owned by the TCStringList instance and will
|
||||
/// be freed by tc_string_list_free. This pointer is never NULL for a valid TCStringList, and the
|
||||
/// *TCStringList at indexes 0..len-1 are not NULL.
|
||||
items: *const NonNull<TCString<'static>>,
|
||||
}
|
||||
|
||||
impl PointerArray for TCStrings {
|
||||
impl PointerArray for TCStringList {
|
||||
type Element = TCString<'static>;
|
||||
|
||||
unsafe fn from_raw_parts(items: *const NonNull<Self::Element>, len: usize, cap: usize) -> Self {
|
||||
TCStrings {
|
||||
TCStringList {
|
||||
len,
|
||||
_capacity: cap,
|
||||
items,
|
||||
|
@ -35,17 +35,17 @@ impl PointerArray for TCStrings {
|
|||
}
|
||||
}
|
||||
|
||||
/// Free a TCStrings instance. The instance, and all TCStrings it contains, must not be used after
|
||||
/// Free a TCStringList instance. The instance, and all TCStringList it contains, must not be used after
|
||||
/// this call.
|
||||
///
|
||||
/// When this call returns, the `items` pointer will be NULL, signalling an invalid TCStrings.
|
||||
/// When this call returns, the `items` pointer will be NULL, signalling an invalid TCStringList.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tc_strings_free(tcstrings: *mut TCStrings) {
|
||||
pub unsafe extern "C" fn tc_string_list_free(tcstrings: *mut TCStringList) {
|
||||
debug_assert!(!tcstrings.is_null());
|
||||
// SAFETY:
|
||||
// - *tcstrings is a valid TCStrings (caller promises to treat it as read-only)
|
||||
let strings = unsafe { TCStrings::take_from_arg(tcstrings, TCStrings::null_value()) };
|
||||
TCStrings::drop_pointer_vector(strings);
|
||||
// - *tcstrings is a valid TCStringList (caller promises to treat it as read-only)
|
||||
let strings = unsafe { TCStringList::take_from_arg(tcstrings, TCStringList::null_value()) };
|
||||
TCStringList::drop_pointer_vector(strings);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -54,7 +54,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn empty_array_has_non_null_pointer() {
|
||||
let tcstrings = TCStrings::return_val(Vec::new());
|
||||
let tcstrings = TCStringList::return_val(Vec::new());
|
||||
assert!(!tcstrings.items.is_null());
|
||||
assert_eq!(tcstrings.len, 0);
|
||||
assert_eq!(tcstrings._capacity, 0);
|
||||
|
@ -62,9 +62,9 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn free_sets_null_pointer() {
|
||||
let mut tcstrings = TCStrings::return_val(Vec::new());
|
||||
let mut tcstrings = TCStringList::return_val(Vec::new());
|
||||
// SAFETY: testing expected behavior
|
||||
unsafe { tc_strings_free(&mut tcstrings) };
|
||||
unsafe { tc_string_list_free(&mut tcstrings) };
|
||||
assert!(tcstrings.items.is_null());
|
||||
assert_eq!(tcstrings.len, 0);
|
||||
assert_eq!(tcstrings._capacity, 0);
|
|
@ -1,8 +1,8 @@
|
|||
use crate::traits::*;
|
||||
use crate::util::err_to_tcstring;
|
||||
use crate::{
|
||||
replica::TCReplica, result::TCResult, status::TCStatus, string::TCString, strings::TCStrings,
|
||||
uuid::TCUuid,
|
||||
replica::TCReplica, result::TCResult, status::TCStatus, string::TCString,
|
||||
stringlist::TCStringList, uuid::TCUuid,
|
||||
};
|
||||
use chrono::{DateTime, TimeZone, Utc};
|
||||
use std::convert::TryFrom;
|
||||
|
@ -316,10 +316,10 @@ pub unsafe extern "C" fn tc_task_has_tag<'a>(task: *mut TCTask, tag: *mut TCStri
|
|||
|
||||
/// Get the tags for the task.
|
||||
///
|
||||
/// The caller must free the returned TCStrings instance. The TCStrings instance does not
|
||||
/// The caller must free the returned TCStringList instance. The TCStringList instance does not
|
||||
/// reference the task and the two may be freed in any order.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tc_task_get_tags<'a>(task: *mut TCTask) -> TCStrings {
|
||||
pub unsafe extern "C" fn tc_task_get_tags<'a>(task: *mut TCTask) -> TCStringList {
|
||||
wrap(task, |task| {
|
||||
let vec: Vec<NonNull<TCString<'static>>> = task
|
||||
.get_tags()
|
||||
|
@ -331,7 +331,7 @@ pub unsafe extern "C" fn tc_task_get_tags<'a>(task: *mut TCTask) -> TCStrings {
|
|||
.expect("TCString::return_val() returned NULL")
|
||||
})
|
||||
.collect();
|
||||
TCStrings::return_val(vec)
|
||||
TCStringList::return_val(vec)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -401,7 +401,10 @@ pub unsafe extern "C" fn tc_task_set_wait(task: *mut TCTask, wait: libc::time_t)
|
|||
|
||||
/// Set a mutable task's modified timestamp. The value cannot be zero.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tc_task_set_modified(task: *mut TCTask, modified: libc::time_t) -> TCResult {
|
||||
pub unsafe extern "C" fn tc_task_set_modified(
|
||||
task: *mut TCTask,
|
||||
modified: libc::time_t,
|
||||
) -> TCResult {
|
||||
wrap_mut(
|
||||
task,
|
||||
|task| {
|
||||
|
|
|
@ -91,9 +91,9 @@ typedef struct TCReplica TCReplica;
|
|||
*
|
||||
* Unless specified otherwise, TaskChampion functions take ownership of a `*TCString` when it is
|
||||
* given as a function argument, and the pointer is invalid when the function returns. Callers
|
||||
* must not use or free TCStrings after passing them to such API functions.
|
||||
* must not use or free TCStringList after passing them to such API functions.
|
||||
*
|
||||
* TCStrings are not threadsafe.
|
||||
* TCString is not threadsafe.
|
||||
*/
|
||||
typedef struct TCString TCString;
|
||||
|
||||
|
@ -127,11 +127,11 @@ typedef struct TCUuid {
|
|||
} TCUuid;
|
||||
|
||||
/**
|
||||
* TCStrings represents a list of strings.
|
||||
* TCStringList represents a list of strings.
|
||||
*
|
||||
* The content of this struct must be treated as read-only.
|
||||
*/
|
||||
typedef struct TCStrings {
|
||||
typedef struct TCStringList {
|
||||
/**
|
||||
* number of strings in items
|
||||
*/
|
||||
|
@ -141,12 +141,12 @@ typedef struct TCStrings {
|
|||
*/
|
||||
size_t _capacity;
|
||||
/**
|
||||
* TCStrings representing each string. these remain owned by the TCStrings instance and will
|
||||
* be freed by tc_strings_free. This pointer is never NULL for a valid TCStrings, and the
|
||||
* *TCStrings at indexes 0..len-1 are not NULL.
|
||||
* TCStringList representing each string. these remain owned by the TCStringList instance and will
|
||||
* be freed by tc_string_list_free. This pointer is never NULL for a valid TCStringList, and the
|
||||
* *TCStringList at indexes 0..len-1 are not NULL.
|
||||
*/
|
||||
struct TCString *const *items;
|
||||
} TCStrings;
|
||||
} TCStringList;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -271,12 +271,12 @@ const char *tc_string_content_with_len(struct TCString *tcstring, size_t *len_ou
|
|||
void tc_string_free(struct TCString *tcstring);
|
||||
|
||||
/**
|
||||
* Free a TCStrings instance. The instance, and all TCStrings it contains, must not be used after
|
||||
* Free a TCStringList instance. The instance, and all TCStringList it contains, must not be used after
|
||||
* this call.
|
||||
*
|
||||
* When this call returns, the `items` pointer will be NULL, signalling an invalid TCStrings.
|
||||
* When this call returns, the `items` pointer will be NULL, signalling an invalid TCStringList.
|
||||
*/
|
||||
void tc_strings_free(struct TCStrings *tcstrings);
|
||||
void tc_string_list_free(struct TCStringList *tcstrings);
|
||||
|
||||
/**
|
||||
* Convert an immutable task into a mutable task.
|
||||
|
@ -357,10 +357,10 @@ bool tc_task_has_tag(struct TCTask *task, struct TCString *tag);
|
|||
/**
|
||||
* Get the tags for the task.
|
||||
*
|
||||
* The caller must free the returned TCStrings instance. The TCStrings instance does not
|
||||
* The caller must free the returned TCStringList instance. The TCStringList instance does not
|
||||
* reference the task and the two may be freed in any order.
|
||||
*/
|
||||
struct TCStrings tc_task_get_tags(struct TCTask *task);
|
||||
struct TCStringList tc_task_get_tags(struct TCTask *task);
|
||||
|
||||
/**
|
||||
* Set a mutable task's status.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue