summaryrefslogtreecommitdiff
path: root/upb/bindings/lua
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2015-05-08 17:30:22 -0700
committerJoshua Haberman <jhaberman@gmail.com>2015-05-08 17:30:22 -0700
commitccc0fd0dbbcebb43f4d85d7df1439e1fc7993bf8 (patch)
treeda3cbc97eed1eb70af5e0f3a687ff37ad239d119 /upb/bindings/lua
parentbd7ea8c6f1854aa37b7792c6f23334ffc0fd94ff (diff)
parent838009ba2b8ea1e99061c66e0fbd9cb53a96ec20 (diff)
Merge pull request #18 from haberman/google-internal
Sync from Google-internal development.
Diffstat (limited to 'upb/bindings/lua')
-rw-r--r--upb/bindings/lua/upb.c2
-rw-r--r--upb/bindings/lua/upb/pb.c21
2 files changed, 12 insertions, 11 deletions
diff --git a/upb/bindings/lua/upb.c b/upb/bindings/lua/upb.c
index 5ad0235..b35af24 100644
--- a/upb/bindings/lua/upb.c
+++ b/upb/bindings/lua/upb.c
@@ -1358,7 +1358,7 @@ static size_t align_up(size_t val, size_t align) {
// If we always read/write as a consistent type to each value, this shouldn't
// violate aliasing.
-#define DEREF(msg, ofs, type) *(type*)(&msg->data[ofs])
+#define DEREF(msg, ofs, type) *(type*)((char*)msg + sizeof(lupb_msg) + ofs)
lupb_msg *lupb_msg_check(lua_State *L, int narg) {
lupb_msg *msg = luaL_checkudata(L, narg, LUPB_MSG);
diff --git a/upb/bindings/lua/upb/pb.c b/upb/bindings/lua/upb/pb.c
index c9f1f47..920648f 100644
--- a/upb/bindings/lua/upb/pb.c
+++ b/upb/bindings/lua/upb/pb.c
@@ -61,19 +61,20 @@ static int lupb_pbdecodermethod_parse(lua_State *L) {
// Handlers need this.
lua_getuservalue(L, -1);
- upb_pbdecoder decoder;
upb_status status = UPB_STATUS_INIT;
- upb_pbdecoder_init(&decoder, method, &status);
+ upb_env env;
+ upb_env_init(&env);
+ upb_env_reporterrorsto(&env, &status);
upb_sink sink;
upb_sink_reset(&sink, handlers, msg);
- upb_pbdecoder_resetoutput(&decoder, &sink);
- upb_bufsrc_putbuf(pb, len, upb_pbdecoder_input(&decoder));
- // TODO: Our need to call uninit isn't longjmp-safe; what if the decode
- // triggers a Lua error? uninit is only needed if the decoder
- // dynamically-allocated a growing stack -- ditch this feature and live with
- // the compile-time limit? Or have a custom allocation function that
- // allocates Lua GC-rooted memory?
- upb_pbdecoder_uninit(&decoder);
+ upb_pbdecoder *decoder = upb_pbdecoder_create(&env, method, &sink);
+ upb_bufsrc_putbuf(pb, len, upb_pbdecoder_input(decoder));
+
+ // TODO: This won't get called in the error case, which longjmp's across us.
+ // This will cause the memory to leak. To remedy this, we should make the
+ // upb_env wrapped in a userdata that guarantees this will get called.
+ upb_env_uninit(&env);
+
lupb_checkstatus(L, &status);
lua_pop(L, 1); // Uservalue.
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback