Marcel Hlopko | 884ae7f | 2021-08-18 13:58:22 +0000 | [diff] [blame] | 1 | // Part of the Crubit project, under the Apache License v2.0 with LLVM |
| 2 | // Exceptions. See /LICENSE for license information. |
| 3 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 | |
Marcel Hlopko | 65978eb | 2022-04-08 07:40:18 -0700 | [diff] [blame] | 5 | #ifndef CRUBIT_COMMON_FFI_TYPES_H_ |
| 6 | #define CRUBIT_COMMON_FFI_TYPES_H_ |
Marcel Hlopko | 884ae7f | 2021-08-18 13:58:22 +0000 | [diff] [blame] | 7 | |
| 8 | #include <cstddef> |
| 9 | |
Lukasz Anforowicz | cec7a8a | 2022-04-27 10:24:51 -0700 | [diff] [blame] | 10 | #include "absl/strings/string_view.h" |
Marcel Hlopko | 884ae7f | 2021-08-18 13:58:22 +0000 | [diff] [blame] | 11 | |
Marcel Hlopko | f15e8ce | 2022-04-08 08:46:09 -0700 | [diff] [blame] | 12 | namespace crubit { |
Marcel Hlopko | 884ae7f | 2021-08-18 13:58:22 +0000 | [diff] [blame] | 13 | |
| 14 | // Owned, Rust-allocated byte array. Call `FreeFfiU8SliceBox` to |
| 15 | // deallocate. |
| 16 | struct FfiU8SliceBox { |
Marcel Hlopko | e936aac | 2021-08-24 20:52:27 +0000 | [diff] [blame] | 17 | const char* ptr; |
Marcel Hlopko | 884ae7f | 2021-08-18 13:58:22 +0000 | [diff] [blame] | 18 | size_t size; |
| 19 | }; |
| 20 | |
| 21 | // Borrowed byte array. |
| 22 | struct FfiU8Slice { |
Marcel Hlopko | e936aac | 2021-08-24 20:52:27 +0000 | [diff] [blame] | 23 | const char* ptr; |
Marcel Hlopko | 884ae7f | 2021-08-18 13:58:22 +0000 | [diff] [blame] | 24 | size_t size; |
| 25 | }; |
| 26 | |
Googler | f427e6a | 2021-10-01 07:59:59 +0000 | [diff] [blame] | 27 | // Returns an `FfiU8Slice` referencing the same data as `s`. |
Marcel Hlopko | 884ae7f | 2021-08-18 13:58:22 +0000 | [diff] [blame] | 28 | FfiU8Slice MakeFfiU8Slice(absl::string_view s); |
| 29 | |
Googler | f427e6a | 2021-10-01 07:59:59 +0000 | [diff] [blame] | 30 | // Returns a `string_view` referencing the same data as `ffi_u8_slice`. |
| 31 | absl::string_view StringViewFromFfiU8Slice(FfiU8Slice ffi_u8_slice); |
| 32 | |
| 33 | // Returns an `FfiU8SliceBox` containing a copy of the data in `ffi_u8_slice`. |
| 34 | // The returned `FfiU8SliceBox` must be freed by calling `FreeFfiU8SliceBox()`. |
| 35 | // Implemented in Rust. |
| 36 | extern "C" FfiU8SliceBox AllocFfiU8SliceBox(FfiU8Slice ffi_u8_slice); |
| 37 | |
| 38 | // Frees the memory associated with an `FfiU8SliceBox`. |
| 39 | // Implemented in Rust. |
Marcel Hlopko | 884ae7f | 2021-08-18 13:58:22 +0000 | [diff] [blame] | 40 | extern "C" void FreeFfiU8SliceBox(FfiU8SliceBox); |
| 41 | |
Googler | 69e0963 | 2023-03-03 12:18:35 -0800 | [diff] [blame] | 42 | // Whether or not the generated binding will have doc comments indicating their |
| 43 | // source location. |
| 44 | enum SourceLocationDocComment { |
| 45 | Disabled, |
| 46 | Enabled, |
| 47 | }; |
| 48 | |
Marcel Hlopko | f15e8ce | 2022-04-08 08:46:09 -0700 | [diff] [blame] | 49 | } // namespace crubit |
Marcel Hlopko | 884ae7f | 2021-08-18 13:58:22 +0000 | [diff] [blame] | 50 | |
Marcel Hlopko | 65978eb | 2022-04-08 07:40:18 -0700 | [diff] [blame] | 51 | #endif // CRUBIT_COMMON_FFI_TYPES_H_ |