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
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#![cfg_attr(feature = "nightly",
    feature(doc_cfg, external_doc, trivial_bounds)
)]
#![cfg_attr(not(feature = "std"),
    no_std,
)]

#![allow(nonstandard_style, trivial_bounds)]
#![warn(
    missing_copy_implementations,
    missing_debug_implementations,
)]
#![deny(
    bare_trait_objects,
    elided_lifetimes_in_paths,
    unconditional_recursion,
    unused_must_use,
)]

#![cfg_attr(feature = "nightly",
    doc(include = "../README.md")
)]
#![cfg_attr(not(feature = "nightly"),
    doc = "See the [user guide](https://getditto.github.io/safer_ffi)."
)]


#[cfg(feature = "proc_macros")]
#[macro_use]
extern crate require_unsafe_in_body;

#[doc(hidden)] pub
extern crate paste;

#[macro_use]
#[path = "utils/_mod.rs"]
#[doc(hidden)] /** Not part of the public API **/ pub
mod __utils__;
use __utils__ as utils;

extern crate proc_macro;
pub use ::proc_macro::{ffi_export, cfg_headers};
cfg_proc_macros! {
    #[::proc_macro_hack::proc_macro_hack]
    /// Creates a compile-time checked [`char_p::Ref`]`<'static>` out of a
    /// string literal.
    ///
    /// [`char_p::Ref`]: `crate::prelude::char_p::Ref`
    pub use ::proc_macro::c_str as c;

    #[doc(inline)]
    pub use ::proc_macro::derive_ReprC;
}

#[macro_use]
#[path = "layout/_mod.rs"]
pub mod layout;

__cfg_headers__! {
    #[doc(hidden)] pub
    use ::inventory;

    #[cfg_attr(feature = "nightly",
        doc(cfg(feature = "headers")),
    )]
    #[path = "headers/_mod.rs"]
    pub
    mod headers;

    #[allow(missing_copy_implementations, missing_debug_implementations)]
    #[doc(hidden)] pub
    struct FfiExport(
        pub
        fn (&'_ mut dyn headers::Definer)
          -> ::std::io::Result<()>
        ,
    );

    ::inventory::collect!(FfiExport);
}

cfg_alloc! {
    extern crate alloc;
}

cfg_alloc! {
    pub
    mod boxed;
}

use self::c_char_module::c_char;
#[path = "c_char.rs"]
mod c_char_module;

pub
mod char_p;

pub
mod closure;

const _: () = {
    #[path = "ffi_export.rs"]
    mod ffi_export;
};

pub
mod ptr;

pub
mod slice;

#[path = "string/_mod.rs"]
pub
mod string;

#[doc(no_inline)]
pub
use tuple::*;

pub
mod tuple;

cfg_alloc! {
    #[doc(inline)]
    pub use string::String;

    #[doc(inline)]
    pub use vec::Vec;
    pub mod vec;
}

macro_rules! reexport_primitive_types {(
    $($ty:ident)*
) => (
    $(
        #[doc(hidden)]
        pub use $ty;
    )*
)} reexport_primitive_types! {
    u8 u16 u32 u64 u128
    i8 i16 i32 i64 i128
    f32 f64
    char
    bool
    str
}
#[doc(hidden)] pub use ::core;
cfg_std! {
    #[doc(hidden)] pub use ::std;
}

#[derive(Clone, Copy)]
#[allow(missing_debug_implementations)]
#[doc(hidden)] pub
struct NotZeroSized;

pub
mod prelude {
    #[doc(no_inline)]
    pub use crate::{
        closure::*,
        ffi_export,
        layout::ReprC,
    };
    pub
    mod char_p {
        #[doc(no_inline)]
        pub use crate::char_p::{
            char_p_raw as Raw,
            char_p_ref as Ref,
        };
        cfg_alloc! {
            #[doc(no_inline)]
            pub use crate::char_p::{
                char_p_boxed as Box,
                new,
            };
        }
    }
    pub
    mod c_slice {
        #[doc(no_inline)]
        pub use crate::slice::{
            slice_mut as Mut,
            slice_raw as Raw,
            slice_ref as Ref,
        };
        cfg_alloc! {
            #[doc(no_inline)]
            pub use crate::slice::slice_boxed as Box;
        }
    }
    pub
    mod repr_c {
        cfg_alloc! {
            #[doc(no_inline)]
            pub use crate::{
                boxed::Box,
                string::String,
                vec::Vec,
            };
        }
    }
    pub
    mod str {
        #[doc(no_inline)]
        pub use crate::string::{
            // str_raw as Raw,
            str_ref as Ref,
        };
        cfg_alloc! {
            #[doc(no_inline)]
            pub use crate::string::str_boxed as Box;
        }
    }
    cfg_proc_macros! {
        #[doc(no_inline)]
        pub use crate::layout::derive_ReprC;
        #[doc(no_inline)]
        pub use c;
    }
    #[doc(no_inline)]
    pub use ::core::{
        convert::{
            TryFrom as _,
            TryInto as _,
        },
        ops::Not as _,
    };

    #[cfg(feature = "out-refs")]
    #[cfg_attr(all(docs, feature = "nightly"),
        doc(cfg(feature = "out-refs"))
    )]
    pub use ::uninit::prelude::{
        // Out reference itself
        Out,
        // Helper trait to go from `&mut T` and `&mut MaybeUninit<T>` to `Out<T>`
        AsOut,
        // Helper trait to have `AsOut` when `T : !Copy`
        ManuallyDropMut,
    };
}

#[macro_export]
macro_rules! NULL {() => (
    $crate::core::ptr::null_mut()
)}

#[cfg(feature = "log")]
#[doc(hidden)]
pub use ::log;

#[allow(missing_copy_implementations, missing_debug_implementations)]
#[doc(hidden)] /** Not part of the public API **/ pub
struct __PanicOnDrop__; impl Drop for __PanicOnDrop__ {
    fn drop (self: &'_ mut Self)
    {
        panic!()
    }
}

#[cfg(feature = "log")]
#[doc(hidden)] /** Not part of the public API **/ #[macro_export]
macro_rules! __abort_with_msg__ { ($($tt:tt)*) => ({
    $crate::log::error!($($tt)*);
    let _panic_on_drop = $crate::__PanicOnDrop__;
    $crate::core::panic!($($tt)*);
})}
#[cfg(all(
    not(feature = "log"),
    feature = "std",
))]
#[doc(hidden)] /** Not part of the public API **/ #[macro_export]
macro_rules! __abort_with_msg__ { ($($tt:tt)*) => ({
    $crate::std::eprintln!($($tt)*);
    $crate::std::process::abort();
})}
#[cfg(all(
    not(feature = "log"),
    not(feature = "std"),
))]
#[doc(hidden)] /** Not part of the public API **/ #[macro_export]
macro_rules! __abort_with_msg__ { ($($tt:tt)*) => ({
    let _panic_on_drop = $crate::__PanicOnDrop__;
    $crate::core::panic!($($tt)*);
})}