summaryrefslogtreecommitdiff
path: root/upb/bindings
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2017-07-01 15:15:52 -0700
committerJosh Haberman <jhaberman@gmail.com>2017-07-02 00:28:25 +0100
commit1b9d37a00ebae8b59773c8501d8712e1c3335302 (patch)
tree1295ee5099609f5a6c05689adfa7962ad4cdc5ab /upb/bindings
parente38098cbfc58c0e2911b2c2b2abff043de42a85b (diff)
Start migrating upb_msglayout to be suitable for generated code.
This involves: - remove upb_msglayout -> upb_msgfactory dependency. - remove upb_msglayout -> upb_msgdef dependency (in progress). - make upb_msglayout use a representation that can be statically initialized by generated code. The goal here is that upb_msglayout becomes a kind of "descriptor lite": it contains enough data to parser and serialize protobufs and manipulate a upb_msg in memory, while being far smaller and simpler than a full descriptor. It also does not include field names, which can be a benefit for applications that do not want to leak field names. Generated code can then create a upb_msglayout, and do most things without ever needing to construct full descriptors/defs if they don't want to.
Diffstat (limited to 'upb/bindings')
-rw-r--r--upb/bindings/lua/msg.c24
-rw-r--r--upb/bindings/lua/upb.h1
-rw-r--r--upb/bindings/lua/upb/pb.c2
3 files changed, 15 insertions, 12 deletions
diff --git a/upb/bindings/lua/msg.c b/upb/bindings/lua/msg.c
index 64c8e7c..c222ca5 100644
--- a/upb/bindings/lua/msg.c
+++ b/upb/bindings/lua/msg.c
@@ -189,7 +189,8 @@ typedef struct lupb_msgfactory {
upb_msgfactory *factory;
} lupb_msgfactory;
-static int lupb_msgclass_pushnew(lua_State *L, int factory, const upb_msglayout *l);
+static int lupb_msgclass_pushnew(lua_State *L, int factory,
+ const upb_msgdef *md);
/* lupb_msgfactory helpers. */
@@ -199,8 +200,6 @@ static lupb_msgfactory *lupb_msgfactory_check(lua_State *L, int narg) {
static void lupb_msgfactory_pushmsgclass(lua_State *L, int narg,
const upb_msgdef *md) {
- const lupb_msgfactory *lfactory = lupb_msgfactory_check(L, narg);
-
lupb_getuservalue(L, narg);
lua_pushlightuserdata(L, (void*)md);
lua_rawget(L, -2);
@@ -208,8 +207,7 @@ static void lupb_msgfactory_pushmsgclass(lua_State *L, int narg,
if (lua_isnil(L, -1)) {
lua_pop(L, 1);
/* TODO: verify md is in symtab? */
- lupb_msgclass_pushnew(L, narg,
- upb_msgfactory_getlayout(lfactory->factory, md));
+ lupb_msgclass_pushnew(L, narg, md);
/* Set in userval. */
lua_pushlightuserdata(L, (void*)md);
@@ -317,6 +315,10 @@ const upb_handlers *lupb_msgclass_getmergehandlers(lua_State *L, int narg) {
lmsgclass->lfactory->factory, upb_msglayout_msgdef(lmsgclass->layout));
}
+upb_msgfactory *lupb_msgclass_getfactory(const lupb_msgclass *lmsgclass) {
+ return lmsgclass->lfactory->factory;
+}
+
/**
* lupb_msgclass_typecheck()
*
@@ -360,13 +362,13 @@ static const lupb_msgclass *lupb_msgclass_getsubmsgclass(lua_State *L, int narg,
return lupb_msgclass_msgclassfor(L, narg, upb_fielddef_msgsubdef(f));
}
-static int lupb_msgclass_pushnew(lua_State *L, int factory, const upb_msglayout *l) {
+static int lupb_msgclass_pushnew(lua_State *L, int factory,
+ const upb_msgdef *md) {
const lupb_msgfactory *lfactory = lupb_msgfactory_check(L, factory);
lupb_msgclass *lmc = lupb_newuserdata(L, sizeof(*lmc), LUPB_MSGCLASS);
- UPB_ASSERT(l);
lupb_uservalseti(L, -1, LUPB_MSGCLASS_FACTORY, factory);
- lmc->layout = l;
+ lmc->layout = upb_msgfactory_getlayout(lfactory->factory, md);
lmc->lfactory = lfactory;
return 1;
@@ -933,7 +935,7 @@ static const lupb_msgclass *lupb_msg_getsubmsgclass(lua_State *L, int narg,
return lupb_msgclass_getsubmsgclass(L, -1, f);
}
-int lupb_msg_pushref(lua_State *L, int msgclass, void *msg) {
+int lupb_msg_pushref(lua_State *L, int msgclass, upb_msg *msg) {
const lupb_msgclass *lmsgclass = lupb_msgclass_check(L, msgclass);
lupb_msg *lmsg = lupb_newuserdata(L, sizeof(lupb_msg), LUPB_MSG);
@@ -966,8 +968,8 @@ static int lupb_msg_pushnew(lua_State *L, int narg) {
lupb_msg *lmsg = lupb_newuserdata(L, size, LUPB_MSG);
lmsg->lmsgclass = lmsgclass;
- lmsg->msg = ADD_BYTES(lmsg, sizeof(*lmsg));
- upb_msg_init(lmsg->msg, lmsgclass->layout, lupb_alloc_get(L));
+ lmsg->msg = upb_msg_init(
+ ADD_BYTES(lmsg, sizeof(*lmsg)), lmsgclass->layout, lupb_alloc_get(L));
lupb_uservalseti(L, -1, LUPB_MSG_MSGCLASSINDEX, narg);
diff --git a/upb/bindings/lua/upb.h b/upb/bindings/lua/upb.h
index 88a201c..982ae57 100644
--- a/upb/bindings/lua/upb.h
+++ b/upb/bindings/lua/upb.h
@@ -135,6 +135,7 @@ const upb_msg *lupb_msg_checkmsg(lua_State *L, int narg,
const lupb_msgclass *lupb_msgclass_check(lua_State *L, int narg);
const upb_msglayout *lupb_msgclass_getlayout(lua_State *L, int narg);
const upb_handlers *lupb_msgclass_getmergehandlers(lua_State *L, int narg);
+upb_msgfactory *lupb_msgclass_getfactory(const lupb_msgclass *lmsgclass);
void lupb_msg_registertypes(lua_State *L);
#endif /* UPB_LUA_UPB_H_ */
diff --git a/upb/bindings/lua/upb/pb.c b/upb/bindings/lua/upb/pb.c
index a25d1ac..731430d 100644
--- a/upb/bindings/lua/upb/pb.c
+++ b/upb/bindings/lua/upb/pb.c
@@ -106,7 +106,7 @@ static int lupb_pb_makemsgtostrencoder(lua_State *L) {
const upb_msglayout *layout = lupb_msgclass_getlayout(L, 1);
const lupb_msgclass *lmsgclass = lupb_msgclass_check(L, 1);
const upb_msgdef *md = upb_msglayout_msgdef(layout);
- upb_msgfactory *factory = upb_msglayout_factory(layout);
+ upb_msgfactory *factory = lupb_msgclass_getfactory(lmsgclass);
const upb_handlers *encode_handlers;
const upb_visitorplan *vp;
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback