summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2010-07-17 18:30:53 -0700
committerJoshua Haberman <joshua@reverberate.org>2010-07-17 18:30:53 -0700
commit0fcfeab521b01160875e863575dd5b63952b1593 (patch)
treed8301bed4c0920239127b978b307d2b6bedf25d6
parentb77db146466a113bbfb9e56472bda1975f7a25a5 (diff)
Bugfixes, test_decoder successfully stream-decodes a stream!
-rw-r--r--core/upb_stream.c5
-rw-r--r--stream/upb_decoder.c39
-rw-r--r--stream/upb_textprinter.c9
3 files changed, 28 insertions, 25 deletions
diff --git a/core/upb_stream.c b/core/upb_stream.c
index e63ba00..0d47392 100644
--- a/core/upb_stream.c
+++ b/core/upb_stream.c
@@ -37,14 +37,19 @@ void upb_streamdata(upb_src *src, upb_sink *sink, upb_status *status) {
CHECKSRC(upb_src_eof(src));
if (depth == 0) break;
--depth;
+ upb_src_endmsg(src);
+ upb_sink_endmsg(sink);
}
+ upb_string_unref(str);
return;
src_err:
+ upb_string_unref(str);
upb_copyerr(status, upb_src_status(src));
return;
sink_err:
+ upb_string_unref(str);
upb_copyerr(status, upb_sink_status(sink));
return;
}
diff --git a/stream/upb_decoder.c b/stream/upb_decoder.c
index 64057c5..949ce2d 100644
--- a/stream/upb_decoder.c
+++ b/stream/upb_decoder.c
@@ -76,7 +76,7 @@ struct upb_decoder {
static upb_strlen_t upb_decoder_offset(upb_decoder *d)
{
- return d->buf_stream_offset - d->buf_offset;
+ return d->buf_stream_offset + d->buf_offset;
}
static bool upb_decoder_nextbuf(upb_decoder *d)
@@ -101,34 +101,30 @@ static bool upb_decoder_nextbuf(upb_decoder *d)
d->buf_bytesleft += upb_string_len(d->buf);
return true;
} else {
- // Error or EOF.
- if(!upb_bytesrc_eof(d->bytesrc)) {
- // Error from bytesrc.
- upb_copyerr(&d->src.status, upb_bytesrc_status(d->bytesrc));
- return false;
- } else if(d->buf_bytesleft == 0) {
- // EOF from bytesrc and we don't have any residual bytes left.
- d->src.eof = true;
- return false;
- } else {
- // No more data left from the bytesrc, but we still have residual bytes.
- return true;
- }
+ return false;
}
}
static const uint8_t *upb_decoder_getbuf_full(upb_decoder *d, uint32_t *bytes)
{
+ if(d->buf_bytesleft < UPB_MAX_ENCODED_SIZE && !upb_bytesrc_eof(d->bytesrc))
+ upb_decoder_nextbuf(d);
+
if(d->buf_bytesleft < UPB_MAX_ENCODED_SIZE) {
- // GCC is currently complaining about use of an uninitialized value if we
- // don't set this now. I think this is incorrect, but leaving this in
- // to suppress the warning for now.
- *bytes = 0;
- if(!upb_decoder_nextbuf(d)) return NULL;
+ if(upb_bytesrc_eof(d->bytesrc) && d->buf_bytesleft > 0) {
+ // We're working through the last few bytes of the buffer.
+ } else if(upb_bytesrc_eof(d->bytesrc)) {
+ // End of stream, no more bytes left.
+ assert(d->buf_bytesleft == 0);
+ d->src.eof = true;
+ return NULL;
+ } else {
+ // We are short of bytes even though the bytesrc isn't EOF; must be error.
+ upb_copyerr(&d->src.status, upb_bytesrc_status(d->bytesrc));
+ return NULL;
+ }
}
- assert(d->buf_bytesleft >= UPB_MAX_ENCODED_SIZE);
-
if(d->buf_offset >= 0) {
// Common case: the main buffer contains at least UPB_MAX_ENCODED_SIZE
// contiguous bytes, so we can read directly out of it.
@@ -467,6 +463,7 @@ bool upb_decoder_startmsg(upb_decoder *d) {
} else {
frame->end_offset = upb_decoder_offset(d) + d->delimited_len;
}
+ d->field = NULL;
return true;
}
diff --git a/stream/upb_textprinter.c b/stream/upb_textprinter.c
index 201edba..75668a3 100644
--- a/stream/upb_textprinter.c
+++ b/stream/upb_textprinter.c
@@ -23,9 +23,9 @@ struct _upb_textprinter {
static void upb_textprinter_endfield(upb_textprinter *p)
{
if(p->single_line)
- upb_bytesink_put(p->bytesink, UPB_STRLIT(' '));
+ upb_bytesink_put(p->bytesink, UPB_STRLIT(" "));
else
- upb_bytesink_put(p->bytesink, UPB_STRLIT('\n'));
+ upb_bytesink_put(p->bytesink, UPB_STRLIT("\n"));
}
static bool upb_textprinter_putval(upb_textprinter *p, upb_value val) {
@@ -86,10 +86,9 @@ static bool upb_textprinter_putdef(upb_textprinter *p, upb_fielddef *f)
static bool upb_textprinter_startmsg(upb_textprinter *p)
{
- upb_textprinter_indent(p);
upb_bytesink_put(p->bytesink, p->f->def->fqname);
upb_bytesink_put(p->bytesink, UPB_STRLIT(" {"));
- if(!p->single_line) upb_bytesink_put(p->bytesink, UPB_STRLIT('\n'));
+ if(!p->single_line) upb_bytesink_put(p->bytesink, UPB_STRLIT("\n"));
p->indent_depth++;
return upb_ok(upb_bytesink_status(p->bytesink));
}
@@ -114,10 +113,12 @@ upb_sink_vtable upb_textprinter_vtbl = {
upb_textprinter *upb_textprinter_new() {
upb_textprinter *p = malloc(sizeof(*p));
upb_sink_init(&p->sink, &upb_textprinter_vtbl);
+ p->str = NULL;
return p;
}
void upb_textprinter_free(upb_textprinter *p) {
+ upb_string_unref(p->str);
free(p);
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback