rename TCStrings to TCStringList
This commit is contained in:
@@ -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")));
|
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;
|
int found_pending = false, found_next = false;
|
||||||
for (size_t i = 0; i < tags.len; i++) {
|
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_pending);
|
||||||
TEST_ASSERT_TRUE(found_next);
|
TEST_ASSERT_TRUE(found_next);
|
||||||
|
|
||||||
tc_strings_free(&tags);
|
tc_string_list_free(&tags);
|
||||||
TEST_ASSERT_NULL(tags.items);
|
TEST_ASSERT_NULL(tags.items);
|
||||||
|
|
||||||
tc_task_free(task);
|
tc_task_free(task);
|
||||||
|
|||||||
@@ -10,6 +10,6 @@ pub mod replica;
|
|||||||
pub mod result;
|
pub mod result;
|
||||||
pub mod status;
|
pub mod status;
|
||||||
pub mod string;
|
pub mod string;
|
||||||
pub mod strings;
|
pub mod stringlist;
|
||||||
pub mod task;
|
pub mod task;
|
||||||
pub mod uuid;
|
pub mod uuid;
|
||||||
|
|||||||
@@ -31,9 +31,9 @@ use std::str::Utf8Error;
|
|||||||
///
|
///
|
||||||
/// Unless specified otherwise, TaskChampion functions take ownership of a `*TCString` when it is
|
/// 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
|
/// 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)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub enum TCString<'a> {
|
pub enum TCString<'a> {
|
||||||
CString(CString),
|
CString(CString),
|
||||||
|
|||||||
@@ -2,28 +2,28 @@ use crate::string::TCString;
|
|||||||
use crate::traits::*;
|
use crate::traits::*;
|
||||||
use std::ptr::NonNull;
|
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.
|
/// The content of this struct must be treated as read-only.
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct TCStrings {
|
pub struct TCStringList {
|
||||||
/// number of strings in items
|
/// number of strings in items
|
||||||
len: libc::size_t,
|
len: libc::size_t,
|
||||||
|
|
||||||
/// total size of items (internal use only)
|
/// total size of items (internal use only)
|
||||||
_capacity: libc::size_t,
|
_capacity: libc::size_t,
|
||||||
|
|
||||||
/// TCStrings representing each string. these remain owned by the TCStrings instance and will
|
/// TCStringList representing each string. these remain owned by the TCStringList instance and will
|
||||||
/// be freed by tc_strings_free. This pointer is never NULL for a valid TCStrings, and the
|
/// be freed by tc_string_list_free. This pointer is never NULL for a valid TCStringList, and the
|
||||||
/// *TCStrings at indexes 0..len-1 are not NULL.
|
/// *TCStringList at indexes 0..len-1 are not NULL.
|
||||||
items: *const NonNull<TCString<'static>>,
|
items: *const NonNull<TCString<'static>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PointerArray for TCStrings {
|
impl PointerArray for TCStringList {
|
||||||
type Element = TCString<'static>;
|
type Element = TCString<'static>;
|
||||||
|
|
||||||
unsafe fn from_raw_parts(items: *const NonNull<Self::Element>, len: usize, cap: usize) -> Self {
|
unsafe fn from_raw_parts(items: *const NonNull<Self::Element>, len: usize, cap: usize) -> Self {
|
||||||
TCStrings {
|
TCStringList {
|
||||||
len,
|
len,
|
||||||
_capacity: cap,
|
_capacity: cap,
|
||||||
items,
|
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.
|
/// 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]
|
#[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());
|
debug_assert!(!tcstrings.is_null());
|
||||||
// SAFETY:
|
// SAFETY:
|
||||||
// - *tcstrings is a valid TCStrings (caller promises to treat it as read-only)
|
// - *tcstrings is a valid TCStringList (caller promises to treat it as read-only)
|
||||||
let strings = unsafe { TCStrings::take_from_arg(tcstrings, TCStrings::null_value()) };
|
let strings = unsafe { TCStringList::take_from_arg(tcstrings, TCStringList::null_value()) };
|
||||||
TCStrings::drop_pointer_vector(strings);
|
TCStringList::drop_pointer_vector(strings);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -54,7 +54,7 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn empty_array_has_non_null_pointer() {
|
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!(!tcstrings.items.is_null());
|
||||||
assert_eq!(tcstrings.len, 0);
|
assert_eq!(tcstrings.len, 0);
|
||||||
assert_eq!(tcstrings._capacity, 0);
|
assert_eq!(tcstrings._capacity, 0);
|
||||||
@@ -62,9 +62,9 @@ mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn free_sets_null_pointer() {
|
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
|
// SAFETY: testing expected behavior
|
||||||
unsafe { tc_strings_free(&mut tcstrings) };
|
unsafe { tc_string_list_free(&mut tcstrings) };
|
||||||
assert!(tcstrings.items.is_null());
|
assert!(tcstrings.items.is_null());
|
||||||
assert_eq!(tcstrings.len, 0);
|
assert_eq!(tcstrings.len, 0);
|
||||||
assert_eq!(tcstrings._capacity, 0);
|
assert_eq!(tcstrings._capacity, 0);
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
use crate::traits::*;
|
use crate::traits::*;
|
||||||
use crate::util::err_to_tcstring;
|
use crate::util::err_to_tcstring;
|
||||||
use crate::{
|
use crate::{
|
||||||
replica::TCReplica, result::TCResult, status::TCStatus, string::TCString, strings::TCStrings,
|
replica::TCReplica, result::TCResult, status::TCStatus, string::TCString,
|
||||||
uuid::TCUuid,
|
stringlist::TCStringList, uuid::TCUuid,
|
||||||
};
|
};
|
||||||
use chrono::{DateTime, TimeZone, Utc};
|
use chrono::{DateTime, TimeZone, Utc};
|
||||||
use std::convert::TryFrom;
|
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.
|
/// 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.
|
/// reference the task and the two may be freed in any order.
|
||||||
#[no_mangle]
|
#[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| {
|
wrap(task, |task| {
|
||||||
let vec: Vec<NonNull<TCString<'static>>> = task
|
let vec: Vec<NonNull<TCString<'static>>> = task
|
||||||
.get_tags()
|
.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")
|
.expect("TCString::return_val() returned NULL")
|
||||||
})
|
})
|
||||||
.collect();
|
.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.
|
/// Set a mutable task's modified timestamp. The value cannot be zero.
|
||||||
#[no_mangle]
|
#[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(
|
wrap_mut(
|
||||||
task,
|
task,
|
||||||
|task| {
|
|task| {
|
||||||
|
|||||||
@@ -91,9 +91,9 @@ typedef struct TCReplica TCReplica;
|
|||||||
*
|
*
|
||||||
* Unless specified otherwise, TaskChampion functions take ownership of a `*TCString` when it is
|
* 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
|
* 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;
|
typedef struct TCString TCString;
|
||||||
|
|
||||||
@@ -127,11 +127,11 @@ typedef struct TCUuid {
|
|||||||
} 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.
|
* The content of this struct must be treated as read-only.
|
||||||
*/
|
*/
|
||||||
typedef struct TCStrings {
|
typedef struct TCStringList {
|
||||||
/**
|
/**
|
||||||
* number of strings in items
|
* number of strings in items
|
||||||
*/
|
*/
|
||||||
@@ -141,12 +141,12 @@ typedef struct TCStrings {
|
|||||||
*/
|
*/
|
||||||
size_t _capacity;
|
size_t _capacity;
|
||||||
/**
|
/**
|
||||||
* TCStrings representing each string. these remain owned by the TCStrings instance and will
|
* TCStringList representing each string. these remain owned by the TCStringList instance and will
|
||||||
* be freed by tc_strings_free. This pointer is never NULL for a valid TCStrings, and the
|
* be freed by tc_string_list_free. This pointer is never NULL for a valid TCStringList, and the
|
||||||
* *TCStrings at indexes 0..len-1 are not NULL.
|
* *TCStringList at indexes 0..len-1 are not NULL.
|
||||||
*/
|
*/
|
||||||
struct TCString *const *items;
|
struct TCString *const *items;
|
||||||
} TCStrings;
|
} TCStringList;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
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);
|
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.
|
* 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.
|
* 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.
|
* 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.
|
* 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.
|
* Set a mutable task's status.
|
||||||
|
|||||||
Reference in New Issue
Block a user