upb: clean up and consolidate the upb/message/ build targets

PiperOrigin-RevId: 594514934
pull/15222/head
Eric Salo 11 months ago committed by Copybara-Service
parent 6e25bb8d4c
commit f0cf0b653c
  1. 3
      protos/BUILD
  2. 2
      protos/protos.cc
  3. 2
      protos/repeated_field.h
  4. 2
      protos/repeated_field_iterator.h
  5. 31
      upb/BUILD
  6. 2
      upb/json/BUILD
  7. 1
      upb/json/decode.c
  8. 145
      upb/message/BUILD
  9. 7
      upb/message/accessors.h
  10. 2
      upb/message/array.h
  11. 2
      upb/message/compare.h
  12. 10
      upb/message/copy.c
  13. 1
      upb/message/copy.h
  14. 74
      upb/message/internal/accessors.h
  15. 8
      upb/message/internal/extension.c
  16. 11
      upb/message/internal/map.h
  17. 2
      upb/message/internal/map_entry.h
  18. 7
      upb/message/internal/map_sorter.h
  19. 1
      upb/message/internal/message.c
  20. 23
      upb/message/internal/message.h
  21. 59
      upb/message/internal/tagged_ptr.h
  22. 23
      upb/message/internal/types.h
  23. 9
      upb/message/map.h
  24. 1
      upb/message/message.c
  25. 2
      upb/message/message.h
  26. 6
      upb/message/promote.c
  27. 32
      upb/message/tagged_ptr.h
  28. 17
      upb/message/types.h
  29. 5
      upb/message/value.h
  30. 1
      upb/mini_descriptor/BUILD
  31. 4
      upb/reflection/BUILD
  32. 1
      upb/reflection/field_def.c
  33. 1
      upb/reflection/message.h
  34. 1
      upb/text/BUILD
  35. 3
      upb/wire/BUILD
  36. 10
      upb/wire/decode.c
  37. 5
      upb/wire/encode.c
  38. 2
      upb/wire/encode.h
  39. 1
      upb/wire/internal/decode_fast.c

@ -35,7 +35,6 @@ cc_library(
"//upb:mem",
"//upb:message",
"//upb:message_copy",
"//upb:message_types",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/strings",
],
@ -59,10 +58,10 @@ cc_library(
"//upb:message_accessors",
"//upb:message_copy",
"//upb:message_promote",
"//upb:message_types",
"//upb:mini_table",
"//upb:wire",
"//upb:wire_reader",
"//upb/message:internal",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",

@ -18,8 +18,8 @@
#include "upb/mem/arena.h"
#include "upb/message/copy.h"
#include "upb/message/internal/extension.h"
#include "upb/message/message.h"
#include "upb/message/promote.h"
#include "upb/message/types.h"
#include "upb/mini_table/extension.h"
#include "upb/mini_table/extension_registry.h"
#include "upb/mini_table/message.h"

@ -22,7 +22,7 @@
#include "upb/mem/arena.h"
#include "upb/message/array.h"
#include "upb/message/copy.h"
#include "upb/message/types.h"
#include "upb/message/message.h"
namespace protos {
namespace internal {

@ -18,7 +18,7 @@
#include "upb/base/string_view.h"
#include "upb/mem/arena.h"
#include "upb/message/array.h"
#include "upb/message/types.h"
#include "upb/message/message.h"
namespace protos {
namespace internal {

@ -115,6 +115,7 @@ cc_library(
":mini_descriptor",
":mini_table",
":wire",
"//upb/message:internal",
],
)
@ -228,24 +229,6 @@ alias(
visibility = ["//visibility:public"],
)
alias(
name = "message_tagged_ptr",
actual = "//upb/message:tagged_ptr",
visibility = ["//upb:friends"],
)
alias(
name = "message_types",
actual = "//upb/message:types",
visibility = ["//visibility:public"],
)
alias(
name = "message_value",
actual = "//upb/message:value",
visibility = ["//visibility:public"],
)
alias(
name = "mini_descriptor",
actual = "//upb/mini_descriptor",
@ -357,9 +340,6 @@ upb_amalgamation(
":message_accessors",
":message_compare",
":message_copy",
":message_tagged_ptr",
":message_types",
":message_value",
":mini_descriptor",
":mini_table",
":mini_table_compat",
@ -370,6 +350,7 @@ upb_amalgamation(
":wire_reader",
"//upb/base:internal",
"//upb/mem:internal",
"//upb/message:internal",
"//upb/mini_descriptor:internal",
"//upb/mini_table:internal",
],
@ -405,9 +386,6 @@ upb_amalgamation(
":message_accessors",
":message_compare",
":message_copy",
":message_tagged_ptr",
":message_types",
":message_value",
":mini_descriptor",
":mini_table",
":mini_table_compat",
@ -418,6 +396,7 @@ upb_amalgamation(
":wire_reader",
"//upb/base:internal",
"//upb/mem:internal",
"//upb/message:internal",
"//upb/mini_descriptor:internal",
"//upb/mini_table:internal",
],
@ -454,9 +433,6 @@ upb_amalgamation(
":message_accessors",
":message_compare",
":message_copy",
":message_tagged_ptr",
":message_types",
":message_value",
":mini_descriptor",
":mini_table",
":mini_table_compat",
@ -467,6 +443,7 @@ upb_amalgamation(
":wire_reader",
"//upb/base:internal",
"//upb/mem:internal",
"//upb/message:internal",
"//upb/mini_descriptor:internal",
"//upb/mini_table:internal",
],

@ -24,7 +24,6 @@ cc_library(
"//upb:lex",
"//upb:mem",
"//upb:message",
"//upb:message_types",
"//upb:mini_table",
"//upb:port",
"//upb:reflection",
@ -103,7 +102,6 @@ upb_c_proto_library(
# "//upb:base",
# "//upb:mem",
# "//upb:message",
# "//upb:message_types",
# "//upb:mini_table",
# "//upb:reflection",
# ],

@ -28,7 +28,6 @@
#include "upb/message/array.h"
#include "upb/message/map.h"
#include "upb/message/message.h"
#include "upb/message/types.h"
#include "upb/mini_table/message.h"
#include "upb/reflection/def.h"
#include "upb/reflection/message.h"

@ -17,102 +17,118 @@ load(
)
cc_library(
name = "accessors",
name = "message",
srcs = [
"accessors.c",
"array.c",
"compat.c",
"map.c",
"map_sorter.c",
"message.c",
],
hdrs = [
"array.h",
"compat.h",
"map.h",
"map_gencode_util.h",
"message.h",
"tagged_ptr.h",
"value.h",
],
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
":internal",
"//upb:base",
"//upb:mem",
"//upb:mini_table",
"//upb:port",
"//upb/base:internal",
"//upb/mini_table:internal",
],
)
cc_library(
name = "internal",
srcs = [
"internal/extension.c",
"internal/message.c",
],
hdrs = [
"accessors.h",
"internal/accessors.h",
"internal/array.h",
"internal/extension.h",
"internal/map.h",
"internal/map_entry.h",
"internal/map_sorter.h",
"internal/message.h",
"internal/tagged_ptr.h",
],
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
":message",
":tagged_ptr",
":types",
"//upb:base",
"//upb:hash",
"//upb:mem",
"//upb:mini_table",
"//upb:port",
"//upb/base:internal",
],
)
cc_library(
name = "compare",
name = "accessors",
srcs = [
"compare.c",
"accessors.c",
],
hdrs = [
"compare.h",
"accessors.h",
],
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
":internal",
":message",
":types",
"//upb:base",
"//upb:mem",
"//upb:mini_table",
"//upb:port",
"//upb:wire",
],
)
cc_library(
name = "copy",
name = "compare",
srcs = [
"copy.c",
"compare.c",
],
hdrs = [
"copy.h",
"compare.h",
],
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
":accessors",
":message",
":tagged_ptr",
":types",
"//upb:base",
"//upb:mem",
"//upb:mini_table",
"//upb:port",
"//upb/mini_table:internal",
"//upb:wire",
],
)
cc_library(
name = "message",
name = "copy",
srcs = [
"array.c",
"compat.c",
"internal/extension.c",
"internal/message.c",
"map.c",
"map_sorter.c",
"message.c",
"copy.c",
],
hdrs = [
"array.h",
"compat.h",
"internal/array.h",
"internal/extension.h",
"internal/map.h",
"internal/map_entry.h",
"internal/map_sorter.h",
"internal/message.h",
"internal/types.h",
"map.h",
"map_gencode_util.h",
"message.h",
"copy.h",
],
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
":types",
":value",
":accessors",
":internal",
":message",
"//upb:base",
"//upb:hash",
"//upb:mem",
"//upb:mini_table",
"//upb:port",
@ -133,9 +149,8 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
":accessors",
":internal",
":message",
":tagged_ptr",
":types",
"//upb:base",
"//upb:eps_copy_input_stream",
"//upb:mem",
@ -161,41 +176,6 @@ cc_library(
],
)
cc_library(
name = "tagged_ptr",
hdrs = ["tagged_ptr.h"],
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
":types",
"//upb:port",
],
)
cc_library(
name = "types",
hdrs = [
"types.h",
],
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [],
)
cc_library(
name = "value",
hdrs = [
"value.h",
],
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
":tagged_ptr",
":types",
"//upb:base",
],
)
proto_library(
name = "message_test_proto",
testonly = 1,
@ -264,6 +244,7 @@ cc_test(
deps = [
":accessors",
":copy",
":internal",
":message",
"//:protobuf",
"//upb:base",
@ -298,9 +279,9 @@ cc_test(
deps = [
":accessors",
":copy",
":internal",
":message",
":promote",
":tagged_ptr",
"//:protobuf",
"//upb:base",
"//upb:mem",
@ -324,14 +305,14 @@ cc_test(
name = "test",
srcs = ["test.cc"],
deps = [
":internal",
":message",
":message_test_upb_minitable_proto",
":message_test_upb_proto",
":message_test_upb_proto_reflection",
":value",
"//upb:base",
"//upb:json",
"//upb:mem",
"//upb:message",
"//upb:mini_table",
"//upb:reflection",
"//upb:wire",

@ -20,10 +20,10 @@
#include "upb/message/internal/array.h"
#include "upb/message/internal/map.h"
#include "upb/message/internal/message.h"
#include "upb/message/internal/types.h"
#include "upb/message/internal/tagged_ptr.h"
#include "upb/message/map.h"
#include "upb/message/tagged_ptr.h"
#include "upb/message/types.h"
#include "upb/message/value.h"
#include "upb/mini_table/enum.h"
#include "upb/mini_table/sub.h"
@ -352,7 +352,8 @@ UPB_API_INLINE void upb_Message_SetMessage(upb_Message* msg,
const upb_MiniTableField* field,
upb_Message* sub_message) {
_upb_Message_SetTaggedMessagePtr(
msg, mini_table, field, _upb_TaggedMessagePtr_Pack(sub_message, false));
msg, mini_table, field,
UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(sub_message, false));
}
UPB_API_INLINE upb_Message* upb_Message_GetOrCreateMutableMessage(

@ -12,7 +12,7 @@
#include "upb/base/descriptor_constants.h"
#include "upb/mem/arena.h"
#include "upb/message/value.h" // IWYU pragma: export
#include "upb/message/value.h"
// Must be last.
#include "upb/port/def.inc"

@ -8,7 +8,7 @@
#ifndef UPB_MESSAGE_COMPARE_H_
#define UPB_MESSAGE_COMPARE_H_
#include "upb/message/types.h"
#include "upb/message/message.h"
#include "upb/mini_table/message.h"
// Must be last.

@ -24,6 +24,7 @@
#include "upb/message/tagged_ptr.h"
#include "upb/mini_table/extension.h"
#include "upb/mini_table/field.h"
#include "upb/mini_table/internal/field.h"
#include "upb/mini_table/internal/size_log2.h"
#include "upb/mini_table/message.h"
#include "upb/mini_table/sub.h"
@ -74,9 +75,9 @@ static bool upb_Clone_MessageValue(void* value, upb_CType value_type,
if (is_empty) sub = UPB_PRIVATE(_upb_MiniTable_Empty)();
UPB_ASSERT(source);
upb_Message* clone = upb_Message_DeepClone(
_upb_TaggedMessagePtr_GetMessage(source), sub, arena);
UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(source), sub, arena);
*(upb_TaggedMessagePtr*)value =
_upb_TaggedMessagePtr_Pack(clone, is_empty);
UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(clone, is_empty);
return clone != NULL;
} break;
}
@ -199,7 +200,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
upb_TaggedMessagePtr tagged =
upb_Message_GetTaggedMessagePtr(src, field, NULL);
const upb_Message* sub_message =
_upb_TaggedMessagePtr_GetMessage(tagged);
UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged);
if (sub_message != NULL) {
// If the message is currently in an unlinked, "empty" state we keep
// it that way, because we don't want to deal with decode options,
@ -215,7 +216,8 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
}
_upb_Message_SetTaggedMessagePtr(
dst, mini_table, field,
_upb_TaggedMessagePtr_Pack(dst_sub_message, is_empty));
UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(dst_sub_message,
is_empty));
}
} break;
case kUpb_CType_String:

@ -11,6 +11,7 @@
#include "upb/mem/arena.h"
#include "upb/message/array.h"
#include "upb/message/map.h"
#include "upb/message/message.h"
#include "upb/mini_table/message.h"
// Must be last.

@ -17,8 +17,7 @@
#include "upb/message/internal/extension.h"
#include "upb/message/internal/map.h"
#include "upb/message/internal/message.h"
#include "upb/message/internal/types.h"
#include "upb/message/tagged_ptr.h"
#include "upb/message/internal/tagged_ptr.h"
#include "upb/mini_table/extension.h"
#include "upb/mini_table/field.h"
@ -52,7 +51,7 @@ extern "C" {
// Hasbit access ///////////////////////////////////////////////////////////////
UPB_INLINE bool UPB_PRIVATE(_upb_Message_GetHasbit)(
const upb_Message* msg, const upb_MiniTableField* f) {
const struct upb_Message* msg, const upb_MiniTableField* f) {
const size_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f);
const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f);
@ -60,7 +59,7 @@ UPB_INLINE bool UPB_PRIVATE(_upb_Message_GetHasbit)(
}
UPB_INLINE void UPB_PRIVATE(_upb_Message_SetHasbit)(
const upb_Message* msg, const upb_MiniTableField* f) {
const struct upb_Message* msg, const upb_MiniTableField* f) {
const size_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f);
const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f);
@ -68,7 +67,7 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_SetHasbit)(
}
UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearHasbit)(
const upb_Message* msg, const upb_MiniTableField* f) {
const struct upb_Message* msg, const upb_MiniTableField* f) {
const size_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f);
const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f);
@ -78,18 +77,18 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearHasbit)(
// Oneof case access ///////////////////////////////////////////////////////////
UPB_INLINE uint32_t* UPB_PRIVATE(_upb_Message_OneofCasePtr)(
upb_Message* msg, const upb_MiniTableField* f) {
struct upb_Message* msg, const upb_MiniTableField* f) {
return UPB_PTR_AT(msg, UPB_PRIVATE(_upb_MiniTableField_OneofOffset)(f),
uint32_t);
}
UPB_INLINE uint32_t UPB_PRIVATE(_upb_Message_GetOneofCase)(
const upb_Message* msg, const upb_MiniTableField* f) {
return *UPB_PRIVATE(_upb_Message_OneofCasePtr)((upb_Message*)msg, f);
const struct upb_Message* msg, const upb_MiniTableField* f) {
return *UPB_PRIVATE(_upb_Message_OneofCasePtr)((struct upb_Message*)msg, f);
}
UPB_INLINE void UPB_PRIVATE(_upb_Message_SetOneofCase)(
upb_Message* msg, const upb_MiniTableField* f) {
struct upb_Message* msg, const upb_MiniTableField* f) {
*UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, f) =
upb_MiniTableField_Number(f);
}
@ -98,18 +97,18 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_SetOneofCase)(
// LINT.ThenChange(GoogleInternalName2)
UPB_INLINE void* _upb_MiniTableField_GetPtr(upb_Message* msg,
UPB_INLINE void* _upb_MiniTableField_GetPtr(struct upb_Message* msg,
const upb_MiniTableField* field) {
return (char*)msg + field->UPB_ONLYBITS(offset);
}
UPB_INLINE const void* _upb_MiniTableField_GetConstPtr(
const upb_Message* msg, const upb_MiniTableField* field) {
const struct upb_Message* msg, const upb_MiniTableField* field) {
return (char*)msg + field->UPB_ONLYBITS(offset);
}
UPB_INLINE void UPB_PRIVATE(_upb_Message_SetPresence)(
upb_Message* msg, const upb_MiniTableField* field) {
struct upb_Message* msg, const upb_MiniTableField* field) {
if (field->presence > 0) {
UPB_PRIVATE(_upb_Message_SetHasbit)(msg, field);
} else if (upb_MiniTableField_IsInOneof(field)) {
@ -195,13 +194,13 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_DataCopy)(
// returned bool value may be ignored since it will always succeed.
UPB_INLINE bool _upb_Message_HasExtensionField(
const upb_Message* msg, const upb_MiniTableExtension* ext) {
const struct upb_Message* msg, const upb_MiniTableExtension* ext) {
UPB_ASSERT(upb_MiniTableField_HasPresence(&ext->UPB_PRIVATE(field)));
return _upb_Message_Getext(msg, ext) != NULL;
}
UPB_INLINE bool _upb_Message_HasNonExtensionField(
const upb_Message* msg, const upb_MiniTableField* field) {
const struct upb_Message* msg, const upb_MiniTableField* field) {
UPB_ASSERT(upb_MiniTableField_HasPresence(field));
UPB_ASSUME(!upb_MiniTableField_IsExtension(field));
if (upb_MiniTableField_IsInOneof(field)) {
@ -213,7 +212,7 @@ UPB_INLINE bool _upb_Message_HasNonExtensionField(
}
static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField(
const upb_Message* msg, const upb_MiniTableField* field,
const struct upb_Message* msg, const upb_MiniTableField* field,
const void* default_val, void* val) {
UPB_ASSUME(!upb_MiniTableField_IsExtension(field));
if ((upb_MiniTableField_IsInOneof(field) ||
@ -227,7 +226,7 @@ static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField(
}
UPB_INLINE void _upb_Message_GetExtensionField(
const upb_Message* msg, const upb_MiniTableExtension* mt_ext,
const struct upb_Message* msg, const upb_MiniTableExtension* mt_ext,
const void* default_val, void* val) {
const struct upb_Extension* ext = _upb_Message_Getext(msg, mt_ext);
const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field);
@ -240,35 +239,8 @@ UPB_INLINE void _upb_Message_GetExtensionField(
}
}
// Gets a mutable Array, Map or Message field.
// NOTE: For repeated/map fields, the resulting upb_Array*/upb_Map* can
// be NULL if a upb_Array/upb_Map has not been allocated yet. Array/map
// fields do not have presence, so this is semantically identical to a
// pointer to an empty array/map, and must be treated the same for all
// semantic purposes.
//
// For message fields, the pointer is guaranteed to be NULL iff the field
// is unset (as message fields do have presence).
UPB_INLINE upb_MutableMessageValue _upb_Message_GetMutableField(
const upb_Message* msg, const upb_MiniTableField* field) {
UPB_ASSUME(!upb_MiniTableField_IsScalar(field) ||
upb_MiniTableField_IsSubMessage(field));
upb_MutableMessageValue default_val;
default_val.msg = NULL;
upb_MutableMessageValue ret;
if (upb_MiniTableField_IsExtension(field)) {
_upb_Message_GetExtensionField(msg, (upb_MiniTableExtension*)field,
&default_val, &ret);
} else {
_upb_Message_GetNonExtensionField(msg, field, &default_val, &ret);
}
return ret;
}
UPB_INLINE void _upb_Message_SetNonExtensionField(
upb_Message* msg, const upb_MiniTableField* field, const void* val) {
struct upb_Message* msg, const upb_MiniTableField* field, const void* val) {
UPB_ASSUME(!upb_MiniTableField_IsExtension(field));
UPB_PRIVATE(_upb_Message_SetPresence)(msg, field);
UPB_PRIVATE(_upb_MiniTableField_DataCopy)
@ -276,8 +248,8 @@ UPB_INLINE void _upb_Message_SetNonExtensionField(
}
UPB_INLINE bool _upb_Message_SetExtensionField(
upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* val,
upb_Arena* a) {
struct upb_Message* msg, const upb_MiniTableExtension* mt_ext,
const void* val, upb_Arena* a) {
UPB_ASSERT(a);
struct upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a);
if (!ext) return false;
@ -287,7 +259,7 @@ UPB_INLINE bool _upb_Message_SetExtensionField(
}
UPB_INLINE void _upb_Message_ClearExtensionField(
upb_Message* msg, const upb_MiniTableExtension* ext_l) {
struct upb_Message* msg, const upb_MiniTableExtension* ext_l) {
upb_Message_Internal* in = upb_Message_Getinternal(msg);
if (!in->internal) return;
const struct upb_Extension* base =
@ -301,7 +273,7 @@ UPB_INLINE void _upb_Message_ClearExtensionField(
}
UPB_INLINE void _upb_Message_ClearNonExtensionField(
upb_Message* msg, const upb_MiniTableField* field) {
struct upb_Message* msg, const upb_MiniTableField* field) {
if (field->presence > 0) {
UPB_PRIVATE(_upb_Message_ClearHasbit)(msg, field);
} else if (upb_MiniTableField_IsInOneof(field)) {
@ -315,19 +287,19 @@ UPB_INLINE void _upb_Message_ClearNonExtensionField(
}
UPB_INLINE void _upb_Message_AssertMapIsUntagged(
const upb_Message* msg, const upb_MiniTableField* field) {
const struct upb_Message* msg, const upb_MiniTableField* field) {
UPB_UNUSED(msg);
UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field);
#ifndef NDEBUG
upb_TaggedMessagePtr default_val = 0;
upb_TaggedMessagePtr tagged;
_upb_Message_GetNonExtensionField(msg, field, &default_val, &tagged);
UPB_ASSERT(!upb_TaggedMessagePtr_IsEmpty(tagged));
UPB_ASSERT(!UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(tagged));
#endif
}
UPB_INLINE struct upb_Map* _upb_Message_GetOrCreateMutableMap(
upb_Message* msg, const upb_MiniTableField* field, size_t key_size,
struct upb_Message* msg, const upb_MiniTableField* field, size_t key_size,
size_t val_size, upb_Arena* arena) {
UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field);
_upb_Message_AssertMapIsUntagged(msg, field);

@ -12,14 +12,13 @@
#include "upb/mem/arena.h"
#include "upb/message/internal/extension.h"
#include "upb/message/internal/message.h"
#include "upb/message/types.h"
#include "upb/mini_table/extension.h"
// Must be last.
#include "upb/port/def.inc"
const struct upb_Extension* _upb_Message_Getext(
const upb_Message* msg, const upb_MiniTableExtension* e) {
const struct upb_Message* msg, const upb_MiniTableExtension* e) {
size_t n;
const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n);
@ -36,7 +35,7 @@ const struct upb_Extension* _upb_Message_Getext(
}
const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)(
const upb_Message* msg, size_t* count) {
const struct upb_Message* msg, size_t* count) {
const upb_Message_Internal* in = upb_Message_Getinternal(msg);
if (in->internal) {
*count = (in->internal->size - in->internal->ext_begin) /
@ -49,7 +48,8 @@ const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)(
}
struct upb_Extension* _upb_Message_GetOrCreateExtension(
upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* arena) {
struct upb_Message* msg, const upb_MiniTableExtension* e,
upb_Arena* arena) {
struct upb_Extension* ext =
(struct upb_Extension*)_upb_Message_Getext(msg, e);
if (ext) return ext;

@ -5,8 +5,6 @@
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE /////////////////////////
#ifndef UPB_MESSAGE_INTERNAL_MAP_H_
#define UPB_MESSAGE_INTERNAL_MAP_H_
@ -17,11 +15,18 @@
#include "upb/base/string_view.h"
#include "upb/hash/str_table.h"
#include "upb/mem/arena.h"
#include "upb/message/map.h"
// Must be last.
#include "upb/port/def.inc"
typedef enum {
kUpb_MapInsertStatus_Inserted = 0,
kUpb_MapInsertStatus_Replaced = 1,
kUpb_MapInsertStatus_OutOfMemory = 2,
} upb_MapInsertStatus;
// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE /////////////////////////
struct upb_Map {
// Size of key and val, based on the map type.
// Strings are represented as '0' because they must be handled specially.

@ -12,7 +12,7 @@
#include "upb/base/string_view.h"
#include "upb/hash/common.h"
#include "upb/message/internal/types.h"
#include "upb/message/internal/message.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

@ -12,6 +12,8 @@
#include <stdlib.h>
#include "upb/base/descriptor_constants.h"
#include "upb/base/string_view.h"
#include "upb/mem/alloc.h"
#include "upb/message/internal/extension.h"
#include "upb/message/internal/map.h"
@ -50,7 +52,8 @@ UPB_INLINE void _upb_mapsorter_destroy(_upb_mapsorter* s) {
if (s->entries) upb_gfree(s->entries);
}
UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map,
UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s,
const struct upb_Map* map,
_upb_sortedmap* sorted, upb_MapEntry* ent) {
if (sorted->pos == sorted->end) return false;
const upb_tabent* tabent = (const upb_tabent*)s->entries[sorted->pos++];
@ -75,7 +78,7 @@ UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s,
}
bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type,
const upb_Map* map, _upb_sortedmap* sorted);
const struct upb_Map* map, _upb_sortedmap* sorted);
bool _upb_mapsorter_pushexts(_upb_mapsorter* s,
const struct upb_Extension* exts, size_t count,

@ -12,7 +12,6 @@
#include "upb/base/internal/log2.h"
#include "upb/mem/arena.h"
#include "upb/message/internal/types.h"
// Must be last.
#include "upb/port/def.inc"

@ -12,15 +12,14 @@
** The definitions in this file are internal to upb.
**/
#ifndef UPB_MESSAGE_INTERNAL_H_
#define UPB_MESSAGE_INTERNAL_H_
#ifndef UPB_MESSAGE_INTERNAL_MESSAGE_H_
#define UPB_MESSAGE_INTERNAL_MESSAGE_H_
#include <stdlib.h>
#include <string.h>
#include "upb/mem/arena.h"
#include "upb/message/internal/extension.h"
#include "upb/message/internal/types.h"
#include "upb/mini_table/message.h"
// Must be last.
@ -39,7 +38,7 @@ extern const double kUpb_NaN;
* these before the user's data. The user's upb_Message* points after the
* upb_Message_Internal. */
struct upb_Message_InternalData {
typedef struct {
/* Total size of this structure, including the data that follows.
* Must be aligned to 8, which is alignof(upb_Extension) */
uint32_t size;
@ -61,6 +60,20 @@ struct upb_Message_InternalData {
uint32_t ext_begin;
/* Data follows, as if there were an array:
* char data[size - sizeof(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;
struct upb_Message {
int unused; // Placeholder cuz Windows won't compile an empty struct.
};
UPB_INLINE size_t upb_msg_sizeof(const upb_MiniTable* m) {
@ -103,4 +116,4 @@ bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need,
#include "upb/port/undef.inc"
#endif /* UPB_MESSAGE_INTERNAL_H_ */
#endif /* UPB_MESSAGE_INTERNAL_MESSAGE_H_ */

@ -0,0 +1,59 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2023 Google LLC. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#ifndef UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_
#define UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_
#include <stdint.h>
#include "upb/message/internal/message.h"
// Must be last.
#include "upb/port/def.inc"
typedef uintptr_t upb_TaggedMessagePtr;
#ifdef __cplusplus
extern "C" {
#endif
// Internal-only because empty messages cannot be created by the user.
UPB_INLINE upb_TaggedMessagePtr
UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(struct upb_Message* ptr, bool empty) {
UPB_ASSERT(((uintptr_t)ptr & 1) == 0);
return (uintptr_t)ptr | (empty ? 1 : 0);
}
UPB_INLINE bool UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(
upb_TaggedMessagePtr ptr) {
return ptr & 1;
}
UPB_INLINE struct upb_Message* UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(
upb_TaggedMessagePtr ptr) {
return (struct upb_Message*)(ptr & ~(uintptr_t)1);
}
UPB_INLINE struct upb_Message* UPB_PRIVATE(
_upb_TaggedMessagePtr_GetNonEmptyMessage)(upb_TaggedMessagePtr ptr) {
UPB_ASSERT(!UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(ptr));
return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(ptr);
}
UPB_INLINE struct upb_Message* UPB_PRIVATE(
_upb_TaggedMessagePtr_GetEmptyMessage)(upb_TaggedMessagePtr ptr) {
UPB_ASSERT(UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(ptr));
return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(ptr);
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#include "upb/port/undef.inc"
#endif /* UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_ */

@ -1,23 +0,0 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2023 Google LLC. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#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_

@ -12,7 +12,8 @@
#include "upb/base/descriptor_constants.h"
#include "upb/mem/arena.h"
#include "upb/message/value.h" // IWYU pragma: export
#include "upb/message/internal/map.h"
#include "upb/message/value.h"
// Must be last.
#include "upb/port/def.inc"
@ -39,12 +40,6 @@ UPB_API bool upb_Map_Get(const upb_Map* map, upb_MessageValue key,
// Removes all entries in the map.
UPB_API void upb_Map_Clear(upb_Map* map);
typedef enum {
kUpb_MapInsertStatus_Inserted = 0,
kUpb_MapInsertStatus_Replaced = 1,
kUpb_MapInsertStatus_OutOfMemory = 2,
} upb_MapInsertStatus;
// Sets the given key to the given value, returning whether the key was inserted
// or replaced. If the key was inserted, then any existing iterators will be
// invalidated.

@ -13,7 +13,6 @@
#include "upb/mem/arena.h"
#include "upb/message/internal/message.h"
#include "upb/message/internal/types.h"
#include "upb/mini_table/message.h"
// Must be last.

@ -15,13 +15,13 @@
#include <stddef.h>
#include "upb/mem/arena.h"
#include "upb/message/types.h" // IWYU pragma: export
#include "upb/mini_table/message.h"
// Must be last.
#include "upb/port/def.inc"
typedef struct upb_Extension upb_Extension;
typedef struct upb_Message upb_Message;
#ifdef __cplusplus
extern "C" {

@ -18,6 +18,7 @@
#include "upb/message/internal/array.h"
#include "upb/message/internal/extension.h"
#include "upb/message/internal/message.h"
#include "upb/message/internal/tagged_ptr.h"
#include "upb/message/map.h"
#include "upb/message/message.h"
#include "upb/message/tagged_ptr.h"
@ -154,7 +155,8 @@ static upb_DecodeStatus upb_Message_PromoteOne(upb_TaggedMessagePtr* tagged,
const upb_MiniTable* mini_table,
int decode_options,
upb_Arena* arena) {
upb_Message* empty = _upb_TaggedMessagePtr_GetEmptyMessage(*tagged);
upb_Message* empty =
UPB_PRIVATE(_upb_TaggedMessagePtr_GetEmptyMessage)(*tagged);
size_t unknown_size;
const char* unknown_data = upb_Message_GetUnknown(empty, &unknown_size);
upb_Message* promoted = upb_Message_New(mini_table, arena);
@ -162,7 +164,7 @@ static upb_DecodeStatus upb_Message_PromoteOne(upb_TaggedMessagePtr* tagged,
upb_DecodeStatus status = upb_Decode(unknown_data, unknown_size, promoted,
mini_table, NULL, decode_options, arena);
if (status == kUpb_DecodeStatus_Ok) {
*tagged = _upb_TaggedMessagePtr_Pack(promoted, false);
*tagged = UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(promoted, false);
}
return status;
}

@ -10,15 +10,16 @@
#include <stdint.h>
#include "upb/message/types.h" // IWYU pragma: export
#include "upb/message/internal/tagged_ptr.h"
#include "upb/message/message.h"
// Must be last.
#include "upb/port/def.inc"
// When a upb_Message* is stored in a message, array, or map, it is stored in a
// tagged form. If the tag bit is set, the referenced upb_Message is of type
// tagged form. If the tag bit is set, the referenced upb_Message is of type
// _kUpb_MiniTable_Empty (a sentinel message type with no fields) instead of
// that field's true message type. This forms the basis of what we call
// that field's true message type. This forms the basis of what we call
// "dynamic tree shaking."
//
// See the documentation for kUpb_DecodeOption_ExperimentalAllowUnlinked for
@ -30,35 +31,16 @@ typedef uintptr_t upb_TaggedMessagePtr;
extern "C" {
#endif
// Internal-only because empty messages cannot be created by the user.
UPB_INLINE upb_TaggedMessagePtr _upb_TaggedMessagePtr_Pack(upb_Message* ptr,
bool empty) {
UPB_ASSERT(((uintptr_t)ptr & 1) == 0);
return (uintptr_t)ptr | (empty ? 1 : 0);
}
// Users who enable unlinked sub-messages must use this to test whether a
// message is empty before accessing it. If a message is empty, it must be
// message is empty before accessing it. If a message is empty, it must be
// first promoted using the interfaces in message/promote.h.
UPB_INLINE bool upb_TaggedMessagePtr_IsEmpty(upb_TaggedMessagePtr ptr) {
return ptr & 1;
}
UPB_INLINE upb_Message* _upb_TaggedMessagePtr_GetMessage(
upb_TaggedMessagePtr ptr) {
return (upb_Message*)(ptr & ~(uintptr_t)1);
return UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(ptr);
}
UPB_INLINE upb_Message* upb_TaggedMessagePtr_GetNonEmptyMessage(
upb_TaggedMessagePtr ptr) {
UPB_ASSERT(!upb_TaggedMessagePtr_IsEmpty(ptr));
return _upb_TaggedMessagePtr_GetMessage(ptr);
}
UPB_INLINE upb_Message* _upb_TaggedMessagePtr_GetEmptyMessage(
upb_TaggedMessagePtr ptr) {
UPB_ASSERT(upb_TaggedMessagePtr_IsEmpty(ptr));
return _upb_TaggedMessagePtr_GetMessage(ptr);
return UPB_PRIVATE(_upb_TaggedMessagePtr_GetNonEmptyMessage)(ptr);
}
#ifdef __cplusplus

@ -1,17 +0,0 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2023 Google LLC. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#ifndef UPB_MESSAGE_TYPES_H_
#define UPB_MESSAGE_TYPES_H_
// This typedef is in a leaf header to resolve a circular dependency between
// messages and mini tables.
typedef struct upb_Message {
int unused; // Placeholder cuz Windows won't compile an empty struct.
} upb_Message;
#endif /* UPB_MESSAGE_TYPES_H_ */

@ -14,7 +14,10 @@
#include <stdint.h>
#include "upb/base/string_view.h"
#include "upb/message/tagged_ptr.h"
#include "upb/message/internal/array.h"
#include "upb/message/internal/map.h"
#include "upb/message/internal/message.h"
#include "upb/message/internal/tagged_ptr.h"
typedef union {
bool bool_val;

@ -66,6 +66,7 @@ cc_test(
"//upb:mini_table",
"//upb:port",
"//upb:wire",
"//upb/message:internal",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",

@ -64,10 +64,10 @@ bootstrap_cc_library(
"//upb:base",
"//upb:mem",
"//upb:message",
"//upb:message_value",
"//upb:mini_descriptor",
"//upb:mini_table",
"//upb:port",
"//upb/message:internal",
],
)
@ -138,12 +138,12 @@ bootstrap_cc_library(
"//upb:message",
"//upb:message_accessors",
"//upb:message_copy",
"//upb:message_value",
"//upb:mini_descriptor",
"//upb:mini_table",
"//upb:port",
"//upb:wire",
"//upb/base:internal",
"//upb/message:internal",
"//upb/mini_descriptor:internal",
],
)

@ -19,7 +19,6 @@
#include "upb/base/upcast.h"
#include "upb/mem/arena.h"
#include "upb/message/accessors.h"
#include "upb/message/value.h"
#include "upb/mini_descriptor/decode.h"
#include "upb/mini_descriptor/internal/encode.h"
#include "upb/mini_descriptor/internal/modifiers.h"

@ -13,7 +13,6 @@
#include "upb/mem/arena.h"
#include "upb/message/map.h"
#include "upb/message/message.h"
#include "upb/message/value.h" // IWYU pragma: export
#include "upb/reflection/common.h"
// Must be last.

@ -25,6 +25,7 @@ cc_library(
"//upb:reflection",
"//upb:wire",
"//upb:wire_reader",
"//upb/message:internal",
],
)

@ -32,11 +32,10 @@ cc_library(
"//upb:mem",
"//upb:message",
"//upb:message_accessors",
"//upb:message_tagged_ptr",
"//upb:message_types",
"//upb:mini_table",
"//upb:port",
"//upb/mem:internal",
"//upb/message:internal",
"//upb/mini_table:internal",
],
)

@ -24,6 +24,7 @@
#include "upb/message/internal/map.h"
#include "upb/message/internal/map_entry.h"
#include "upb/message/internal/message.h"
#include "upb/message/internal/tagged_ptr.h"
#include "upb/message/map.h"
#include "upb/message/message.h"
#include "upb/message/tagged_ptr.h"
@ -32,6 +33,7 @@
#include "upb/mini_table/extension_registry.h"
#include "upb/mini_table/field.h"
#include "upb/mini_table/internal/field.h"
#include "upb/mini_table/internal/message.h"
#include "upb/mini_table/internal/size_log2.h"
#include "upb/mini_table/message.h"
#include "upb/mini_table/sub.h"
@ -258,7 +260,8 @@ static upb_Message* _upb_Decoder_NewSubMessage(upb_Decoder* d,
_upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_UnlinkedSubMessage);
}
upb_TaggedMessagePtr tagged = _upb_TaggedMessagePtr_Pack(msg, is_empty);
upb_TaggedMessagePtr tagged =
UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(msg, is_empty);
memcpy(target, &tagged, sizeof(tagged));
return msg;
}
@ -271,13 +274,14 @@ static upb_Message* _upb_Decoder_ReuseSubMessage(
UPB_ASSERT(subl);
if (!upb_TaggedMessagePtr_IsEmpty(tagged) ||
UPB_PRIVATE(_upb_MiniTable_IsEmpty)(subl)) {
return _upb_TaggedMessagePtr_GetMessage(tagged);
return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged);
}
// We found an empty message from a previous parse that was performed before
// this field was linked. But it is linked now, so we want to allocate a new
// message of the correct type and promote data into it before continuing.
upb_Message* existing = _upb_TaggedMessagePtr_GetEmptyMessage(tagged);
upb_Message* existing =
UPB_PRIVATE(_upb_TaggedMessagePtr_GetEmptyMessage)(tagged);
upb_Message* promoted = _upb_Decoder_NewSubMessage(d, subs, field, target);
size_t size;
const char* unknown = upb_Message_GetUnknown(existing, &size);

@ -26,12 +26,14 @@
#include "upb/message/internal/map.h"
#include "upb/message/internal/map_entry.h"
#include "upb/message/internal/map_sorter.h"
#include "upb/message/internal/tagged_ptr.h"
#include "upb/message/map.h"
#include "upb/message/message.h"
#include "upb/message/tagged_ptr.h"
#include "upb/mini_table/extension.h"
#include "upb/mini_table/field.h"
#include "upb/mini_table/internal/field.h"
#include "upb/mini_table/internal/message.h"
#include "upb/mini_table/message.h"
#include "upb/mini_table/sub.h"
#include "upb/wire/internal/constants.h"
@ -217,7 +219,8 @@ static void encode_TaggedMessagePtr(upb_encstate* e,
if (upb_TaggedMessagePtr_IsEmpty(tagged)) {
m = UPB_PRIVATE(_upb_MiniTable_Empty)();
}
encode_message(e, _upb_TaggedMessagePtr_GetMessage(tagged), m, size);
encode_message(e, UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged), m,
size);
}
static void encode_scalar(upb_encstate* e, const void* _field_mem,

@ -14,7 +14,7 @@
#include <stdint.h>
#include "upb/mem/arena.h"
#include "upb/message/types.h"
#include "upb/message/message.h"
#include "upb/mini_table/message.h"
// Must be last.

@ -19,7 +19,6 @@
#include "upb/message/array.h"
#include "upb/message/internal/array.h"
#include "upb/message/internal/types.h"
#include "upb/mini_table/sub.h"
#include "upb/wire/internal/decoder.h"

Loading…
Cancel
Save