upb: tag wire/types.h as an export for (only) wire/reader.h

PiperOrigin-RevId: 565212511
pull/14079/head
Eric Salo 1 year ago committed by Copybara-Service
parent 027b8115ce
commit 9ce03d7d05
  1. 8
      upb/protos/protos.cc
  2. 5
      upb/python/message.c
  3. 4
      upb/upb/message/BUILD
  4. 20
      upb/upb/message/promote.c
  5. 1
      upb/upb/message/promote.h
  6. 38
      upb/upb/message/promote_test.cc
  7. 2
      upb/upb/port/atomic.h
  8. 6
      upb/upb/wire/BUILD
  9. 19
      upb/upb/wire/decode.c
  10. 5
      upb/upb/wire/decode.h
  11. 20
      upb/upb/wire/encode.c
  12. 7
      upb/upb/wire/encode.h
  13. 11
      upb/upb/wire/internal/constants.h
  14. 2
      upb/upb/wire/reader.h
  15. 2
      upb/upb/wire/types.h

@ -48,7 +48,6 @@
#include "upb/upb/mini_table/message.h"
#include "upb/upb/wire/decode.h"
#include "upb/upb/wire/encode.h"
#include "upb/upb/wire/types.h"
namespace protos {
@ -139,9 +138,8 @@ bool HasExtensionOrUnknown(const upb_Message* msg,
const upb_MiniTableExtension* eid) {
MessageLock msg_lock(msg);
return _upb_Message_Getext(msg, eid) != nullptr ||
upb_MiniTable_FindUnknown(msg, eid->field.number,
kUpb_WireFormat_DefaultDepthLimit)
.status == kUpb_FindUnknown_Ok;
upb_MiniTable_FindUnknown(msg, eid->field.number, 0).status ==
kUpb_FindUnknown_Ok;
}
const upb_Message_Extension* GetOrPromoteExtension(
@ -150,7 +148,7 @@ const upb_Message_Extension* GetOrPromoteExtension(
const upb_Message_Extension* ext = _upb_Message_Getext(msg, eid);
if (ext == nullptr) {
upb_GetExtension_Status ext_status = upb_MiniTable_GetOrPromoteExtension(
(upb_Message*)msg, eid, kUpb_WireFormat_DefaultDepthLimit, arena, &ext);
(upb_Message*)msg, eid, 0, arena, &ext);
if (ext_status != kUpb_GetExtension_Ok) {
ext = nullptr;
}

@ -1297,9 +1297,8 @@ PyObject* PyUpb_Message_MergeFromString(PyObject* _self, PyObject* arg) {
const upb_MiniTable* layout = upb_MessageDef_MiniTable(msgdef);
upb_Arena* arena = PyUpb_Arena_Get(self->arena);
PyUpb_ModuleState* state = PyUpb_ModuleState_Get();
int options = upb_DecodeOptions_MaxDepth(
state->allow_oversize_protos ? UINT16_MAX
: kUpb_WireFormat_DefaultDepthLimit);
int options =
upb_DecodeOptions_MaxDepth(state->allow_oversize_protos ? UINT16_MAX : 0);
upb_DecodeStatus status =
upb_Decode(buf, size, self->ptr.msg, layout, extreg, options, arena);
Py_XDECREF(bytes);

@ -140,6 +140,7 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
":accessors",
":accessors_internal",
":internal",
":message",
":types",
@ -148,9 +149,12 @@ cc_library(
"//upb:collections_internal",
"//upb:eps_copy_input_stream",
"//upb:mem",
"//upb:message_tagged_ptr",
"//upb:mini_table",
"//upb:mini_table_internal",
"//upb:port",
"//upb:wire",
"//upb:wire_internal",
"//upb:wire_reader",
],
)

@ -30,15 +30,28 @@
#include "upb/upb/message/promote.h"
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "upb/upb/base/descriptor_constants.h"
#include "upb/upb/collections/array.h"
#include "upb/upb/collections/internal/array.h"
#include "upb/upb/collections/map.h"
#include "upb/upb/mem/arena.h"
#include "upb/upb/message/accessors.h"
#include "upb/upb/message/internal/accessors.h"
#include "upb/upb/message/internal/extension.h"
#include "upb/upb/message/internal/message.h"
#include "upb/upb/message/message.h"
#include "upb/upb/message/tagged_ptr.h"
#include "upb/upb/mini_table/extension.h"
#include "upb/upb/mini_table/field.h"
#include "upb/upb/mini_table/internal/field.h"
#include "upb/upb/mini_table/message.h"
#include "upb/upb/wire/decode.h"
#include "upb/upb/wire/encode.h"
#include "upb/upb/wire/eps_copy_input_stream.h"
#include "upb/upb/wire/internal/constants.h"
#include "upb/upb/wire/reader.h"
// Must be last.
@ -87,8 +100,7 @@ upb_GetExtension_Status upb_MiniTable_GetOrPromoteExtension(
// Check unknown fields, if available promote.
int field_number = ext_table->field.number;
upb_FindUnknownRet result = upb_MiniTable_FindUnknown(
msg, field_number, kUpb_WireFormat_DefaultDepthLimit);
upb_FindUnknownRet result = upb_MiniTable_FindUnknown(msg, field_number, 0);
if (result.status != kUpb_FindUnknown_Ok) {
return kUpb_GetExtension_NotPresent;
}
@ -130,6 +142,8 @@ static upb_FindUnknownRet upb_FindUnknownRet_ParseError(void) {
upb_FindUnknownRet upb_MiniTable_FindUnknown(const upb_Message* msg,
uint32_t field_number,
int depth_limit) {
depth_limit = depth_limit ? depth_limit : kUpb_WireFormat_DefaultDepthLimit;
size_t size;
upb_FindUnknownRet ret;

@ -80,6 +80,7 @@ typedef struct {
} upb_FindUnknownRet;
// Finds first occurrence of unknown data by tag id in message.
// A depth_limit of zero means to just use the upb default depth limit.
upb_FindUnknownRet upb_MiniTable_FindUnknown(const upb_Message* msg,
uint32_t field_number,
int depth_limit);

@ -78,13 +78,11 @@ TEST(GeneratedCode, FindUnknown) {
arena);
upb_FindUnknownRet result = upb_MiniTable_FindUnknown(
base_msg, upb_test_ModelExtension1_model_ext_ext.field.number,
kUpb_WireFormat_DefaultDepthLimit);
base_msg, upb_test_ModelExtension1_model_ext_ext.field.number, 0);
EXPECT_EQ(kUpb_FindUnknown_Ok, result.status);
result = upb_MiniTable_FindUnknown(
base_msg, upb_test_ModelExtension2_model_ext_ext.field.number,
kUpb_WireFormat_DefaultDepthLimit);
base_msg, upb_test_ModelExtension2_model_ext_ext.field.number, 0);
EXPECT_EQ(kUpb_FindUnknown_NotPresent, result.status);
upb_Arena_Free(arena);
@ -376,8 +374,8 @@ TEST(GeneratedCode, PromoteUnknownMessage) {
upb_MiniTable_SetSubMessage(mini_table, (upb_MiniTableField*)submsg_field,
&upb_test_ModelWithExtensions_msg_init));
const int decode_options = upb_DecodeOptions_MaxDepth(
kUpb_WireFormat_DefaultDepthLimit); // UPB_DECODE_ALIAS disabled.
const int decode_options =
upb_DecodeOptions_MaxDepth(0); // UPB_DECODE_ALIAS disabled.
upb_test_ModelWithExtensions* promoted;
upb_DecodeStatus promote_result =
upb_Message_PromoteMessage(msg, mini_table, submsg_field, decode_options,
@ -424,8 +422,8 @@ TEST(GeneratedCode, ReparseUnlinked) {
upb_MiniTable_SetSubMessage(mini_table, (upb_MiniTableField*)submsg_field,
&upb_test_ModelWithExtensions_msg_init));
const int decode_options = upb_DecodeOptions_MaxDepth(
kUpb_WireFormat_DefaultDepthLimit); // UPB_DECODE_ALIAS disabled.
const int decode_options =
upb_DecodeOptions_MaxDepth(0); // UPB_DECODE_ALIAS disabled.
upb_test_ModelWithExtensions* promoted;
upb_DecodeStatus promote_result =
upb_Message_PromoteMessage(msg, mini_table, submsg_field, decode_options,
@ -552,8 +550,8 @@ TEST(GeneratedCode, PromoteUnknownRepeatedMessage) {
EXPECT_TRUE(upb_MiniTable_SetSubMessage(
mini_table, (upb_MiniTableField*)repeated_field,
&upb_test_ModelWithExtensions_msg_init));
const int decode_options = upb_DecodeOptions_MaxDepth(
kUpb_WireFormat_DefaultDepthLimit); // UPB_DECODE_ALIAS disabled.
const int decode_options =
upb_DecodeOptions_MaxDepth(0); // UPB_DECODE_ALIAS disabled.
upb_DecodeStatus promote_result =
upb_Array_PromoteMessages(array, &upb_test_ModelWithExtensions_msg_init,
decode_options, arena.ptr());
@ -726,15 +724,14 @@ TEST(GeneratedCode, PromoteUnknownMessageOld) {
int32_t val = upb_Message_GetInt32(
msg, upb_MiniTable_FindFieldByNumber(mini_table, 4), 0);
EXPECT_EQ(val, 11);
upb_FindUnknownRet unknown =
upb_MiniTable_FindUnknown(msg, 5, kUpb_WireFormat_DefaultDepthLimit);
upb_FindUnknownRet unknown = upb_MiniTable_FindUnknown(msg, 5, 0);
EXPECT_EQ(unknown.status, kUpb_FindUnknown_Ok);
// Update mini table and promote unknown to a message.
EXPECT_TRUE(upb_MiniTable_SetSubMessage(
mini_table, (upb_MiniTableField*)&mini_table->fields[1],
&upb_test_ModelWithExtensions_msg_init));
const int decode_options = upb_DecodeOptions_MaxDepth(
kUpb_WireFormat_DefaultDepthLimit); // UPB_DECODE_ALIAS disabled.
const int decode_options =
upb_DecodeOptions_MaxDepth(0); // UPB_DECODE_ALIAS disabled.
upb_UnknownToMessageRet promote_result =
upb_MiniTable_PromoteUnknownToMessage(
msg, mini_table, &mini_table->fields[1],
@ -775,16 +772,15 @@ TEST(GeneratedCode, PromoteUnknownRepeatedMessageOld) {
EXPECT_EQ(val, 123);
// Check that we have repeated field data in an unknown.
upb_FindUnknownRet unknown =
upb_MiniTable_FindUnknown(msg, 6, kUpb_WireFormat_DefaultDepthLimit);
upb_FindUnknownRet unknown = upb_MiniTable_FindUnknown(msg, 6, 0);
EXPECT_EQ(unknown.status, kUpb_FindUnknown_Ok);
// Update mini table and promote unknown to a message.
EXPECT_TRUE(upb_MiniTable_SetSubMessage(
mini_table, (upb_MiniTableField*)&mini_table->fields[2],
&upb_test_ModelWithExtensions_msg_init));
const int decode_options = upb_DecodeOptions_MaxDepth(
kUpb_WireFormat_DefaultDepthLimit); // UPB_DECODE_ALIAS disabled.
const int decode_options =
upb_DecodeOptions_MaxDepth(0); // UPB_DECODE_ALIAS disabled.
upb_UnknownToMessage_Status promote_result =
upb_MiniTable_PromoteUnknownToMessageArray(
msg, &mini_table->fields[2], &upb_test_ModelWithExtensions_msg_init,
@ -824,8 +820,7 @@ TEST(GeneratedCode, PromoteUnknownToMapOld) {
CreateMiniTableWithEmptySubTablesForMapsOld(arena);
upb_MiniTable* map_entry_mini_table = CreateMapEntryMiniTableOld(arena);
upb_Message* msg = _upb_Message_New(mini_table, arena);
const int decode_options =
upb_DecodeOptions_MaxDepth(kUpb_WireFormat_DefaultDepthLimit);
const int decode_options = upb_DecodeOptions_MaxDepth(0);
upb_DecodeStatus decode_status =
upb_Decode(serialized, serialized_size, msg, mini_table, nullptr,
decode_options, arena);
@ -835,8 +830,7 @@ TEST(GeneratedCode, PromoteUnknownToMapOld) {
EXPECT_EQ(val, 123);
// Check that we have map data in an unknown.
upb_FindUnknownRet unknown =
upb_MiniTable_FindUnknown(msg, 3, kUpb_WireFormat_DefaultDepthLimit);
upb_FindUnknownRet unknown = upb_MiniTable_FindUnknown(msg, 3, 0);
EXPECT_EQ(unknown.status, kUpb_FindUnknown_Ok);
// Update mini table and promote unknown to a message.

@ -35,8 +35,10 @@
#ifdef UPB_USE_C11_ATOMICS
// IWYU pragma: begin_exports
#include <stdatomic.h>
#include <stdbool.h>
// IWYU pragma: end_exports
#define upb_Atomic_Init(addr, val) atomic_init(addr, val)
#define upb_Atomic_Load(addr, order) atomic_load_explicit(addr, order)

@ -38,7 +38,7 @@ cc_library(
],
hdrs = [
"decode_fast.h",
"internal/common.h",
"internal/constants.h",
"internal/decode.h",
"internal/swap.h",
],
@ -49,14 +49,18 @@ cc_library(
":reader",
":types",
"//upb:base",
"//upb:collections",
"//upb:collections_internal",
"//upb:hash",
"//upb:mem",
"//upb:mem_internal",
"//upb:message",
"//upb:message_accessors_internal",
"//upb:message_internal",
"//upb:message_internal_types",
"//upb:message_tagged_ptr",
"//upb:mini_table",
"//upb:mini_table_internal",
"//upb:port",
"@utf8_range",
],

@ -37,16 +37,33 @@
#include <string.h>
#include "upb/upb/base/descriptor_constants.h"
#include "upb/upb/base/string_view.h"
#include "upb/upb/collections/array.h"
#include "upb/upb/collections/internal/array.h"
#include "upb/upb/collections/internal/map.h"
#include "upb/upb/collections/internal/map_entry.h"
#include "upb/upb/collections/map.h"
#include "upb/upb/hash/common.h"
#include "upb/upb/mem/arena.h"
#include "upb/upb/mem/internal/arena.h"
#include "upb/upb/message/internal/accessors.h"
#include "upb/upb/message/internal/extension.h"
#include "upb/upb/message/internal/message.h"
#include "upb/upb/message/message.h"
#include "upb/upb/message/tagged_ptr.h"
#include "upb/upb/mini_table/enum.h"
#include "upb/upb/mini_table/extension.h"
#include "upb/upb/mini_table/extension_registry.h"
#include "upb/upb/mini_table/field.h"
#include "upb/upb/mini_table/internal/enum.h"
#include "upb/upb/mini_table/internal/field.h"
#include "upb/upb/mini_table/internal/message.h"
#include "upb/upb/mini_table/message.h"
#include "upb/upb/mini_table/sub.h"
#include "upb/upb/port/atomic.h"
#include "upb/upb/wire/encode.h"
#include "upb/upb/wire/eps_copy_input_stream.h"
#include "upb/upb/wire/internal/common.h"
#include "upb/upb/wire/internal/constants.h"
#include "upb/upb/wire/internal/decode.h"
#include "upb/upb/wire/internal/swap.h"
#include "upb/upb/wire/reader.h"

@ -33,10 +33,13 @@
#ifndef UPB_WIRE_DECODE_H_
#define UPB_WIRE_DECODE_H_
#include <stddef.h>
#include <stdint.h>
#include "upb/upb/mem/arena.h"
#include "upb/upb/message/message.h"
#include "upb/upb/mini_table/extension_registry.h"
#include "upb/upb/wire/types.h"
#include "upb/upb/mini_table/message.h"
// Must be last.
#include "upb/upb/port/def.inc"

@ -32,15 +32,33 @@
#include "upb/upb/wire/encode.h"
#include <setjmp.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "upb/upb/base/descriptor_constants.h"
#include "upb/upb/base/string_view.h"
#include "upb/upb/collections/array.h"
#include "upb/upb/collections/internal/array.h"
#include "upb/upb/collections/internal/map.h"
#include "upb/upb/collections/internal/map_entry.h"
#include "upb/upb/collections/internal/map_sorter.h"
#include "upb/upb/hash/common.h"
#include "upb/upb/hash/str_table.h"
#include "upb/upb/mem/arena.h"
#include "upb/upb/message/internal/accessors.h"
#include "upb/upb/message/internal/extension.h"
#include "upb/upb/message/message.h"
#include "upb/upb/message/tagged_ptr.h"
#include "upb/upb/mini_table/field.h"
#include "upb/upb/mini_table/internal/field.h"
#include "upb/upb/mini_table/internal/message.h"
#include "upb/upb/mini_table/message.h"
#include "upb/upb/mini_table/sub.h"
#include "upb/upb/wire/internal/common.h"
#include "upb/upb/wire/internal/constants.h"
#include "upb/upb/wire/internal/swap.h"
#include "upb/upb/wire/types.h"
// Must be last.
#include "upb/upb/port/def.inc"

@ -33,8 +33,11 @@
#ifndef UPB_WIRE_ENCODE_H_
#define UPB_WIRE_ENCODE_H_
#include "upb/upb/message/message.h"
#include "upb/upb/wire/types.h"
#include <stddef.h>
#include <stdint.h>
#include "upb/upb/mem/arena.h"
#include "upb/upb/mini_table/message.h"
// Must be last.
#include "upb/upb/port/def.inc"

@ -28,11 +28,10 @@
// (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_WIRE_INTERNAL_COMMON_H_
#define UPB_WIRE_INTERNAL_COMMON_H_
#ifndef UPB_WIRE_INTERNAL_CONSTANTS_H_
#define UPB_WIRE_INTERNAL_CONSTANTS_H_
// Must be last.
#include "upb/upb/port/def.inc"
#define kUpb_WireFormat_DefaultDepthLimit 100
// MessageSet wire format is:
// message MessageSet {
@ -48,6 +47,4 @@ enum {
kUpb_MsgSet_Message = 3,
};
#include "upb/upb/port/undef.inc"
#endif /* UPB_WIRE_INTERNAL_COMMON_H_ */
#endif /* UPB_WIRE_INTERNAL_CONSTANTS_H_ */

@ -33,7 +33,7 @@
#include "upb/upb/wire/eps_copy_input_stream.h"
#include "upb/upb/wire/internal/swap.h"
#include "upb/upb/wire/types.h"
#include "upb/upb/wire/types.h" // IWYU pragma: export
// Must be last.
#include "upb/upb/port/def.inc"

@ -31,8 +31,6 @@
#ifndef UPB_WIRE_TYPES_H_
#define UPB_WIRE_TYPES_H_
#define kUpb_WireFormat_DefaultDepthLimit 100
// A list of types as they are encoded on the wire.
typedef enum {
kUpb_WireType_Varint = 0,

Loading…
Cancel
Save