Skip to main content

cujson_sys/
lib.rs

1//! Raw FFI bindings to cuJSON.
2//!
3//! Mirrors `crates/cujson-sys/cuda/cujson_capi.h` field-for-field and
4//! function-for-function. `#![no_std]`-compatible: everything here is
5//! `#[repr(C)]` primitives and raw pointers, no allocation.
6#![no_std]
7#![allow(non_camel_case_types)]
8
9#[cfg(feature = "cuda")]
10use core::ffi::{c_char, c_int};
11
12/// Mirrors `cujson_status` (cujson_capi.h). A plain `i32`, not a Rust
13/// `enum`, because the value comes from C and an out-of-range value from a
14/// future header change must not be undefined behavior to hold.
15pub type cujson_status = i32;
16
17pub const CUJSON_OK: cujson_status = 0;
18pub const CUJSON_ERR_UTF8: cujson_status = 1;
19pub const CUJSON_ERR_UNBALANCED: cujson_status = 2;
20pub const CUJSON_ERR_INPUT_TOO_LARGE: cujson_status = 3;
21pub const CUJSON_ERR_CUDA: cujson_status = 4;
22pub const CUJSON_ERR_INTERNAL: cujson_status = 5;
23pub const CUJSON_ERR_EMPTY_INPUT: cujson_status = 6;
24
25/// Mirrors `cujson_tape` (cujson_capi.h). Layout verified against a C
26/// compile of the header by `tests/layout.rs` (tier 1, no nvcc needed).
27#[repr(C)]
28#[derive(Debug)]
29pub struct cujson_tape {
30    pub structural: *mut i32,
31    pub pair_pos: *mut i32,
32    pub len: usize,
33    pub cuda_error: i32,
34    pub _alloc: *mut core::ffi::c_void,
35}
36
37impl Default for cujson_tape {
38    fn default() -> Self {
39        cujson_tape {
40            structural: core::ptr::null_mut(),
41            pair_pos: core::ptr::null_mut(),
42            len: 0,
43            cuda_error: 0,
44            _alloc: core::ptr::null_mut(),
45        }
46    }
47}
48
49#[cfg(feature = "cuda")]
50unsafe extern "C" {
51    pub fn cujson_parse_standard(
52        data: *const u8,
53        size: usize,
54        out: *mut cujson_tape,
55    ) -> cujson_status;
56    pub fn cujson_parse_lines(
57        data: *const u8,
58        size: usize,
59        chunk_bytes: usize,
60        out: *mut cujson_tape,
61    ) -> cujson_status;
62    pub fn cujson_tape_free(tape: *mut cujson_tape);
63    pub fn cujson_pinned_cache_trim();
64    pub fn cujson_status_str(s: cujson_status) -> *const c_char;
65    pub fn cujson_cuda_runtime_version() -> c_int;
66    pub fn cujson_device_count() -> c_int;
67    pub fn cujson_device_name(device: c_int, buf: *mut c_char, buf_len: usize) -> cujson_status;
68    pub fn cujson_compiled_archs() -> *const c_char;
69    pub fn cujson_cuda_error_string(err: c_int) -> *const c_char;
70    pub fn cujson_cuda_driver_version() -> c_int;
71    pub fn cujson_mem_get_info(free_bytes: *mut usize, total_bytes: *mut usize) -> cujson_status;
72}