upb: Remove the mirrored definitions in upb_MapEntry and upb_MessageInternal

Create message/internal/types.h as a new leaf header
Move map_entry.h from message/internal/ to collections/internal/ where it belongs

PiperOrigin-RevId: 562889855
pull/13863/head
Eric Salo 1 year ago committed by Copybara-Service
parent ad88453480
commit 3be9a6ca12
  1. 16
      upb/BUILD
  2. 3
      upb/upb/collections/BUILD
  3. 21
      upb/upb/collections/internal/map_entry.h
  4. 2
      upb/upb/collections/internal/map_sorter.h
  5. 25
      upb/upb/message/BUILD
  6. 18
      upb/upb/message/internal/message.h
  7. 46
      upb/upb/message/internal/types.h
  8. 2
      upb/upb/wire/BUILD
  9. 16
      upb/upb/wire/decode.c
  10. 1
      upb/upb/wire/decode_fast.c

@ -24,13 +24,13 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
load("@rules_python//python:defs.bzl", "py_binary")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("//bazel:build_defs.bzl", "UPB_DEFAULT_COPTS")
load(
"//bazel:upb_proto_library.bzl",
"upb_proto_library_copts",
"upb_proto_reflection_library",
)
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load(
"//upbc:bootstrap_compiler.bzl",
"bootstrap_cc_library",
@ -380,14 +380,14 @@ alias(
)
alias(
name = "message_promote",
actual = "//upb/message:promote",
name = "message_internal_types",
actual = "//upb/message:internal_types",
visibility = ["//visibility:public"],
)
alias(
name = "message_rep_internal",
actual = "//upb/message:rep_internal",
name = "message_promote",
actual = "//upb/message:promote",
visibility = ["//visibility:public"],
)
@ -552,7 +552,7 @@ upb_amalgamation(
":message",
":message_accessors",
":message_internal",
":message_rep_internal",
":message_internal_types",
":message_tagged_ptr",
":message_types",
":mini_descriptor",
@ -600,7 +600,7 @@ upb_amalgamation(
":message",
":message_accessors",
":message_internal",
":message_rep_internal",
":message_internal_types",
":message_tagged_ptr",
":message_types",
":mini_descriptor",
@ -649,7 +649,7 @@ upb_amalgamation(
":message",
":message_accessors",
":message_internal",
":message_rep_internal",
":message_internal_types",
":message_tagged_ptr",
":message_types",
":mini_descriptor",

@ -53,6 +53,7 @@ cc_library(
hdrs = [
"internal/array.h",
"internal/map.h",
"internal/map_entry.h",
"internal/map_sorter.h",
"map_gencode_util.h",
"message_value.h",
@ -65,7 +66,7 @@ cc_library(
"//:hash",
"//:mem",
"//:message_internal",
"//:message_rep_internal",
"//:message_internal_types",
"//:message_tagged_ptr",
"//:mini_table",
"//:port",

@ -28,13 +28,12 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef UPB_MINI_TABLE_INTERNAL_MAP_ENTRY_DATA_H_
#define UPB_MINI_TABLE_INTERNAL_MAP_ENTRY_DATA_H_
#include <stdint.h>
#ifndef UPB_COLLECTIONS_INTERNAL_MAP_ENTRY_H_
#define UPB_COLLECTIONS_INTERNAL_MAP_ENTRY_H_
#include "upb/base/string_view.h"
#include "upb/hash/common.h"
#include "upb/message/internal/types.h"
// Map entries aren't actually stored for map fields, they are only used during
// parsing. For parsing, it helps a lot if all map entry messages have the same
@ -44,7 +43,7 @@
// Note that users can and do create map entries directly, which will also use
// this layout.
//
// NOTE: sync with mini_table/decode.c.
// NOTE: sync with wire/decode.c.
typedef struct {
// We only need 2 hasbits max, but due to alignment we'll use 8 bytes here,
// and the uint64_t helps make this clear.
@ -60,16 +59,8 @@ typedef struct {
} upb_MapEntryData;
typedef struct {
// LINT.IfChange(internal_layout)
union {
void* internal_data;
// Force 8-byte alignment, since the data members may contain members that
// require 8-byte alignment.
double d;
};
// LINT.ThenChange(//depot/google3/third_party/upb/upb/message/internal/message.h:internal_layout)
upb_Message_Internal internal;
upb_MapEntryData data;
} upb_MapEntry;
#endif // UPB_MINI_TABLE_INTERNAL_MAP_ENTRY_DATA_H_
#endif // UPB_COLLECTIONS_INTERNAL_MAP_ENTRY_H_

@ -36,8 +36,8 @@
#include <stdlib.h>
#include "upb/collections/internal/map.h"
#include "upb/collections/internal/map_entry.h"
#include "upb/message/internal/extension.h"
#include "upb/message/internal/map_entry.h"
// Must be last.
#include "upb/port/def.inc"

@ -108,6 +108,7 @@ cc_library(
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
":internal_types",
":types",
"//:base",
"//:base_internal",
@ -118,6 +119,17 @@ cc_library(
],
)
cc_library(
name = "internal_types",
hdrs = [
"internal/types.h",
],
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
],
)
cc_library(
name = "message",
hdrs = [
@ -163,19 +175,6 @@ cc_library(
],
)
cc_library(
name = "rep_internal",
hdrs = [
"internal/map_entry.h",
],
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
"//:base",
"//:hash",
],
)
cc_library(
name = "split64",
hdrs = [

@ -43,6 +43,7 @@
#include "upb/hash/common.h"
#include "upb/message/internal/extension.h"
#include "upb/message/internal/types.h"
#include "upb/message/message.h"
#include "upb/mini_table/extension.h"
#include "upb/mini_table/extension_registry.h"
@ -64,7 +65,7 @@ extern const double kUpb_NaN;
* these before the user's data. The user's upb_Message* points after the
* upb_Message_Internal. */
typedef struct {
struct upb_Message_InternalData {
/* Total size of this structure, including the data that follows.
* Must be aligned to 8, which is alignof(upb_Message_Extension) */
uint32_t size;
@ -86,20 +87,7 @@ typedef struct {
uint32_t ext_begin;
/* Data follows, as if there were an array:
* char data[size - sizeof(upb_Message_InternalData)]; */
} upb_Message_InternalData;
typedef struct {
// LINT.IfChange(internal_layout)
union {
upb_Message_InternalData* internal;
// Force 8-byte alignment, since the data members may contain members that
// require 8-byte alignment.
double d;
};
// LINT.ThenChange(//depot/google3/third_party/upb/upb/message/internal/map_entry.h:internal_layout)
/* Message data follows. */
} upb_Message_Internal;
};
/* Maps upb_CType -> memory size. */
extern char _upb_CTypeo_size[12];

@ -0,0 +1,46 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2023 Google LLC. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google LLC nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef UPB_MINI_TABLE_INTERNAL_TYPES_H_
#define UPB_MINI_TABLE_INTERNAL_TYPES_H_
typedef struct upb_Message_InternalData upb_Message_InternalData;
typedef struct {
union {
upb_Message_InternalData* internal;
// Force 8-byte alignment, since the data members may contain members that
// require 8-byte alignment.
double d;
};
} upb_Message_Internal;
#endif // UPB_MINI_TABLE_INTERNAL_TYPES_H_

@ -73,7 +73,7 @@ cc_library(
"//:message",
"//:message_accessors_internal",
"//:message_internal",
"//:message_rep_internal",
"//:message_internal_types",
"//:mini_table",
"//:port",
"@utf8_range",

@ -30,14 +30,18 @@
#include "upb/wire/decode.h"
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include "upb/base/descriptor_constants.h"
#include "upb/collections/internal/array.h"
#include "upb/collections/internal/map.h"
#include "upb/collections/internal/map_entry.h"
#include "upb/mem/internal/arena.h"
#include "upb/message/internal/accessors.h"
#include "upb/message/internal/map_entry.h"
#include "upb/mini_table/sub.h"
#include "upb/port/atomic.h"
#include "upb/wire/encode.h"
@ -95,13 +99,13 @@ static const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr,
UPB_NORETURN static void* _upb_Decoder_ErrorJmp(upb_Decoder* d,
upb_DecodeStatus status) {
assert(status != kUpb_DecodeStatus_Ok);
UPB_ASSERT(status != kUpb_DecodeStatus_Ok);
d->status = status;
UPB_LONGJMP(d->err, 1);
}
const char* _upb_FastDecoder_ErrorJmp(upb_Decoder* d, int status) {
assert(status != kUpb_DecodeStatus_Ok);
UPB_ASSERT(status != kUpb_DecodeStatus_Ok);
d->status = status;
UPB_LONGJMP(d->err, 1);
return NULL;
@ -748,7 +752,7 @@ UPB_NOINLINE
const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr,
const upb_Message* msg,
const upb_MiniTable* l) {
assert(l->required_count);
UPB_ASSERT(l->required_count);
if (UPB_LIKELY((d->options & kUpb_DecodeOption_CheckRequired) == 0)) {
return ptr;
}
@ -1014,10 +1018,10 @@ static void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt,
// All other members of the oneof must be message fields that are also
// unlinked.
do {
assert(upb_MiniTableField_CType(oneof) == kUpb_CType_Message);
UPB_ASSERT(upb_MiniTableField_CType(oneof) == kUpb_CType_Message);
const upb_MiniTableSub* oneof_sub =
&mt->subs[oneof->UPB_PRIVATE(submsg_index)];
assert(!oneof_sub);
UPB_ASSERT(!oneof_sub);
} while (upb_MiniTable_NextOneofField(mt, &oneof));
}
#endif // NDEBUG

@ -41,6 +41,7 @@
#include "upb/wire/decode_fast.h"
#include "upb/collections/internal/array.h"
#include "upb/message/internal/types.h"
#include "upb/wire/internal/decode.h"
// Must be last.

Loading…
Cancel
Save