#[unsafe(no_mangle)]pub unsafe extern "C" fn hurray_tensor_context_new(
abi_version: u32,
descriptor_bytes: *const u8,
descriptor_len: u64,
owner: *mut c_void,
owner_release: HurrayOwnerReleaseFn,
out_ctx: *mut *mut HurrayTensorContext,
) -> HurrayStatusExpand description
Creates a HurrayTensorContext owning a copy of descriptor_bytes.
abi_version MUST be the producing build’s HURRAY_C_ABI_VERSION; a consumer
compares it against its own before trusting anything else about the capsule.
owner and owner_release are optional and opaque. When owner_release is
non-null it is invoked exactly once, with owner, during
hurray_tensor_context_destroy.
The caller owns the returned handle and MUST destroy it exactly once.
§Safety
out_ctxMUST be a valid, non-null, writable pointer.descriptor_bytesMUST point to at leastdescriptor_lenreadable bytes, unlessdescriptor_lenis0, in which case it MAY be null.ownerMUST remain valid untilowner_releaseis invoked.
§Examples
use hurray_ffi::tensor_context::{
hurray_tensor_context_destroy, hurray_tensor_context_new,
};
use hurray_ffi::{HurrayTensorContext, HURRAY_C_ABI_VERSION, HURRAY_OK};
let descriptor = [0x48u8, 0x52, 0x52, 0x59]; // "HRRY"
let mut ctx: *mut HurrayTensorContext = std::ptr::null_mut();
assert_eq!(
unsafe {
hurray_tensor_context_new(
HURRAY_C_ABI_VERSION,
descriptor.as_ptr(),
descriptor.len() as u64,
std::ptr::null_mut(),
None,
&mut ctx,
)
},
HURRAY_OK,
);
assert_eq!(unsafe { hurray_tensor_context_destroy(&mut ctx) }, HURRAY_OK);
assert!(ctx.is_null()); // destroy nulls the caller's pointer