From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 61B426C7D3; Wed, 17 Feb 2021 23:17:01 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 61B426C7D3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1613593021; bh=v6E5w/p5L9E0evyAtG4fYs51V6PP/t+3H0rBJfrAdUU=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=AAxZGY2VCreSwpF3cTyxBlVrrSATK55ZzBNQ7YEdRFYNeYtt3d5S84DZ1JU/Ph+CG tT+S8DmfkypKq7GisksqavVZNWWrGG73BTFQXiepgzYIsmd5SdYGnNzmlNaiUGxM3z +NUsPRXbBga0U8n/hN+1H2fxJb7xw7VuwPehsfnM= Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 5117D6C183 for ; Wed, 17 Feb 2021 23:16:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5117D6C183 Received: by mail-lf1-f48.google.com with SMTP id w36so23901240lfu.4 for ; Wed, 17 Feb 2021 12:16:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CskpI8OoPmQJ6baATDENHfuueTnVfClHwvPJNguCTw8=; b=FGenveMvxLIAkUA5zbXbHAmNsfKscJ358rU0f5O8abnnmD4yhSmeucAoebEy+9ofNL Q77gX9v5b0QVASPb6ZOu2XpVOdYCAcYdEP14i1l84RYEQasHkTrTkugPve9TszUZswjS Y82V57A7qszUcv1oAB18qyPpiL9fBxo75r1oynMmUK4jJCRiLcOmrL8PYr7/aPSIPcUf JkstbLg1G/UOtfP73rGHKyprxoQPqlATw0NiYLux/7AvrXbkJ4r2JYh2hnP5B2gyexQc 88O5jBoaBTfE3jI1p9kiirTf/4DyelJdkIzPUxTGPUbdsTrXT9FWwD6K8m9Yrr3XbehO hYKw== X-Gm-Message-State: AOAM531klz9m0cW+OpMHwoquV8JdJAN7Y4hhtZR7ajOk76eqcUtwci6L Tn2OSBx5vdawW3b/0hQ8nRRnAgsAZg0= X-Google-Smtp-Source: ABdhPJzL8RmUR37SV9oTKb3GlT/jeTyGm9YKWbYxqJz4xhtmJXNlNe4GZZmSMbCKL8j14nBX78Naog== X-Received: by 2002:a05:6512:b04:: with SMTP id w4mr332161lfu.43.1613592964211; Wed, 17 Feb 2021 12:16:04 -0800 (PST) Received: from grain.localdomain ([5.18.171.94]) by smtp.gmail.com with ESMTPSA id b8sm355174lfo.84.2021.02.17.12.16.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 12:16:03 -0800 (PST) Received: by grain.localdomain (Postfix, from userid 1000) id B569E560256; Wed, 17 Feb 2021 23:15:25 +0300 (MSK) To: tml Date: Wed, 17 Feb 2021 23:15:20 +0300 Message-Id: <20210217201521.436951-4-gorcunov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210217201521.436951-1-gorcunov@gmail.com> References: <20210217123945.396396-1-gorcunov@gmail.com> <20210217201521.436951-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 3/4] cmod: export cmod_call helper X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Cyrill Gorcunov via Tarantool-patches Reply-To: Cyrill Gorcunov Cc: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This will allow us to reuse this code in when function is executed from box.schema.func. Part-of #4642 Signed-off-by: Cyrill Gorcunov --- src/box/lua/cmod.c | 24 +++++++++--------------- src/box/lua/cmod.h | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/box/lua/cmod.c b/src/box/lua/cmod.c index 6b383d8fe..d7d395b7d 100644 --- a/src/box/lua/cmod.c +++ b/src/box/lua/cmod.c @@ -12,7 +12,6 @@ #include "box/error.h" #include "box/port.h" -#include "box/func_def.h" #include "tt_static.h" @@ -805,9 +804,9 @@ lfunc_gc(struct lua_State *L) return 0; } -/** Execute a function. */ int -do_lfunc_call(struct cmod_func *cf, struct port *args, struct port *ret) +cmod_call(struct cmod *m, box_function_f func_addr, + struct port *args, struct port *ret) { struct region *region = &fiber()->gc; size_t region_svp = region_used(region); @@ -823,17 +822,12 @@ do_lfunc_call(struct cmod_func *cf, struct port *args, struct port *ret) }; /* - * Unlike box.schema.func cmod doesn't support - * module run-time reloading and while a function - * is alive a module can't disappear. Still it is - * unclear if there some existing users are running - * code which already tries to unload a function inside - * this call execution, thus make sure the module won't - * disapper inbetween. + * The function may get rescheduled inside, + * thus make sure the module won't disappear. */ - cmod_ref(cf->cmod); - int rc = cf->addr(&ctx, data, data + data_sz); - cmod_unref(cf->cmod); + cmod_ref(m); + int rc = func_addr(&ctx, data, data + data_sz); + cmod_unref(m); region_truncate(region, region_svp); if (rc != 0) { @@ -843,7 +837,7 @@ do_lfunc_call(struct cmod_func *cf, struct port *args, struct port *ret) return -1; } - return rc; + return 0; } /** Call a function by its name from the Lua code. */ @@ -869,7 +863,7 @@ lfunc_call(struct lua_State *L) struct port ret; - if (do_lfunc_call(cf, &args, &ret) != 0) { + if (cmod_call(cf->cmod, cf->addr, &args, &ret) != 0) { port_destroy(&args); return luaT_error(L); } diff --git a/src/box/lua/cmod.h b/src/box/lua/cmod.h index 224779a04..c34cc156a 100644 --- a/src/box/lua/cmod.h +++ b/src/box/lua/cmod.h @@ -9,6 +9,7 @@ #include #include +#include "box/func_def.h" #include "trivia/config.h" #if defined(__cplusplus) @@ -110,6 +111,20 @@ int cmod_find_package(const char *package, size_t package_len, char *path, size_t path_len); +/** + * Execute a function. + * + * @param m the module function sits in. + * @param func_addr function address to call. + * @args args incoming arguments. + * @ret rets execution results. + * + * @return 0 on success, -1 otherwise(diag is set). + */ +int +cmod_call(struct cmod *m, box_function_f func_addr, + struct port *args, struct port *ret); + /** * Initialize cmod Lua module. * -- 2.29.2