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 A4DAA13101AC; Thu, 6 Mar 2025 19:20:44 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A4DAA13101AC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1741278044; bh=OoQBaY9KgeQW9PrpdVpUmQOZ3R8clHZ1HOXqPl6nxiA=; 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=PtvE5qSdgG5cqugaPK8F8n3sEsvZBOauw6KDTkKdAkmlr2RL9/HBvWuCdbE+sSPf5 dJcNKqmwCOL1Nm6ihY272ZyXBLu6gUJPMAOmae0wVRGY68l2XKZuDQwOVD+HlisxGj qlz0kFUJ+u17BvJ8QSUgCGQTIeAGfbeS4BoWkxu0= Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 E16F5131019D for ; Thu, 6 Mar 2025 19:20:08 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E16F5131019D Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-543d8badc30so1009331e87.0 for ; Thu, 06 Mar 2025 08:20:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741278008; x=1741882808; 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=87OUd49fypZeM4MLpGIjBVbfqmvLZuPADYz7mZmiDYk=; b=vUYOIRvo4vFv4oK6ZuEhJ94Swe8RIjCgDC0Vtuhx9+lYkEmre/orEhH02bHsMmqyL2 pjeZgUWNHLYvXp/3kcIo5BNfEXbCsCNbnh811GLBxkAdc7w3dgW9ivJ1lvtE9ehvq5mk hDDq/lCERR97OJdr1iRXxV66O5NLMv1U7qz3NVTTJWAh3e2pdmK47Ro2Ks3DyKf6VA0F aTd0yCg+grb8SSHDOHXjCzrSa2TcG5NedqH7S/tHjwehvOtZuyseugxOR+wK3CKlPz9k 6sg0evg1MuaC1JtcXxf7hvuo9o98fZJnNDmnlCT+hXaDADzPAeyXMlrLMO4CTg10bcMi WqGw== X-Gm-Message-State: AOJu0YyF8QYsH/pK5flawEUXSRS4oACcKOFz7AGj4RY623dLjWdZhTLs 4VPdqbZCh/ajL75EhOcgbtbRU9ol/IjZlm4MU9xl82q9UIWVmImWDC6tjkfd X-Gm-Gg: ASbGncsLR+gPucMYbdWQVSiF2J4o4o1erOS4PX8ipROhXVBxyMKW4CmbwOwWf7A94pg CQ5+HzDl0Aj3PUVIfIIXaSbxgPyfaEKB4tJw6Tw8FxZpzg8T77dyut5mQDlqtdURKWSEzbrU0x/ cGQf0cAit9oOa82CUIuLurTWapNfcSgSOrr+fhbuRJSvfc/mAJ6/oUmJ/+WlwFNLxH/dAl4ijYn 9Ujz9xDzC9vxXcYCl1FV6IYhOdqg+jsJcpotVtvMLP2Nqzcg0L4g4SQGRwgA6TabMalGfkPyxvt jEC3FwFplYFoI2i6LDJpH8/avQ0Ot62D4zZfmA== X-Google-Smtp-Source: AGHT+IG+oT2dD8RQag82N++9gPcP+6ahC6AXQCQkGtOD6xoMq1OZJJtPVGhiE720FvjaKs6YyXuPCg== X-Received: by 2002:a05:6512:3094:b0:549:8d67:c48e with SMTP id 2adb3069b0e04-5498d67c635mr803549e87.29.1741278007789; Thu, 06 Mar 2025 08:20:07 -0800 (PST) Received: from localhost ([79.164.223.111]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5498ae579a3sm219715e87.53.2025.03.06.08.20.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 08:20:07 -0800 (PST) X-Google-Original-From: Sergey Bronnikov To: tarantool-patches@dev.tarantool.org, Sergey Kaplun Date: Thu, 6 Mar 2025 19:18:58 +0300 Message-ID: <014847f53621375016f13b8c7d9b3a8cc8bbeb5b.1741277815.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 | 55 +++++++++++--------------------------------------- 1 file changed, 12 insertions(+), 43 deletions(-) diff --git a/src/lib_misc.c b/src/lib_misc.c index 9c827157..1c81fd80 100644 --- a/src/lib_misc.c +++ b/src/lib_misc.c @@ -287,7 +287,7 @@ 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)); @@ -418,32 +418,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 */ @@ -457,27 +438,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: - 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_ERRRUN)) { + lua_pushnil(L); + lua_pushstring(L, err2msg(LJ_ERR_PROF_NOTRUNNING)); + lua_pushinteger(L, EINVAL); + return 3; + } else if (LJ_UNLIKELY(status != PROFILE_SUCCESS)) { + return prof_error(L, status, NULL); } + lua_pushboolean(L, 1); return 1; #endif /* !LJ_HASMEMPROF */ -- 2.43.0