summaryrefslogtreecommitdiff
path: root/upb
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2018-09-03 15:06:43 -0700
committerJoshua Haberman <jhaberman@gmail.com>2018-09-03 15:06:43 -0700
commit694d51f4d6cb8adf4a2f7975e5bb899327875de7 (patch)
tree29ea62eeb151c4cfc739522e19ee30dbee57a137 /upb
parent41379a7064b6488099f203521fb69ceea0f6cc15 (diff)
Changed C API to only define structs, a table, and a few minimal inline functions.
Diffstat (limited to 'upb')
-rw-r--r--upb/bindings/lua/upb/pb.c25
-rw-r--r--upb/decode.c11
-rw-r--r--upb/decode.h3
-rw-r--r--upb/encode.c8
-rw-r--r--upb/encode.h2
5 files changed, 18 insertions, 31 deletions
diff --git a/upb/bindings/lua/upb/pb.c b/upb/bindings/lua/upb/pb.c
index 466e8f7..15e8107 100644
--- a/upb/bindings/lua/upb/pb.c
+++ b/upb/bindings/lua/upb/pb.c
@@ -13,21 +13,13 @@
static int lupb_pb_decode(lua_State *L) {
size_t len;
- upb_status status = UPB_STATUS_INIT;
const upb_msglayout *layout;
upb_msg *msg = lupb_msg_checkmsg2(L, 1, &layout);
const char *pb = lua_tolstring(L, 2, &len);
upb_stringview buf = upb_stringview_make(pb, len);
- upb_env env;
-
- upb_env_init(&env);
- upb_env_reporterrorsto(&env, &status);
-
- upb_decode(buf, msg, (const void*)layout, &env);
- /* Free resources before we potentially bail on error. */
- upb_env_uninit(&env);
- lupb_checkstatus(L, &status);
+ upb_decode(buf, msg, layout);
+ /* TODO(haberman): check for error. */
return 0;
}
@@ -35,21 +27,20 @@ static int lupb_pb_decode(lua_State *L) {
static int lupb_pb_encode(lua_State *L) {
const upb_msglayout *layout;
const upb_msg *msg = lupb_msg_checkmsg2(L, 1, &layout);
- upb_env env;
+ upb_arena arena;
size_t size;
upb_status status = UPB_STATUS_INIT;
char *result;
- upb_env_init(&env);
- upb_env_reporterrorsto(&env, &status);
+ upb_arena_init(&arena);
- result = upb_encode(msg, (const void*)layout, &env, &size);
+ result = upb_encode(msg, (const void*)layout, &arena, &size);
/* Free resources before we potentially bail on error. */
- upb_env_uninit(&env);
- lupb_checkstatus(L, &status);
-
lua_pushlstring(L, result, size);
+ upb_arena_uninit(&arena);
+ /* TODO(haberman): check for error. */
+
return 1;
}
diff --git a/upb/decode.c b/upb/decode.c
index 8a29709..1e5a6bc 100644
--- a/upb/decode.c
+++ b/upb/decode.c
@@ -28,7 +28,6 @@ const uint8_t upb_desctype_to_fieldtype[] = {
/* Data pertaining to the parse. */
typedef struct {
- upb_env *env;
/* Current decoding pointer. Points to the beginning of a field until we
* have finished decoding the whole field. */
const char *ptr;
@@ -213,7 +212,7 @@ static upb_array *upb_getorcreatearr(upb_decstate *d, upb_decframe *frame,
if (!arr) {
upb_fieldtype_t type = upb_desctype_to_fieldtype[field->descriptortype];
- arr = upb_array_new(type, upb_env_arena(d->env));
+ arr = upb_array_new(type, upb_msg_arena(frame->msg));
if (!arr) {
return NULL;
}
@@ -275,7 +274,7 @@ static bool upb_decode_submsg(upb_decstate *d, upb_decframe *frame,
UPB_ASSERT(subm);
if (!submsg) {
- submsg = upb_msg_new((upb_msglayout *)subm, upb_env_arena(d->env));
+ submsg = upb_msg_new(subm, upb_msg_arena(frame->msg));
CHK(submsg);
*(void**)submsg_slot = submsg;
}
@@ -455,7 +454,7 @@ static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame,
subm = frame->m->submsgs[field->submsg_index];
UPB_ASSERT(subm);
- submsg = upb_msg_new((upb_msglayout *)subm, upb_env_arena(d->env));
+ submsg = upb_msg_new(subm, upb_msg_arena(frame->msg));
CHK(submsg);
field_mem = upb_array_add(arr, 1);
@@ -587,11 +586,9 @@ static bool upb_decode_message(upb_decstate *d, const char *limit,
return true;
}
-bool upb_decode(upb_stringview buf, void *msg, const upb_msglayout *l,
- upb_env *env) {
+bool upb_decode(upb_stringview buf, void *msg, const upb_msglayout *l) {
upb_decstate state;
state.ptr = buf.data;
- state.env = env;
return upb_decode_message(&state, buf.data + buf.size, 0, msg, l);
}
diff --git a/upb/decode.h b/upb/decode.h
index 963b399..79774ed 100644
--- a/upb/decode.h
+++ b/upb/decode.h
@@ -9,8 +9,7 @@
UPB_BEGIN_EXTERN_C
-bool upb_decode(upb_stringview buf, void *msg, const upb_msglayout *l,
- upb_env *env);
+bool upb_decode(upb_stringview buf, upb_msg *msg, const upb_msglayout *l);
UPB_END_EXTERN_C
diff --git a/upb/encode.c b/upb/encode.c
index 24d72a8..d38676d 100644
--- a/upb/encode.c
+++ b/upb/encode.c
@@ -47,7 +47,7 @@ static uint32_t upb_zzencode_32(int32_t n) { return (n << 1) ^ (n >> 31); }
static uint64_t upb_zzencode_64(int64_t n) { return (n << 1) ^ (n >> 63); }
typedef struct {
- upb_env *env;
+ upb_alloc *alloc;
char *buf, *ptr, *limit;
} upb_encstate;
@@ -62,7 +62,7 @@ static size_t upb_roundup_pow2(size_t bytes) {
static bool upb_encode_growbuffer(upb_encstate *e, size_t bytes) {
size_t old_size = e->limit - e->buf;
size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr));
- char *new_buf = upb_env_realloc(e->env, e->buf, old_size, new_size);
+ char *new_buf = upb_realloc(e->alloc, e->buf, old_size, new_size);
CHK(new_buf);
/* We want previous data at the end, realloc() put it at the beginning. */
@@ -371,10 +371,10 @@ bool upb_encode_message(upb_encstate *e, const char *msg,
return true;
}
-char *upb_encode(const void *msg, const upb_msglayout *m, upb_env *env,
+char *upb_encode(const void *msg, const upb_msglayout *m, upb_arena *arena,
size_t *size) {
upb_encstate e;
- e.env = env;
+ e.alloc = upb_arena_alloc(arena);
e.buf = NULL;
e.limit = NULL;
e.ptr = NULL;
diff --git a/upb/encode.h b/upb/encode.h
index 8f42736..1a451b0 100644
--- a/upb/encode.h
+++ b/upb/encode.h
@@ -9,7 +9,7 @@
UPB_BEGIN_EXTERN_C
-char *upb_encode(const void *msg, const upb_msglayout *l, upb_env *env,
+char *upb_encode(const void *msg, const upb_msglayout *l, upb_arena *arena,
size_t *size);
UPB_END_EXTERN_C
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback