Skip to main content

hurray_tensor_destroy

Function hurray_tensor_destroy 

Source
#[unsafe(no_mangle)]
pub unsafe extern "C" fn hurray_tensor_destroy( handle: *mut *mut HurrayTensor, ) -> HurrayStatus
Expand description

Destroys a tensor handle — its descriptor, every buffer it owns, and its owner reference — then writes null through handle.

One call rather than two, so the teardown order is not the caller’s problem. A non-null owner_release is invoked exactly once, with the owner pointer given at construction.

§Safety

§Examples

use hurray_ffi::tensor::{hurray_tensor_destroy, hurray_tensor_new};
use hurray_ffi::{
    hurray_buffer_list_new, HurrayBufferList, HurrayTensor, HURRAY_C_ABI_VERSION,
    HURRAY_ERR_INTERNAL, HURRAY_OK,
};
assert_eq!(unsafe { hurray_tensor_destroy(&mut tensor) }, HURRAY_OK);
assert!(tensor.is_null());

// A second destroy finds the caller's variable dead and says so, rather than
// freeing anything twice.
assert_eq!(
    unsafe { hurray_tensor_destroy(&mut tensor) },
    HURRAY_ERR_INTERNAL,
);