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 0361B1218BCD; Tue, 25 Feb 2025 10:34:14 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 0361B1218BCD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1740468854; bh=qQHN9vkSD+vgeu1ZFzmQtDdrBwz/MqSgavoiKsl324s=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ygLyyzrkCYpWJ5ALYjM3TyAcxLmKF9UxOkal547e2lPPNmHr7QJMzUegPQZuNnZyT LSilvXbwHKCP8drUHInJEAG5Wufmd0aEtvhV8e05FNzvSFbL3Lj/o0LBOSfqYQHJDj udC6LWZzKXwgpcWerbFjLboij6Akj3DI+K8mPmt0= Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 713DB1218BCD for ; Tue, 25 Feb 2025 10:33:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 713DB1218BCD Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-309311e7b39so47868271fa.2 for ; Mon, 24 Feb 2025 23:33:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740468806; x=1741073606; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qhneiZ2n+bjpGTnUgYeKLrnEgylfFWdRdJI3ytyqRjA=; b=NV2d15vKYgDYGAv+p0SOqH137BYVVMM/G8gdrNcVegNGTJRod9hBUvAlzSPytTlQl1 RIxTXi1/8gcyz8fv1T1wRDzpWI09j8erGGGyz29/vgNCgu5iKrQLzPWThO5nMPMrxaF2 02k5r1btYh5FSKUyETmwzH5SCZaxigEw3LYC3OJ7RkNLYNGUwXWRrZ6ENQ9YgeM/r+/+ XlGl2M0NFMwC53VvscX48T8zHem3mmKfJNWIyXGsIWZEiekkeMVJMsmbCxTiGLFkSX7/ 09nZjsfO04QJd4cl5Z8pOOcLVBkWJhVk6uggKZZkkzd6Zje4MpdaWLYSIkrSrdoAKPaE KbwA== X-Gm-Message-State: AOJu0YxZduUFmKdGUHBeyHy5bzq9blybmKWmeKEpRlnN/h/xTqy7wKqk XEhRAj+ETP1zpcks/CdjrBYmJwRmhPmt2Axp87GEgLeozYpvj2swT7bh+lkcj+Q= X-Gm-Gg: ASbGnct2bhOmZZJj3lVH/SmDfrQeZ3QJED/np9agsVJ7O72kjM6FaywQjh7gz8ZGjYe b/enkcbMZhwrQhpJjfxNsGhwS7lBE1n6T65ak3rPHeJIbFzmbzyfJ6XjJ0uVSMJncWFsHOTA+ve huEeaQ2N8XZbpYOvijMWodvCj7ouv9CAvFVAq8/2Dab5JCQJV5yNQhxvV1phuFNrJoGeyI6BCiu Xr3Xjz/eUhQCTpFSdODMcyUxQX97Irdda2YcvROkSDJ3yfKXz2dp4hSDdon3YJXy8m6l8dHKAha 9+LCwIdnWNCu1/EqlnE= X-Google-Smtp-Source: AGHT+IGgsKB9WB97wwuikJVLw4C6BSnBxucN9scuIXfMIFFbwvLEml7Mi6hXvsWCqmjBjGwKaQBuUw== X-Received: by 2002:a2e:9843:0:b0:307:2aea:5594 with SMTP id 38308e7fff4ca-30a598e5bf3mr54477431fa.18.1740468805247; Mon, 24 Feb 2025 23:33:25 -0800 (PST) Received: from localhost ([79.164.223.111]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-30a81ac3151sm1509011fa.68.2025.02.24.23.33.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 23:33:23 -0800 (PST) X-Google-Original-From: Sergey Bronnikov To: tarantool-patches@dev.tarantool.org, Sergey Kaplun Date: Tue, 25 Feb 2025 10:32:48 +0300 Message-ID: <24b8d43f6ce2796ba2cb9e6740182c82ea0ddf35.1740468394.git.sergeyb@tarantool.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH luajit 2/3] misc: use prof_error for handling errors 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: Sergey Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" The patch consolidates handling profilers errors into a single place - in a function `prof_error()` and handles PROFILE_ERRIO, generated in a function `misc_memprof_start`, in a `prof_error()`. --- src/lib_misc.c | 49 +++++++++---------------------------------------- 1 file changed, 9 insertions(+), 40 deletions(-) diff --git a/src/lib_misc.c b/src/lib_misc.c index b4b58509..c4b40996 100644 --- a/src/lib_misc.c +++ b/src/lib_misc.c @@ -286,14 +286,14 @@ static int prof_error(lua_State *L, int status, const char *err_details) lua_pushstring(L, err2msg(LJ_ERR_PROF_MISUSE)); lua_pushinteger(L, EINVAL); return 3; -#if LJ_HASSYSPROF +#if LJ_HASSYSPROF || LJ_HASMEMPROF case PROFILE_ERRRUN: lua_pushnil(L); lua_pushstring(L, err2msg(LJ_ERR_PROF_ISRUNNING)); lua_pushinteger(L, EINVAL); return 3; case PROFILE_ERRIO: - return luaL_fileresult(L, 0, NULL); + return luaL_fileresult(L, 0, err_details); #endif default: lj_assertL(0, "bad sysprof error %d", status); @@ -417,32 +417,13 @@ LJLIB_CF(misc_memprof_start) if (ctx->fd == -1) { lj_mem_free(ctx->g, ctx, sizeof(*ctx)); - return luaL_fileresult(L, 0, fname); + return prof_error(L, PROFILE_ERRIO, fname); } memprof_status = lj_memprof_start(L, &opt); + if (LJ_UNLIKELY(memprof_status != PROFILE_SUCCESS)) + return prof_error(L, memprof_status, NULL); - if (LJ_UNLIKELY(memprof_status != PROFILE_SUCCESS)) { - switch (memprof_status) { - case PROFILE_ERRUSE: - lua_pushnil(L); - lua_pushstring(L, err2msg(LJ_ERR_PROF_MISUSE)); - lua_pushinteger(L, EINVAL); - return 3; -#if LJ_HASMEMPROF - case PROFILE_ERRRUN: - lua_pushnil(L); - lua_pushstring(L, err2msg(LJ_ERR_PROF_ISRUNNING)); - lua_pushinteger(L, EINVAL); - return 3; - case PROFILE_ERRIO: - return luaL_fileresult(L, 0, fname); -#endif - default: - lj_assertL(0, "bad memprof error %d", memprof_status); - return 0; - } - } lua_pushboolean(L, 1); return 1; #endif /* !LJ_HASMEMPROF */ @@ -456,27 +437,15 @@ LJLIB_CF(misc_memprof_stop) return prof_error(L, PROFILE_ERRUSE, err_details); #else int status = lj_memprof_stop(L); - if (status != PROFILE_SUCCESS) { - switch (status) { - case PROFILE_ERRUSE: - lua_pushnil(L); - lua_pushstring(L, err2msg(LJ_ERR_PROF_MISUSE)); - lua_pushinteger(L, EINVAL); - return 3; -#if LJ_HASMEMPROF - case PROFILE_ERRRUN: + if (LJ_UNLIKELY(status == PROFILE_ERRRUN)) { lua_pushnil(L); lua_pushstring(L, err2msg(LJ_ERR_PROF_NOTRUNNING)); lua_pushinteger(L, EINVAL); return 3; - case PROFILE_ERRIO: - return luaL_fileresult(L, 0, NULL); -#endif - default: - lj_assertL(0, "bad memprof error %d", status); - return 0; - } } + if (LJ_UNLIKELY(status != PROFILE_SUCCESS)) + return prof_error(L, status, NULL); + lua_pushboolean(L, 1); return 1; #endif /* !LJ_HASMEMPROF */ -- 2.43.0