summaryrefslogtreecommitdiff
path: root/upb/upb.c
diff options
context:
space:
mode:
authorJosh Haberman <haberman@google.com>2013-02-15 16:27:18 -0800
committerJosh Haberman <haberman@google.com>2013-02-15 16:27:18 -0800
commit7d3e2bd2c4cfd1296d1d6f996d7548de26540d41 (patch)
treeb4b35967b3322c65cfb1a32220e8718de09d85fc /upb/upb.c
parentea198bdcf947ba4bd51474bdd4f7b82b5e4cf41d (diff)
Sync with 8 months of Google-internal development.
Many things have changed and been simplified. The memory-management story for upb_def and upb_handlers is much more robust; upb_def and upb_handlers should be fairly stable interfaces now. There is still much work to do for the runtime component (upb_sink).
Diffstat (limited to 'upb/upb.c')
-rw-r--r--upb/upb.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/upb/upb.c b/upb/upb.c
index 5a00961..226fc78 100644
--- a/upb/upb.c
+++ b/upb/upb.c
@@ -29,24 +29,31 @@ void upb_status_uninit(upb_status *status) {
free(status->buf);
}
-void upb_status_seterrf(upb_status *s, const char *msg, ...) {
- s->code = UPB_ERROR;
+bool upb_ok(const upb_status *status) { return !status->error; }
+bool upb_eof(const upb_status *status) { return status->eof_; }
+
+void upb_status_seterrf(upb_status *status, const char *msg, ...) {
+ if (!status) return;
+ status->error = true;
+ status->space = NULL;
va_list args;
va_start(args, msg);
- upb_vrprintf(&s->buf, &s->bufsize, 0, msg, args);
+ upb_vrprintf(&status->buf, &status->bufsize, 0, msg, args);
va_end(args);
- s->str = s->buf;
+ status->str = status->buf;
}
void upb_status_seterrliteral(upb_status *status, const char *msg) {
+ if (!status) return;
status->error = true;
status->str = msg;
status->space = NULL;
}
void upb_status_copy(upb_status *to, const upb_status *from) {
+ if (!to) return;
to->error = from->error;
- to->eof = from->eof;
+ to->eof_ = from->eof_;
to->code = from->code;
to->space = from->space;
if (from->str == from->buf) {
@@ -78,19 +85,26 @@ const char *upb_status_getstr(const upb_status *_status) {
}
void upb_status_clear(upb_status *status) {
+ if (!status) return;
status->error = false;
- status->eof = false;
+ status->eof_ = false;
status->code = 0;
status->space = NULL;
status->str = NULL;
}
void upb_status_setcode(upb_status *status, upb_errorspace *space, int code) {
+ if (!status) return;
status->code = code;
status->space = space;
status->str = NULL;
}
+void upb_status_seteof(upb_status *status) {
+ if (!status) return;
+ status->eof_ = true;
+}
+
int upb_vrprintf(char **buf, size_t *size, size_t ofs,
const char *fmt, va_list args) {
// Try once without reallocating. We have to va_copy because we might have
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback