diff options
author | Joshua Haberman <joshua@reverberate.org> | 2010-07-10 14:37:02 -0700 |
---|---|---|
committer | Joshua Haberman <joshua@reverberate.org> | 2010-07-10 14:37:02 -0700 |
commit | 67b16cbe5c55d00d7e576cdf479392f3a0e927a5 (patch) | |
tree | 9d40b4d04c2a6980fd6e2125f723cec8f0ac1cb5 | |
parent | 2ef013126c682a44d15554ea7a04144fc9a10fed (diff) |
Basic test_def links and passes no-op test!
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | core/upb_def.c | 42 | ||||
-rw-r--r-- | core/upb_def.h | 6 | ||||
-rw-r--r-- | core/upb_stream_vtbl.h | 51 | ||||
-rw-r--r-- | stream/upb_decoder.c | 1 |
5 files changed, 78 insertions, 30 deletions
@@ -102,14 +102,16 @@ VALGRIND=valgrind --leak-check=full --error-exitcode=1 #VALGRIND= test: tests @echo Running all tests under valgrind. + @set -e # Abort on error. # Needs to be rewritten to separate the benchmark. # valgrind --error-exitcode=1 ./tests/test_table @for test in tests/*; do \ if [ -x ./$$test ] ; then \ - echo $(VALGRIND) ./$$test: \\c; \ - $(VALGRIND) ./$$test; \ + echo !!! $(VALGRIND) ./$$test; \ + $(VALGRIND) ./$$test || exit 1; \ fi \ - done; + done; \ + echo "All tests passed!" tests/t.test_vs_proto2.googlemessage1 \ tests/t.test_vs_proto2.googlemessage2: \ diff --git a/core/upb_def.c b/core/upb_def.c index 1f57c70..cc4fd80 100644 --- a/core/upb_def.c +++ b/core/upb_def.c @@ -764,7 +764,6 @@ static void upb_free_symtab(upb_strtable *t) void _upb_symtab_free(upb_symtab *s) { upb_free_symtab(&s->symtab); - upb_free_symtab(&s->psymtab); upb_rwlock_destroy(&s->lock); free(s); } @@ -932,30 +931,30 @@ static upb_fielddef *upb_baredecoder_getdef(upb_baredecoder *d) static bool upb_baredecoder_getval(upb_baredecoder *d, upb_valueptr val) { - if(d->wire_type == UPB_WIRE_TYPE_DELIMITED) { - d->str = upb_string_tryrecycle(d->str); - upb_string_substr(d->str, d->input, d->offset, d->delimited_len); - } else { - switch(d->wire_type) { - case UPB_WIRE_TYPE_VARINT: - *val.uint64 = upb_baredecoder_readv64(d); - break; - case UPB_WIRE_TYPE_32BIT_VARINT: - *val.uint32 = upb_baredecoder_readv32(d); - break; - case UPB_WIRE_TYPE_64BIT: - *val.uint64 = upb_baredecoder_readf64(d); - break; - case UPB_WIRE_TYPE_32BIT: - *val.uint32 = upb_baredecoder_readf32(d); - break; - default: - assert(false); - } + switch(d->wire_type) { + case UPB_WIRE_TYPE_VARINT: + *val.uint64 = upb_baredecoder_readv64(d); + break; + case UPB_WIRE_TYPE_32BIT_VARINT: + *val.uint32 = upb_baredecoder_readv32(d); + break; + case UPB_WIRE_TYPE_64BIT: + *val.uint64 = upb_baredecoder_readf64(d); + break; + case UPB_WIRE_TYPE_32BIT: + *val.uint32 = upb_baredecoder_readf32(d); + break; + default: + assert(false); } return true; } +static bool upb_baredecoder_getstr(upb_baredecoder *d, upb_string *str) { + upb_string_substr(str, d->input, d->offset, d->delimited_len); + return true; +} + static bool upb_baredecoder_skipval(upb_baredecoder *d) { upb_value val; @@ -977,6 +976,7 @@ static bool upb_baredecoder_endmsg(upb_baredecoder *d) static upb_src_vtable upb_baredecoder_src_vtbl = { (upb_src_getdef_fptr)&upb_baredecoder_getdef, (upb_src_getval_fptr)&upb_baredecoder_getval, + (upb_src_getstr_fptr)&upb_baredecoder_getstr, (upb_src_skipval_fptr)&upb_baredecoder_skipval, (upb_src_startmsg_fptr)&upb_baredecoder_startmsg, (upb_src_endmsg_fptr)&upb_baredecoder_endmsg, diff --git a/core/upb_def.h b/core/upb_def.h index c297e83..5c8c11e 100644 --- a/core/upb_def.h +++ b/core/upb_def.h @@ -207,11 +207,7 @@ bool upb_enum_done(upb_enum_iter *iter); typedef struct { upb_atomic_refcount_t refcount; upb_rwlock_t lock; // Protects all members except the refcount. - upb_msgdef *fds_msgdef; // In psymtab, ptr here for convenience. - - // Our symbol tables; we own refs to the defs therein. - upb_strtable symtab; // The main symbol table. - upb_strtable psymtab; // Private symbols, for internal use. + upb_strtable symtab; // The symbol table. } upb_symtab; // Initializes a upb_symtab. Contexts are not freed explicitly, but unref'd diff --git a/core/upb_stream_vtbl.h b/core/upb_stream_vtbl.h index 0ec45d2..52172d2 100644 --- a/core/upb_stream_vtbl.h +++ b/core/upb_stream_vtbl.h @@ -27,28 +27,35 @@ struct upb_bytesink; typedef struct upb_bytesink upb_bytesink; // Typedefs for function pointers to all of the virtual functions. -typedef struct _upb_fielddef (*upb_src_getdef_fptr)(upb_src *src); + +// upb_src. +typedef struct _upb_fielddef *(*upb_src_getdef_fptr)(upb_src *src); typedef bool (*upb_src_getval_fptr)(upb_src *src, upb_valueptr val); +typedef bool (*upb_src_getstr_fptr)(upb_src *src, upb_string *str); typedef bool (*upb_src_skipval_fptr)(upb_src *src); typedef bool (*upb_src_startmsg_fptr)(upb_src *src); typedef bool (*upb_src_endmsg_fptr)(upb_src *src); +// upb_sink. typedef bool (*upb_sink_putdef_fptr)(upb_sink *sink, struct _upb_fielddef *def); typedef bool (*upb_sink_putval_fptr)(upb_sink *sink, upb_value val); typedef bool (*upb_sink_startmsg_fptr)(upb_sink *sink); typedef bool (*upb_sink_endmsg_fptr)(upb_sink *sink); +// upb_bytesrc. typedef upb_string *(*upb_bytesrc_get_fptr)(upb_bytesrc *src); typedef void (*upb_bytesrc_recycle_fptr)(upb_bytesrc *src, upb_string *str); typedef bool (*upb_bytesrc_append_fptr)( upb_bytesrc *src, upb_string *str, upb_strlen_t len); +// upb_bytesink. typedef int32_t (*upb_bytesink_put_fptr)(upb_bytesink *sink, upb_string *str); // Vtables for the above interfaces. typedef struct { upb_src_getdef_fptr getdef; upb_src_getval_fptr getval; + upb_src_getstr_fptr getstr; upb_src_skipval_fptr skipval; upb_src_startmsg_fptr startmsg; upb_src_endmsg_fptr endmsg; @@ -86,6 +93,48 @@ INLINE void upb_src_init(upb_src *s, upb_src_vtable *vtbl) { #endif } +// Implementation of virtual function dispatch. +INLINE struct _upb_fielddef *upb_src_getdef(upb_src *src) { + return src->vtbl->getdef(src); +} +INLINE bool upb_src_getval(upb_src *src, upb_valueptr val) { + return src->vtbl->getval(src, val); +} +INLINE bool upb_src_getstr(upb_src *src, upb_string *str) { + return src->vtbl->getstr(src, str); +} +INLINE bool upb_src_skipval(upb_src *src) { return src->vtbl->skipval(src); } +INLINE bool upb_src_startmsg(upb_src *src) { return src->vtbl->startmsg(src); } +INLINE bool upb_src_endmsg(upb_src *src) { return src->vtbl->endmsg(src); } + +// Implementation of type-specific upb_src accessors. If we encounter a upb_src +// where these can be implemented directly in a measurably more efficient way, +// we can make these part of the vtable also. +// +// For <64-bit types we have to use a temporary to accommodate baredecoder, +// which does not know the actual width of the type. +INLINE bool upb_src_getbool(upb_src *src, bool *_bool) { + upb_value val; + bool ret = upb_src_getval(src, upb_value_addrof(&val)); + *_bool = val._bool; + return ret; +} + +INLINE bool upb_src_getint32(upb_src *src, int32_t *i32) { + upb_value val; + bool ret = upb_src_getval(src, upb_value_addrof(&val)); + *i32 = val.int32; + return ret; +} + +// TODO. +bool upb_src_getint32(upb_src *src, int32_t *val); +bool upb_src_getint64(upb_src *src, int64_t *val); +bool upb_src_getuint32(upb_src *src, uint32_t *val); +bool upb_src_getuint64(upb_src *src, uint64_t *val); +bool upb_src_getfloat(upb_src *src, float *val); +bool upb_src_getdouble(upb_src *src, double *val); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/stream/upb_decoder.c b/stream/upb_decoder.c index e3fdc49..52fc72b 100644 --- a/stream/upb_decoder.c +++ b/stream/upb_decoder.c @@ -536,6 +536,7 @@ static bool upb_decoder_skipgroup(upb_decoder *d) upb_src_vtable upb_decoder_src_vtbl = { (upb_src_getdef_fptr)&upb_decoder_getdef, (upb_src_getval_fptr)&upb_decoder_getval, + (upb_src_getstr_fptr)&upb_decoder_getstr, (upb_src_skipval_fptr)&upb_decoder_skipval, (upb_src_startmsg_fptr)&upb_decoder_startmsg, (upb_src_endmsg_fptr)&upb_decoder_endmsg, |