Skip to content

Commit 6ec98ee

Browse files
committed
Add error codes to all things
1 parent c5862d6 commit 6ec98ee

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

src/generic/stage2/json_iterator.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
9696
}
9797

9898
switch (*value) {
99-
case '{': if (peek_next_char() == '}') { advance(); visitor.empty_object(*this); break; } goto object_begin;
100-
case '[': if (peek_next_char() == ']') { advance(); visitor.empty_array(*this); break; } goto array_begin;
99+
case '{': if (peek_next_char() == '}') { advance(); SIMDJSON_TRY( visitor.empty_object(*this) ); break; } goto object_begin;
100+
case '[': if (peek_next_char() == ']') { advance(); SIMDJSON_TRY( visitor.empty_array(*this) ); break; } goto array_begin;
101101
default: SIMDJSON_TRY( visitor.root_primitive(*this, value) ); break;
102102
}
103103
}
@@ -114,7 +114,7 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
114114
{
115115
auto key = advance();
116116
if (*key != '"') { log_error("Object does not start with a key"); return TAPE_ERROR; }
117-
visitor.increment_count(*this);
117+
SIMDJSON_TRY( visitor.increment_count(*this) );
118118
SIMDJSON_TRY( visitor.key(*this, key) );
119119
}
120120

@@ -123,16 +123,16 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
123123
{
124124
auto value = advance();
125125
switch (*value) {
126-
case '{': if (peek_next_char() == '}') { advance(); visitor.empty_object(*this); break; } goto object_begin;
127-
case '[': if (peek_next_char() == ']') { advance(); visitor.empty_array(*this); break; } goto array_begin;
126+
case '{': if (peek_next_char() == '}') { advance(); SIMDJSON_TRY( visitor.empty_object(*this) ); break; } goto object_begin;
127+
case '[': if (peek_next_char() == ']') { advance(); SIMDJSON_TRY( visitor.empty_array(*this) ); break; } goto array_begin;
128128
default: SIMDJSON_TRY( visitor.primitive(*this, value) ); break;
129129
}
130130
}
131131

132132
object_continue:
133133
switch (*advance()) {
134134
case ',':
135-
visitor.increment_count(*this);
135+
SIMDJSON_TRY( visitor.increment_count(*this) );
136136
{
137137
auto key = advance();
138138
if (simdjson_unlikely( *key != '"' )) { log_error("Key string missing at beginning of field in object"); return TAPE_ERROR; }
@@ -156,21 +156,21 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
156156
depth++;
157157
if (depth >= dom_parser.max_depth()) { log_error("Exceeded max depth!"); return DEPTH_ERROR; }
158158
SIMDJSON_TRY( visitor.start_array(*this) );
159-
visitor.increment_count(*this);
159+
SIMDJSON_TRY( visitor.increment_count(*this) );
160160

161161
array_value:
162162
{
163163
auto value = advance();
164164
switch (*value) {
165-
case '{': if (peek_next_char() == '}') { advance(); visitor.empty_object(*this); break; } goto object_begin;
166-
case '[': if (peek_next_char() == ']') { advance(); visitor.empty_array(*this); break; } goto array_begin;
165+
case '{': if (peek_next_char() == '}') { advance(); SIMDJSON_TRY( visitor.empty_object(*this) ); break; } goto object_begin;
166+
case '[': if (peek_next_char() == ']') { advance(); SIMDJSON_TRY( visitor.empty_array(*this) ); break; } goto array_begin;
167167
default: SIMDJSON_TRY( visitor.primitive(*this, value) ); break;
168168
}
169169
}
170170

171171
array_continue:
172172
switch (*advance()) {
173-
case ',': visitor.increment_count(*this); goto array_value;
173+
case ',': SIMDJSON_TRY( visitor.increment_count(*this) ); goto array_value;
174174
case ']': SIMDJSON_TRY( visitor.end_array(*this) ); goto scope_end;
175175
default: log_error("Missing comma between array values"); return TAPE_ERROR;
176176
}

src/generic/stage2/tape_builder.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct tape_builder {
1717
return iter.walk_document<STREAMING>(builder);
1818
}
1919

20-
simdjson_really_inline error_code root_primitive(json_iterator &iter, const uint8_t *value) {
20+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code root_primitive(json_iterator &iter, const uint8_t *value) {
2121
switch (*value) {
2222
case '"': return parse_string(iter, value);
2323
case 't': return parse_root_true_atom(iter, value);
@@ -32,7 +32,7 @@ struct tape_builder {
3232
return TAPE_ERROR;
3333
}
3434
}
35-
simdjson_really_inline error_code primitive(json_iterator &iter, const uint8_t *value) {
35+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code primitive(json_iterator &iter, const uint8_t *value) {
3636
switch (*value) {
3737
case '"': return parse_string(iter, value);
3838
case 't': return parse_true_atom(iter, value);
@@ -47,13 +47,13 @@ struct tape_builder {
4747
return TAPE_ERROR;
4848
}
4949
}
50-
simdjson_really_inline void empty_object(json_iterator &iter) {
50+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code empty_object(json_iterator &iter) {
5151
iter.log_value("empty object");
52-
empty_container(iter, internal::tape_type::START_OBJECT, internal::tape_type::END_OBJECT);
52+
return empty_container(iter, internal::tape_type::START_OBJECT, internal::tape_type::END_OBJECT);
5353
}
54-
simdjson_really_inline void empty_array(json_iterator &iter) {
54+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code empty_array(json_iterator &iter) {
5555
iter.log_value("empty array");
56-
empty_container(iter, internal::tape_type::START_ARRAY, internal::tape_type::END_ARRAY);
56+
return empty_container(iter, internal::tape_type::START_ARRAY, internal::tape_type::END_ARRAY);
5757
}
5858

5959
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code start_document(json_iterator &iter) {
@@ -95,8 +95,9 @@ struct tape_builder {
9595
}
9696

9797
// increment_count increments the count of keys in an object or values in an array.
98-
simdjson_really_inline void increment_count(json_iterator &iter) {
98+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code increment_count(json_iterator &iter) {
9999
iter.dom_parser.open_containers[iter.depth].count++; // we have a key value pair in the object at parser.dom_parser.depth - 1
100+
return SUCCESS;
100101
}
101102
simdjson_really_inline bool in_array(json_iterator &iter) noexcept {
102103
return iter.dom_parser.is_array[iter.depth];
@@ -128,7 +129,7 @@ struct tape_builder {
128129
return SUCCESS;
129130
}
130131

131-
simdjson_really_inline error_code parse_root_number(json_iterator &iter, const uint8_t *value) {
132+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code parse_root_number(json_iterator &iter, const uint8_t *value) {
132133
//
133134
// We need to make a copy to make sure that the string is space terminated.
134135
// This is not about padding the input, which should already padded up
@@ -201,10 +202,11 @@ struct tape_builder {
201202
return uint32_t(tape.next_tape_loc - iter.dom_parser.doc->tape.get());
202203
}
203204

204-
simdjson_really_inline void empty_container(json_iterator &iter, internal::tape_type start, internal::tape_type end) {
205+
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code empty_container(json_iterator &iter, internal::tape_type start, internal::tape_type end) {
205206
auto start_index = next_tape_index(iter);
206207
tape.append(start_index+2, start);
207208
tape.append(start_index, end);
209+
return SUCCESS;
208210
}
209211

210212
simdjson_really_inline void start_container(json_iterator &iter) {

0 commit comments

Comments
 (0)