Fixed amalgamated build.

pull/13171/head
Joshua Haberman 7 years ago
parent 058a17f6a6
commit 72c333eb03
  1. 12
      upb/decode.c
  2. 16
      upb/encode.c

@ -104,11 +104,11 @@ static bool upb_decode_tag(const char **ptr, const char *limit,
return true; return true;
} }
static int32_t upb_zzdec_32(uint32_t n) { static int32_t upb_zzdecode_32(uint32_t n) {
return (n >> 1) ^ -(int32_t)(n & 1); return (n >> 1) ^ -(int32_t)(n & 1);
} }
static int64_t upb_zzdec_64(uint64_t n) { static int64_t upb_zzdecode_64(uint64_t n) {
return (n >> 1) ^ -(int64_t)(n & 1); return (n >> 1) ^ -(int64_t)(n & 1);
} }
@ -317,12 +317,12 @@ static bool upb_decode_varintfield(upb_decstate *d, upb_decframe *frame,
break; break;
} }
case UPB_DESCRIPTOR_TYPE_SINT32: { case UPB_DESCRIPTOR_TYPE_SINT32: {
int32_t decoded = upb_zzdec_32(val); int32_t decoded = upb_zzdecode_32(val);
memcpy(field_mem, &decoded, sizeof(decoded)); memcpy(field_mem, &decoded, sizeof(decoded));
break; break;
} }
case UPB_DESCRIPTOR_TYPE_SINT64: { case UPB_DESCRIPTOR_TYPE_SINT64: {
int64_t decoded = upb_zzdec_64(val); int64_t decoded = upb_zzdecode_64(val);
memcpy(field_mem, &decoded, sizeof(decoded)); memcpy(field_mem, &decoded, sizeof(decoded));
break; break;
} }
@ -443,9 +443,9 @@ static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame,
case UPB_DESCRIPTOR_TYPE_BOOL: case UPB_DESCRIPTOR_TYPE_BOOL:
VARINT_CASE(bool, bool); VARINT_CASE(bool, bool);
case UPB_DESCRIPTOR_TYPE_SINT32: case UPB_DESCRIPTOR_TYPE_SINT32:
VARINT_CASE(int32_t, upb_zzdec_32); VARINT_CASE(int32_t, upb_zzdecode_32);
case UPB_DESCRIPTOR_TYPE_SINT64: case UPB_DESCRIPTOR_TYPE_SINT64:
VARINT_CASE(int64_t, upb_zzdec_64); VARINT_CASE(int64_t, upb_zzdecode_64);
case UPB_DESCRIPTOR_TYPE_MESSAGE: case UPB_DESCRIPTOR_TYPE_MESSAGE:
CHK(val.size <= (size_t)(frame->limit - val.data)); CHK(val.size <= (size_t)(frame->limit - val.data));
return upb_decode_submsg(d, frame, val.data + val.size, field, 0); return upb_decode_submsg(d, frame, val.data + val.size, field, 0);

@ -8,7 +8,7 @@
#define CHK(x) do { if (!(x)) { return false; } } while(0) #define CHK(x) do { if (!(x)) { return false; } } while(0)
/* Maps descriptor type -> upb field type. */ /* Maps descriptor type -> upb field type. */
static const uint8_t upb_desctype_to_fieldtype[] = { static const uint8_t upb_desctype_to_fieldtype2[] = {
UPB_WIRE_TYPE_END_GROUP, /* ENDGROUP */ UPB_WIRE_TYPE_END_GROUP, /* ENDGROUP */
UPB_TYPE_DOUBLE, /* DOUBLE */ UPB_TYPE_DOUBLE, /* DOUBLE */
UPB_TYPE_FLOAT, /* FLOAT */ UPB_TYPE_FLOAT, /* FLOAT */
@ -43,8 +43,8 @@ static size_t upb_encode_varint(uint64_t val, char *buf) {
return i; return i;
} }
static uint32_t upb_zzenc_32(int32_t n) { return (n << 1) ^ (n >> 31); } static uint32_t upb_zzencode_32(int32_t n) { return (n << 1) ^ (n >> 31); }
static uint64_t upb_zzenc_64(int64_t n) { return (n << 1) ^ (n >> 63); } static uint64_t upb_zzencode_64(int64_t n) { return (n << 1) ^ (n >> 63); }
typedef struct { typedef struct {
upb_env *env; upb_env *env;
@ -162,7 +162,7 @@ static bool upb_encode_array(upb_encstate *e, const char *field_mem,
return true; return true;
} }
UPB_ASSERT(arr->type == upb_desctype_to_fieldtype[f->type]); UPB_ASSERT(arr->type == upb_desctype_to_fieldtype2[f->type]);
#define VARINT_CASE(ctype, encode) { \ #define VARINT_CASE(ctype, encode) { \
ctype *start = arr->data; \ ctype *start = arr->data; \
@ -202,9 +202,9 @@ do { ; } while(0)
case UPB_DESCRIPTOR_TYPE_BOOL: case UPB_DESCRIPTOR_TYPE_BOOL:
VARINT_CASE(bool, *ptr); VARINT_CASE(bool, *ptr);
case UPB_DESCRIPTOR_TYPE_SINT32: case UPB_DESCRIPTOR_TYPE_SINT32:
VARINT_CASE(int32_t, upb_zzenc_32(*ptr)); VARINT_CASE(int32_t, upb_zzencode_32(*ptr));
case UPB_DESCRIPTOR_TYPE_SINT64: case UPB_DESCRIPTOR_TYPE_SINT64:
VARINT_CASE(int64_t, upb_zzenc_64(*ptr)); VARINT_CASE(int64_t, upb_zzencode_64(*ptr));
case UPB_DESCRIPTOR_TYPE_STRING: case UPB_DESCRIPTOR_TYPE_STRING:
case UPB_DESCRIPTOR_TYPE_BYTES: { case UPB_DESCRIPTOR_TYPE_BYTES: {
upb_stringview *start = arr->data; upb_stringview *start = arr->data;
@ -288,9 +288,9 @@ static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem,
case UPB_DESCRIPTOR_TYPE_BOOL: case UPB_DESCRIPTOR_TYPE_BOOL:
CASE(bool, varint, UPB_WIRE_TYPE_VARINT, val); CASE(bool, varint, UPB_WIRE_TYPE_VARINT, val);
case UPB_DESCRIPTOR_TYPE_SINT32: case UPB_DESCRIPTOR_TYPE_SINT32:
CASE(int32_t, varint, UPB_WIRE_TYPE_VARINT, upb_zzenc_32(val)); CASE(int32_t, varint, UPB_WIRE_TYPE_VARINT, upb_zzencode_32(val));
case UPB_DESCRIPTOR_TYPE_SINT64: case UPB_DESCRIPTOR_TYPE_SINT64:
CASE(int64_t, varint, UPB_WIRE_TYPE_VARINT, upb_zzenc_64(val)); CASE(int64_t, varint, UPB_WIRE_TYPE_VARINT, upb_zzencode_64(val));
case UPB_DESCRIPTOR_TYPE_STRING: case UPB_DESCRIPTOR_TYPE_STRING:
case UPB_DESCRIPTOR_TYPE_BYTES: { case UPB_DESCRIPTOR_TYPE_BYTES: {
upb_stringview view = *(upb_stringview*)field_mem; upb_stringview view = *(upb_stringview*)field_mem;

Loading…
Cancel
Save