executorch_sys/cxx_bridge/
core.rs

1// Clippy doesnt detect the 'Safety' comments in the cxx bridge.
2#![allow(clippy::missing_safety_doc)]
3
4use cxx::{type_id, ExternType};
5
6#[cxx::bridge]
7pub(crate) mod ffi {
8
9    unsafe extern "C++" {
10        include!("executorch-sys/cpp/executorch_rs/cxx_bridge.hpp");
11
12        /// Redefinition of the [`MemoryAllocator`](crate::MemoryAllocator).
13        type MemoryAllocator = crate::MemoryAllocator;
14
15        /// Dynamically allocates memory using malloc() and frees all pointers at
16        /// destruction time.
17        ///
18        /// For systems with malloc(), this can be easier than using a fixed-sized
19        /// MemoryAllocator.
20        #[namespace = "executorch::extension"]
21        type MallocMemoryAllocator;
22
23        /// Construct a new Malloc memory allocator.
24        #[namespace = "executorch_rs"]
25        fn MallocMemoryAllocator_new() -> UniquePtr<MallocMemoryAllocator>;
26
27        /// Get a pointer to the base class `MemoryAllocator`.
28        ///
29        /// Safety: The caller must ensure that the pointer is valid for the lifetime of the `MemoryAllocator`.
30        #[namespace = "executorch_rs"]
31        unsafe fn MallocMemoryAllocator_as_memory_allocator(
32            self_: Pin<&mut MallocMemoryAllocator>,
33        ) -> *mut MemoryAllocator;
34    }
35}
36
37unsafe impl ExternType for crate::ScalarType {
38    type Id = type_id!("ScalarType");
39    type Kind = cxx::kind::Trivial;
40}
41
42unsafe impl ExternType for crate::TensorShapeDynamism {
43    type Id = type_id!("TensorShapeDynamism");
44    type Kind = cxx::kind::Trivial;
45}
46
47unsafe impl ExternType for crate::Error {
48    type Id = type_id!("Error");
49    type Kind = cxx::kind::Trivial;
50}
51
52unsafe impl ExternType for crate::MethodMeta {
53    type Id = type_id!("MethodMeta");
54    type Kind = cxx::kind::Trivial;
55}
56
57unsafe impl ExternType for crate::ArrayRefEValue {
58    type Id = type_id!("ArrayRefEValue");
59    type Kind = cxx::kind::Trivial;
60}
61
62unsafe impl ExternType for crate::VecEValue {
63    type Id = type_id!("VecEValue");
64    type Kind = cxx::kind::Trivial;
65}
66
67unsafe impl ExternType for crate::ProgramVerification {
68    type Id = type_id!("ProgramVerification");
69    type Kind = cxx::kind::Trivial;
70}
71
72unsafe impl ExternType for crate::MemoryAllocator {
73    type Id = type_id!("MemoryAllocator");
74    type Kind = cxx::kind::Trivial;
75}