From patchwork Thu Sep 29 15:39:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dirk Feytons X-Patchwork-Id: 676648 X-Patchwork-Delegate: nbd@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3slJkY3c75z9sBX for ; Fri, 30 Sep 2016 01:43:17 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=DTOBTH8M; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bpdS5-0005Cx-Kl; Thu, 29 Sep 2016 15:40:49 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bpdRz-0004BD-HY for lede-dev@lists.infradead.org; Thu, 29 Sep 2016 15:40:44 +0000 Received: by mail-wm0-x244.google.com with SMTP id w84so11307477wmg.0 for ; Thu, 29 Sep 2016 08:40:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hzflwxuhbdTqbChYLrzmCC0U4WWXk+B30gv435bOJnc=; b=DTOBTH8MZUXS/BvTm/fs7hB3s50iGDTu3IhuXGIKtQeXzR5h8wbvaRT5WI7bwyjIsa rTwDlC3vIiFjgMpedaCjSsXvZYYM8WIWl3BiYUXXCTENk/iz7OygZ4//GO/lXiR2yoEW 3sC/oQu2M/OY0zIz5fjaKLlfo1RUx20mXlbv14FWgLhhrDkRnpXxnDk9BnZt9dSO9Zgv 0BXsO/rBqNA+l1jTirCszFxIomQgPpTZW58bsK0Xt8Ja+RkviDPPz/4spX+SipZiSQPq vlcpFNlYHN1NieJVDFKzfBLkcNsM/Y6ZgMxCPADP3qo1GYbJB66+KD2vSwN88vT3Ok34 GoTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hzflwxuhbdTqbChYLrzmCC0U4WWXk+B30gv435bOJnc=; b=a9KXfB3Vl5Hq1anz2FrwOTmGOykgHsgqKBtP98c8Hxwd1RgRSsayzuT2cpto91QY2E qr1iOpmajPnAJvZEAdP/5LJvkv5OxJ2PClJaBHrP9B1F6YHRt4i1CfY+H8FVks0zXW3e pz27KpU2AlPvj0P5WIAnJBOYUkXRsaWTdjZIS85T9bHxs80qkQ5i1gp2epJF6pu69n4M Kl6PTpsVxO2adqzL0quiT/J0cZYc2DW62OCIy6WT8X3UHP+vKGd8YONQ37vzS5jwMR4m MJ2SnNfPF5/m2IWIsNiPe9Df41B1oAKVOag+LfZZUM8+zJP33Muf8o8at9BQNNcKM2zU +cWg== X-Gm-Message-State: AA6/9RmZx+9f8cX6RPremHDc2vYC2UncZC3RRsQHxJCQur9chnANUEs/29iOi0/iVlF+oQ== X-Received: by 10.28.136.195 with SMTP id k186mr6187203wmd.39.1475163621259; Thu, 29 Sep 2016 08:40:21 -0700 (PDT) Received: from cplx1020.edegem.eu.thmulti.com ([141.11.62.7]) by smtp.gmail.com with ESMTPSA id w9sm14682229wjf.47.2016.09.29.08.40.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Sep 2016 08:40:20 -0700 (PDT) From: Dirk Feytons To: lede-dev@lists.infradead.org, nbd@nbd.name Date: Thu, 29 Sep 2016 17:39:57 +0200 Message-Id: <1475163597-11817-2-git-send-email-dirk.feytons@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1475163597-11817-1-git-send-email-dirk.feytons@gmail.com> References: <1475163597-11817-1-git-send-email-dirk.feytons@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160929_084043_812387_F680001A X-CRM114-Status: GOOD ( 10.91 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:244 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (dirk.feytons[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid Subject: [LEDE-DEV] [PATCH 2/2] uci/lua: add explicit close() method X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dirk Feytons MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This allows a caller to explicitly free the cursor as soon as it is no longer needed instead of having to wait for the garbage collector. Signed-off-by: Dirk Feytons --- lua/uci.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lua/uci.c b/lua/uci.c index ddb9c5c..22055cb 100644 --- a/lua/uci.c +++ b/lua/uci.c @@ -933,8 +933,19 @@ uci_lua_list_configs(lua_State *L) static int uci_lua_gc(lua_State *L) { - struct uci_context *ctx = find_context(L, NULL); - uci_free_context(ctx); + struct uci_context **ctx; + + if (!lua_isuserdata(L, 1)) { + if (!global_ctx) + return 0; + ctx = &global_ctx; + } else { + ctx = luaL_checkudata(L, 1, METANAME); + if (!*ctx) + return 0; + } + uci_free_context(*ctx); + *ctx = NULL; return 0; } @@ -970,6 +981,7 @@ uci_lua_cursor(lua_State *L) static const luaL_Reg uci[] = { { "__gc", uci_lua_gc }, + { "close", uci_lua_gc }, { "cursor", uci_lua_cursor }, { "load", uci_lua_load }, { "unload", uci_lua_unload },