Macro libyml::yaml_free

source ·
macro_rules! yaml_free {
    ($ptr:expr) => { ... };
}
Expand description

Frees memory allocated by yaml_malloc! or yaml_realloc!.

This macro wraps the yaml_free function, providing a more Rust-like interface.

§Arguments

  • ptr - A pointer to the memory block to free.

§Safety

While this macro provides a safer interface than direct use of yaml_free, it is still unsafe because:

  • The caller must ensure that ptr was allocated by yaml_malloc! or yaml_realloc!.
  • After calling this macro, ptr becomes invalid and must not be used.

§Examples

use libyml::{yaml_malloc, yaml_free};

unsafe {
    let size = 1024;
    if let Some(ptr) = yaml_malloc!(u8, size) {
        // Use the allocated memory
        // ...
        yaml_free!(ptr);
        // ptr is now invalid and must not be used
    }
}