Skip to content

Commit

Permalink
lock down internal reflection
Browse files Browse the repository at this point in the history
- upb_DefPool_FindExtensionByMiniTable() has been promoted to a public function.
- There are now zero uses of the internal reflection headers outside of upb core (but still a few left in generated code).

PiperOrigin-RevId: 480211522
  • Loading branch information
ericsalo authored and copybara-github committed Oct 11, 2022
1 parent 41335a0 commit 85bf467
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
1 change: 0 additions & 1 deletion python/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ py_extension(
"//:descriptor_upb_proto_reflection",
"//:port",
"//:reflection",
"//:reflection_internal",
"//:table_internal",
"//:textformat",
"//:upb",
Expand Down
4 changes: 2 additions & 2 deletions python/extension_dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

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

// -----------------------------------------------------------------------------
// ExtensionDict
Expand Down Expand Up @@ -76,7 +76,7 @@ static PyObject* PyUpb_ExtensionDict_FindExtensionByNumber(PyObject* _self,
const upb_MiniTable_Extension* ext =
(upb_MiniTable_Extension*)_upb_extreg_get(reg, l, number);
if (ext) {
const upb_FieldDef* f = _upb_DefPool_FindExtensionByMiniTable(symtab, ext);
const upb_FieldDef* f = upb_DefPool_FindExtensionByMiniTable(symtab, ext);
return PyUpb_FieldDescriptor_Get(f);
} else {
Py_RETURN_NONE;
Expand Down
4 changes: 2 additions & 2 deletions upb/reflection/def_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s) {

upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s) { return s->arena; }

const upb_FieldDef* _upb_DefPool_FindExtensionByMiniTable(
const upb_FieldDef* upb_DefPool_FindExtensionByMiniTable(
const upb_DefPool* s, const upb_MiniTable_Extension* ext) {
upb_value v;
bool ok = upb_inttable_lookup(&s->exts, (uintptr_t)ext, &v);
Expand All @@ -413,7 +413,7 @@ const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s,
int32_t fieldnum) {
const upb_MiniTable* l = upb_MessageDef_MiniTable(m);
const upb_MiniTable_Extension* ext = _upb_extreg_get(s->extreg, l, fieldnum);
return ext ? _upb_DefPool_FindExtensionByMiniTable(s, ext) : NULL;
return ext ? upb_DefPool_FindExtensionByMiniTable(s, ext) : NULL;
}

const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry(
Expand Down
15 changes: 9 additions & 6 deletions upb/reflection/def_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,19 @@ const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s,
const char* name,
size_t len);

const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize(
const upb_DefPool* s, const char* name, size_t size);
const upb_FieldDef* upb_DefPool_FindExtensionByMiniTable(
const upb_DefPool* s, const upb_MiniTable_Extension* ext);

const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s,
const char* sym);

const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize(
const upb_DefPool* s, const char* name, size_t size);

const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s,
const upb_MessageDef* m,
int32_t fieldnum);

const upb_ServiceDef* upb_DefPool_FindServiceByName(const upb_DefPool* s,
const char* name);

Expand All @@ -83,10 +90,6 @@ const upb_FileDef* upb_DefPool_AddFile(
upb_DefPool* s, const google_protobuf_FileDescriptorProto* file_proto,
upb_Status* status);

const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s,
const upb_MessageDef* m,
int32_t fieldnum);

const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry(
const upb_DefPool* s);

Expand Down
2 changes: 0 additions & 2 deletions upb/reflection/def_pool_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ extern "C" {
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);
Expand Down
4 changes: 2 additions & 2 deletions upb/reflection/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "upb/internal/table.h"
#include "upb/map.h"
#include "upb/msg.h"
#include "upb/reflection/def_pool_internal.h"
#include "upb/reflection/def_pool.h"
#include "upb/reflection/def_type.h"
#include "upb/reflection/field_def_internal.h"
#include "upb/reflection/message_def.h"
Expand Down Expand Up @@ -267,7 +267,7 @@ bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m,
if (i - n < count) {
ext += count - 1 - (i - n);
memcpy(out_val, &ext->data, sizeof(*out_val));
*out_f = _upb_DefPool_FindExtensionByMiniTable(ext_pool, ext->ext);
*out_f = upb_DefPool_FindExtensionByMiniTable(ext_pool, ext->ext);
*iter = i;
return true;
}
Expand Down

0 comments on commit 85bf467

Please sign in to comment.