#[no_mangle]
pub unsafe extern "C" fn vs_destroy(
    list: *mut VoluntaryServitude<*const c_void>
) -> u8
Expand description

Free VoluntaryServitude (preserves existing iterators)

Returns 1 if pointer to VoluntaryServitude is NULL

Returns 0 otherwise

Warning: UB if pointer to VoluntaryServitude is invalid

Rust

use std::ptr::null_mut;
use voluntary_servitude::ffi::*;

unsafe {
    let vs = vs_new();
    let data: i32 = 5;
    assert_eq!(vs_append(vs, &data as *const i32 as *const c_void), 0);
    let iter = vs_iter(vs);
    assert_eq!(vs_destroy(vs), 0);

    assert_eq!(*(vs_iter_next(iter) as *const i32), 5);
    assert_eq!(vs_iter_destroy(iter), 0);

    // Returns 1 on NULL pointer
    assert_eq!(vs_destroy(null_mut()), 1);
}

C

#include<assert.h>
#include "../include/voluntary_servitude.h"

int main(int argc, char **argv) {
    vs_t * vs = vs_new();
    vs_iter_t * iter = vs_iter(vs);
    const unsigned int data = 5;
    assert(vs_append(vs, (void *) &data) == 0);
    assert(vs_destroy(vs) == 0);

    assert(*(unsigned int *) vs_iter_next(iter) == 5);
    assert(vs_iter_destroy(vs) == 0);

    // Returns 1 on NULL pointer
    assert(vs_destroy(NULL) == 1);
    return 0;
}