1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! `asdf/util.h`: the one entry point that header declares.
//!
//! # Why a free function is part of the ABI
//!
//! Four entry points hand the caller a buffer the library allocated:
//! `asdf_write_to_mem`, `asdf_ndarray_read_all`, `asdf_ndarray_read_tile_ndim`
//! and `asdf_ndarray_read_tile_2d`, each when asked to allocate the
//! destination itself. Before libasdf 0.2.0 the headers told the caller to
//! release those with `free()`, which made the C runtime's allocator part of
//! the interface -- an implementation could not use any other one, and on
//! Windows a caller linked against a different CRT would free into the wrong
//! heap. Raised as [libasdf#250]; `asdf_free` is the answer.
//!
//! It does not change what this crate allocates with. `CMallocBuf` still uses
//! `malloc`, because callers written against the older headers are still
//! calling `free()` on these buffers and must keep working.
//!
//! [libasdf#250]: https://github.com/asdf-format/libasdf/issues/250
use c_void;
use crateguard;
/// Release a buffer libasdf allocated on the caller's behalf.
///
/// Only for the four allocating entry points listed in `asdf/util.h`. Every
/// other pointer the library hands out has its own destructor and must not
/// come here.
///
/// # Safety
/// `buf` must be null, or a pointer returned by one of those entry points and
/// not yet released.
pub unsafe extern "C"