From e412879ea6ff7fc3a610caf844cf5c811bebdad4 Mon Sep 17 00:00:00 2001 From: Georgy Moshkin <gmoshkin@picodata.io> Date: Mon, 19 Dec 2022 12:26:26 +0300 Subject: [PATCH] picodata: add support for static stored procedures using ".foo" syntax --- src/box/module_cache.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/box/module_cache.c b/src/box/module_cache.c index 3d9b1883df..145a3e5dea 100644 --- a/src/box/module_cache.c +++ b/src/box/module_cache.c @@ -380,9 +380,32 @@ module_new(const char *package, size_t package_len, 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); + cache_put(m); + 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); @@ -406,6 +429,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) -- GitLab