libmarpa_asf_sys/lib.rs
1//! Generated bindings to [libmarpa]
2//!
3//! [libmarpa]: https://jeffreykegler.github.io/Marpa-web-site/libmarpa.html
4
5#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
6
7// bindgen's output trips lints that newer toolchains raise (unsafe fns without `# Safety` docs,
8// pointer offsets cast from usize, transmutes in bitfield accessors, libc declarations whose
9// integer widths differ from std's); generated code is not this crate's to rewrite.
10#[allow(
11 unknown_lints,
12 clippy::missing_safety_doc,
13 clippy::ptr_offset_with_cast,
14 unnecessary_transmutes,
15 suspicious_runtime_symbol_definitions
16)]
17mod raw {
18 include!(concat!(env!("OUT_DIR"), "/raw.rs"));
19}
20pub use crate::raw::*;
21
22/// Per-thread counters of the obstack chunk cache in `c/marpa_obs.c` (test-only, the
23/// `chunk-cache-stats` feature). All zero on targets without the cache (Windows, wasm).
24#[cfg(feature = "chunk-cache-stats")]
25#[repr(C)]
26#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
27pub struct ChunkCacheStats {
28 /// Chunk requests served from the cache.
29 pub hits: u64,
30 /// Freed default-size chunks the cache kept.
31 pub kept: u64,
32 /// Freed default-size chunks freed because the cache was full.
33 pub over_cap: u64,
34 /// Chunk requests of a non-default (larger) size, once the thread has a cache.
35 pub oversize: u64,
36 /// Chunks cached now.
37 pub count: u64,
38 /// Most chunks cached at once.
39 pub peak: u64,
40}
41
42#[cfg(feature = "chunk-cache-stats")]
43unsafe extern "C" {
44 fn marpa_asf_obs_chunk_cache_stats(out: *mut ChunkCacheStats);
45}
46
47/// The calling thread's chunk-cache counters.
48#[cfg(feature = "chunk-cache-stats")]
49pub fn chunk_cache_stats() -> ChunkCacheStats {
50 let mut out = ChunkCacheStats::default();
51 // SAFETY: the C function writes one `struct marpa_asf_obs_chunk_cache_stats`, whose six
52 // `unsigned long long` fields this `repr(C)` struct mirrors.
53 unsafe { marpa_asf_obs_chunk_cache_stats(&mut out) };
54 out
55}
56
57#[cfg(test)]
58mod test;