Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org, korablev@tarantool.org
Cc: kostja@tarantool.org, Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [tarantool-patches] [PATCH v2 11/12] box: use own vtab per each function object
Date: Wed, 10 Jul 2019 14:00:59 +0300	[thread overview]
Message-ID: <ee37064f1535a928299ae10941db4dbca212f606.1562756438.git.kshcherbatov@tarantool.org> (raw)
In-Reply-To: <cover.1562756438.git.kshcherbatov@tarantool.org>

Tarantool functions used to refer to a static func_vtab object
based on it's type. With this patch, each function has own vtab
object, so it's virtual method may be overridden.
It is required to call builtin functions in func_call directly
in further patches.

Needed for #4113, #2200, #2233
---
 src/box/func.c     | 8 +++-----
 src/box/func.h     | 2 +-
 src/box/lua/call.c | 8 ++------
 src/box/sql/func.c | 3 +--
 4 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/src/box/func.c b/src/box/func.c
index 8d93a83b2..e36649d15 100644
--- a/src/box/func.c
+++ b/src/box/func.c
@@ -437,7 +437,7 @@ func_c_new(struct func_def *def)
 		diag_set(OutOfMemory, sizeof(*func), "malloc", "func");
 		return NULL;
 	}
-	func->base.vtab = &func_c_vtab;
+	func->base.vtab = func_c_vtab;
 	func->func = NULL;
 	func->module = NULL;
 	return &func->base;
@@ -462,7 +462,6 @@ func_c_unload(struct func_c *func)
 static void
 func_c_destroy(struct func *base)
 {
-	assert(base->vtab == &func_c_vtab);
 	assert(base != NULL && base->def->language == FUNC_LANGUAGE_C);
 	struct func_c *func = (struct func_c *) base;
 	func_c_unload(func);
@@ -505,7 +504,6 @@ func_c_load(struct func_c *func)
 int
 func_c_call(struct func *base, struct port *args, struct port *ret)
 {
-	assert(base->vtab == &func_c_vtab);
 	assert(base != NULL && base->def->language == FUNC_LANGUAGE_C);
 	struct func_c *func = (struct func_c *) base;
 	if (func->func == NULL) {
@@ -551,7 +549,7 @@ void
 func_delete(struct func *func)
 {
 	struct func_def *def = func->def;
-	func->vtab->destroy(func);
+	func->vtab.destroy(func);
 	free(def);
 }
 
@@ -617,7 +615,7 @@ func_call(struct func *base, struct port *args, struct port *ret)
 		}
 		fiber_set_user(fiber(), &base->owner_credentials);
 	}
-	int rc = base->vtab->call(base, args, ret);
+	int rc = base->vtab.call(base, args, ret);
 	/* Restore the original user */
 	if (orig_credentials)
 		fiber_set_user(fiber(), orig_credentials);
diff --git a/src/box/func.h b/src/box/func.h
index 2236fd873..7e4dd37a3 100644
--- a/src/box/func.h
+++ b/src/box/func.h
@@ -72,7 +72,7 @@ struct func_vtab {
 struct func {
 	struct func_def *def;
 	/** Virtual method table. */
-	const struct func_vtab *vtab;
+	struct func_vtab vtab;
 	/**
 	 * Authentication id of the owner of the function,
 	 * used for set-user-id functions.
diff --git a/src/box/lua/call.c b/src/box/lua/call.c
index 4297218cd..752f05745 100644
--- a/src/box/lua/call.c
+++ b/src/box/lua/call.c
@@ -708,14 +708,14 @@ func_lua_new(struct func_def *def)
 	}
 	if (def->body != NULL) {
 		func->base.def = def;
-		func->base.vtab = &func_persistent_lua_vtab;
+		func->base.vtab = func_persistent_lua_vtab;
 		if (func_persistent_lua_load(func) != 0) {
 			free(func);
 			return NULL;
 		}
 	} else {
 		func->lua_ref = LUA_REFNIL;
-		func->base.vtab = &func_lua_vtab;
+		func->base.vtab = func_lua_vtab;
 	}
 	return &func->base;
 }
@@ -724,7 +724,6 @@ static void
 func_lua_destroy(struct func *func)
 {
 	assert(func != NULL && func->def->language == FUNC_LANGUAGE_LUA);
-	assert(func->vtab == &func_lua_vtab);
 	free(func);
 }
 
@@ -732,7 +731,6 @@ static inline int
 func_lua_call(struct func *func, struct port *args, struct port *ret)
 {
 	assert(func != NULL && func->def->language == FUNC_LANGUAGE_LUA);
-	assert(func->vtab == &func_lua_vtab);
 	return box_lua_call(func->def->name, func->def->name_len, args, ret);
 }
 
@@ -752,7 +750,6 @@ func_persistent_lua_destroy(struct func *base)
 {
 	assert(base != NULL && base->def->language == FUNC_LANGUAGE_LUA &&
 	       base->def->body != NULL);
-	assert(base->vtab == &func_persistent_lua_vtab);
 	struct func_lua *func = (struct func_lua *) base;
 	func_persistent_lua_unload(func);
 	free(func);
@@ -763,7 +760,6 @@ func_persistent_lua_call(struct func *base, struct port *args, struct port *ret)
 {
 	assert(base != NULL && base->def->language == FUNC_LANGUAGE_LUA &&
 	       base->def->body != NULL);
-	assert(base->vtab == &func_persistent_lua_vtab);
 	struct func_lua *func = (struct func_lua *)base;
 	struct execute_lua_ctx ctx;
 	ctx.lua_ref = func->lua_ref;
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 18db8530d..f79939cb6 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -2183,14 +2183,13 @@ func_sql_builtin_new(struct func_def *def)
 	}
 	/** Don't export SQL builtins in Lua for now. */
 	def->exports.lua = false;
-	func->base.vtab = &func_sql_builtin_vtab;
+	func->base.vtab = func_sql_builtin_vtab;
 	return &func->base;
 }
 
 static void
 func_sql_builtin_destroy(struct func *base)
 {
-	assert(base->vtab == &func_sql_builtin_vtab);
 	assert(base != NULL && base->def->language == FUNC_LANGUAGE_SQL_BUILTIN);
 	free(base);
 }
-- 
2.21.0

  parent reply	other threads:[~2019-07-10 11:01 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-10 11:00 [tarantool-patches] [PATCH v2 00/12] sql: uniform SQL and Lua functions subsystem Kirill Shcherbatov
2019-07-10 11:00 ` [tarantool-patches] [PATCH v2 01/12] sql: get rid of SOUNDEX, MATCH Kirill Shcherbatov
2019-07-10 18:45   ` [tarantool-patches] " Konstantin Osipov
2019-07-12  8:44   ` Kirill Yukhin
2019-07-10 11:00 ` [tarantool-patches] [PATCH v2 10/12] sql: refactor builtins signatures with port Kirill Shcherbatov
2019-07-10 18:47   ` [tarantool-patches] " Konstantin Osipov
2019-07-11  7:33     ` Kirill Shcherbatov
2019-07-10 11:00 ` Kirill Shcherbatov [this message]
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 12/12] sql: use schema's func hash instead of FuncDef hash Kirill Shcherbatov
2019-07-10 20:22   ` [tarantool-patches] " Konstantin Osipov
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 02/12] sql: get rid of LIKELY, UNLIKELY and LIKEHOOD Kirill Shcherbatov
2019-07-10 19:02   ` [tarantool-patches] " Konstantin Osipov
2019-07-11  7:38     ` Kirill Shcherbatov
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 03/12] sql: put analyze helpers to FuncDef cache Kirill Shcherbatov
2019-07-10 19:04   ` [tarantool-patches] " Konstantin Osipov
2019-07-12  8:47   ` Kirill Yukhin
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 04/12] sql: rework LIKE case-insensitive mode Kirill Shcherbatov
2019-07-10 19:09   ` [tarantool-patches] " Konstantin Osipov
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 05/12] sql: replace bool is_derived_coll marker with flag Kirill Shcherbatov
2019-07-10 19:10   ` [tarantool-patches] " Konstantin Osipov
2019-07-12  8:48   ` Kirill Yukhin
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 06/12] sql: remove SQL_PreferBuiltin flag Kirill Shcherbatov
2019-07-10 19:11   ` [tarantool-patches] " Konstantin Osipov
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 07/12] sql: move LIKE UConverter object to collation library Kirill Shcherbatov
2019-07-12  8:49   ` [tarantool-patches] " Kirill Yukhin
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 08/12] sql: rfc for SQL and Lua functions Kirill Shcherbatov
2019-07-10 19:17   ` [tarantool-patches] " Konstantin Osipov
2019-07-10 19:18     ` Konstantin Osipov
2019-07-11  7:40       ` Kirill Shcherbatov
2019-07-11 13:59   ` Kirill Yukhin
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 09/12] box: introduce Lua persistent functions Kirill Shcherbatov
2019-07-10 19:26   ` [tarantool-patches] " Konstantin Osipov
2019-07-12 21:49   ` Konstantin Osipov
2019-07-13 13:55     ` Kirill Yukhin
2019-07-13 14:17       ` Kirill Yukhin

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=ee37064f1535a928299ae10941db4dbca212f606.1562756438.git.kshcherbatov@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH v2 11/12] box: use own vtab per each function object' \
    /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