Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] Move rollback to savepoint from ffi to C-API
@ 2019-12-13 12:08 Leonid Vasiliev
  2020-01-16 21:17 ` Alexander Turenko
  0 siblings, 1 reply; 7+ messages in thread
From: Leonid Vasiliev @ 2019-12-13 12:08 UTC (permalink / raw)
  To: alexander.turenko; +Cc: tarantool-patches

https://github.com/tarantool/tarantool/issues/4427
https://github.com/tarantool/tarantool/tree/lvasiliev/gh-4427-move-rallback-from-ffi-to-c-api-v2

After the "FFI vs C-API" discussion
---
 src/box/lua/init.c     | 28 ++++++++++++++++++++++++++++
 src/box/lua/schema.lua |  5 +----
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/src/box/lua/init.c b/src/box/lua/init.c
index 7ffed409d..3d26dbb93 100644
--- a/src/box/lua/init.c
+++ b/src/box/lua/init.c
@@ -107,6 +107,26 @@ lbox_rollback(lua_State *L)
 	return 0;
 }
 
+static int
+lbox_txn_rollback_to_savepoint(struct lua_State *L)
+{
+	if (lua_gettop(L) != 1 || lua_type(L, 1) != LUA_TCDATA)
+		luaL_error(L, "Usage: txn:rollback to savepoint(savepoint)");
+
+	uint32_t cdata_type;
+	struct txn_savepoint **sp_ptr = luaL_checkcdata(L, 1, &cdata_type);
+
+	if (sp_ptr == NULL)
+		luaL_error(L, "Usage: txn:rollback to savepoint(savepoint)");
+
+	int rc = box_txn_rollback_to_savepoint(*sp_ptr);
+	if (rc != 0)
+		return luaT_push_nil_and_error(L);
+
+	lua_pushnumber(L, 0);
+	return 1;
+}
+
 /**
  * Get a next txn statement from the current transaction. This is
  * a C closure and 2 upvalues should be available: first is a
@@ -288,6 +308,11 @@ static const struct luaL_Reg boxlib_backup[] = {
 	{NULL, NULL}
 };
 
+static const struct luaL_Reg boxlib_internal[] = {
+	{"rollback_to_savepoint", lbox_txn_rollback_to_savepoint},
+	{NULL, NULL}
+};
+
 #include "say.h"
 
 void
@@ -300,6 +325,9 @@ box_lua_init(struct lua_State *L)
 	luaL_register(L, "box.backup", boxlib_backup);
 	lua_pop(L, 1);
 
+	luaL_register(L, "box.internal", boxlib_internal);
+	lua_pop(L, 1);
+
 	box_lua_error_init(L);
 	box_lua_tuple_init(L);
 	box_lua_call_init(L);
diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua
index e898c3aa6..b08a8c615 100644
--- a/src/box/lua/schema.lua
+++ b/src/box/lua/schema.lua
@@ -77,9 +77,6 @@ ffi.cdef[[
     box_txn_savepoint_t *
     box_txn_savepoint();
 
-    int
-    box_txn_rollback_to_savepoint(box_txn_savepoint_t *savepoint);
-
     struct port_tuple_entry {
         struct port_tuple_entry *next;
         struct tuple *tuple;
@@ -351,7 +348,7 @@ box.rollback_to_savepoint = function(savepoint)
     if savepoint.txn_id ~= builtin.box_txn_id() then
         box.error(box.error.NO_SUCH_SAVEPOINT)
     end
-    if builtin.box_txn_rollback_to_savepoint(savepoint.csavepoint) == -1 then
+    if box.internal.rollback_to_savepoint(savepoint.csavepoint) == nil then
         box.error()
     end
 end
-- 
2.17.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-02-05 16:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-13 12:08 [Tarantool-patches] [PATCH] Move rollback to savepoint from ffi to C-API Leonid Vasiliev
2020-01-16 21:17 ` Alexander Turenko
2020-01-20 21:17   ` Leonid Vasiliev
2020-01-21  2:33     ` Alexander Turenko
2020-01-24 14:35       ` Igor Munkin
2020-01-27  7:24         ` Leonid Vasiliev
2020-02-05 16:53           ` Alexander Turenko

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