Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
From 261ab204ea9e132426a7ce42549a4c6ca883ca66 Mon Sep 17 00:00:00 2001
From: Georgy Moshkin <gmoshkin@picodata.io>
Date: Thu, 17 Feb 2022 14:00:14 +0300
Subject: [PATCH 3/3] picodata: add support for static stored procedures using
".foo" syntax
box.schema.func.create(".func_name", {language = "C"}) will create a
stored procedure which calls the function `func_name` from the current
executable
---
src/box/module_cache.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/src/box/module_cache.c b/src/box/module_cache.c
index 7f81902bd..a48c18ea0 100644
--- a/src/box/module_cache.c
+++ b/src/box/module_cache.c
@@ -387,9 +387,37 @@ error:
return NULL;
}
+struct module *
+module_current_exe()
+{
+ struct module *m = cache_find(NULL, 0);
+ if (m != NULL)
+ return m;
+
+ size_t size = sizeof(struct module) + 1;
+ m = malloc(size);
+ if (m == NULL) {
+ diag_set(OutOfMemory, size, "malloc", "module");
+ return NULL;
+ }
+ memset(m, 0, size);
+ m->handle = dlopen(0, RTLD_NOW);
+ module_ref(m);
+
+ if (cache_put(m) != 0) {
+ module_unload(m);
+ return NULL;
+ }
+
+ return m;
+}
+
struct module *
module_load_force(const char *package, size_t package_len)
{
+ if (package_len == 0)
+ return module_current_exe();
+
char path[PATH_MAX];
size_t size = sizeof(path);
@@ -416,6 +444,9 @@ module_load_force(const char *package, size_t package_len)
struct module *
module_load(const char *package, size_t package_len)
{
+ if (package_len == 0)
+ return module_current_exe();
+
char path[PATH_MAX];
if (find_package(package, package_len, path, sizeof(path)) != 0)
--
2.25.1