mirror of
https://github.com/protocolbuffers/protobuf
synced 2026-08-26 02:23:14 -04:00
Use RawMiniTable instead of raw pointers to upb_MiniTable
Likewise for `RawMiniTableEnum` and `RawMiniTableField`. These are all `NonNull` wrappers around opaque pointees. I think this makes our code much more consistent with how we handle other types like `RawMessage` and `RawArena`. PiperOrigin-RevId: 804603058
This commit is contained in:
parent
ae308fc280
commit
ca8fe5c42f
9 changed files with 86 additions and 124 deletions
|
|
@ -28,8 +28,6 @@ extern crate upb;
|
|||
use crate::upb;
|
||||
|
||||
// Temporarily 'pub' since the gencode is directly referencing various parts of upb.
|
||||
pub use upb::upb_MiniTable;
|
||||
pub use upb::upb_MiniTableEnum;
|
||||
pub use upb::upb_MiniTableEnum_Build;
|
||||
pub use upb::upb_MiniTable_Build;
|
||||
pub use upb::upb_MiniTable_Link;
|
||||
|
|
@ -37,6 +35,8 @@ pub use upb::Arena;
|
|||
pub use upb::AssociatedMiniTable;
|
||||
pub use upb::AssociatedMiniTableEnum;
|
||||
pub use upb::MessagePtr;
|
||||
pub use upb::RawMiniTable;
|
||||
pub use upb::RawMiniTableEnum;
|
||||
use upb::*;
|
||||
|
||||
pub fn debug_string<T: UpbGetMessagePtr>(msg: &T) -> String {
|
||||
|
|
@ -52,12 +52,12 @@ pub(crate) type PtrAndLen = upb::StringView;
|
|||
// This struct represents a raw minitable pointer. We need it to be Send and Sync so that we can
|
||||
// store it in a static OnceLock for lazy initialization of minitables. It should not be used for
|
||||
// any other purpose.
|
||||
pub struct MiniTablePtr(pub *mut upb_MiniTable);
|
||||
pub struct MiniTablePtr(pub RawMiniTable);
|
||||
unsafe impl Send for MiniTablePtr {}
|
||||
unsafe impl Sync for MiniTablePtr {}
|
||||
|
||||
// Same as above, but for enum minitables.
|
||||
pub struct MiniTableEnumPtr(pub *const upb_MiniTableEnum);
|
||||
pub struct MiniTableEnumPtr(pub RawMiniTableEnum);
|
||||
unsafe impl Send for MiniTableEnumPtr {}
|
||||
unsafe impl Sync for MiniTableEnumPtr {}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
// license that can be found in the LICENSE file or at
|
||||
// https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
use super::sys::mini_table::mini_table::{upb_MiniTable, upb_MiniTableEnum};
|
||||
use super::sys::mini_table::mini_table::{RawMiniTable, RawMiniTableEnum};
|
||||
|
||||
/// A trait for types which have an associated MiniTable (e.g. generated
|
||||
/// messages, and their mut and view proxy types).
|
||||
|
|
@ -26,10 +26,10 @@ use super::sys::mini_table::mini_table::{upb_MiniTable, upb_MiniTableEnum};
|
|||
/// always have the same non-null value, the underlying pointee should never
|
||||
/// be modified and should have 'static lifetime).
|
||||
pub unsafe trait AssociatedMiniTable {
|
||||
fn mini_table() -> *const upb_MiniTable;
|
||||
fn mini_table() -> RawMiniTable;
|
||||
}
|
||||
|
||||
/// A trait for closed enums that have an associated MiniTable.
|
||||
pub unsafe trait AssociatedMiniTableEnum {
|
||||
fn mini_table() -> *const upb_MiniTableEnum;
|
||||
fn mini_table() -> RawMiniTableEnum;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,5 +55,5 @@ pub use sys::message::message::{
|
|||
pub use sys::message::message_value::upb_MessageValue;
|
||||
pub use sys::mini_table::mini_table::{
|
||||
upb_MiniTable, upb_MiniTableEnum, upb_MiniTableEnum_Build, upb_MiniTable_Build,
|
||||
upb_MiniTable_GetFieldByIndex, upb_MiniTable_Link, upb_MiniTable_SubMessage, upb_Status,
|
||||
upb_MiniTable_Link, upb_MiniTable_SubMessage, upb_Status, RawMiniTable, RawMiniTableEnum,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use sys::mem::arena::RawArena;
|
|||
use sys::message::array::RawArray;
|
||||
use sys::message::map::RawMap;
|
||||
use sys::mini_table::extension_registry::upb_ExtensionRegistry;
|
||||
use sys::mini_table::mini_table::{upb_MiniTable, upb_MiniTableField};
|
||||
use sys::mini_table::mini_table::{RawMiniTable, RawMiniTableField};
|
||||
use sys::opaque_pointee::opaque_pointee;
|
||||
|
||||
opaque_pointee!(upb_Message);
|
||||
|
|
@ -24,18 +24,17 @@ pub type RawMessage = NonNull<upb_Message>;
|
|||
extern "C" {
|
||||
/// # Safety
|
||||
/// - `mini_table` and `arena` must be valid to deref
|
||||
pub fn upb_Message_New(mini_table: *const upb_MiniTable, arena: RawArena)
|
||||
-> Option<RawMessage>;
|
||||
pub fn upb_Message_New(mini_table: RawMiniTable, arena: RawArena) -> Option<RawMessage>;
|
||||
|
||||
/// # Safety
|
||||
/// - `m` and `mini_table` must be valid to deref
|
||||
/// - `mini_table` must be the MiniTable associated with `m`
|
||||
pub fn upb_Message_Clear(m: RawMessage, mini_table: *const upb_MiniTable);
|
||||
pub fn upb_Message_Clear(m: RawMessage, mini_table: RawMiniTable);
|
||||
|
||||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be a field associated with `f`
|
||||
pub fn upb_Message_ClearBaseField(m: RawMessage, f: *const upb_MiniTableField);
|
||||
pub fn upb_Message_ClearBaseField(m: RawMessage, f: RawMiniTableField);
|
||||
|
||||
/// Copies the contents from `src` into `dst`.
|
||||
///
|
||||
|
|
@ -50,7 +49,7 @@ extern "C" {
|
|||
pub fn upb_Message_DeepCopy(
|
||||
dst: RawMessage,
|
||||
src: RawMessage,
|
||||
mini_table: *const upb_MiniTable,
|
||||
mini_table: RawMiniTable,
|
||||
arena: RawArena,
|
||||
) -> bool;
|
||||
|
||||
|
|
@ -59,79 +58,51 @@ extern "C" {
|
|||
/// - `mini_table` must be the MiniTable associated with `m`
|
||||
pub fn upb_Message_DeepClone(
|
||||
m: RawMessage,
|
||||
mini_table: *const upb_MiniTable,
|
||||
mini_table: RawMiniTable,
|
||||
arena: RawArena,
|
||||
) -> Option<RawMessage>;
|
||||
|
||||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be a bool field associated with `m`
|
||||
pub fn upb_Message_GetBool(
|
||||
m: RawMessage,
|
||||
f: *const upb_MiniTableField,
|
||||
default_val: bool,
|
||||
) -> bool;
|
||||
pub fn upb_Message_GetBool(m: RawMessage, f: RawMiniTableField, default_val: bool) -> bool;
|
||||
|
||||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be an i32 field associated with `m`
|
||||
pub fn upb_Message_GetInt32(
|
||||
m: RawMessage,
|
||||
f: *const upb_MiniTableField,
|
||||
default_val: i32,
|
||||
) -> i32;
|
||||
pub fn upb_Message_GetInt32(m: RawMessage, f: RawMiniTableField, default_val: i32) -> i32;
|
||||
|
||||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be an i64 field associated with `m`
|
||||
pub fn upb_Message_GetInt64(
|
||||
m: RawMessage,
|
||||
f: *const upb_MiniTableField,
|
||||
default_val: i64,
|
||||
) -> i64;
|
||||
pub fn upb_Message_GetInt64(m: RawMessage, f: RawMiniTableField, default_val: i64) -> i64;
|
||||
|
||||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be a u32 field associated with `m`
|
||||
pub fn upb_Message_GetUInt32(
|
||||
m: RawMessage,
|
||||
f: *const upb_MiniTableField,
|
||||
default_val: u32,
|
||||
) -> u32;
|
||||
pub fn upb_Message_GetUInt32(m: RawMessage, f: RawMiniTableField, default_val: u32) -> u32;
|
||||
|
||||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be a u64 field associated with `m`
|
||||
pub fn upb_Message_GetUInt64(
|
||||
m: RawMessage,
|
||||
f: *const upb_MiniTableField,
|
||||
default_val: u64,
|
||||
) -> u64;
|
||||
pub fn upb_Message_GetUInt64(m: RawMessage, f: RawMiniTableField, default_val: u64) -> u64;
|
||||
|
||||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be a f32 field associated with `m`
|
||||
pub fn upb_Message_GetFloat(
|
||||
m: RawMessage,
|
||||
f: *const upb_MiniTableField,
|
||||
default_val: f32,
|
||||
) -> f32;
|
||||
pub fn upb_Message_GetFloat(m: RawMessage, f: RawMiniTableField, default_val: f32) -> f32;
|
||||
|
||||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be a f64 field associated with `m`
|
||||
pub fn upb_Message_GetDouble(
|
||||
m: RawMessage,
|
||||
f: *const upb_MiniTableField,
|
||||
default_val: f64,
|
||||
) -> f64;
|
||||
pub fn upb_Message_GetDouble(m: RawMessage, f: RawMiniTableField, default_val: f64) -> f64;
|
||||
|
||||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be a string or bytes field associated with `m`
|
||||
pub fn upb_Message_GetString(
|
||||
m: RawMessage,
|
||||
f: *const upb_MiniTableField,
|
||||
f: RawMiniTableField,
|
||||
default_val: StringView,
|
||||
) -> StringView;
|
||||
|
||||
|
|
@ -143,10 +114,7 @@ extern "C" {
|
|||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be a message-typed field associated with `m`
|
||||
pub fn upb_Message_GetMessage(
|
||||
m: RawMessage,
|
||||
f: *const upb_MiniTableField,
|
||||
) -> Option<RawMessage>;
|
||||
pub fn upb_Message_GetMessage(m: RawMessage, f: RawMiniTableField) -> Option<RawMessage>;
|
||||
|
||||
/// Gets or creates a mutable upb_Message* assigned to the corresponding
|
||||
/// field in the message.
|
||||
|
|
@ -159,8 +127,8 @@ extern "C" {
|
|||
/// - `f` must be a message-typed field associated with `m`
|
||||
pub fn upb_Message_GetOrCreateMutableMessage(
|
||||
m: RawMessage,
|
||||
mini_table: *const upb_MiniTable,
|
||||
f: *const upb_MiniTableField,
|
||||
mini_table: RawMiniTable,
|
||||
f: RawMiniTableField,
|
||||
arena: RawArena,
|
||||
) -> Option<RawMessage>;
|
||||
|
||||
|
|
@ -172,7 +140,7 @@ extern "C" {
|
|||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be a repeated field associated with `m`
|
||||
pub fn upb_Message_GetArray(m: RawMessage, f: *const upb_MiniTableField) -> Option<RawArray>;
|
||||
pub fn upb_Message_GetArray(m: RawMessage, f: RawMiniTableField) -> Option<RawArray>;
|
||||
|
||||
/// Gets or creates a mutable upb_Array* assigned to the corresponding field
|
||||
/// in the message.
|
||||
|
|
@ -184,7 +152,7 @@ extern "C" {
|
|||
/// - `f` must be a map field associated with `m`
|
||||
pub fn upb_Message_GetOrCreateMutableArray(
|
||||
m: RawMessage,
|
||||
f: *const upb_MiniTableField,
|
||||
f: RawMiniTableField,
|
||||
arena: RawArena,
|
||||
) -> Option<RawArray>;
|
||||
|
||||
|
|
@ -196,7 +164,7 @@ extern "C" {
|
|||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be a map associated with `m`
|
||||
pub fn upb_Message_GetMap(m: RawMessage, f: *const upb_MiniTableField) -> Option<RawMap>;
|
||||
pub fn upb_Message_GetMap(m: RawMessage, f: RawMiniTableField) -> Option<RawMap>;
|
||||
|
||||
/// Gets or creates a mutable upb_Map* assigned to the corresponding field
|
||||
/// in the message.
|
||||
|
|
@ -209,15 +177,15 @@ extern "C" {
|
|||
/// - `f` must be a map field associated with `m`
|
||||
pub fn upb_Message_GetOrCreateMutableMap(
|
||||
m: RawMessage,
|
||||
map_entry_mini_table: *const upb_MiniTable,
|
||||
f: *const upb_MiniTableField,
|
||||
map_entry_mini_table: RawMiniTable,
|
||||
f: RawMiniTableField,
|
||||
arena: RawArena,
|
||||
) -> Option<RawMap>;
|
||||
|
||||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `mini_table` must be the MiniTable associated with `m`
|
||||
pub fn upb_Message_HasBaseField(m: RawMessage, f: *const upb_MiniTableField) -> bool;
|
||||
pub fn upb_Message_HasBaseField(m: RawMessage, f: RawMiniTableField) -> bool;
|
||||
|
||||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
|
|
@ -226,7 +194,7 @@ extern "C" {
|
|||
/// for the field described by `f`
|
||||
pub fn upb_Message_SetBaseField(
|
||||
m: RawMessage,
|
||||
f: *const upb_MiniTableField,
|
||||
f: RawMiniTableField,
|
||||
val: *const core::ffi::c_void,
|
||||
);
|
||||
|
||||
|
|
@ -236,7 +204,7 @@ extern "C" {
|
|||
pub fn upb_Message_IsEqual(
|
||||
m1: RawMessage,
|
||||
m2: RawMessage,
|
||||
mini_table: *const upb_MiniTable,
|
||||
mini_table: RawMiniTable,
|
||||
options: i32,
|
||||
) -> bool;
|
||||
|
||||
|
|
@ -248,7 +216,7 @@ extern "C" {
|
|||
pub fn upb_Message_MergeFrom(
|
||||
dst: RawMessage,
|
||||
src: RawMessage,
|
||||
mini_table: *const upb_MiniTable,
|
||||
mini_table: RawMiniTable,
|
||||
extreg: *const upb_ExtensionRegistry,
|
||||
arena: RawArena,
|
||||
) -> bool;
|
||||
|
|
@ -256,55 +224,47 @@ extern "C" {
|
|||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be a bool field associated with `f`
|
||||
pub fn upb_Message_SetBaseFieldBool(m: RawMessage, f: *const upb_MiniTableField, val: bool);
|
||||
pub fn upb_Message_SetBaseFieldBool(m: RawMessage, f: RawMiniTableField, val: bool);
|
||||
|
||||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be an i32 field associated with `m`
|
||||
pub fn upb_Message_SetBaseFieldInt32(m: RawMessage, f: *const upb_MiniTableField, val: i32);
|
||||
pub fn upb_Message_SetBaseFieldInt32(m: RawMessage, f: RawMiniTableField, val: i32);
|
||||
|
||||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be an i64 field associated with `m`
|
||||
pub fn upb_Message_SetBaseFieldInt64(m: RawMessage, f: *const upb_MiniTableField, val: i64);
|
||||
pub fn upb_Message_SetBaseFieldInt64(m: RawMessage, f: RawMiniTableField, val: i64);
|
||||
|
||||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be a u32 field associated with `m`
|
||||
pub fn upb_Message_SetBaseFieldUInt32(m: RawMessage, f: *const upb_MiniTableField, val: u32);
|
||||
pub fn upb_Message_SetBaseFieldUInt32(m: RawMessage, f: RawMiniTableField, val: u32);
|
||||
|
||||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be a u64 field associated with `m`
|
||||
pub fn upb_Message_SetBaseFieldUInt64(m: RawMessage, f: *const upb_MiniTableField, val: u64);
|
||||
pub fn upb_Message_SetBaseFieldUInt64(m: RawMessage, f: RawMiniTableField, val: u64);
|
||||
|
||||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be an f32 field associated with `m`
|
||||
pub fn upb_Message_SetBaseFieldFloat(m: RawMessage, f: *const upb_MiniTableField, val: f32);
|
||||
pub fn upb_Message_SetBaseFieldFloat(m: RawMessage, f: RawMiniTableField, val: f32);
|
||||
|
||||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be an f64 field associated with `m`
|
||||
pub fn upb_Message_SetBaseFieldDouble(m: RawMessage, f: *const upb_MiniTableField, val: f64);
|
||||
pub fn upb_Message_SetBaseFieldDouble(m: RawMessage, f: RawMiniTableField, val: f64);
|
||||
|
||||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be an string or bytes field associated with `m`
|
||||
pub fn upb_Message_SetBaseFieldString(
|
||||
m: RawMessage,
|
||||
f: *const upb_MiniTableField,
|
||||
val: StringView,
|
||||
);
|
||||
pub fn upb_Message_SetBaseFieldString(m: RawMessage, f: RawMiniTableField, val: StringView);
|
||||
|
||||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be a message-typed field associated with `m`
|
||||
pub fn upb_Message_SetBaseFieldMessage(
|
||||
m: RawMessage,
|
||||
f: *const upb_MiniTableField,
|
||||
val: RawMessage,
|
||||
);
|
||||
pub fn upb_Message_SetBaseFieldMessage(m: RawMessage, f: RawMiniTableField, val: RawMessage);
|
||||
|
||||
/// Returns the field number of which oneof field is set, or 0 if none are.
|
||||
/// `f` is any arbitrary field contained within the oneof.
|
||||
|
|
@ -312,7 +272,7 @@ extern "C" {
|
|||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be a field within a oneof associated with `m`
|
||||
pub fn upb_Message_WhichOneofFieldNumber(m: RawMessage, f: *const upb_MiniTableField) -> u32;
|
||||
pub fn upb_Message_WhichOneofFieldNumber(m: RawMessage, f: RawMiniTableField) -> u32;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ opaque_pointee!(upb_MiniTable);
|
|||
pub type RawMiniTable = NonNull<upb_MiniTable>;
|
||||
|
||||
opaque_pointee!(upb_MiniTableEnum);
|
||||
pub type RawMiniTableEnum = NonNull<upb_MiniTableEnum>;
|
||||
|
||||
opaque_pointee!(upb_MiniTableField);
|
||||
pub type RawMiniTableField = NonNull<upb_MiniTableField>;
|
||||
|
|
@ -33,7 +34,7 @@ extern "C" {
|
|||
/// # Safety
|
||||
/// - `m` must be legal to deref
|
||||
pub fn upb_MiniTable_FindFieldByNumber(
|
||||
m: *const upb_MiniTable,
|
||||
m: RawMiniTable,
|
||||
number: u32,
|
||||
) -> *const upb_MiniTableField;
|
||||
|
||||
|
|
@ -44,19 +45,13 @@ extern "C" {
|
|||
/// # Safety
|
||||
/// - `m` must be legal to deref
|
||||
/// - `number` must be a valid field index in the `m` table
|
||||
pub fn upb_MiniTable_GetFieldByIndex(
|
||||
m: *const upb_MiniTable,
|
||||
number: u32,
|
||||
) -> *const upb_MiniTableField;
|
||||
pub fn upb_MiniTable_GetFieldByIndex(m: RawMiniTable, number: u32) -> RawMiniTableField;
|
||||
|
||||
/// Gets the sub-MiniTable associated with `f`.
|
||||
/// # Safety
|
||||
/// - `m` and `f` must be valid to deref
|
||||
/// - `f` must be a mesage or map typed field associated with `m`
|
||||
pub fn upb_MiniTable_SubMessage(
|
||||
m: *const upb_MiniTable,
|
||||
f: *const upb_MiniTableField,
|
||||
) -> *const upb_MiniTable;
|
||||
pub fn upb_MiniTable_SubMessage(m: RawMiniTable, f: RawMiniTableField) -> RawMiniTable;
|
||||
|
||||
/// Builds a mini table from the data encoded in the buffer [data, len]. If
|
||||
/// any errors occur, returns null and sets a status message if status is
|
||||
|
|
@ -84,7 +79,7 @@ extern "C" {
|
|||
len: usize,
|
||||
arena: RawArena,
|
||||
status: *mut upb_Status,
|
||||
) -> *const upb_MiniTableEnum;
|
||||
) -> *mut upb_MiniTableEnum;
|
||||
|
||||
/// Links a message to its sub-messages and sub-enums. The caller must pass
|
||||
/// arrays of sub-tables and sub-enums, in the same length and order as is
|
||||
|
|
@ -101,10 +96,10 @@ extern "C" {
|
|||
/// to `upb_MiniTableEnum`.
|
||||
/// - This must only be called once for a given MiniTable.
|
||||
pub fn upb_MiniTable_Link(
|
||||
m: *mut upb_MiniTable,
|
||||
sub_tables: *const *const upb_MiniTable,
|
||||
m: RawMiniTable,
|
||||
sub_tables: *const RawMiniTable,
|
||||
sub_table_count: usize,
|
||||
sub_enums: *const *const upb_MiniTableEnum,
|
||||
sub_enums: *const RawMiniTableEnum,
|
||||
sub_enum_count: usize,
|
||||
) -> bool;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ mod sys {
|
|||
}
|
||||
|
||||
use sys::message::message::RawMessage;
|
||||
use sys::mini_table::mini_table::upb_MiniTable;
|
||||
use sys::mini_table::mini_table::RawMiniTable;
|
||||
|
||||
extern "C" {
|
||||
/// Returns the minimum needed length (excluding NULL) that `buf` has to be
|
||||
|
|
@ -23,7 +23,7 @@ extern "C" {
|
|||
/// `size` is 0)
|
||||
pub fn upb_DebugString(
|
||||
msg: RawMessage,
|
||||
mt: *const upb_MiniTable,
|
||||
mt: RawMiniTable,
|
||||
options: i32, // bitmask of `text_encode_options` values
|
||||
buf: *mut u8,
|
||||
size: usize,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ mod sys {
|
|||
use sys::mem::arena::RawArena;
|
||||
use sys::message::message::RawMessage;
|
||||
use sys::mini_table::extension_registry::upb_ExtensionRegistry;
|
||||
use sys::mini_table::mini_table::upb_MiniTable;
|
||||
use sys::mini_table::mini_table::RawMiniTable;
|
||||
|
||||
// LINT.IfChange(encode_status)
|
||||
#[repr(C)]
|
||||
|
|
@ -45,7 +45,7 @@ extern "C" {
|
|||
// - `buf` and `buf_size` are legally writable.
|
||||
pub fn upb_Encode(
|
||||
msg: RawMessage,
|
||||
mini_table: *const upb_MiniTable,
|
||||
mini_table: RawMiniTable,
|
||||
options: i32,
|
||||
arena: RawArena,
|
||||
buf: *mut *mut u8,
|
||||
|
|
@ -60,7 +60,7 @@ extern "C" {
|
|||
buf: *const u8,
|
||||
buf_size: usize,
|
||||
msg: RawMessage,
|
||||
mini_table: *const upb_MiniTable,
|
||||
mini_table: RawMiniTable,
|
||||
extreg: *const upb_ExtensionRegistry,
|
||||
options: i32,
|
||||
arena: RawArena,
|
||||
|
|
|
|||
|
|
@ -87,15 +87,19 @@ void MiniTable(Context& ctx, const EnumDescriptor& desc,
|
|||
{"mini_descriptor_length", mini_descriptor.size()}},
|
||||
R"rs(
|
||||
unsafe impl $pbr$::AssociatedMiniTableEnum for $name$ {
|
||||
fn mini_table() -> *const $pbr$::upb_MiniTableEnum {
|
||||
fn mini_table() -> $pbr$::RawMiniTableEnum {
|
||||
static MINI_TABLE: $std$::sync::OnceLock<$pbr$::MiniTableEnumPtr> =
|
||||
$std$::sync::OnceLock::new();
|
||||
MINI_TABLE.get_or_init(|| unsafe {
|
||||
$pbr$::MiniTableEnumPtr($pbr$::upb_MiniTableEnum_Build(
|
||||
"$mini_descriptor$".as_ptr(), $mini_descriptor_length$,
|
||||
$pbr$::THREAD_LOCAL_ARENA.with(|a| a.raw()),
|
||||
$std$::ptr::null_mut()))
|
||||
}).0
|
||||
unsafe {
|
||||
MINI_TABLE.get_or_init(|| {
|
||||
$pbr$::MiniTableEnumPtr(
|
||||
$std$::ptr::NonNull::new_unchecked(
|
||||
$pbr$::upb_MiniTableEnum_Build(
|
||||
"$mini_descriptor$".as_ptr(), $mini_descriptor_length$,
|
||||
$pbr$::THREAD_LOCAL_ARENA.with(|a| a.raw()),
|
||||
$std$::ptr::null_mut())))
|
||||
}).0
|
||||
}
|
||||
}
|
||||
}
|
||||
)rs");
|
||||
|
|
|
|||
|
|
@ -216,8 +216,8 @@ void UpbMiniTableLinking(Context& ctx, const Descriptor& msg,
|
|||
];
|
||||
assert!($pbr$::upb_MiniTable_Link(
|
||||
$minitable_symbol_name$.0,
|
||||
submessages.as_ptr() as *const *const $pbr$::upb_MiniTable,
|
||||
submessages.len(), subenums.as_ptr(), subenums.len()));
|
||||
submessages.as_ptr(), submessages.len(),
|
||||
subenums.as_ptr(), subenums.len()));
|
||||
)rs");
|
||||
}
|
||||
|
||||
|
|
@ -258,11 +258,12 @@ void UpbGeneratedMessageTraitImpls(Context& ctx, const Descriptor& msg,
|
|||
{"mini_descriptor_length", mini_descriptor.size()}},
|
||||
R"rs(
|
||||
$minitable_symbol_name$.0 =
|
||||
$pbr$::upb_MiniTable_Build(
|
||||
"$mini_descriptor$".as_ptr(),
|
||||
$mini_descriptor_length$,
|
||||
$pbr$::THREAD_LOCAL_ARENA.with(|a| a.raw()),
|
||||
$std$::ptr::null_mut());
|
||||
$std$::ptr::NonNull::new_unchecked(
|
||||
$pbr$::upb_MiniTable_Build(
|
||||
"$mini_descriptor$".as_ptr(),
|
||||
$mini_descriptor_length$,
|
||||
$pbr$::THREAD_LOCAL_ARENA.with(|a| a.raw()),
|
||||
$std$::ptr::null_mut()));
|
||||
)rs");
|
||||
}
|
||||
for (const Descriptor* d : scc.descriptors) {
|
||||
|
|
@ -282,13 +283,15 @@ void UpbGeneratedMessageTraitImpls(Context& ctx, const Descriptor& msg,
|
|||
// lock-free.
|
||||
R"rs(
|
||||
unsafe impl $pbr$::AssociatedMiniTable for $name$ {
|
||||
fn mini_table() -> *const $pbr$::upb_MiniTable {
|
||||
fn mini_table() -> $pbr$::RawMiniTable {
|
||||
static ONCE_LOCK: $std$::sync::OnceLock<$pbr$::MiniTablePtr> =
|
||||
$std$::sync::OnceLock::new();
|
||||
ONCE_LOCK.get_or_init(|| unsafe {
|
||||
$mini_table_impl$
|
||||
$pbr$::MiniTablePtr($minitable_symbol_name$.0)
|
||||
}).0
|
||||
unsafe {
|
||||
ONCE_LOCK.get_or_init(|| {
|
||||
$mini_table_impl$
|
||||
$pbr$::MiniTablePtr($minitable_symbol_name$.0)
|
||||
}).0
|
||||
}
|
||||
}
|
||||
}
|
||||
)rs");
|
||||
|
|
@ -305,14 +308,14 @@ void UpbGeneratedMessageTraitImpls(Context& ctx, const Descriptor& msg,
|
|||
|
||||
unsafe impl $pbr$::AssociatedMiniTable for $Msg$View<'_> {
|
||||
#[inline(always)]
|
||||
fn mini_table() -> *const $pbr$::upb_MiniTable {
|
||||
fn mini_table() -> $pbr$::RawMiniTable {
|
||||
<$Msg$ as $pbr$::AssociatedMiniTable>::mini_table()
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl $pbr$::AssociatedMiniTable for $Msg$Mut<'_> {
|
||||
#[inline(always)]
|
||||
fn mini_table() -> *const $pbr$::upb_MiniTable {
|
||||
fn mini_table() -> $pbr$::RawMiniTable {
|
||||
<$Msg$ as $pbr$::AssociatedMiniTable>::mini_table()
|
||||
}
|
||||
}
|
||||
|
|
@ -418,7 +421,7 @@ void GenerateRs(Context& ctx, const Descriptor& msg, const upb::DefPool& pool) {
|
|||
// This variable must not be referenced except by protobuf generated
|
||||
// code.
|
||||
pub(crate) static mut $minitable_symbol_name$: $pbr$::MiniTablePtr =
|
||||
$pbr$::MiniTablePtr($std$::ptr::null_mut());
|
||||
$pbr$::MiniTablePtr($std$::ptr::NonNull::dangling());
|
||||
)rs");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue