Skip to content

Commit

Permalink
rename the upb_MiniTable subtypes to follow the upb style guide:
Browse files Browse the repository at this point in the history
upb_MiniTable_Enum -> upb_MiniTableEnum
upb_MiniTable_Extension -> upb_MiniTableExtension
upb_MiniTable_Field -> upb_MiniTableField
upb_MiniTable_File -> upb_MiniTableFile
upb_MiniTable_Sub -> upb_MiniTableSub

PiperOrigin-RevId: 486712960
  • Loading branch information
ericsalo authored and copybara-github committed Nov 7, 2022
1 parent cb7a519 commit 75907f7
Show file tree
Hide file tree
Showing 34 changed files with 344 additions and 341 deletions.
2 changes: 1 addition & 1 deletion docs/style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ typedef struct {
const int32_t* _values; // List of values <0 or >63
uint64_t _mask; // Bits are set for acceptable value 0 <= x < 64
int _value_count;
} upb_MiniTable_Enum;
} upb_MiniTableEnum;
```
8 changes: 4 additions & 4 deletions protos/protos.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ typename T::CProxy CreateMessage(upb_Message* msg) {

class ExtensionMiniTableProvider {
public:
ExtensionMiniTableProvider(const upb_MiniTable_Extension* mini_table_ext)
ExtensionMiniTableProvider(const upb_MiniTableExtension* mini_table_ext)
: mini_table_ext_(mini_table_ext) {}
const upb_MiniTable_Extension* mini_table_ext() const {
const upb_MiniTableExtension* mini_table_ext() const {
return mini_table_ext_;
}

private:
const upb_MiniTable_Extension* mini_table_ext_;
const upb_MiniTableExtension* mini_table_ext_;
};

// -------------------------------------------------------------------
Expand All @@ -183,7 +183,7 @@ class ExtensionIdentifier : public ExtensionMiniTableProvider {
using Extension = ExtensionType;
using Extendee = ExtendeeType;

ExtensionIdentifier(const upb_MiniTable_Extension* mini_table_ext)
ExtensionIdentifier(const upb_MiniTableExtension* mini_table_ext)
: ExtensionMiniTableProvider(mini_table_ext) {}
};

Expand Down
4 changes: 2 additions & 2 deletions python/extension_dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ static PyObject* PyUpb_ExtensionDict_FindExtensionByNumber(PyObject* _self,
const upb_DefPool* symtab = upb_FileDef_Pool(file);
const upb_ExtensionRegistry* reg = upb_DefPool_ExtensionRegistry(symtab);
int64_t number = PyLong_AsLong(arg);
const upb_MiniTable_Extension* ext =
(upb_MiniTable_Extension*)upb_ExtensionRegistry_Lookup(reg, l, number);
const upb_MiniTableExtension* ext =
(upb_MiniTableExtension*)upb_ExtensionRegistry_Lookup(reg, l, number);
if (ext) {
const upb_FieldDef* f = upb_DefPool_FindExtensionByMiniTable(symtab, ext);
return PyUpb_FieldDescriptor_Get(f);
Expand Down
12 changes: 6 additions & 6 deletions upb/extension_registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena) {
}

bool upb_ExtensionRegistry_AddArray(upb_ExtensionRegistry* r,
const upb_MiniTable_Extension** e,
const upb_MiniTableExtension** e,
size_t count) {
char buf[EXTREG_KEY_SIZE];
const upb_MiniTable_Extension** start = e;
const upb_MiniTable_Extension** end = UPB_PTRADD(e, count);
const upb_MiniTableExtension** start = e;
const upb_MiniTableExtension** end = UPB_PTRADD(e, count);
for (; e < end; e++) {
const upb_MiniTable_Extension* ext = *e;
const upb_MiniTableExtension* ext = *e;
extreg_key(buf, ext->extendee, ext->field.number);
upb_value v;
if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) {
Expand All @@ -77,14 +77,14 @@ bool upb_ExtensionRegistry_AddArray(upb_ExtensionRegistry* r,
failure:
/* Back out the entries previously added. */
for (end = e, e = start; e < end; e++) {
const upb_MiniTable_Extension* ext = *e;
const upb_MiniTableExtension* ext = *e;
extreg_key(buf, ext->extendee, ext->field.number);
upb_strtable_remove2(&r->exts, buf, EXTREG_KEY_SIZE, NULL);
}
return false;
}

const upb_MiniTable_Extension* upb_ExtensionRegistry_Lookup(
const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup(
const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num) {
char buf[EXTREG_KEY_SIZE];
upb_value v;
Expand Down
6 changes: 3 additions & 3 deletions upb/extension_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ extern "C" {
*/

typedef struct upb_ExtensionRegistry upb_ExtensionRegistry;
typedef struct upb_MiniTable_Extension upb_MiniTable_Extension;
typedef struct upb_MiniTableExtension upb_MiniTableExtension;

// Creates a upb_ExtensionRegistry in the given arena.
// The arena must outlive any use of the extreg.
Expand All @@ -85,12 +85,12 @@ upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena);
// Possible errors include OOM or an extension number that already exists.
// TODO: There is currently no way to determine the exact reason for failure.
bool upb_ExtensionRegistry_AddArray(upb_ExtensionRegistry* r,
const upb_MiniTable_Extension** e,
const upb_MiniTableExtension** e,
size_t count);

// Looks up the extension (if any) defined for message type |t| and field
// number |num|. Returns the extension if found, otherwise NULL.
const upb_MiniTable_Extension* upb_ExtensionRegistry_Lookup(
const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup(
const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num);

#ifdef __cplusplus
Expand Down
22 changes: 11 additions & 11 deletions upb/fuzz_test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Builder {
void BuildMessages();
void BuildEnums();
void BuildExtensions(upb_ExtensionRegistry** exts);
bool LinkExtension(upb_MiniTable_Extension* ext);
bool LinkExtension(upb_MiniTableExtension* ext);
void LinkMessages();

size_t NextLink() {
Expand All @@ -67,7 +67,7 @@ class Builder {
: mini_tables_[NextLink() % mini_tables_.size()];
}

const upb_MiniTable_Enum* NextEnumTable() {
const upb_MiniTableEnum* NextEnumTable() {
return enum_tables_.empty()
? nullptr
: enum_tables_[NextLink() % enum_tables_.size()];
Expand All @@ -76,7 +76,7 @@ class Builder {
const MiniTableFuzzInput* input_;
upb_Arena* arena_;
std::vector<const upb_MiniTable*> mini_tables_;
std::vector<const upb_MiniTable_Enum*> enum_tables_;
std::vector<const upb_MiniTableEnum*> enum_tables_;
size_t link_ = 0;
};

Expand All @@ -96,14 +96,14 @@ void Builder::BuildEnums() {
upb::Status status;
enum_tables_.reserve(input_->enum_mini_descriptors.size());
for (const auto& d : input_->enum_mini_descriptors) {
upb_MiniTable_Enum* enum_table =
upb_MiniTableEnum* enum_table =
upb_MiniTable_BuildEnum(d.data(), d.size(), arena_, status.ptr());
if (enum_table) enum_tables_.push_back(enum_table);
}
}

bool Builder::LinkExtension(upb_MiniTable_Extension* ext) {
upb_MiniTable_Field* field = &ext->field;
bool Builder::LinkExtension(upb_MiniTableExtension* ext) {
upb_MiniTableField* field = &ext->field;
if (field->descriptortype == kUpb_FieldType_Message ||
field->descriptortype == kUpb_FieldType_Group) {
auto mt = NextMiniTable();
Expand All @@ -128,9 +128,9 @@ void Builder::BuildExtensions(upb_ExtensionRegistry** exts) {
const char* end = ptr + input_->extensions.size();
// Iterate through the buffer, building extensions as long as we can.
while (ptr < end) {
upb_MiniTable_Extension* ext = reinterpret_cast<upb_MiniTable_Extension*>(
upb_MiniTableExtension* ext = reinterpret_cast<upb_MiniTableExtension*>(
upb_Arena_Malloc(arena_, sizeof(*ext)));
upb_MiniTable_Sub sub;
upb_MiniTableSub sub;
const upb_MiniTable* extendee = NextMiniTable();
if (!extendee) break;
ptr = upb_MiniTable_BuildExtension(ptr, end - ptr, ext, extendee, sub,
Expand All @@ -140,7 +140,7 @@ void Builder::BuildExtensions(upb_ExtensionRegistry** exts) {
if (upb_ExtensionRegistry_Lookup(*exts, ext->extendee, ext->field.number))
continue;
upb_ExtensionRegistry_AddArray(
*exts, const_cast<const upb_MiniTable_Extension**>(&ext), 1);
*exts, const_cast<const upb_MiniTableExtension**>(&ext), 1);
}
}
}
Expand All @@ -150,8 +150,8 @@ void Builder::LinkMessages() {
upb_MiniTable* table = const_cast<upb_MiniTable*>(t);
// For each field that requires a sub-table, assign one as appropriate.
for (size_t i = 0; i < table->field_count; i++) {
upb_MiniTable_Field* field =
const_cast<upb_MiniTable_Field*>(&table->fields[i]);
upb_MiniTableField* field =
const_cast<upb_MiniTableField*>(&table->fields[i]);
if (link_ == input_->links.size()) link_ = 0;
if (field->descriptortype == kUpb_FieldType_Message ||
field->descriptortype == kUpb_FieldType_Group) {
Expand Down
26 changes: 13 additions & 13 deletions upb/mini_table/accessors.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "upb/msg.h"
#include "upb/port/def.inc"

static size_t _upb_MiniTable_Field_GetSize(const upb_MiniTable_Field* f) {
static size_t _upb_MiniTableField_Size(const upb_MiniTableField* f) {
static unsigned char sizes[] = {
0, /* 0 */
8, /* kUpb_FieldType_Double */
Expand All @@ -61,7 +61,7 @@ static size_t _upb_MiniTable_Field_GetSize(const upb_MiniTable_Field* f) {
}

// Maps descriptor type to elem_size_lg2.
static int _upb_MiniTable_Field_CTypeLg2Size(const upb_MiniTable_Field* f) {
static int _upb_MiniTableField_CTypeLg2Size(const upb_MiniTableField* f) {
static const uint8_t sizes[] = {
-1, /* invalid descriptor type */
3, /* DOUBLE */
Expand All @@ -87,8 +87,8 @@ static int _upb_MiniTable_Field_CTypeLg2Size(const upb_MiniTable_Field* f) {
}

bool upb_MiniTable_HasField(const upb_Message* msg,
const upb_MiniTable_Field* field) {
if (_upb_MiniTable_Field_InOneOf(field)) {
const upb_MiniTableField* field) {
if (_upb_MiniTableField_InOneOf(field)) {
return _upb_getoneofcase_field(msg, field) == field->number;
} else if (field->presence > 0) {
return _upb_hasbit_field(msg, field);
Expand All @@ -100,23 +100,23 @@ bool upb_MiniTable_HasField(const upb_Message* msg,
}

void upb_MiniTable_ClearField(upb_Message* msg,
const upb_MiniTable_Field* field) {
const upb_MiniTableField* field) {
char* mem = UPB_PTR_AT(msg, field->offset, char);
if (field->presence > 0) {
_upb_clearhas_field(msg, field);
} else if (_upb_MiniTable_Field_InOneOf(field)) {
} else if (_upb_MiniTableField_InOneOf(field)) {
uint32_t* oneof_case = _upb_oneofcase_field(msg, field);
if (*oneof_case != field->number) return;
*oneof_case = 0;
}
memset(mem, 0, _upb_MiniTable_Field_GetSize(field));
memset(mem, 0, _upb_MiniTableField_Size(field));
}

void* upb_MiniTable_ResizeArray(upb_Message* msg,
const upb_MiniTable_Field* field, size_t len,
const upb_MiniTableField* field, size_t len,
upb_Arena* arena) {
return _upb_Array_Resize_accessor2(
msg, field->offset, len, _upb_MiniTable_Field_CTypeLg2Size(field), arena);
msg, field->offset, len, _upb_MiniTableField_CTypeLg2Size(field), arena);
}

typedef struct {
Expand Down Expand Up @@ -204,7 +204,7 @@ static upb_UnknownToMessageRet upb_MiniTable_ParseUnknownMessage(
}

upb_GetExtension_Status upb_MiniTable_GetOrPromoteExtension(
upb_Message* msg, const upb_MiniTable_Extension* ext_table,
upb_Message* msg, const upb_MiniTableExtension* ext_table,
int decode_options, upb_Arena* arena,
const upb_Message_Extension** extension) {
UPB_ASSERT(ext_table->field.descriptortype == kUpb_FieldType_Message);
Expand Down Expand Up @@ -248,7 +248,7 @@ upb_GetExtension_Status upb_MiniTable_GetOrPromoteExtension(
}

upb_GetExtensionAsBytes_Status upb_MiniTable_GetExtensionAsBytes(
const upb_Message* msg, const upb_MiniTable_Extension* ext_table,
const upb_Message* msg, const upb_MiniTableExtension* ext_table,
int encode_options, upb_Arena* arena, const char** extension_data,
size_t* len) {
const upb_Message_Extension* msg_ext = _upb_Message_Getext(msg, ext_table);
Expand Down Expand Up @@ -406,7 +406,7 @@ upb_FindUnknownRet upb_MiniTable_FindUnknown(const upb_Message* msg,

upb_UnknownToMessageRet upb_MiniTable_PromoteUnknownToMessage(
upb_Message* msg, const upb_MiniTable* mini_table,
const upb_MiniTable_Field* field, const upb_MiniTable* sub_mini_table,
const upb_MiniTableField* field, const upb_MiniTable* sub_mini_table,
int decode_options, upb_Arena* arena) {
upb_FindUnknownRet unknown;
// We need to loop and merge unknowns that have matching tag field->number.
Expand Down Expand Up @@ -454,7 +454,7 @@ upb_UnknownToMessageRet upb_MiniTable_PromoteUnknownToMessage(
// TODO(b/251007554): Optimize. Instead of converting messages one at a time,
// scan all unknown data once and compact.
upb_UnknownToMessage_Status upb_MiniTable_PromoteUnknownToMessageArray(
upb_Message* msg, const upb_MiniTable_Field* field,
upb_Message* msg, const upb_MiniTableField* field,
const upb_MiniTable* mini_table, int decode_options, upb_Arena* arena) {
upb_Array* repeated_messages = upb_MiniTable_GetMutableArray(msg, field);
// Find all unknowns with given field number and parse.
Expand Down
Loading

0 comments on commit 75907f7

Please sign in to comment.