1#![cfg_attr(not(any(test, feature = "std")), no_std)]
2
3extern crate alloc;
4
5pub(crate) mod cjson_ffi;
6mod cjson;
7
8pub(crate) mod cjson_utils_ffi;
9mod cjson_utils;
10
11pub use cjson::{CJson, CJsonRef, CJsonResult, CJsonError};
13pub use cjson_utils::{JsonPointer, JsonPatch, JsonMergePatch, JsonUtils};
14
15#[cfg(all(not(any(test, feature = "std")), not(feature = "disable_panic")))]
17use core::alloc::Layout;
18
19#[cfg(all(not(any(test, feature = "std")), not(feature = "disable_panic")))]
20struct CJsonAllocator;
21
22#[cfg(all(not(any(test, feature = "std")), not(feature = "disable_panic")))]
23unsafe impl core::alloc::GlobalAlloc for CJsonAllocator {
24 unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
25 unsafe extern "C" {
26 fn malloc(size: usize) -> *mut u8;
27 }
28 unsafe { malloc(layout.size()) }
29 }
30
31 unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
32 unsafe extern "C" {
33 fn free(ptr: *mut u8);
34 }
35 unsafe { free(ptr) }
36 }
37}
38
39#[cfg(all(not(any(test, feature = "std")), not(feature = "disable_panic")))]
40#[global_allocator]
41static ALLOCATOR: CJsonAllocator = CJsonAllocator;
42
43#[cfg(all(not(any(test, feature = "std")), not(feature = "disable_panic")))]
45#[panic_handler]
46fn panic(_info: &core::panic::PanicInfo) -> ! {
47 loop {}
48}
49