Tarantool development patches archive
 help / color / mirror / Atom feed
* [PATCH] schema: fix box.func cleanup after a function is dropped
@ 2019-07-01 11:19 Vladimir Davydov
  2019-07-01 11:19 ` Vladimir Davydov
  0 siblings, 1 reply; 2+ messages in thread
From: Vladimir Davydov @ 2019-07-01 11:19 UTC (permalink / raw)
  To: tarantool-patches

Fixes commit abf5ef4fead9 ("box: export registered functions in box.func
folder").
---
 src/box/lua/call.c          |  2 +-
 src/box/schema.h            | 30 +++++++++++++++---------------
 test/box/function1.result   | 16 ++++++++++++++++
 test/box/function1.test.lua |  4 ++++
 4 files changed, 36 insertions(+), 16 deletions(-)

diff --git a/src/box/lua/call.c b/src/box/lua/call.c
index a236325b..38f2f696 100644
--- a/src/box/lua/call.c
+++ b/src/box/lua/call.c
@@ -712,7 +712,7 @@ lbox_func_new_or_delete(struct trigger *trigger, void *event)
 {
 	struct lua_State *L = (struct lua_State *) trigger->data;
 	struct func *func = (struct func *)event;
-	if (func != NULL)
+	if (func_by_id(func->def->fid) != NULL)
 		lbox_func_new(L, func);
 	else
 		lbox_func_delete(L, func);
diff --git a/src/box/schema.h b/src/box/schema.h
index f0039b29..30366382 100644
--- a/src/box/schema.h
+++ b/src/box/schema.h
@@ -41,6 +41,8 @@
 extern "C" {
 #endif /* defined(__cplusplus) */
 
+struct func;
+
 extern uint32_t schema_version;
 extern uint32_t space_cache_version;
 
@@ -89,6 +91,19 @@ space_cache_find(uint32_t id)
 	return NULL;
 }
 
+/**
+ * Insert a new function object in the function cache.
+ * @param func Function object to insert.
+ */
+void
+func_cache_insert(struct func *func);
+
+void
+func_cache_delete(uint32_t fid);
+
+struct func *
+func_by_id(uint32_t fid);
+
 struct func *
 func_by_name(const char *name, uint32_t name_len);
 
@@ -162,21 +177,6 @@ schema_free();
 
 struct space *schema_space(uint32_t id);
 
-/**
- * Insert a new function object in the function cache.
- * @param func Function object to insert.
- */
-void
-func_cache_insert(struct func *func);
-
-void
-func_cache_delete(uint32_t fid);
-
-struct func;
-
-struct func *
-func_by_id(uint32_t fid);
-
 static inline struct func *
 func_cache_find(uint32_t fid)
 {
diff --git a/test/box/function1.result b/test/box/function1.result
index 99006926..439e19e9 100644
--- a/test/box/function1.result
+++ b/test/box/function1.result
@@ -79,6 +79,10 @@ box.func["function1.args"]:call({ 15 })
 box.schema.func.drop("function1.args")
 ---
 ...
+box.func["function1.args"]
+---
+- null
+...
 box.schema.func.create('function1.multi_inc', {language = "C"})
 ---
 ...
@@ -377,6 +381,10 @@ func.drop()
 ---
 - error: 'builtin/box/schema.lua: Use func:drop(...) instead of func.drop(...)'
 ...
+box.func.divide
+---
+- null
+...
 func:drop()
 ---
 - error: Function 'divide' does not exist
@@ -422,6 +430,10 @@ func:call({4, 2, 1})
 func:drop()
 ---
 ...
+box.func["function1.divide"]
+---
+- null
+...
 func
 ---
 - language: C
@@ -471,6 +483,10 @@ func:call({{1, 2, 99, 3, -1}})
 func:drop()
 ---
 ...
+box.func.minmax
+---
+- null
+...
 -- Test access checks for registered functions.
 function secret() return 1 end
 ---
diff --git a/test/box/function1.test.lua b/test/box/function1.test.lua
index 25966b91..4ec9c04a 100644
--- a/test/box/function1.test.lua
+++ b/test/box/function1.test.lua
@@ -26,6 +26,7 @@ box.func["function1.args"]:call()
 box.func["function1.args"]:call({ "xx" })
 box.func["function1.args"]:call({ 15 })
 box.schema.func.drop("function1.args")
+box.func["function1.args"]
 
 box.schema.func.create('function1.multi_inc', {language = "C"})
 box.schema.user.grant('guest', 'execute', 'function', 'function1.multi_inc')
@@ -132,6 +133,7 @@ func:call({4, 2, 1})
 func:drop()
 func
 func.drop()
+box.func.divide
 func:drop()
 func:call({4, 2})
 box.internal.func_call('divide', 4, 2)
@@ -145,6 +147,7 @@ func:call({4})
 func:call({4, 2})
 func:call({4, 2, 1})
 func:drop()
+box.func["function1.divide"]
 func
 func:drop()
 func:call({4, 2})
@@ -165,6 +168,7 @@ box.schema.func.create("minmax")
 func = box.func.minmax
 func:call({{1, 2, 99, 3, -1}})
 func:drop()
+box.func.minmax
 
 -- Test access checks for registered functions.
 function secret() return 1 end
-- 
2.11.0

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

end of thread, other threads:[~2019-07-01 11:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-01 11:19 [PATCH] schema: fix box.func cleanup after a function is dropped Vladimir Davydov
2019-07-01 11:19 ` Vladimir Davydov

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