Tarantool development patches archive
 help / color / mirror / Atom feed
From: Leonid Vasiliev <lvasiliev@tarantool.org>
To: v.shpilevoy@tarantool.org, alexander.turenko@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH V6 07/10] error: export error_unref() function
Date: Mon, 20 Apr 2020 01:25:09 +0300	[thread overview]
Message-ID: <efed0a5c1d4ed9e6a77b6daf7b9bdcd151a6f2ea.1587334824.git.lvasiliev@tarantool.org> (raw)
In-Reply-To: <cover.1587334824.git.lvasiliev@tarantool.org>
In-Reply-To: <cover.1587334824.git.lvasiliev@tarantool.org>

From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>

C struct error objects can be created directly only in C.
C-side increments their reference counter when pushes to the Lua
stack.

It is not going to be so convenient soon. error_unpack() function
will be used in netbox to decode error object via Lua FFI.

Such error object will have 0 refs and no Lua GC callback
established. Because it won't be pushed on Lua stack natually,
from Lua C. To make such errors alive their reference counter
will be incremented and error_unref() will be set as GC callback.

Follow up for #4398
---
 extra/exports       |  1 +
 src/lib/core/diag.c | 20 ++++++++++++++++++++
 src/lib/core/diag.h | 21 ++-------------------
 3 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/extra/exports b/extra/exports
index 9467398..3317ddb 100644
--- a/extra/exports
+++ b/extra/exports
@@ -242,6 +242,7 @@ box_error_last
 box_error_clear
 box_error_set
 error_set_prev
+error_unref
 box_latch_new
 box_latch_delete
 box_latch_lock
diff --git a/src/lib/core/diag.c b/src/lib/core/diag.c
index e143db1..787f0f8 100644
--- a/src/lib/core/diag.c
+++ b/src/lib/core/diag.c
@@ -31,6 +31,26 @@
 #include "diag.h"
 #include "fiber.h"
 
+void
+error_unref(struct error *e)
+{
+	assert(e->refs > 0);
+	struct error *to_delete = e;
+	while (--to_delete->refs == 0) {
+		/* Unlink error from lists completely.*/
+		struct error *cause = to_delete->cause;
+		assert(to_delete->effect == NULL);
+		if (to_delete->cause != NULL) {
+			to_delete->cause->effect = NULL;
+			to_delete->cause = NULL;
+		}
+		to_delete->destroy(to_delete);
+		if (cause == NULL)
+			return;
+		to_delete = cause;
+	}
+}
+
 int
 error_set_prev(struct error *e, struct error *prev)
 {
diff --git a/src/lib/core/diag.h b/src/lib/core/diag.h
index 7a5454d..beb6a75 100644
--- a/src/lib/core/diag.h
+++ b/src/lib/core/diag.h
@@ -118,25 +118,8 @@ error_ref(struct error *e)
 	e->refs++;
 }
 
-static inline void
-error_unref(struct error *e)
-{
-	assert(e->refs > 0);
-	struct error *to_delete = e;
-	while (--to_delete->refs == 0) {
-		/* Unlink error from lists completely.*/
-		struct error *cause = to_delete->cause;
-		assert(to_delete->effect == NULL);
-		if (to_delete->cause != NULL) {
-			to_delete->cause->effect = NULL;
-			to_delete->cause = NULL;
-		}
-		to_delete->destroy(to_delete);
-		if (cause == NULL)
-			return;
-		to_delete = cause;
-	}
-}
+void
+error_unref(struct error *e);
 
 /**
  * Unlink error from its effect. For instance:
-- 
2.7.4

  parent reply	other threads:[~2020-04-19 22:25 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-19 22:25 [Tarantool-patches] [PATCH V6 00/10] Extending error functionality Leonid Vasiliev
2020-04-19 22:25 ` [Tarantool-patches] [PATCH V6 01/10] error: add custom error type Leonid Vasiliev
2020-04-19 22:25 ` [Tarantool-patches] [PATCH V6 02/10] session: add offset to SQL session settings array Leonid Vasiliev
2020-04-19 22:25 ` [Tarantool-patches] [PATCH V6 03/10] error: add session setting for error type marshaling Leonid Vasiliev
2020-04-19 22:25 ` [Tarantool-patches] [PATCH V6 04/10] error: update constructors of some errors Leonid Vasiliev
2020-04-19 22:25 ` [Tarantool-patches] [PATCH V6 05/10] box: move Lua MP_EXT decoder from tuple.c Leonid Vasiliev
2020-04-19 22:25 ` [Tarantool-patches] [PATCH V6 06/10] error: add error MsgPack encoding Leonid Vasiliev
2020-04-19 22:25 ` Leonid Vasiliev [this message]
2020-04-19 22:25 ` [Tarantool-patches] [PATCH V6 08/10] error: make iproto errors reuse mp_error module Leonid Vasiliev
2020-04-19 22:25 ` [Tarantool-patches] [PATCH V6 09/10] iproto: rename IPROTO_ERROR and IPROTO_ERROR_STACK Leonid Vasiliev
2020-04-19 22:25 ` [Tarantool-patches] [PATCH V6 10/10] error: fix iproto error stack overlapped by old error Leonid Vasiliev
2020-04-20  0:26 ` [Tarantool-patches] [PATCH V6 00/10] Extending error functionality Vladislav Shpilevoy
2020-04-20  8:05   ` lvasiliev
2020-04-20  8:05   ` Kirill Yukhin
2020-04-21 19:03     ` Konstantin Osipov
2020-04-22 16:17       ` lvasiliev
2020-04-22 17:23         ` Konstantin Osipov
2020-04-20  8:30 ` Kirill Yukhin

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=efed0a5c1d4ed9e6a77b6daf7b9bdcd151a6f2ea.1587334824.git.lvasiliev@tarantool.org \
    --to=lvasiliev@tarantool.org \
    --cc=alexander.turenko@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH V6 07/10] error: export error_unref() function' \
    /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