
louise
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#1209 · main · 10 min 03 s
1Étoiles
0Forks
0Issues
| 1 | //! `louise bindgen`: Louise bindings for the simple functions of a C |
| 2 | //! header (ADR 0015). |
| 3 | //! |
| 4 | //! It writes two files: a Louise module of `@extern` declarations, and |
| 5 | //! the C shim they call, which converts values (ADR 0005, Revision 1). |
| 6 | //! Both are meant to be checked in and regenerated, not edited. |
| 7 | //! |
| 8 | //! **The supported subset.** A function is bound when every parameter |
| 9 | //! and its result are among: |
| 10 | //! |
| 11 | //! | C | Louise | |
| 12 | //! |---|---| |
| 13 | //! | integer types (`int`, `unsigned long`, `int64_t`, `size_t`, ...) | `Int`: a value out of range panics, both ways | |
| 14 | //! | `float`, `double` | `Float` | |
| 15 | //! | `bool`, `_Bool` | `Bool` | |
| 16 | //! | `const char *s` followed by an integer named `n` or ending in `len`, `length` or `size` | one `String`: pointer and length | |
| 17 | //! | `const char *` alone | `String` (NUL-terminated: stops at an embedded NUL); a result is copied, and `NULL` panics | |
| 18 | //! | a pointer to an *opaque* struct (declared, never defined in the header) | `Resource<T>` | |
| 19 | //! | a function pointer with one `void *` parameter, plus one `void *` parameter of the function itself | a callback, `fn(...) -> R / <ffi>` | |
| 20 | //! | `void` result | `()` | |
| 21 | //! |
| 22 | //! - **Resources.** A pointer *result* becomes a resource only from a |
| 23 | //! function named like a constructor (`_new`, `_create`, `_open`, |
| 24 | //! `_copy`, `_clone`); other functions may return a pointer they still |
| 25 | //! own. Its finalizer is the one `void f(T *)` function whose name ends |
| 26 | //! in `_free`, `_destroy`, `_delete` or `_release`; that function is not |
| 27 | //! bound (calling it would free the value twice). Resources are not |
| 28 | //! thread-safe (pinned to their actor). A `NULL` result panics. |
| 29 | //! - **Callbacks** follow ADR 0015: a trampoline per C signature, with |
| 30 | //! `tl_callback` as the environment. Their parameters and results are |
| 31 | //! scalars or `const char *`. |
| 32 | //! - **Effects.** Every binding performs `<ffi>`: bindgen cannot know that |
| 33 | //! a C function is pure. |
| 34 | //! - **Everything else is skipped and reported:** macros, enums, structs |
| 35 | //! with fields, variables, `static inline` functions, variadic |
| 36 | //! functions, writable `char *`, other pointers, arrays, structs by |
| 37 | //! value, callbacks without a `void *` environment. |
| 38 | //! |
| 39 | //! Headers are read without a preprocessor (see [`parse`]), so a function |
| 40 | //! declared through a macro is reported as unrecognised. |
| 41 | |
| 42 | mod generate; |
| 43 | mod parse; |
| 44 | |
| 45 | pub use generate::{Bindings, Skipped, generate}; |