Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Bronnikov via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: tarantool-patches@dev.tarantool.org,
	Sergey Kaplun <skaplun@tarantool.org>
Subject: [Tarantool-patches] [PATCH luajit 2/3] misc: use prof_error for handling errors
Date: Thu,  6 Mar 2025 19:18:58 +0300	[thread overview]
Message-ID: <014847f53621375016f13b8c7d9b3a8cc8bbeb5b.1741277815.git.sergeyb@tarantool.org> (raw)
In-Reply-To: <cover.1741277815.git.sergeyb@tarantool.org>

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


  parent reply	other threads:[~2025-03-06 16:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-06 16:18 [Tarantool-patches] [PATCH luajit 0/3] Fix sysprof error on stop not started sysprof Sergey Bronnikov via Tarantool-patches
2025-03-06 16:18 ` [Tarantool-patches] [PATCH luajit 1/3] sysprof: rename sysprof_error to prof_error Sergey Bronnikov via Tarantool-patches
2025-03-06 16:18 ` Sergey Bronnikov via Tarantool-patches [this message]
2025-03-07  7:18   ` [Tarantool-patches] [PATCH luajit 2/3] misc: use prof_error for handling errors Sergey Kaplun via Tarantool-patches
2025-03-06 16:19 ` [Tarantool-patches] [PATCH luajit 3/3] sysprof: fix a message with stop without run Sergey Bronnikov via Tarantool-patches
2025-03-07  7:21   ` Sergey Kaplun via Tarantool-patches
2025-03-07 10:44     ` Sergey Bronnikov via Tarantool-patches
  -- strict thread matches above, loose matches on Subject: below --
2025-02-25  7:32 [Tarantool-patches] [PATCH luajit 0/3] Fix sysprof error on stop not started sysprof Sergey Bronnikov via Tarantool-patches
2025-02-25  7:32 ` [Tarantool-patches] [PATCH luajit 2/3] misc: use prof_error for handling errors Sergey Bronnikov via Tarantool-patches
2025-03-05 14:49   ` Sergey Kaplun via Tarantool-patches
2025-03-06 16:04     ` Sergey Bronnikov via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=014847f53621375016f13b8c7d9b3a8cc8bbeb5b.1741277815.git.sergeyb@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=estetus@gmail.com \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit 2/3] misc: use prof_error for handling errors' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox