Fix mistake in previous rename: upb_MessageDef_FindFieldByNameWithSize.

pull/13171/head
Joshua Haberman 3 years ago
parent 215fe1eda8
commit c56fe27f88
  1. 2
      python/descriptor.c
  2. 3
      rename.sed
  3. 2
      upb/bindings/lua/def.c
  4. 16
      upb/bindings/lua/msg.c
  5. 12
      upb/def.c
  6. 4
      upb/def.h
  7. 2
      upb/def.hpp
  8. 46
      upb/json_decode.c
  9. 32
      upb/json_encode.c
  10. 11
      upb/reflection.c

@ -392,7 +392,7 @@ static PyObject* PyUpb_Descriptor_GetFieldsByNumber(PyObject* _self,
(void*)&upb_MessageDef_Field,
(void*)&PyUpb_FieldDescriptor_Get,
},
(void*)&upb_MessageDef_FindFieldByNumberWithSize,
(void*)&upb_MessageDef_FindFieldByNumber,
(void*)&upb_FieldDef_Number,
};
PyUpb_DescriptorBase* self = (void*)_self;

@ -71,7 +71,7 @@ s/upb_msgdef_field/upb_MessageDef_Field/g;
s/upb_msgdef_oneof/upb_MessageDef_Oneof/g;
s/upb_msgdef_ntooz/upb_MessageDef_FindOneofByName/g;
s/upb_msgdef_ntofz/upb_MessageDef_FindFieldByName/g;
s/upb_msgdef_itof/upb_MessageDef_FindFieldByNumberWithSize/g;
s/upb_msgdef_itof/upb_MessageDef_FindFieldByNumber/g;
s/upb_msgdef_ntof/upb_MessageDef_FindFieldByNameWithSize/g;
s/upb_msgdef_ntoo/upb_MessageDef_FindOneofByNameWithSize/g;
s/upb_msgdef_layout/upb_MessageDef_MiniTable/g;
@ -89,6 +89,7 @@ s/upb_msgdef_lookupjsonnamez/upb_MessageDef_FindByNameName/g;
s/upb_msgdef_lookupjsonname/upb_MessageDef_FindByJsonNameWithSize/g;
s/upb_msgdef/upb_MessageDef/g;
s/WithSizez//g;
s/upb_MessageDef_FindFieldByNumberWithSize/upb_MessageDef_FindFieldByNumber/g;
s/upb_extrange_options/upb_ExtensionRange_Options/g;
s/upb_extrange_hasoptions/upb_ExtensionRange_HasOptions/g;

@ -368,7 +368,7 @@ static int lupb_MessageDef_Field(lua_State* L) {
switch (lua_type(L, 2)) {
case LUA_TNUMBER:
f = upb_MessageDef_FindFieldByNumberWithSize(m, lua_tointeger(L, 2));
f = upb_MessageDef_FindFieldByNumber(m, lua_tointeger(L, 2));
break;
case LUA_TSTRING:
f = upb_MessageDef_FindFieldByName(m, lua_tostring(L, 2));

@ -733,10 +733,10 @@ static void lupb_Message_Newwrapper(lua_State* L, int narg,
upb_MutableMessageValue val) {
if (upb_FieldDef_IsMap(f)) {
const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f);
const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumberWithSize(
entry, kUpb_MapEntry_KeyFieldNumber);
const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumberWithSize(
entry, kUpb_MapEntry_ValueFieldNumber);
const upb_FieldDef* key_f =
upb_MessageDef_FindFieldByNumber(entry, kUpb_MapEntry_KeyFieldNumber);
const upb_FieldDef* val_f =
upb_MessageDef_FindFieldByNumber(entry, kUpb_MapEntry_ValueFieldNumber);
lupb_map* lmap =
lupb_Message_Newud(L, narg, sizeof(*lmap), LUPB_MAP, val_f);
lmap->key_type = upb_FieldDef_CType(key_f);
@ -849,10 +849,10 @@ static int lupb_Message_Newindex(lua_State* L) {
if (upb_FieldDef_IsMap(f)) {
lupb_map* lmap = lupb_map_check(L, 3);
const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f);
const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumberWithSize(
entry, kUpb_MapEntry_KeyFieldNumber);
const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumberWithSize(
entry, kUpb_MapEntry_ValueFieldNumber);
const upb_FieldDef* key_f =
upb_MessageDef_FindFieldByNumber(entry, kUpb_MapEntry_KeyFieldNumber);
const upb_FieldDef* val_f =
upb_MessageDef_FindFieldByNumber(entry, kUpb_MapEntry_ValueFieldNumber);
upb_CType key_type = upb_FieldDef_CType(key_f);
upb_CType value_type = upb_FieldDef_CType(val_f);
luaL_argcheck(L, lmap->key_type == key_type, 3, "key type mismatch");

@ -691,8 +691,8 @@ upb_Syntax upb_MessageDef_Syntax(const upb_MessageDef* m) {
return m->file->syntax;
}
const upb_FieldDef* upb_MessageDef_FindFieldByNumberWithSize(
const upb_MessageDef* m, uint32_t i) {
const upb_FieldDef* upb_MessageDef_FindFieldByNumber(const upb_MessageDef* m,
uint32_t i) {
upb_value val;
return upb_inttable_lookup(&m->itof, i, &val) ? upb_value_getconstptr(val)
: NULL;
@ -1365,8 +1365,8 @@ static void assign_layout_indices(const upb_MessageDef* m, upb_MiniTable* l,
int n = upb_MessageDef_numfields(m);
int dense_below = 0;
for (i = 0; i < n; i++) {
upb_FieldDef* f = (upb_FieldDef*)upb_MessageDef_FindFieldByNumberWithSize(
m, fields[i].number);
upb_FieldDef* f =
(upb_FieldDef*)upb_MessageDef_FindFieldByNumber(m, fields[i].number);
UPB_ASSERT(f);
f->layout_index = i;
if (i < UINT8_MAX && fields[i].number == i + 1 &&
@ -1487,8 +1487,8 @@ static void make_layout(symtab_addctx* ctx, const upb_MessageDef* m) {
if (upb_MessageDef_IsMapEntry(m)) {
/* TODO(haberman): refactor this method so this special case is more
* elegant. */
const upb_FieldDef* key = upb_MessageDef_FindFieldByNumberWithSize(m, 1);
const upb_FieldDef* val = upb_MessageDef_FindFieldByNumberWithSize(m, 2);
const upb_FieldDef* key = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_FieldDef* val = upb_MessageDef_FindFieldByNumber(m, 2);
fields[0].number = 1;
fields[1].number = 2;
fields[0].mode = kUpb_FieldMode_Scalar;

@ -188,8 +188,8 @@ const upb_ExtensionRange* upb_MessageDef_ExtensionRange(const upb_MessageDef* m,
int i);
const upb_FieldDef* upb_MessageDef_Field(const upb_MessageDef* m, int i);
const upb_OneofDef* upb_MessageDef_Oneof(const upb_MessageDef* m, int i);
const upb_FieldDef* upb_MessageDef_FindFieldByNumberWithSize(
const upb_MessageDef* m, uint32_t i);
const upb_FieldDef* upb_MessageDef_FindFieldByNumber(const upb_MessageDef* m,
uint32_t i);
const upb_FieldDef* upb_MessageDef_FindFieldByNameWithSize(
const upb_MessageDef* m, const char* name, size_t len);
const upb_OneofDef* upb_MessageDef_FindOneofByNameWithSize(

@ -194,7 +194,7 @@ class MessageDefPtr {
// These return null pointers if the field is not found.
FieldDefPtr FindFieldByNumber(uint32_t number) const {
return FieldDefPtr(upb_MessageDef_FindFieldByNumberWithSize(ptr_, number));
return FieldDefPtr(upb_MessageDef_FindFieldByNumber(ptr_, number));
}
FieldDefPtr FindFieldByName(const char* name, size_t len) const {
return FieldDefPtr(upb_MessageDef_FindFieldByNameWithSize(ptr_, name, len));

@ -894,10 +894,8 @@ static void jsondec_array(jsondec* d, upb_Message* msg, const upb_FieldDef* f) {
static void jsondec_map(jsondec* d, upb_Message* msg, const upb_FieldDef* f) {
upb_Map* map = upb_Message_Mutable(msg, f, d->arena).map;
const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f);
const upb_FieldDef* key_f =
upb_MessageDef_FindFieldByNumberWithSize(entry, 1);
const upb_FieldDef* val_f =
upb_MessageDef_FindFieldByNumberWithSize(entry, 2);
const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry, 1);
const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(entry, 2);
jsondec_objstart(d);
while (jsondec_objnext(d)) {
@ -1139,10 +1137,9 @@ static void jsondec_timestamp(jsondec* d, upb_Message* msg,
jsondec_err(d, "Timestamp out of range");
}
upb_Message_Set(msg, upb_MessageDef_FindFieldByNumberWithSize(m, 1), seconds,
d->arena);
upb_Message_Set(msg, upb_MessageDef_FindFieldByNumberWithSize(m, 2), nanos,
upb_Message_Set(msg, upb_MessageDef_FindFieldByNumber(m, 1), seconds,
d->arena);
upb_Message_Set(msg, upb_MessageDef_FindFieldByNumber(m, 2), nanos, d->arena);
return;
malformed:
@ -1174,15 +1171,14 @@ static void jsondec_duration(jsondec* d, upb_Message* msg,
nanos.int32_val = -nanos.int32_val;
}
upb_Message_Set(msg, upb_MessageDef_FindFieldByNumberWithSize(m, 1), seconds,
d->arena);
upb_Message_Set(msg, upb_MessageDef_FindFieldByNumberWithSize(m, 2), nanos,
upb_Message_Set(msg, upb_MessageDef_FindFieldByNumber(m, 1), seconds,
d->arena);
upb_Message_Set(msg, upb_MessageDef_FindFieldByNumber(m, 2), nanos, d->arena);
}
static void jsondec_listvalue(jsondec* d, upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumberWithSize(m, 1);
const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_MessageDef* value_m = upb_FieldDef_MessageSubDef(values_f);
upb_Array* values = upb_Message_Mutable(msg, values_f, d->arena).array;
@ -1199,10 +1195,9 @@ static void jsondec_listvalue(jsondec* d, upb_Message* msg,
static void jsondec_struct(jsondec* d, upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* fields_f = upb_MessageDef_FindFieldByNumberWithSize(m, 1);
const upb_FieldDef* fields_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(fields_f);
const upb_FieldDef* value_f =
upb_MessageDef_FindFieldByNumberWithSize(entry_m, 2);
const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(entry_m, 2);
const upb_MessageDef* value_m = upb_FieldDef_MessageSubDef(value_f);
upb_Map* fields = upb_Message_Mutable(msg, fields_f, d->arena).map;
@ -1228,42 +1223,42 @@ static void jsondec_wellknownvalue(jsondec* d, upb_Message* msg,
switch (jsondec_peek(d)) {
case JD_NUMBER:
/* double number_value = 2; */
f = upb_MessageDef_FindFieldByNumberWithSize(m, 2);
f = upb_MessageDef_FindFieldByNumber(m, 2);
val.double_val = jsondec_number(d);
break;
case JD_STRING:
/* string string_value = 3; */
f = upb_MessageDef_FindFieldByNumberWithSize(m, 3);
f = upb_MessageDef_FindFieldByNumber(m, 3);
val.str_val = jsondec_string(d);
break;
case JD_FALSE:
/* bool bool_value = 4; */
f = upb_MessageDef_FindFieldByNumberWithSize(m, 4);
f = upb_MessageDef_FindFieldByNumber(m, 4);
val.bool_val = false;
jsondec_false(d);
break;
case JD_TRUE:
/* bool bool_value = 4; */
f = upb_MessageDef_FindFieldByNumberWithSize(m, 4);
f = upb_MessageDef_FindFieldByNumber(m, 4);
val.bool_val = true;
jsondec_true(d);
break;
case JD_NULL:
/* NullValue null_value = 1; */
f = upb_MessageDef_FindFieldByNumberWithSize(m, 1);
f = upb_MessageDef_FindFieldByNumber(m, 1);
val.int32_val = 0;
jsondec_null(d);
break;
/* Note: these cases return, because upb_Message_Mutable() is enough. */
case JD_OBJECT:
/* Struct struct_value = 5; */
f = upb_MessageDef_FindFieldByNumberWithSize(m, 5);
f = upb_MessageDef_FindFieldByNumber(m, 5);
submsg = upb_Message_Mutable(msg, f, d->arena).msg;
jsondec_struct(d, submsg, upb_FieldDef_MessageSubDef(f));
return;
case JD_ARRAY:
/* ListValue list_value = 6; */
f = upb_MessageDef_FindFieldByNumberWithSize(m, 6);
f = upb_MessageDef_FindFieldByNumber(m, 6);
submsg = upb_Message_Mutable(msg, f, d->arena).msg;
jsondec_listvalue(d, submsg, upb_FieldDef_MessageSubDef(f));
return;
@ -1310,7 +1305,7 @@ static upb_StringView jsondec_mask(jsondec* d, const char* buf,
static void jsondec_fieldmask(jsondec* d, upb_Message* msg,
const upb_MessageDef* m) {
/* repeated string paths = 1; */
const upb_FieldDef* paths_f = upb_MessageDef_FindFieldByNumberWithSize(m, 1);
const upb_FieldDef* paths_f = upb_MessageDef_FindFieldByNumber(m, 1);
upb_Array* arr = upb_Message_Mutable(msg, paths_f, d->arena).array;
upb_StringView str = jsondec_string(d);
const char* ptr = str.data;
@ -1350,8 +1345,7 @@ static void jsondec_anyfield(jsondec* d, upb_Message* msg,
static const upb_MessageDef* jsondec_typeurl(jsondec* d, upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* type_url_f =
upb_MessageDef_FindFieldByNumberWithSize(m, 1);
const upb_FieldDef* type_url_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_MessageDef* type_m;
upb_StringView type_url = jsondec_string(d);
const char* end = type_url.data + type_url.size;
@ -1382,7 +1376,7 @@ static const upb_MessageDef* jsondec_typeurl(jsondec* d, upb_Message* msg,
static void jsondec_any(jsondec* d, upb_Message* msg, const upb_MessageDef* m) {
/* string type_url = 1;
* bytes value = 2; */
const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumberWithSize(m, 2);
const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 2);
upb_Message* any_msg;
const upb_MessageDef* any_m = NULL;
const char* pre_type_data = NULL;
@ -1444,7 +1438,7 @@ static void jsondec_any(jsondec* d, upb_Message* msg, const upb_MessageDef* m) {
static void jsondec_wrapper(jsondec* d, upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumberWithSize(m, 1);
const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 1);
upb_MessageValue val = jsondec_value(d, value_f);
upb_Message_Set(msg, value_f, val, d->arena);
}

@ -141,9 +141,8 @@ static void jsonenc_nanos(jsonenc* e, int32_t nanos) {
static void jsonenc_timestamp(jsonenc* e, const upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* seconds_f =
upb_MessageDef_FindFieldByNumberWithSize(m, 1);
const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumberWithSize(m, 2);
const upb_FieldDef* seconds_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumber(m, 2);
int64_t seconds = upb_Message_Get(msg, seconds_f).int64_val;
int32_t nanos = upb_Message_Get(msg, nanos_f).int32_val;
int L, N, I, J, K, hour, min, sec;
@ -185,9 +184,8 @@ static void jsonenc_timestamp(jsonenc* e, const upb_Message* msg,
static void jsonenc_duration(jsonenc* e, const upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* seconds_f =
upb_MessageDef_FindFieldByNumberWithSize(m, 1);
const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumberWithSize(m, 2);
const upb_FieldDef* seconds_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumber(m, 2);
int64_t seconds = upb_Message_Get(msg, seconds_f).int64_val;
int32_t nanos = upb_Message_Get(msg, nanos_f).int32_val;
@ -336,7 +334,7 @@ static void upb_JsonEncode_Float(jsonenc* e, float val) {
static void jsonenc_wrapper(jsonenc* e, const upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumberWithSize(m, 1);
const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(m, 1);
upb_MessageValue val = upb_Message_Get(msg, val_f);
jsonenc_scalar(e, val, val_f);
}
@ -380,9 +378,8 @@ badurl:
static void jsonenc_any(jsonenc* e, const upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* type_url_f =
upb_MessageDef_FindFieldByNumberWithSize(m, 1);
const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumberWithSize(m, 2);
const upb_FieldDef* type_url_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 2);
upb_StringView type_url = upb_Message_Get(msg, type_url_f).str_val;
upb_StringView value = upb_Message_Get(msg, value_f).str_val;
const upb_MessageDef* any_m = jsonenc_getanymsg(e, type_url);
@ -441,7 +438,7 @@ static void jsonenc_fieldpath(jsonenc* e, upb_StringView path) {
static void jsonenc_fieldmask(jsonenc* e, const upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* paths_f = upb_MessageDef_FindFieldByNumberWithSize(m, 1);
const upb_FieldDef* paths_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_Array* paths = upb_Message_Get(msg, paths_f).array_val;
bool first = true;
size_t i, n = 0;
@ -460,11 +457,10 @@ static void jsonenc_fieldmask(jsonenc* e, const upb_Message* msg,
static void jsonenc_struct(jsonenc* e, const upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* fields_f = upb_MessageDef_FindFieldByNumberWithSize(m, 1);
const upb_FieldDef* fields_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_Map* fields = upb_Message_Get(msg, fields_f).map_val;
const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(fields_f);
const upb_FieldDef* value_f =
upb_MessageDef_FindFieldByNumberWithSize(entry_m, 2);
const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(entry_m, 2);
size_t iter = kUpb_Map_Begin;
bool first = true;
@ -487,7 +483,7 @@ static void jsonenc_struct(jsonenc* e, const upb_Message* msg,
static void jsonenc_listvalue(jsonenc* e, const upb_Message* msg,
const upb_MessageDef* m) {
const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumberWithSize(m, 1);
const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumber(m, 1);
const upb_MessageDef* values_m = upb_FieldDef_MessageSubDef(values_f);
const upb_Array* values = upb_Message_Get(msg, values_f).array_val;
size_t i;
@ -669,10 +665,8 @@ static void jsonenc_array(jsonenc* e, const upb_Array* arr,
static void jsonenc_map(jsonenc* e, const upb_Map* map, const upb_FieldDef* f) {
const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f);
const upb_FieldDef* key_f =
upb_MessageDef_FindFieldByNumberWithSize(entry, 1);
const upb_FieldDef* val_f =
upb_MessageDef_FindFieldByNumberWithSize(entry, 2);
const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry, 1);
const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(entry, 2);
size_t iter = kUpb_Map_Begin;
bool first = true;

@ -180,10 +180,10 @@ make:
if (!a) return (upb_MutableMessageValue){.array = NULL};
if (upb_FieldDef_IsMap(f)) {
const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f);
const upb_FieldDef* key = upb_MessageDef_FindFieldByNumberWithSize(
entry, kUpb_MapEntry_KeyFieldNumber);
const upb_FieldDef* value = upb_MessageDef_FindFieldByNumberWithSize(
entry, kUpb_MapEntry_ValueFieldNumber);
const upb_FieldDef* key =
upb_MessageDef_FindFieldByNumber(entry, kUpb_MapEntry_KeyFieldNumber);
const upb_FieldDef* value =
upb_MessageDef_FindFieldByNumber(entry, kUpb_MapEntry_ValueFieldNumber);
ret.map =
upb_Map_New(a, upb_FieldDef_CType(key), upb_FieldDef_CType(value));
} else if (upb_FieldDef_IsRepeated(f)) {
@ -313,8 +313,7 @@ bool _upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m,
const upb_MessageDef* subm = upb_FieldDef_MessageSubDef(f);
if (!subm) continue;
if (upb_FieldDef_IsMap(f)) {
const upb_FieldDef* val_f =
upb_MessageDef_FindFieldByNumberWithSize(subm, 2);
const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(subm, 2);
const upb_MessageDef* val_m = upb_FieldDef_MessageSubDef(val_f);
upb_Map* map = (upb_Map*)val.map_val;
size_t iter = kUpb_Map_Begin;

Loading…
Cancel
Save