Skip to main content

hurray_buffer_list_push

Function hurray_buffer_list_push 

Source
#[unsafe(no_mangle)]
pub unsafe extern "C" fn hurray_buffer_list_push( list: *mut HurrayBufferList, buffer: *mut HurrayBuffer, ) -> HurrayStatus
Expand description

Appends buffer to list, transferring ownership of the handle to the list.

On success the caller MUST NOT destroy buffer — destroying the list destroys it. On failure ownership stays with the caller.

Buffers MUST be pushed in descriptor buffer-table order: the first push is buffer index 0, the second is index 1, and so on.

§Safety

  • list MUST be a live handle from hurray_buffer_list_new.
  • buffer MUST be a live handle from hurray_buffer_from_ptr that has not been destroyed and is not already owned by another list.

§Examples

use hurray_ffi::buffer::hurray_buffer_from_ptr;
use hurray_ffi::buffer_list::{
    hurray_buffer_list_destroy, hurray_buffer_list_len, hurray_buffer_list_new,
    hurray_buffer_list_push,
};
use hurray_ffi::{HurrayBuffer, HurrayBufferList, HURRAY_OK};

#[repr(align(64))]
struct Aligned([u8; 64]);
let mut data = Aligned([0u8; 64]);

let mut buffer: *mut HurrayBuffer = std::ptr::null_mut();
assert_eq!(
    unsafe {
        hurray_buffer_from_ptr(
            data.0.as_mut_ptr().cast(), 64, 64, 0, 0, 0,
            None, std::ptr::null_mut(), &mut buffer,
        )
    },
    HURRAY_OK
);

let mut list: *mut HurrayBufferList = std::ptr::null_mut();
unsafe { hurray_buffer_list_new(1, &mut list) };
assert_eq!(unsafe { hurray_buffer_list_push(list, buffer) }, HURRAY_OK);

let mut len: u64 = 0;
unsafe { hurray_buffer_list_len(list, &mut len) };
assert_eq!(len, 1);

// Destroying the list destroys the pushed buffer too.
unsafe { hurray_buffer_list_destroy(&mut list) };