Addressed PR comments.

pull/13171/head
Joshua Haberman 3 years ago
parent 1437245d41
commit 5b3447ebd3
  1. 6
      python/message.c
  2. 16
      upb/msg.c

@ -989,9 +989,8 @@ PyObject* PyUpb_CMessage_MergeFromString(PyObject* _self, PyObject* arg) {
const upb_extreg* extreg = upb_symtab_extreg(upb_filedef_symtab(file));
const upb_msglayout* layout = upb_msgdef_layout(msgdef);
upb_arena* arena = PyUpb_Arena_Get(self->arena);
int options = 0;
PyUpb_ModuleState* state = PyUpb_ModuleState_Get();
options |=
int options =
UPB_DECODE_MAXDEPTH(state->allow_oversize_protos ? UINT32_MAX : 100);
upb_DecodeStatus status =
_upb_decode(buf, size, self->ptr.msg, layout, extreg, options, arena);
@ -1186,11 +1185,10 @@ PyObject* PyUpb_CMessage_SerializeInternal(PyObject* _self, PyObject* args,
const upb_msgdef* msgdef = _PyUpb_CMessage_GetMsgdef(self);
const upb_msglayout* layout = upb_msgdef_layout(msgdef);
size_t size = 0;
int options = 0;
int options = UPB_ENCODE_MAXDEPTH(UINT32_MAX);
if (check_required) options |= UPB_ENCODE_CHECKREQUIRED;
if (deterministic) options |= UPB_ENCODE_DETERMINISTIC;
// Python does not currently have any effective limit on serialization depth.
options |= UPB_ENCODE_MAXDEPTH(UINT32_MAX);
char* pb = upb_encode_ex(self->ptr.msg, layout, options, arena, &size);
PyObject* ret = NULL;

@ -252,34 +252,36 @@ static void _upb_mapsorter_getkeys(const void *_a, const void *_b, void *a_key,
_upb_map_fromkey(b_tabkey, b_key, size);
}
#define COMPARE_INTEGERS(a, b) ((a) < (b) ? -1 : ((a) == (b) ? 0 : 1))
static int _upb_mapsorter_cmpi64(const void *_a, const void *_b) {
int64_t a, b;
_upb_mapsorter_getkeys(_a, _b, &a, &b, 8);
return a - b;
return COMPARE_INTEGERS(a, b);
}
static int _upb_mapsorter_cmpu64(const void *_a, const void *_b) {
uint64_t a, b;
_upb_mapsorter_getkeys(_a, _b, &a, &b, 8);
return a - b;
return COMPARE_INTEGERS(a, b);
}
static int _upb_mapsorter_cmpi32(const void *_a, const void *_b) {
int32_t a, b;
_upb_mapsorter_getkeys(_a, _b, &a, &b, 4);
return a - b;
return COMPARE_INTEGERS(a, b);
}
static int _upb_mapsorter_cmpu32(const void *_a, const void *_b) {
uint32_t a, b;
_upb_mapsorter_getkeys(_a, _b, &a, &b, 4);
return a - b;
return COMPARE_INTEGERS(a, b);
}
static int _upb_mapsorter_cmpbool(const void *_a, const void *_b) {
bool a, b;
_upb_mapsorter_getkeys(_a, _b, &a, &b, 1);
return a - b;
return COMPARE_INTEGERS(a, b);
}
static int _upb_mapsorter_cmpstr(const void *_a, const void *_b) {
@ -288,9 +290,11 @@ static int _upb_mapsorter_cmpstr(const void *_a, const void *_b) {
size_t common_size = UPB_MIN(a.size, b.size);
int cmp = memcmp(a.data, b.data, common_size);
if (cmp) return -cmp;
return a.size - b.size;
return COMPARE_INTEGERS(a.size, b.size);
}
#undef COMPARE_INTEGERS
bool _upb_mapsorter_pushmap(_upb_mapsorter *s, upb_descriptortype_t key_type,
const upb_map *map, _upb_sortedmap *sorted) {
int map_size = _upb_map_size(map);

Loading…
Cancel
Save