From baa69491f2e8fb65693d767daa0e03ef66b320c0 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov <kostja@tarantool.org> Date: Thu, 9 Jul 2015 21:52:10 +0300 Subject: [PATCH] reflection: review fixes - fix a coding bug/regression in fiber.cc with wrong check of result of the dynamic cast - style fixes - fix initialization of type objects when some members of inheritance hierarchy were excluded from type hierarchy --- src/box/memtx_engine.cc | 2 +- src/box/xlog.cc | 4 +++- src/exception.cc | 15 +++++++++------ src/fiber.cc | 5 +++-- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/box/memtx_engine.cc b/src/box/memtx_engine.cc index 5d9b1193e4..36de2cb686 100644 --- a/src/box/memtx_engine.cc +++ b/src/box/memtx_engine.cc @@ -782,7 +782,7 @@ MemtxEngine::waitCheckpoint() } catch (Exception *e) { e->log(); result = -1; - SystemError *se = dynamic_cast<SystemError *>(e); + SystemError *se = type_cast(SystemError, e); if (se) errno = se->errnum(); } diff --git a/src/box/xlog.cc b/src/box/xlog.cc index bd7e8be55c..f89fe88654 100644 --- a/src/box/xlog.cc +++ b/src/box/xlog.cc @@ -75,7 +75,9 @@ XlogError::XlogError(const struct type *type, const char *file, unsigned line, va_end(ap); } -const struct type type_XlogGapError = make_type("XlogGapError", &type_Exception); +const struct type type_XlogGapError = + make_type("XlogGapError", &type_XlogError); + XlogGapError::XlogGapError(const char *file, unsigned line, const struct vclock *from, const struct vclock *to) diff --git a/src/exception.cc b/src/exception.cc index 861ef2b6c1..020eafec52 100644 --- a/src/exception.cc +++ b/src/exception.cc @@ -79,15 +79,15 @@ Exception::~Exception() Exception::Exception(const struct type *type_arg, const char *file, unsigned line) - : Object(), type(type_arg), m_ref(0) { + :type(type_arg), m_ref(0) { if (m_file != NULL) { snprintf(m_file, sizeof(m_file), "%s", file); m_line = line; } else { - m_file[0] = 0; + m_file[0] = '\0'; m_line = 0; } - m_errmsg[0] = 0; + m_errmsg[0] = '\0'; if (this == &out_of_memory) { /* A special workaround for out_of_memory static init */ out_of_memory.m_ref = 1; @@ -108,9 +108,11 @@ static const struct method systemerror_methods[] = { const struct type type_SystemError = make_type("SystemError", &type_Exception, systemerror_methods); -SystemError::SystemError(const struct type *type, const char *file, unsigned line) + +SystemError::SystemError(const struct type *type, + const char *file, unsigned line) :Exception(type, file, line), - m_errno(errno) + m_errno(errno) { /* nothing */ } @@ -149,7 +151,8 @@ SystemError::log() const } const struct type type_OutOfMemory = - make_type("OutOfMemory", &type_Exception); + make_type("OutOfMemory", &type_SystemError); + OutOfMemory::OutOfMemory(const char *file, unsigned line, size_t amount, const char *allocator, const char *object) diff --git a/src/fiber.cc b/src/fiber.cc index 188f49eaf6..70dd95f9e0 100644 --- a/src/fiber.cc +++ b/src/fiber.cc @@ -225,7 +225,8 @@ fiber_join(struct fiber *fiber) /* Move exception to the caller */ diag_move(&fiber->diag, &fiber()->diag); Exception *e = diag_last_error(&fiber()->diag); - if (e != NULL && type_cast(FiberCancelException, e)) + /** Raise exception again, unless it's FiberCancelException */ + if (e != NULL && type_cast(FiberCancelException, e) == NULL) e->raise(); fiber_testcancel(); } @@ -707,7 +708,7 @@ cord_costart_thread_func(void *arg) } diag_move(&f->diag, &fiber()->diag); Exception *e = diag_last_error(&fiber()->diag); - if (e != NULL && type_cast(FiberCancelException, e)) + if (e != NULL && type_cast(FiberCancelException, e) == NULL) e->raise(); return NULL; -- GitLab