Skip to content

Commit

Permalink
create reflection_internal library
Browse files Browse the repository at this point in the history
internal declarations are now physically removed from the public headers

PiperOrigin-RevId: 478921131
  • Loading branch information
ericsalo authored and copybara-github committed Oct 5, 2022
1 parent 52c1598 commit 44916d7
Show file tree
Hide file tree
Showing 42 changed files with 740 additions and 247 deletions.
68 changes: 64 additions & 4 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,14 @@ cc_library(
"upb/port_def.inc",
"upb/port_undef.inc",
"upb/reflection/def.h",
"upb/reflection/def_pool_internal.h",
],
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
":descriptor_upb_proto",
":reflection",
":reflection_internal",
":table_internal",
],
)
Expand Down Expand Up @@ -397,32 +399,42 @@ cc_library(
srcs = [
"upb/reflection/common.h",
"upb/reflection/def_builder.c",
"upb/reflection/def_builder.h",
"upb/reflection/def_builder_internal.h",
"upb/reflection/def_pool.c",
"upb/reflection/def_pool.h",
"upb/reflection/def_pool_internal.h",
"upb/reflection/def_type.c",
"upb/reflection/def_type.h",
"upb/reflection/desc_state.c",
"upb/reflection/desc_state.h",
"upb/reflection/desc_state_internal.h",
"upb/reflection/enum_def.c",
"upb/reflection/enum_def.h",
"upb/reflection/enum_def_internal.h",
"upb/reflection/enum_value_def.c",
"upb/reflection/enum_value_def.h",
"upb/reflection/enum_value_def_internal.h",
"upb/reflection/extension_range.c",
"upb/reflection/extension_range.h",
"upb/reflection/extension_range_internal.h",
"upb/reflection/field_def.c",
"upb/reflection/field_def.h",
"upb/reflection/field_def_internal.h",
"upb/reflection/file_def.c",
"upb/reflection/file_def.h",
"upb/reflection/file_def_internal.h",
"upb/reflection/message.c",
"upb/reflection/message_def.c",
"upb/reflection/message_def.h",
"upb/reflection/message_def_internal.h",
"upb/reflection/method_def.c",
"upb/reflection/method_def.h",
"upb/reflection/method_def_internal.h",
"upb/reflection/oneof_def.c",
"upb/reflection/oneof_def.h",
"upb/reflection/oneof_def_internal.h",
"upb/reflection/service_def.c",
"upb/reflection/service_def.h",
"upb/reflection/service_def_internal.h",
],
hdrs = [
"upb/def.h",
Expand All @@ -447,6 +459,51 @@ cc_library(
],
)

cc_library(
name = "reflection_internal",
srcs = [
"upb/reflection/common.h",
"upb/reflection/def_builder_internal.h",
"upb/reflection/def_pool.h",
"upb/reflection/def_type.h",
"upb/reflection/desc_state_internal.h",
"upb/reflection/enum_def.h",
"upb/reflection/enum_value_def.h",
"upb/reflection/extension_range.h",
"upb/reflection/field_def.h",
"upb/reflection/file_def.h",
"upb/reflection/message.h",
"upb/reflection/message_def.h",
"upb/reflection/method_def.h",
"upb/reflection/oneof_def.h",
"upb/reflection/service_def.h",
],
hdrs = [
"upb/reflection/def_pool_internal.h",
"upb/reflection/enum_def_internal.h",
"upb/reflection/enum_value_def_internal.h",
"upb/reflection/extension_range_internal.h",
"upb/reflection/field_def_internal.h",
"upb/reflection/file_def_internal.h",
"upb/reflection/message_def_internal.h",
"upb/reflection/method_def_internal.h",
"upb/reflection/oneof_def_internal.h",
"upb/reflection/service_def_internal.h",
],
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
":collections",
":descriptor_upb_proto",
":mini_table",
":mini_table_internal",
":port",
":reflection",
":table_internal",
":upb",
],
)

cc_library(
name = "textformat",
srcs = [
Expand Down Expand Up @@ -498,15 +555,15 @@ cc_test(
name = "def_builder_test",
srcs = [
"upb/reflection/common.h",
"upb/reflection/def_builder.h",
"upb/reflection/def_builder_internal.h",
"upb/reflection/def_builder_test.cc",
"upb/reflection/def_pool.h",
"upb/reflection/def_type.h",
],
deps = [
":descriptor_upb_proto",
":port",
":reflection",
":reflection_internal",
":table_internal",
":upb",
"@com_google_googletest//:gtest_main",
Expand Down Expand Up @@ -985,6 +1042,7 @@ upb_amalgamation(
":mini_table",
":port",
":reflection",
":reflection_internal",
":upb",
],
strip_import_prefix = ["src"],
Expand Down Expand Up @@ -1019,6 +1077,7 @@ upb_amalgamation(
":mini_table",
":port",
":reflection",
":reflection_internal",
":table_internal",
":unicode_internal",
":upb",
Expand Down Expand Up @@ -1056,6 +1115,7 @@ upb_amalgamation(
":mini_table",
":port",
":reflection",
":reflection_internal",
":table_internal",
":unicode_internal",
":upb",
Expand Down
1 change: 1 addition & 0 deletions python/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ py_extension(
"//:descriptor_upb_proto_reflection",
"//:port",
"//:reflection",
"//:reflection_internal",
"//:table_internal",
"//:textformat",
"//:upb",
Expand Down
1 change: 1 addition & 0 deletions python/extension_dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "python/message.h"
#include "python/protobuf.h"
#include "upb/reflection/def_pool_internal.h"

// -----------------------------------------------------------------------------
// ExtensionDict
Expand Down
3 changes: 1 addition & 2 deletions upb/reflection/def_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "upb/reflection/def_builder.h"

#include <string.h>

#include "upb/reflection/def_builder_internal.h"
#include "upb/reflection/def_pool.h"
#include "upb/reflection/def_type.h"
#include "upb/reflection/field_def.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef UPB_REFLECTION_DEF_BUILDER_H_
#define UPB_REFLECTION_DEF_BUILDER_H_
#ifndef UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_
#define UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_

#include "upb/reflection/common.h"
#include "upb/reflection/def_pool.h"
#include "upb/reflection/def_pool_internal.h"
#include "upb/reflection/def_type.h"

// Must be last.
#include "upb/port_def.inc"

// We want to copy the options verbatim into the destination options proto.
// We use serialize+parse as our deep copy.
#define UBP_DEF_SET_OPTIONS(target, desc_type, options_type, proto) \
#define UPB_DEF_SET_OPTIONS(target, desc_type, options_type, proto) \
if (google_protobuf_##desc_type##_has_options(proto)) { \
size_t size; \
char* pb = google_protobuf_##options_type##_serialize( \
Expand Down Expand Up @@ -170,4 +170,4 @@ UPB_INLINE void _upb_DefBuilder_CheckIdentFull(upb_DefBuilder* ctx,

#include "upb/port_undef.inc"

#endif /* UPB_REFLECTION_DEF_BUILDER_H_ */
#endif /* UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ */
3 changes: 1 addition & 2 deletions upb/reflection/def_builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "upb/reflection/def_builder.h"

#include "gtest/gtest.h"
#include "upb/reflection/def.hpp"
#include "upb/reflection/def_builder_internal.h"

// Must be last.
#include "upb/port_def.inc"
Expand Down
17 changes: 8 additions & 9 deletions upb/reflection/def_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "upb/reflection/def_pool.h"

#include "upb/reflection/def_builder.h"
#include "upb/reflection/def_builder_internal.h"
#include "upb/reflection/def_pool_internal.h"
#include "upb/reflection/def_type.h"
#include "upb/reflection/enum_def.h"
#include "upb/reflection/enum_value_def.h"
#include "upb/reflection/field_def.h"
#include "upb/reflection/file_def.h"
#include "upb/reflection/message_def.h"
#include "upb/reflection/service_def.h"
#include "upb/reflection/enum_def_internal.h"
#include "upb/reflection/enum_value_def_internal.h"
#include "upb/reflection/field_def_internal.h"
#include "upb/reflection/file_def_internal.h"
#include "upb/reflection/message_def_internal.h"
#include "upb/reflection/service_def_internal.h"

// Must be last.
#include "upb/port_def.inc"
Expand Down
33 changes: 0 additions & 33 deletions upb/reflection/def_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,39 +94,6 @@ const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s,
const upb_MessageDef* m,
size_t* count);

// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE /////////////////////////

upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s);
size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s);
upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s);
const upb_FieldDef* _upb_DefPool_FindExtensionByMiniTable(
const upb_DefPool* s, const upb_MiniTable_Extension* ext);

bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTable_Extension* ext,
upb_FieldDef* f);
bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v,
upb_Status* status);
bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size,
upb_value* v);

void** _upb_DefPool_ScratchData(const upb_DefPool* s);
size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s);

// For generated code only: loads a generated descriptor.
typedef struct _upb_DefPool_Init {
struct _upb_DefPool_Init** deps; // Dependencies of this file.
const upb_MiniTable_File* layout;
const char* filename;
upb_StringView descriptor; // Serialized descriptor.
} _upb_DefPool_Init;

bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init);

// Should only be directly called by tests. This variant lets us suppress
// the use of compiled-in tables, forcing a rebuild of the tables at runtime.
bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init,
bool rebuild_minitable);

#ifdef __cplusplus
} /* extern "C" */
#endif
Expand Down
77 changes: 77 additions & 0 deletions upb/reflection/def_pool_internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2009-2021, Google LLC
* All rights reserved.
*
* 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 Google LLC 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_REFLECTION_DEF_POOL_INTERNAL_H_
#define UPB_REFLECTION_DEF_POOL_INTERNAL_H_

#include "upb/reflection/def_pool.h"

// Must be last.
#include "upb/port_def.inc"

#ifdef __cplusplus
extern "C" {
#endif

upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s);
size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s);
upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s);
const upb_FieldDef* _upb_DefPool_FindExtensionByMiniTable(
const upb_DefPool* s, const upb_MiniTable_Extension* ext);

bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTable_Extension* ext,
upb_FieldDef* f);
bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v,
upb_Status* status);
bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size,
upb_value* v);

void** _upb_DefPool_ScratchData(const upb_DefPool* s);
size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s);

// For generated code only: loads a generated descriptor.
typedef struct _upb_DefPool_Init {
struct _upb_DefPool_Init** deps; // Dependencies of this file.
const upb_MiniTable_File* layout;
const char* filename;
upb_StringView descriptor; // Serialized descriptor.
} _upb_DefPool_Init;

bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init);

// Should only be directly called by tests. This variant lets us suppress
// the use of compiled-in tables, forcing a rebuild of the tables at runtime.
bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init,
bool rebuild_minitable);

#ifdef __cplusplus
} /* extern "C" */
#endif

#include "upb/port_undef.inc"

#endif /* UPB_REFLECTION_DEF_POOL_INTERNAL_H_ */
2 changes: 1 addition & 1 deletion upb/reflection/desc_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "upb/reflection/desc_state.h"
#include "upb/reflection/desc_state_internal.h"

// Must be last.
#include "upb/port_def.inc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef UPB_REFLECTION_DESC_STATE_H_
#define UPB_REFLECTION_DESC_STATE_H_
#ifndef UPB_REFLECTION_DESC_STATE_INTERNAL_H_
#define UPB_REFLECTION_DESC_STATE_INTERNAL_H_

#include "upb/mini_table.h"

Expand Down Expand Up @@ -60,4 +60,4 @@ bool _upb_DescState_Grow(upb_DescState* d, upb_Arena* a);

#include "upb/port_undef.inc"

#endif /* UPB_REFLECTION_DESC_STATE_H_ */
#endif /* UPB_REFLECTION_DESC_STATE_INTERNAL_H_ */
Loading

0 comments on commit 44916d7

Please sign in to comment.