upb: fix the leaking port defs

PiperOrigin-RevId: 559225386
pull/13675/head^2
Eric Salo 2 years ago committed by Copybara-Service
parent d06eac7b5e
commit 21ecc29ed0
  1. 18
      BUILD
  2. 1
      python/BUILD
  3. 20
      upb/message/promote_test.cc
  4. 20
      upb/mini_table/BUILD
  5. 81
      upb/mini_table/compat.c
  6. 24
      upb/mini_table/compat.h
  7. 3
      upb/wire/BUILD
  8. 2
      upb/wire/decode.c
  9. 2
      upb/wire/decode.h
  10. 2
      upb/wire/encode.c
  11. 2
      upb/wire/encode.h
  12. 2
      upb/wire/types.h
  13. 2
      upbc/upbdev.h

18
BUILD

@ -411,6 +411,15 @@ alias(
visibility = ["//:friends"],
)
# begin:google_only
# alias(
# name = "mini_table_compat",
# actual = "//upb/mini_table:compat",
# compatible_with = ["//buildenv/target:non_prod"],
# visibility = ["//:friends"],
# )
# end:google_only
alias(
name = "mini_table_internal",
actual = "//upb/mini_table:internal",
@ -535,8 +544,9 @@ upb_amalgamation(
":mini_table",
":mini_table_internal",
":port",
":reflection_internal",
":reflection",
":reflection_internal",
":wire",
":wire_internal",
":wire_reader",
":wire_types",
@ -582,8 +592,9 @@ upb_amalgamation(
":mini_table",
":mini_table_internal",
":port",
":reflection_internal",
":reflection",
":reflection_internal",
":wire",
":wire_internal",
":wire_reader",
":wire_types",
@ -630,8 +641,9 @@ upb_amalgamation(
":mini_table",
":mini_table_internal",
":port",
":reflection_internal",
":reflection",
":reflection_internal",
":wire",
":wire_internal",
":wire_reader",
":wire_types",

@ -243,7 +243,6 @@ py_extension(
"//:port",
"//:reflection",
"//:text",
"//:wire",
"//:wire_reader",
"//:wire_types",
"//upb/util:compare",

@ -56,26 +56,6 @@
namespace {
// Proto2 test messages field numbers used for reflective access.
const uint32_t kFieldOptionalInt32 = 1;
const uint32_t kFieldOptionalUInt32 = 3;
const uint32_t kFieldOptionalBool = 13;
const uint32_t kFieldOptionalString = 14;
const uint32_t kFieldOptionalNestedMessage = 18;
const uint32_t kFieldOptionalRepeatedInt32 = 31;
const uint32_t kFieldOptionalNestedMessageA = 1;
const uint32_t kFieldOptionalOneOfUInt32 = 111;
const uint32_t kFieldOptionalOneOfString = 113;
const uint32_t kFieldProto3OptionalInt64 = 2;
const uint32_t kFieldProto3OptionalUInt64 = 4;
const char kTestStr1[] = "Hello1";
const char kTestStr2[] = "Hello2";
const int32_t kTestInt32 = 567;
const int32_t kTestUInt32 = 0xF1234567;
const uint64_t kTestUInt64 = 0xFEDCBAFF87654321;
TEST(GeneratedCode, FindUnknown) {
upb_Arena* arena = upb_Arena_New();
upb_test_ModelWithExtensions* msg = upb_test_ModelWithExtensions_new(arena);

@ -28,6 +28,26 @@ load(
"UPB_DEFAULT_COPTS",
)
# begin:google_only
# cc_library(
# name = "compat",
# srcs = [
# "compat.c",
# ],
# hdrs = [
# "compat.h",
# ],
# compatible_with = ["//buildenv/target:non_prod"],
# copts = UPB_DEFAULT_COPTS,
# visibility = ["//:__pkg__"],
# deps = [
# ":mini_table",
# "//:base",
# "//:port",
# ],
# )
# end:google_only
cc_library(
name = "mini_table",
srcs = [

@ -0,0 +1,81 @@
// 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.
#include "upb/mini_table/compat.h"
#include "upb/base/descriptor_constants.h"
#include "upb/mini_table/field.h"
#include "upb/mini_table/message.h"
// Must be last.
#include "upb/port/def.inc"
static bool upb_deep_check(const upb_MiniTable* src, const upb_MiniTable* dst,
bool eq) {
if (src->field_count != dst->field_count) return false;
for (int i = 0; i < src->field_count; i++) {
const upb_MiniTableField* src_field = &src->fields[i];
const upb_MiniTableField* dst_field =
upb_MiniTable_FindFieldByNumber(dst, src_field->number);
if (upb_MiniTableField_CType(src_field) !=
upb_MiniTableField_CType(dst_field)) return false;
if (src_field->mode != dst_field->mode) return false;
if (src_field->offset != dst_field->offset) return false;
if (src_field->presence != dst_field->presence) return false;
if (src_field->UPB_PRIVATE(submsg_index) !=
dst_field->UPB_PRIVATE(submsg_index)) return false;
// Go no further if we are only checking for compatibility.
if (!eq) continue;
if (upb_MiniTableField_CType(src_field) == kUpb_CType_Message) {
const upb_MiniTable* sub_src =
upb_MiniTable_GetSubMessageTable(src, src_field);
const upb_MiniTable* sub_dst =
upb_MiniTable_GetSubMessageTable(dst, dst_field);
if (sub_src != NULL && !upb_MiniTable_Equals(sub_src, sub_dst)) {
return false;
}
}
}
return true;
}
bool upb_MiniTable_Compatible(const upb_MiniTable* src,
const upb_MiniTable* dst) {
return upb_deep_check(src, dst, false);
}
bool upb_MiniTable_Equals(const upb_MiniTable* src, const upb_MiniTable* dst) {
return upb_deep_check(src, dst, true);
}

@ -28,20 +28,34 @@
// (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_COMMON_H_
#define UPB_WIRE_COMMON_H_
#ifndef UPB_MINI_TABLE_COMPAT_H_
#define UPB_MINI_TABLE_COMPAT_H_
#include "upb/mini_table/message.h"
// Must be last.
#include "upb/port/def.inc"
// upb does not support mixing minitables from different sources but these
// functions are still used by some existing users so for now we make them
// available here. This may or may not change in the future so do not add
// them to new code.
#ifdef __cplusplus
extern "C" {
#endif
#define kUpb_WireFormat_DefaultDepthLimit 100
// Checks if memory layout of src is compatible with dst.
bool upb_MiniTable_Compatible(const upb_MiniTable* src,
const upb_MiniTable* dst);
// Checks equality of mini tables originating from different language runtimes.
bool upb_MiniTable_Equals(const upb_MiniTable* src, const upb_MiniTable* dst);
#ifdef __cplusplus
}
} /* extern "C" */
#endif
#endif // UPB_WIRE_COMMON_H_
#include "upb/port/undef.inc"
#endif /* UPB_MINI_TABLE_COMPAT_H_ */

@ -30,7 +30,6 @@ cc_library(
srcs = [
],
hdrs = [
"common.h",
"decode.h",
"encode.h",
],
@ -38,6 +37,7 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
":internal",
":types",
"//:mem",
"//:message",
"//:mini_table",
@ -48,7 +48,6 @@ cc_library(
cc_library(
name = "internal",
srcs = [
"common.h",
"decode.c",
"decode.h",
"decode_fast.c",

@ -40,14 +40,12 @@
#include "upb/message/internal/map_entry.h"
#include "upb/mini_table/sub.h"
#include "upb/port/atomic.h"
#include "upb/wire/common.h"
#include "upb/wire/encode.h"
#include "upb/wire/eps_copy_input_stream.h"
#include "upb/wire/internal/common.h"
#include "upb/wire/internal/decode.h"
#include "upb/wire/internal/swap.h"
#include "upb/wire/reader.h"
#include "upb/wire/types.h"
// Must be last.
#include "upb/port/def.inc"

@ -36,7 +36,7 @@
#include "upb/mem/arena.h"
#include "upb/message/message.h"
#include "upb/mini_table/extension_registry.h"
#include "upb/wire/common.h"
#include "upb/wire/types.h"
// Must be last.
#include "upb/port/def.inc"

@ -39,10 +39,8 @@
#include "upb/message/internal/accessors.h"
#include "upb/message/internal/extension.h"
#include "upb/mini_table/sub.h"
#include "upb/wire/common.h"
#include "upb/wire/internal/common.h"
#include "upb/wire/internal/swap.h"
#include "upb/wire/types.h"
// Must be last.
#include "upb/port/def.inc"

@ -34,7 +34,7 @@
#define UPB_WIRE_ENCODE_H_
#include "upb/message/message.h"
#include "upb/wire/common.h"
#include "upb/wire/types.h"
// Must be last.
#include "upb/port/def.inc"

@ -31,6 +31,8 @@
#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,

@ -59,7 +59,7 @@ UPB_API void upbdev_ProcessStdout(const char* buf, size_t size,
// The following wrappers allow the protoc plugins to call the above functions
// without pulling in the entire pb_runtime library.
UPB_API upb_Arena* upbdev_Arena_New();
UPB_API upb_Arena* upbdev_Arena_New(void);
UPB_API void upbdev_Status_Clear(upb_Status* status);
#ifdef __cplusplus

Loading…
Cancel
Save