Auto-generate files after cl/696138522

pull/19246/head
Protobuf Team Bot 5 months ago
parent 890145d254
commit aec1aeb76e
  1. 47
      php/ext/google/protobuf/php-upb.c
  2. 1560
      php/ext/google/protobuf/php-upb.h
  3. 47
      ruby/ext/google/protobuf_c/ruby-upb.c
  4. 1560
      ruby/ext/google/protobuf_c/ruby-upb.h

@ -530,6 +530,7 @@ typedef struct {
upb_Arena* arena; /* TODO: should we have a tmp arena for tmp data? */ upb_Arena* arena; /* TODO: should we have a tmp arena for tmp data? */
const upb_DefPool* symtab; const upb_DefPool* symtab;
int depth; int depth;
int result;
upb_Status* status; upb_Status* status;
jmp_buf err; jmp_buf err;
int line; int line;
@ -1159,6 +1160,16 @@ static int64_t jsondec_strtoint64(jsondec* d, upb_StringView str) {
return ret; return ret;
} }
static void jsondec_checkempty(jsondec* d, upb_StringView str,
const upb_FieldDef* f) {
if (str.size != 0) return;
d->result = kUpb_JsonDecodeResult_OkWithEmptyStringNumerics;
upb_Status_SetErrorFormat(d->status,
"Empty string is not a valid number (field: %s). "
"This will be an error in a future version.",
upb_FieldDef_FullName(f));
}
/* Primitive value types ******************************************************/ /* Primitive value types ******************************************************/
/* Parse INT32 or INT64 value. */ /* Parse INT32 or INT64 value. */
@ -1180,6 +1191,7 @@ static upb_MessageValue jsondec_int(jsondec* d, const upb_FieldDef* f) {
} }
case JD_STRING: { case JD_STRING: {
upb_StringView str = jsondec_string(d); upb_StringView str = jsondec_string(d);
jsondec_checkempty(d, str, f);
val.int64_val = jsondec_strtoint64(d, str); val.int64_val = jsondec_strtoint64(d, str);
break; break;
} }
@ -1217,6 +1229,7 @@ static upb_MessageValue jsondec_uint(jsondec* d, const upb_FieldDef* f) {
} }
case JD_STRING: { case JD_STRING: {
upb_StringView str = jsondec_string(d); upb_StringView str = jsondec_string(d);
jsondec_checkempty(d, str, f);
val.uint64_val = jsondec_strtouint64(d, str); val.uint64_val = jsondec_strtouint64(d, str);
break; break;
} }
@ -1245,14 +1258,26 @@ static upb_MessageValue jsondec_double(jsondec* d, const upb_FieldDef* f) {
break; break;
case JD_STRING: case JD_STRING:
str = jsondec_string(d); str = jsondec_string(d);
if (jsondec_streql(str, "NaN")) { if (str.size == 0) {
jsondec_checkempty(d, str, f);
val.double_val = 0.0;
} else if (jsondec_streql(str, "NaN")) {
val.double_val = NAN; val.double_val = NAN;
} else if (jsondec_streql(str, "Infinity")) { } else if (jsondec_streql(str, "Infinity")) {
val.double_val = INFINITY; val.double_val = INFINITY;
} else if (jsondec_streql(str, "-Infinity")) { } else if (jsondec_streql(str, "-Infinity")) {
val.double_val = -INFINITY; val.double_val = -INFINITY;
} else { } else {
val.double_val = strtod(str.data, NULL); char* end;
val.double_val = strtod(str.data, &end);
if (end != str.data + str.size) {
d->result = kUpb_JsonDecodeResult_OkWithEmptyStringNumerics;
upb_Status_SetErrorFormat(
d->status,
"Non-number characters in quoted number (field: %s). "
"This will be an error in a future version.",
upb_FieldDef_FullName(f));
}
} }
break; break;
default: default:
@ -1994,10 +2019,10 @@ static void jsondec_wellknown(jsondec* d, upb_Message* msg,
} }
} }
static bool upb_JsonDecoder_Decode(jsondec* const d, upb_Message* const msg, static int upb_JsonDecoder_Decode(jsondec* const d, upb_Message* const msg,
const upb_MessageDef* const m) { const upb_MessageDef* const m) {
UPB_ASSERT(!upb_Message_IsFrozen(msg)); UPB_ASSERT(!upb_Message_IsFrozen(msg));
if (UPB_SETJMP(d->err)) return false; if (UPB_SETJMP(d->err)) return kUpb_JsonDecodeResult_Error;
jsondec_tomsg(d, msg, m); jsondec_tomsg(d, msg, m);
@ -2006,16 +2031,19 @@ static bool upb_JsonDecoder_Decode(jsondec* const d, upb_Message* const msg,
jsondec_consumews(d); jsondec_consumews(d);
if (d->ptr == d->end) { if (d->ptr == d->end) {
return true; return d->result;
} else { } else {
jsondec_seterrmsg(d, "unexpected trailing characters"); jsondec_seterrmsg(d, "unexpected trailing characters");
return false; return kUpb_JsonDecodeResult_Error;
} }
} }
bool upb_JsonDecode(const char* buf, size_t size, upb_Message* msg, int upb_JsonDecodeDetectingNonconformance(const char* buf, size_t size,
const upb_MessageDef* m, const upb_DefPool* symtab, upb_Message* msg,
int options, upb_Arena* arena, upb_Status* status) { const upb_MessageDef* m,
const upb_DefPool* symtab,
int options, upb_Arena* arena,
upb_Status* status) {
UPB_ASSERT(!upb_Message_IsFrozen(msg)); UPB_ASSERT(!upb_Message_IsFrozen(msg));
jsondec d; jsondec d;
@ -2028,6 +2056,7 @@ bool upb_JsonDecode(const char* buf, size_t size, upb_Message* msg,
d.status = status; d.status = status;
d.options = options; d.options = options;
d.depth = 64; d.depth = 64;
d.result = kUpb_JsonDecodeResult_Ok;
d.line = 1; d.line = 1;
d.line_begin = d.ptr; d.line_begin = d.ptr;
d.debug_field = NULL; d.debug_field = NULL;

File diff suppressed because it is too large Load Diff

@ -530,6 +530,7 @@ typedef struct {
upb_Arena* arena; /* TODO: should we have a tmp arena for tmp data? */ upb_Arena* arena; /* TODO: should we have a tmp arena for tmp data? */
const upb_DefPool* symtab; const upb_DefPool* symtab;
int depth; int depth;
int result;
upb_Status* status; upb_Status* status;
jmp_buf err; jmp_buf err;
int line; int line;
@ -1159,6 +1160,16 @@ static int64_t jsondec_strtoint64(jsondec* d, upb_StringView str) {
return ret; return ret;
} }
static void jsondec_checkempty(jsondec* d, upb_StringView str,
const upb_FieldDef* f) {
if (str.size != 0) return;
d->result = kUpb_JsonDecodeResult_OkWithEmptyStringNumerics;
upb_Status_SetErrorFormat(d->status,
"Empty string is not a valid number (field: %s). "
"This will be an error in a future version.",
upb_FieldDef_FullName(f));
}
/* Primitive value types ******************************************************/ /* Primitive value types ******************************************************/
/* Parse INT32 or INT64 value. */ /* Parse INT32 or INT64 value. */
@ -1180,6 +1191,7 @@ static upb_MessageValue jsondec_int(jsondec* d, const upb_FieldDef* f) {
} }
case JD_STRING: { case JD_STRING: {
upb_StringView str = jsondec_string(d); upb_StringView str = jsondec_string(d);
jsondec_checkempty(d, str, f);
val.int64_val = jsondec_strtoint64(d, str); val.int64_val = jsondec_strtoint64(d, str);
break; break;
} }
@ -1217,6 +1229,7 @@ static upb_MessageValue jsondec_uint(jsondec* d, const upb_FieldDef* f) {
} }
case JD_STRING: { case JD_STRING: {
upb_StringView str = jsondec_string(d); upb_StringView str = jsondec_string(d);
jsondec_checkempty(d, str, f);
val.uint64_val = jsondec_strtouint64(d, str); val.uint64_val = jsondec_strtouint64(d, str);
break; break;
} }
@ -1245,14 +1258,26 @@ static upb_MessageValue jsondec_double(jsondec* d, const upb_FieldDef* f) {
break; break;
case JD_STRING: case JD_STRING:
str = jsondec_string(d); str = jsondec_string(d);
if (jsondec_streql(str, "NaN")) { if (str.size == 0) {
jsondec_checkempty(d, str, f);
val.double_val = 0.0;
} else if (jsondec_streql(str, "NaN")) {
val.double_val = NAN; val.double_val = NAN;
} else if (jsondec_streql(str, "Infinity")) { } else if (jsondec_streql(str, "Infinity")) {
val.double_val = INFINITY; val.double_val = INFINITY;
} else if (jsondec_streql(str, "-Infinity")) { } else if (jsondec_streql(str, "-Infinity")) {
val.double_val = -INFINITY; val.double_val = -INFINITY;
} else { } else {
val.double_val = strtod(str.data, NULL); char* end;
val.double_val = strtod(str.data, &end);
if (end != str.data + str.size) {
d->result = kUpb_JsonDecodeResult_OkWithEmptyStringNumerics;
upb_Status_SetErrorFormat(
d->status,
"Non-number characters in quoted number (field: %s). "
"This will be an error in a future version.",
upb_FieldDef_FullName(f));
}
} }
break; break;
default: default:
@ -1994,10 +2019,10 @@ static void jsondec_wellknown(jsondec* d, upb_Message* msg,
} }
} }
static bool upb_JsonDecoder_Decode(jsondec* const d, upb_Message* const msg, static int upb_JsonDecoder_Decode(jsondec* const d, upb_Message* const msg,
const upb_MessageDef* const m) { const upb_MessageDef* const m) {
UPB_ASSERT(!upb_Message_IsFrozen(msg)); UPB_ASSERT(!upb_Message_IsFrozen(msg));
if (UPB_SETJMP(d->err)) return false; if (UPB_SETJMP(d->err)) return kUpb_JsonDecodeResult_Error;
jsondec_tomsg(d, msg, m); jsondec_tomsg(d, msg, m);
@ -2006,16 +2031,19 @@ static bool upb_JsonDecoder_Decode(jsondec* const d, upb_Message* const msg,
jsondec_consumews(d); jsondec_consumews(d);
if (d->ptr == d->end) { if (d->ptr == d->end) {
return true; return d->result;
} else { } else {
jsondec_seterrmsg(d, "unexpected trailing characters"); jsondec_seterrmsg(d, "unexpected trailing characters");
return false; return kUpb_JsonDecodeResult_Error;
} }
} }
bool upb_JsonDecode(const char* buf, size_t size, upb_Message* msg, int upb_JsonDecodeDetectingNonconformance(const char* buf, size_t size,
const upb_MessageDef* m, const upb_DefPool* symtab, upb_Message* msg,
int options, upb_Arena* arena, upb_Status* status) { const upb_MessageDef* m,
const upb_DefPool* symtab,
int options, upb_Arena* arena,
upb_Status* status) {
UPB_ASSERT(!upb_Message_IsFrozen(msg)); UPB_ASSERT(!upb_Message_IsFrozen(msg));
jsondec d; jsondec d;
@ -2028,6 +2056,7 @@ bool upb_JsonDecode(const char* buf, size_t size, upb_Message* msg,
d.status = status; d.status = status;
d.options = options; d.options = options;
d.depth = 64; d.depth = 64;
d.result = kUpb_JsonDecodeResult_Ok;
d.line = 1; d.line = 1;
d.line_begin = d.ptr; d.line_begin = d.ptr;
d.debug_field = NULL; d.debug_field = NULL;

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save