summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2011-01-24 21:15:44 -0800
committerJoshua Haberman <joshua@reverberate.org>2011-01-24 21:15:44 -0800
commit93381f1411def0dba5677b71cd4df859d99777f3 (patch)
tree2de4fd9d3e377fe5469028ac057e6ffa7df40f50 /core
parentfe659c8c93c464fcbcfb5739935a2e4341d01fd4 (diff)
Decoder compiles again! But probably doesn't work.
Diffstat (limited to 'core')
-rw-r--r--core/upb.c2
-rw-r--r--core/upb.h2
-rw-r--r--core/upb_def.c2
-rw-r--r--core/upb_stream_vtbl.h26
4 files changed, 14 insertions, 18 deletions
diff --git a/core/upb.c b/core/upb.c
index da2a0f0..ff2d47e 100644
--- a/core/upb.c
+++ b/core/upb.c
@@ -18,7 +18,7 @@
(1 << wire_type) | (allows_delimited << UPB_WIRE_TYPE_DELIMITED), \
#ctype},
-upb_type_info upb_types[] = {
+const upb_type_info upb_types[] = {
{0, 0, 0, 0, ""}, // There is no type 0.
TYPE_INFO(UPB_WIRE_TYPE_64BIT, double, 1) // DOUBLE
TYPE_INFO(UPB_WIRE_TYPE_32BIT, float, 1) // FLOAT
diff --git a/core/upb.h b/core/upb.h
index d394a08..7b228a0 100644
--- a/core/upb.h
+++ b/core/upb.h
@@ -101,7 +101,7 @@ typedef struct {
} upb_type_info;
// A static array of info about all of the field types, indexed by type number.
-extern upb_type_info upb_types[];
+extern const upb_type_info upb_types[];
// The number of a field, eg. "optional string foo = 3".
typedef int32_t upb_field_number_t;
diff --git a/core/upb_def.c b/core/upb_def.c
index c21843e..2eda89f 100644
--- a/core/upb_def.c
+++ b/core/upb_def.c
@@ -717,7 +717,7 @@ static upb_flow_t upb_msgdef_endmsg(void *_b) {
size_t max_align = 0;
for (int i = 0; i < n; i++) {
upb_fielddef *f = sorted_fields[i];
- upb_type_info *type_info = &upb_types[f->type];
+ const upb_type_info *type_info = &upb_types[f->type];
// This identifies the set bit. When we implement is_initialized (a
// general check about whether all required bits are set) we will probably
diff --git a/core/upb_stream_vtbl.h b/core/upb_stream_vtbl.h
index fd71b2d..ddefba9 100644
--- a/core/upb_stream_vtbl.h
+++ b/core/upb_stream_vtbl.h
@@ -27,9 +27,9 @@ typedef void (*upb_src_run_fptr)(upb_src *src, upb_status *status);
// upb_bytesrc.
typedef upb_strlen_t (*upb_bytesrc_read_fptr)(
- upb_bytesrc *src, void *buf, upb_strlen_t count);
+ upb_bytesrc *src, void *buf, upb_strlen_t count, upb_status *status);
typedef bool (*upb_bytesrc_getstr_fptr)(
- upb_bytesrc *src, upb_string *str, upb_strlen_t count);
+ upb_bytesrc *src, upb_string *str, upb_status *status);
// upb_bytesink.
typedef upb_strlen_t (*upb_bytesink_write_fptr)(
@@ -102,35 +102,31 @@ INLINE void upb_src_run(upb_src *src, upb_status *status) {
// upb_bytesrc
INLINE upb_strlen_t upb_bytesrc_read(upb_bytesrc *src, void *buf,
- upb_strlen_t count) {
- return src->vtbl->read(src, buf, count);
+ upb_strlen_t count, upb_status *status) {
+ return src->vtbl->read(src, buf, count, status);
}
INLINE bool upb_bytesrc_getstr(upb_bytesrc *src, upb_string *str,
- upb_strlen_t count) {
- return src->vtbl->getstr(src, str, count);
+ upb_status *status) {
+ return src->vtbl->getstr(src, str, status);
}
INLINE bool upb_bytesrc_getfullstr(upb_bytesrc *src, upb_string *str,
upb_status *status) {
// We start with a getstr, because that could possibly alias data instead of
// copying.
- if (!upb_bytesrc_getstr(src, str, UPB_STRLEN_MAX)) goto error;
+ if (!upb_bytesrc_getstr(src, str, status)) return false;
// Trade-off between number of read calls and amount of overallocation.
const size_t bufsize = 4096;
- while (!upb_bytesrc_eof(src)) {
+ do {
upb_strlen_t len = upb_string_len(str);
char *buf = upb_string_getrwbuf(str, len + bufsize);
- upb_strlen_t read = upb_bytesrc_read(src, buf + len, bufsize);
- if (read < 0) goto error;
+ upb_strlen_t read = upb_bytesrc_read(src, buf + len, bufsize, status);
+ if (read < 0) return false;
// Resize to proper size.
upb_string_getrwbuf(str, len + read);
- }
+ } while (!status->code != UPB_EOF);
return true;
-
-error:
- upb_copyerr(status, upb_bytesrc_status(src));
- return false;
}
INLINE upb_status *upb_bytesrc_status(upb_bytesrc *src) { return &src->status; }
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback