From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp55.i.mail.ru (smtp55.i.mail.ru [217.69.128.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 8B8804696C8 for ; Wed, 15 Apr 2020 12:32:09 +0300 (MSK) From: Leonid Vasiliev Date: Wed, 15 Apr 2020 12:32:01 +0300 Message-Id: <6dc1ed5e5650ed017206d6dacd68a0f83870daee.1586934134.git.lvasiliev@tarantool.org> In-Reply-To: References: In-Reply-To: References: Subject: [Tarantool-patches] [PATCH V3 6/7] error: update constructors of some errors List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org We want to have a transparent marshalling through net.box for errors. To do this, we need to recreate the error on the client side with the same parameters as on the server. For convenience, we update AccessDeniedError constructor which has points to static strings and add the XlogGapError constructor that does not require vclock. Needed for #4398 --- src/box/error.cc | 18 +++++++++--------- src/box/error.h | 8 ++++++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/box/error.cc b/src/box/error.cc index d854b86..acfd2f7 100644 --- a/src/box/error.cc +++ b/src/box/error.cc @@ -254,6 +254,13 @@ XlogGapError::XlogGapError(const char *file, unsigned line, (long long) vclock_sum(to), s_to ? s_to : ""); } +XlogGapError::XlogGapError(const char *file, unsigned line, + const char *msg) + : XlogError(&type_XlogGapError, file, line) +{ + error_format_msg(this, "%s", msg); +} + struct error * BuildXlogGapError(const char *file, unsigned line, const struct vclock *from, const struct vclock *to) @@ -290,15 +297,8 @@ AccessDeniedError::AccessDeniedError(const char *file, unsigned int line, struct on_access_denied_ctx ctx = {access_type, object_type, object_name}; trigger_run(&on_access_denied, (void *) &ctx); - /* - * We want to use ctx parameters as error parameters - * later, so we have to alloc space for it. - * As m_access_type and m_object_type are constant - * literals they are statically allocated. We must copy - * only m_object_name. - */ - m_object_type = object_type; - m_access_type = access_type; + m_object_type = strdup(object_type); + m_access_type = strdup(access_type); m_object_name = strdup(object_name); } diff --git a/src/box/error.h b/src/box/error.h index 540008f..4388723 100644 --- a/src/box/error.h +++ b/src/box/error.h @@ -244,6 +244,8 @@ public: ~AccessDeniedError() { free(m_object_name); + free(m_object_type); + free(m_access_type); } const char * @@ -266,11 +268,11 @@ public: private: /** Type of object the required access was denied to */ - const char *m_object_type; + char *m_object_type; /** Name of object the required access was denied to */ char *m_object_name; /** Type of declined access */ - const char *m_access_type; + char *m_access_type; }; /** @@ -300,6 +302,8 @@ struct XlogGapError: public XlogError { XlogGapError(const char *file, unsigned line, const struct vclock *from, const struct vclock *to); + XlogGapError(const char *file, unsigned line, + const char *msg); virtual void raise() { throw this; } }; -- 2.7.4