address some clippy lints
This commit is contained in:
@@ -20,7 +20,7 @@ impl PassByValue for TCAnnotation {
|
|||||||
// SAFETY:
|
// SAFETY:
|
||||||
// - any time_t value is valid
|
// - any time_t value is valid
|
||||||
// - time_t is copy, so ownership is not important
|
// - time_t is copy, so ownership is not important
|
||||||
let entry = unsafe { self.entry.val_from_arg() }.unwrap();
|
let entry = unsafe { libc::time_t::val_from_arg(self.entry) }.unwrap();
|
||||||
// SAFETY:
|
// SAFETY:
|
||||||
// - self.description is not NULL (field docstring)
|
// - self.description is not NULL (field docstring)
|
||||||
// - self.description came from return_ptr in as_ctype
|
// - self.description came from return_ptr in as_ctype
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
// Not working yet in stable - https://github.com/rust-lang/rust-clippy/issues/8020
|
// Not working yet in stable - https://github.com/rust-lang/rust-clippy/issues/8020
|
||||||
// #![warn(clippy::undocumented_unsafe_blocks)]
|
// #![warn(clippy::undocumented_unsafe_blocks)]
|
||||||
|
|
||||||
|
// docstrings for extern "C" functions are reflected into C, and do not benefit
|
||||||
|
// from safety docs.
|
||||||
|
#![allow(clippy::missing_safety_doc)]
|
||||||
|
|
||||||
mod traits;
|
mod traits;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ pub unsafe extern "C" fn tc_replica_new_in_memory() -> *mut TCReplica {
|
|||||||
/// Create a new TCReplica with an on-disk database having the given filename. On error, a string
|
/// Create a new TCReplica with an on-disk database having the given filename. On error, a string
|
||||||
/// is written to the `error_out` parameter (if it is not NULL) and NULL is returned.
|
/// is written to the `error_out` parameter (if it is not NULL) and NULL is returned.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_replica_new_on_disk<'a>(
|
pub unsafe extern "C" fn tc_replica_new_on_disk(
|
||||||
path: *mut TCString,
|
path: *mut TCString,
|
||||||
error_out: *mut *mut TCString,
|
error_out: *mut *mut TCString,
|
||||||
) -> *mut TCReplica {
|
) -> *mut TCReplica {
|
||||||
@@ -169,7 +169,7 @@ pub unsafe extern "C" fn tc_replica_all_task_uuids(rep: *mut TCReplica) -> TCUui
|
|||||||
let uuids: Vec<_> = rep
|
let uuids: Vec<_> = rep
|
||||||
.all_task_uuids()?
|
.all_task_uuids()?
|
||||||
.drain(..)
|
.drain(..)
|
||||||
.map(|uuid| TCUuid::return_val(uuid))
|
.map(TCUuid::return_val)
|
||||||
.collect();
|
.collect();
|
||||||
Ok(TCUuidList::return_val(uuids))
|
Ok(TCUuidList::return_val(uuids))
|
||||||
},
|
},
|
||||||
@@ -265,10 +265,7 @@ pub unsafe extern "C" fn tc_replica_import_task_with_uuid(
|
|||||||
/// If undone_out is not NULL, then on success it is set to 1 if operations were undone, or 0 if
|
/// If undone_out is not NULL, then on success it is set to 1 if operations were undone, or 0 if
|
||||||
/// there are no operations that can be done.
|
/// there are no operations that can be done.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_replica_undo<'a>(
|
pub unsafe extern "C" fn tc_replica_undo(rep: *mut TCReplica, undone_out: *mut i32) -> TCResult {
|
||||||
rep: *mut TCReplica,
|
|
||||||
undone_out: *mut i32,
|
|
||||||
) -> TCResult {
|
|
||||||
wrap(
|
wrap(
|
||||||
rep,
|
rep,
|
||||||
|rep| {
|
|rep| {
|
||||||
@@ -323,9 +320,9 @@ pub unsafe extern "C" fn tc_replica_rebuild_working_set(
|
|||||||
/// to this function will return NULL. The rep pointer must not be NULL. The caller must free the
|
/// to this function will return NULL. The rep pointer must not be NULL. The caller must free the
|
||||||
/// returned string.
|
/// returned string.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_replica_error<'a>(rep: *mut TCReplica) -> *mut TCString<'static> {
|
pub unsafe extern "C" fn tc_replica_error(rep: *mut TCReplica) -> *mut TCString<'static> {
|
||||||
// SAFETY: see type docstring
|
// SAFETY: see type docstring
|
||||||
let rep: &'a mut TCReplica = unsafe { TCReplica::from_ptr_arg_ref_mut(rep) };
|
let rep: &mut TCReplica = unsafe { TCReplica::from_ptr_arg_ref_mut(rep) };
|
||||||
if let Some(tcstring) = rep.error.take() {
|
if let Some(tcstring) = rep.error.take() {
|
||||||
// SAFETY: see TCString docstring
|
// SAFETY: see TCString docstring
|
||||||
unsafe { tcstring.return_ptr() }
|
unsafe { tcstring.return_ptr() }
|
||||||
|
|||||||
@@ -103,15 +103,15 @@ impl From<Task> for TCTask {
|
|||||||
|
|
||||||
/// Utility function to get a shared reference to the underlying Task. All Task getters
|
/// Utility function to get a shared reference to the underlying Task. All Task getters
|
||||||
/// are error-free, so this does not handle errors.
|
/// are error-free, so this does not handle errors.
|
||||||
fn wrap<'a, T, F>(task: *mut TCTask, f: F) -> T
|
fn wrap<T, F>(task: *mut TCTask, f: F) -> T
|
||||||
where
|
where
|
||||||
F: FnOnce(&Task) -> T,
|
F: FnOnce(&Task) -> T,
|
||||||
{
|
{
|
||||||
// SAFETY:
|
// SAFETY:
|
||||||
// - task is not null (promised by caller)
|
// - task is not null (promised by caller)
|
||||||
// - task outlives 'a (promised by caller)
|
// - task outlives this function (promised by caller)
|
||||||
let tctask: &'a mut TCTask = unsafe { TCTask::from_ptr_arg_ref_mut(task) };
|
let tctask: &mut TCTask = unsafe { TCTask::from_ptr_arg_ref_mut(task) };
|
||||||
let task: &'a Task = match &tctask.inner {
|
let task: &Task = match &tctask.inner {
|
||||||
Inner::Immutable(t) => t,
|
Inner::Immutable(t) => t,
|
||||||
Inner::Mutable(t, _) => t.deref(),
|
Inner::Mutable(t, _) => t.deref(),
|
||||||
Inner::Invalid => unreachable!(),
|
Inner::Invalid => unreachable!(),
|
||||||
@@ -123,15 +123,15 @@ where
|
|||||||
/// Utility function to get a mutable reference to the underlying Task. The
|
/// Utility function to get a mutable reference to the underlying Task. The
|
||||||
/// TCTask must be mutable. The inner function may use `?` syntax to return an
|
/// TCTask must be mutable. The inner function may use `?` syntax to return an
|
||||||
/// error, which will be represented with the `err_value` returned to C.
|
/// error, which will be represented with the `err_value` returned to C.
|
||||||
fn wrap_mut<'a, T, F>(task: *mut TCTask, f: F, err_value: T) -> T
|
fn wrap_mut<T, F>(task: *mut TCTask, f: F, err_value: T) -> T
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut TaskMut) -> anyhow::Result<T>,
|
F: FnOnce(&mut TaskMut) -> anyhow::Result<T>,
|
||||||
{
|
{
|
||||||
// SAFETY:
|
// SAFETY:
|
||||||
// - task is not null (promised by caller)
|
// - task is not null (promised by caller)
|
||||||
// - task outlives 'a (promised by caller)
|
// - task outlives this function (promised by caller)
|
||||||
let tctask: &'a mut TCTask = unsafe { TCTask::from_ptr_arg_ref_mut(task) };
|
let tctask: &mut TCTask = unsafe { TCTask::from_ptr_arg_ref_mut(task) };
|
||||||
let task: &'a mut TaskMut = match tctask.inner {
|
let task: &mut TaskMut = match tctask.inner {
|
||||||
Inner::Immutable(_) => panic!("Task is immutable"),
|
Inner::Immutable(_) => panic!("Task is immutable"),
|
||||||
Inner::Mutable(ref mut t, _) => t,
|
Inner::Mutable(ref mut t, _) => t,
|
||||||
Inner::Invalid => unreachable!(),
|
Inner::Invalid => unreachable!(),
|
||||||
@@ -205,11 +205,11 @@ impl CList for TCTaskList {
|
|||||||
/// if (!success) { ... }
|
/// if (!success) { ... }
|
||||||
/// ```
|
/// ```
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_task_to_mut<'a>(task: *mut TCTask, tcreplica: *mut TCReplica) {
|
pub unsafe extern "C" fn tc_task_to_mut(task: *mut TCTask, tcreplica: *mut TCReplica) {
|
||||||
// SAFETY:
|
// SAFETY:
|
||||||
// - task is not null (promised by caller)
|
// - task is not null (promised by caller)
|
||||||
// - task outlives 'a (promised by caller)
|
// - task outlives 'a (promised by caller)
|
||||||
let tctask: &'a mut TCTask = unsafe { TCTask::from_ptr_arg_ref_mut(task) };
|
let tctask: &mut TCTask = unsafe { TCTask::from_ptr_arg_ref_mut(task) };
|
||||||
// SAFETY:
|
// SAFETY:
|
||||||
// - tcreplica is not NULL (promised by caller)
|
// - tcreplica is not NULL (promised by caller)
|
||||||
// - tcreplica lives until later call to to_immut via tc_task_to_immut (promised by caller,
|
// - tcreplica lives until later call to to_immut via tc_task_to_immut (promised by caller,
|
||||||
@@ -223,11 +223,11 @@ pub unsafe extern "C" fn tc_task_to_mut<'a>(task: *mut TCTask, tcreplica: *mut T
|
|||||||
///
|
///
|
||||||
/// The replica passed to `tc_task_to_mut` may be used freely after this call.
|
/// The replica passed to `tc_task_to_mut` may be used freely after this call.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_task_to_immut<'a>(task: *mut TCTask) {
|
pub unsafe extern "C" fn tc_task_to_immut(task: *mut TCTask) {
|
||||||
// SAFETY:
|
// SAFETY:
|
||||||
// - task is not null (promised by caller)
|
// - task is not null (promised by caller)
|
||||||
// - task outlives 'a (promised by caller)
|
// - task outlives 'a (promised by caller)
|
||||||
let tctask: &'a mut TCTask = unsafe { TCTask::from_ptr_arg_ref_mut(task) };
|
let tctask: &mut TCTask = unsafe { TCTask::from_ptr_arg_ref_mut(task) };
|
||||||
tctask.to_immut();
|
tctask.to_immut();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,7 +239,7 @@ pub unsafe extern "C" fn tc_task_get_uuid(task: *mut TCTask) -> TCUuid {
|
|||||||
|
|
||||||
/// Get a task's status.
|
/// Get a task's status.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_task_get_status<'a>(task: *mut TCTask) -> TCStatus {
|
pub unsafe extern "C" fn tc_task_get_status(task: *mut TCTask) -> TCStatus {
|
||||||
wrap(task, |task| task.get_status().into())
|
wrap(task, |task| task.get_status().into())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,7 +265,7 @@ pub unsafe extern "C" fn tc_task_get_taskmap(task: *mut TCTask) -> TCKVList {
|
|||||||
/// Get a task's description, or NULL if the task cannot be represented as a C string (e.g., if it
|
/// Get a task's description, or NULL if the task cannot be represented as a C string (e.g., if it
|
||||||
/// contains embedded NUL characters).
|
/// contains embedded NUL characters).
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_task_get_description<'a>(task: *mut TCTask) -> *mut TCString<'static> {
|
pub unsafe extern "C" fn tc_task_get_description(task: *mut TCTask) -> *mut TCString<'static> {
|
||||||
wrap(task, |task| {
|
wrap(task, |task| {
|
||||||
let descr: TCString = task.get_description().into();
|
let descr: TCString = task.get_description().into();
|
||||||
// SAFETY: see TCString docstring
|
// SAFETY: see TCString docstring
|
||||||
@@ -275,19 +275,19 @@ pub unsafe extern "C" fn tc_task_get_description<'a>(task: *mut TCTask) -> *mut
|
|||||||
|
|
||||||
/// Get the entry timestamp for a task (when it was created), or 0 if not set.
|
/// Get the entry timestamp for a task (when it was created), or 0 if not set.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_task_get_entry<'a>(task: *mut TCTask) -> libc::time_t {
|
pub unsafe extern "C" fn tc_task_get_entry(task: *mut TCTask) -> libc::time_t {
|
||||||
wrap(task, |task| libc::time_t::as_ctype(task.get_entry()))
|
wrap(task, |task| libc::time_t::as_ctype(task.get_entry()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the wait timestamp for a task, or 0 if not set.
|
/// Get the wait timestamp for a task, or 0 if not set.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_task_get_wait<'a>(task: *mut TCTask) -> libc::time_t {
|
pub unsafe extern "C" fn tc_task_get_wait(task: *mut TCTask) -> libc::time_t {
|
||||||
wrap(task, |task| libc::time_t::as_ctype(task.get_wait()))
|
wrap(task, |task| libc::time_t::as_ctype(task.get_wait()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the modified timestamp for a task, or 0 if not set.
|
/// Get the modified timestamp for a task, or 0 if not set.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_task_get_modified<'a>(task: *mut TCTask) -> libc::time_t {
|
pub unsafe extern "C" fn tc_task_get_modified(task: *mut TCTask) -> libc::time_t {
|
||||||
wrap(task, |task| libc::time_t::as_ctype(task.get_modified()))
|
wrap(task, |task| libc::time_t::as_ctype(task.get_modified()))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,7 +306,7 @@ pub unsafe extern "C" fn tc_task_is_active(task: *mut TCTask) -> bool {
|
|||||||
/// Check if a task has the given tag. If the tag is invalid, this function will return false, as
|
/// Check if a task has the given tag. If the tag is invalid, this function will return false, as
|
||||||
/// that (invalid) tag is not present. No error will be reported via `tc_task_error`.
|
/// that (invalid) tag is not present. No error will be reported via `tc_task_error`.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_task_has_tag<'a>(task: *mut TCTask, tag: *mut TCString) -> bool {
|
pub unsafe extern "C" fn tc_task_has_tag(task: *mut TCTask, tag: *mut TCString) -> bool {
|
||||||
// SAFETY: see TCString docstring
|
// SAFETY: see TCString docstring
|
||||||
let tcstring = unsafe { TCString::take_from_ptr_arg(tag) };
|
let tcstring = unsafe { TCString::take_from_ptr_arg(tag) };
|
||||||
wrap(task, |task| {
|
wrap(task, |task| {
|
||||||
@@ -323,7 +323,7 @@ pub unsafe extern "C" fn tc_task_has_tag<'a>(task: *mut TCTask, tag: *mut TCStri
|
|||||||
/// The caller must free the returned TCStringList instance. The TCStringList 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) -> TCStringList {
|
pub unsafe extern "C" fn tc_task_get_tags(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()
|
||||||
@@ -344,7 +344,7 @@ pub unsafe extern "C" fn tc_task_get_tags<'a>(task: *mut TCTask) -> TCStringList
|
|||||||
/// The caller must free the returned TCAnnotationList instance. The TCStringList instance does not
|
/// The caller must free the returned TCAnnotationList 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_annotations<'a>(task: *mut TCTask) -> TCAnnotationList {
|
pub unsafe extern "C" fn tc_task_get_annotations(task: *mut TCTask) -> TCAnnotationList {
|
||||||
wrap(task, |task| {
|
wrap(task, |task| {
|
||||||
let vec: Vec<TCAnnotation> = task
|
let vec: Vec<TCAnnotation> = task
|
||||||
.get_annotations()
|
.get_annotations()
|
||||||
@@ -404,7 +404,7 @@ pub unsafe extern "C" fn tc_task_get_legacy_uda<'a>(
|
|||||||
///
|
///
|
||||||
/// Legacy UDAs are represented with an empty string in the ns field.
|
/// Legacy UDAs are represented with an empty string in the ns field.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_task_get_udas<'a>(task: *mut TCTask) -> TCUDAList {
|
pub unsafe extern "C" fn tc_task_get_udas(task: *mut TCTask) -> TCUDAList {
|
||||||
wrap(task, |task| {
|
wrap(task, |task| {
|
||||||
let vec: Vec<TCUDA> = task
|
let vec: Vec<TCUDA> = task
|
||||||
.get_udas()
|
.get_udas()
|
||||||
@@ -425,7 +425,7 @@ pub unsafe extern "C" fn tc_task_get_udas<'a>(task: *mut TCTask) -> TCUDAList {
|
|||||||
/// 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.
|
/// included in the key field.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_task_get_legacy_udas<'a>(task: *mut TCTask) -> TCUDAList {
|
pub unsafe extern "C" fn tc_task_get_legacy_udas(task: *mut TCTask) -> TCUDAList {
|
||||||
wrap(task, |task| {
|
wrap(task, |task| {
|
||||||
let vec: Vec<TCUDA> = task
|
let vec: Vec<TCUDA> = task
|
||||||
.get_legacy_udas()
|
.get_legacy_udas()
|
||||||
@@ -443,7 +443,7 @@ pub unsafe extern "C" fn tc_task_get_legacy_udas<'a>(task: *mut TCTask) -> TCUDA
|
|||||||
|
|
||||||
/// Set a mutable task's status.
|
/// Set a mutable task's status.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_task_set_status<'a>(task: *mut TCTask, status: TCStatus) -> TCResult {
|
pub unsafe extern "C" fn tc_task_set_status(task: *mut TCTask, status: TCStatus) -> TCResult {
|
||||||
wrap_mut(
|
wrap_mut(
|
||||||
task,
|
task,
|
||||||
|task| {
|
|task| {
|
||||||
@@ -456,7 +456,7 @@ pub unsafe extern "C" fn tc_task_set_status<'a>(task: *mut TCTask, status: TCSta
|
|||||||
|
|
||||||
/// Set a mutable task's description.
|
/// Set a mutable task's description.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_task_set_description<'a>(
|
pub unsafe extern "C" fn tc_task_set_description(
|
||||||
task: *mut TCTask,
|
task: *mut TCTask,
|
||||||
description: *mut TCString,
|
description: *mut TCString,
|
||||||
) -> TCResult {
|
) -> TCResult {
|
||||||
@@ -640,7 +640,7 @@ pub unsafe extern "C" fn tc_task_remove_annotation(task: *mut TCTask, entry: i64
|
|||||||
|
|
||||||
/// Set a UDA on a mutable task.
|
/// Set a UDA on a mutable task.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_task_set_uda<'a>(
|
pub unsafe extern "C" fn tc_task_set_uda(
|
||||||
task: *mut TCTask,
|
task: *mut TCTask,
|
||||||
ns: *mut TCString,
|
ns: *mut TCString,
|
||||||
key: *mut TCString,
|
key: *mut TCString,
|
||||||
@@ -668,7 +668,7 @@ pub unsafe extern "C" fn tc_task_set_uda<'a>(
|
|||||||
|
|
||||||
/// Remove a UDA fraom a mutable task.
|
/// Remove a UDA fraom a mutable task.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_task_remove_uda<'a>(
|
pub unsafe extern "C" fn tc_task_remove_uda(
|
||||||
task: *mut TCTask,
|
task: *mut TCTask,
|
||||||
ns: *mut TCString,
|
ns: *mut TCString,
|
||||||
key: *mut TCString,
|
key: *mut TCString,
|
||||||
@@ -689,7 +689,7 @@ pub unsafe extern "C" fn tc_task_remove_uda<'a>(
|
|||||||
|
|
||||||
/// Set a legacy UDA on a mutable task.
|
/// Set a legacy UDA on a mutable task.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_task_set_legacy_uda<'a>(
|
pub unsafe extern "C" fn tc_task_set_legacy_uda(
|
||||||
task: *mut TCTask,
|
task: *mut TCTask,
|
||||||
key: *mut TCString,
|
key: *mut TCString,
|
||||||
value: *mut TCString,
|
value: *mut TCString,
|
||||||
@@ -710,7 +710,7 @@ pub unsafe extern "C" fn tc_task_set_legacy_uda<'a>(
|
|||||||
|
|
||||||
/// Remove a UDA fraom a mutable task.
|
/// Remove a UDA fraom a mutable task.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_task_remove_legacy_uda<'a>(
|
pub unsafe extern "C" fn tc_task_remove_legacy_uda(
|
||||||
task: *mut TCTask,
|
task: *mut TCTask,
|
||||||
key: *mut TCString,
|
key: *mut TCString,
|
||||||
) -> TCResult {
|
) -> TCResult {
|
||||||
@@ -730,11 +730,11 @@ pub unsafe extern "C" fn tc_task_remove_legacy_uda<'a>(
|
|||||||
/// to this function will return NULL. The task pointer must not be NULL. The caller must free the
|
/// to this function will return NULL. The task pointer must not be NULL. The caller must free the
|
||||||
/// returned string.
|
/// returned string.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_task_error<'a>(task: *mut TCTask) -> *mut TCString<'static> {
|
pub unsafe extern "C" fn tc_task_error(task: *mut TCTask) -> *mut TCString<'static> {
|
||||||
// SAFETY:
|
// SAFETY:
|
||||||
// - task is not null (promised by caller)
|
// - task is not null (promised by caller)
|
||||||
// - task outlives 'a (promised by caller)
|
// - task outlives 'a (promised by caller)
|
||||||
let task: &'a mut TCTask = unsafe { TCTask::from_ptr_arg_ref_mut(task) };
|
let task: &mut TCTask = unsafe { TCTask::from_ptr_arg_ref_mut(task) };
|
||||||
if let Some(tcstring) = task.error.take() {
|
if let Some(tcstring) = task.error.take() {
|
||||||
unsafe { tcstring.return_ptr() }
|
unsafe { tcstring.return_ptr() }
|
||||||
} else {
|
} else {
|
||||||
@@ -747,7 +747,7 @@ pub unsafe extern "C" fn tc_task_error<'a>(task: *mut TCTask) -> *mut TCString<'
|
|||||||
///
|
///
|
||||||
/// If the task is currently mutable, it will first be made immutable.
|
/// If the task is currently mutable, it will first be made immutable.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_task_free<'a>(task: *mut TCTask) {
|
pub unsafe extern "C" fn tc_task_free(task: *mut TCTask) {
|
||||||
// SAFETY:
|
// SAFETY:
|
||||||
// - rep is not NULL (promised by caller)
|
// - rep is not NULL (promised by caller)
|
||||||
// - caller will not use the TCTask after this (promised by caller)
|
// - caller will not use the TCTask after this (promised by caller)
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ impl CList for TCUuidList {
|
|||||||
/// Write the string representation of a TCUuid into the given buffer, which must be
|
/// Write the string representation of a TCUuid into the given buffer, which must be
|
||||||
/// at least TC_UUID_STRING_BYTES long. No NUL terminator is added.
|
/// at least TC_UUID_STRING_BYTES long. No NUL terminator is added.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_uuid_to_buf<'a>(tcuuid: TCUuid, buf: *mut libc::c_char) {
|
pub unsafe extern "C" fn tc_uuid_to_buf(tcuuid: TCUuid, buf: *mut libc::c_char) {
|
||||||
debug_assert!(!buf.is_null());
|
debug_assert!(!buf.is_null());
|
||||||
// SAFETY:
|
// SAFETY:
|
||||||
// - buf is valid for len bytes (by C convention)
|
// - buf is valid for len bytes (by C convention)
|
||||||
@@ -83,7 +83,7 @@ pub unsafe extern "C" fn tc_uuid_to_buf<'a>(tcuuid: TCUuid, buf: *mut libc::c_ch
|
|||||||
// - content of buf will not be mutated during the lifetime of this slice (lifetime
|
// - content of buf will not be mutated during the lifetime of this slice (lifetime
|
||||||
// does not outlive this function call)
|
// does not outlive this function call)
|
||||||
// - the length of the buffer is less than isize::MAX (promised by caller)
|
// - the length of the buffer is less than isize::MAX (promised by caller)
|
||||||
let buf: &'a mut [u8] = unsafe {
|
let buf: &mut [u8] = unsafe {
|
||||||
std::slice::from_raw_parts_mut(buf as *mut u8, ::uuid::adapter::Hyphenated::LENGTH)
|
std::slice::from_raw_parts_mut(buf as *mut u8, ::uuid::adapter::Hyphenated::LENGTH)
|
||||||
};
|
};
|
||||||
// SAFETY:
|
// SAFETY:
|
||||||
@@ -107,7 +107,7 @@ pub unsafe extern "C" fn tc_uuid_to_str(tcuuid: TCUuid) -> *mut TCString<'static
|
|||||||
/// Parse the given string as a UUID. Returns TC_RESULT_ERROR on parse failure or if the given
|
/// Parse the given string as a UUID. Returns TC_RESULT_ERROR on parse failure or if the given
|
||||||
/// string is not valid.
|
/// string is not valid.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tc_uuid_from_str<'a>(s: *mut TCString, uuid_out: *mut TCUuid) -> TCResult {
|
pub unsafe extern "C" fn tc_uuid_from_str(s: *mut TCString, uuid_out: *mut TCUuid) -> TCResult {
|
||||||
debug_assert!(!s.is_null());
|
debug_assert!(!s.is_null());
|
||||||
debug_assert!(!uuid_out.is_null());
|
debug_assert!(!uuid_out.is_null());
|
||||||
// SAFETY: see TCString docstring
|
// SAFETY: see TCString docstring
|
||||||
|
|||||||
@@ -18,14 +18,14 @@ impl From<WorkingSet> for TCWorkingSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Utility function to get a shared reference to the underlying WorkingSet.
|
/// Utility function to get a shared reference to the underlying WorkingSet.
|
||||||
fn wrap<'a, T, F>(ws: *mut TCWorkingSet, f: F) -> T
|
fn wrap<T, F>(ws: *mut TCWorkingSet, f: F) -> T
|
||||||
where
|
where
|
||||||
F: FnOnce(&WorkingSet) -> T,
|
F: FnOnce(&WorkingSet) -> T,
|
||||||
{
|
{
|
||||||
// SAFETY:
|
// SAFETY:
|
||||||
// - ws is not null (promised by caller)
|
// - ws is not null (promised by caller)
|
||||||
// - ws outlives 'a (promised by caller)
|
// - ws outlives 'a (promised by caller)
|
||||||
let tcws: &'a TCWorkingSet = unsafe { TCWorkingSet::from_ptr_arg_ref(ws) };
|
let tcws: &TCWorkingSet = unsafe { TCWorkingSet::from_ptr_arg_ref(ws) };
|
||||||
f(&tcws.0)
|
f(&tcws.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user