Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Leonid Vasiliev <lvasiliev@tarantool.org>,
	alexander.turenko@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH V5 5.5/6] box: move Lua MP_EXT decoder from tuple.c
Date: Sat, 18 Apr 2020 23:14:28 +0200	[thread overview]
Message-ID: <a1aa1cce-8489-d256-44c8-174d86873d75@tarantool.org> (raw)
In-Reply-To: <cover.1587223627.git.lvasiliev@tarantool.org>

Lua C module 'msgpack' supports registration of custom extension
decoders for MP_EXT values. That is needed to make 'msgpack' not
depending on any modules which use it.

So far the only extension were tuples - struct tuple cdata needed
to be encoded as an array.

That is going to change in next commits, where struct error cdata
appears. So the decoder can't be located in src/box/lua/tuple.c.
It is moved to a more common place - src/box/lua/init.c.

Needed for #4398

---
diff --git a/src/box/lua/init.c b/src/box/lua/init.c
index 63e8b8216..b05ff90be 100644
--- a/src/box/lua/init.c
+++ b/src/box/lua/init.c
@@ -36,6 +36,7 @@
 
 #include "lua/utils.h" /* luaT_error() */
 #include "lua/trigger.h"
+#include "lua/msgpack.h"
 
 #include "box/box.h"
 #include "box/txn.h"
@@ -386,6 +387,21 @@ static const struct luaL_Reg boxlib_backup[] = {
 	{NULL, NULL}
 };
 
+/**
+ * A MsgPack extensions handler, for types defined in box.
+ */
+static enum mp_type
+luamp_encode_extension_box(struct lua_State *L, int idx,
+			   struct mpstream *stream)
+{
+	struct tuple *tuple = luaT_istuple(L, idx);
+	if (tuple != NULL) {
+		tuple_to_mpstream(tuple, stream);
+		return MP_ARRAY;
+	}
+	return MP_EXT;
+}
+
 #include "say.h"
 
 void
@@ -426,6 +442,8 @@ box_lua_init(struct lua_State *L)
 	luaopen_merger(L);
 	lua_pop(L, 1);
 
+	luamp_set_encode_extension(luamp_encode_extension_box);
+
 	/* Load Lua extension */
 	for (const char **s = lua_sources; *s; s += 2) {
 		const char *modname = *s;
diff --git a/src/box/lua/tuple.c b/src/box/lua/tuple.c
index aba906d1f..03b4b8a2e 100644
--- a/src/box/lua/tuple.c
+++ b/src/box/lua/tuple.c
@@ -290,20 +290,6 @@ tuple_to_mpstream(struct tuple *tuple, struct mpstream *stream)
 	mpstream_advance(stream, bsize);
 }
 
-/* A MsgPack extensions handler that supports tuples */
-static enum mp_type
-luamp_encode_extension_box(struct lua_State *L, int idx,
-			   struct mpstream *stream)
-{
-	struct tuple *tuple = luaT_istuple(L, idx);
-	if (tuple != NULL) {
-		tuple_to_mpstream(tuple, stream);
-		return MP_ARRAY;
-	}
-
-	return MP_EXT;
-}
-
 /**
  * Convert a tuple into lua table. Named fields are stored as
  * {name = value} pairs. Not named fields are stored as
@@ -582,8 +568,6 @@ box_lua_tuple_init(struct lua_State *L)
 	luaL_register_module(L, tuplelib_name, lbox_tuplelib);
 	lua_pop(L, 1);
 
-	luamp_set_encode_extension(luamp_encode_extension_box);
-
 	tuple_serializer_update_options();
 	trigger_create(&tuple_serializer.update_trigger,
 		       on_msgpack_serializer_update, NULL, NULL);

      parent reply	other threads:[~2020-04-18 21:14 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-18 15:29 [Tarantool-patches] [PATCH V5 0/6] Extending error functionality Leonid Vasiliev
2020-04-18 15:29 ` [Tarantool-patches] [PATCH V5 1/6] error: add custom error type Leonid Vasiliev
2020-04-18 18:52   ` Vladislav Shpilevoy
2020-04-18 15:29 ` [Tarantool-patches] [PATCH V5 2/6] error: send custom type in IProto Leonid Vasiliev
2020-04-18 20:39   ` Vladislav Shpilevoy
2020-04-18 15:29 ` [Tarantool-patches] [PATCH V5 3/6] session: add offset to SQL session settings array Leonid Vasiliev
2020-04-18 15:29 ` [Tarantool-patches] [PATCH V5 4/6] error: add session setting for error type marshaling Leonid Vasiliev
2020-04-18 20:40   ` Vladislav Shpilevoy
2020-04-18 15:29 ` [Tarantool-patches] [PATCH V5 5/6] error: update constructors of some errors Leonid Vasiliev
2020-04-18 20:39   ` Vladislav Shpilevoy
2020-04-18 15:29 ` [Tarantool-patches] [PATCH V5 6/6] error: add error MsgPack encoding Leonid Vasiliev
2020-04-18 20:39   ` Vladislav Shpilevoy
2020-04-18 21:14 ` Vladislav Shpilevoy [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a1aa1cce-8489-d256-44c8-174d86873d75@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=alexander.turenko@tarantool.org \
    --cc=lvasiliev@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH V5 5.5/6] box: move Lua MP_EXT decoder from tuple.c' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox