diff --git a/src/box/mp_error.cc b/src/box/mp_error.cc index 03b3625224c64271aed0d78938f4850c29dffa31..a6219433e92ab78aff71efcf4b91caf352b305f8 100644 --- a/src/box/mp_error.cc +++ b/src/box/mp_error.cc @@ -204,14 +204,8 @@ mp_encode_error_one(char *data, const struct error *error) } static struct error * -error_build_xc(struct mp_error *mp_error) +error_build(struct mp_error *mp_error) { - /* - * To create an error the "raw" constructor is used - * because OOM error must be thrown in OOM case. - * Builders returns a pointer to the static OOM error - * in OOM case. - */ struct error *err = NULL; if (mp_error->type == NULL || mp_error->message == NULL || mp_error->file == NULL) { @@ -373,11 +367,7 @@ mp_decode_error_one(const char **data) } } - try { - err = error_build_xc(&mp_err); - } catch (OutOfMemory *e) { - assert(err == NULL && !diag_is_empty(diag_get())); - } + err = error_build(&mp_err); finish: region_truncate(region, region_svp); mp_error_destroy(&mp_err); diff --git a/src/lib/core/exception.cc b/src/lib/core/exception.cc index ee3921f2828a094e24a98405770d12073dcdefd8..736b30dcdc2ef150a79df10b1ab7e484cc8d6d45 100644 --- a/src/lib/core/exception.cc +++ b/src/lib/core/exception.cc @@ -82,20 +82,12 @@ exception_get_int(struct error *e, const struct method_info *method) } /* extern "C" */ -/** out_of_memory::size is zero-initialized by the linker. */ -static OutOfMemory out_of_memory(__FILE__, __LINE__, - sizeof(OutOfMemory), "malloc", "exception"); - const struct type_info type_Exception = make_type("Exception", NULL); void * Exception::operator new(size_t size) { - void *buf = malloc(size); - if (buf != NULL) - return buf; - diag_set_error(diag_get(), &out_of_memory); - throw &out_of_memory; + return xmalloc(size); } void @@ -106,9 +98,7 @@ Exception::operator delete(void *ptr) Exception::~Exception() { - if (this != &out_of_memory) { - assert(refs == 0); - } + assert(refs == 0); TRASH((struct error *) this); } @@ -306,61 +296,48 @@ FileFormatError::FileFormatError(const char *file, unsigned line, va_end(ap); } -#define BuildAlloc(type) \ - void *p = malloc(sizeof(type)); \ - if (p == NULL) \ - return &out_of_memory; - struct error * BuildOutOfMemory(const char *file, unsigned line, size_t amount, const char *allocator, const char *object) { - BuildAlloc(OutOfMemory); - return new (p) OutOfMemory(file, line, amount, allocator, - object); + return new OutOfMemory(file, line, amount, allocator, object); } struct error * BuildTimedOut(const char *file, unsigned line) { - BuildAlloc(TimedOut); - return new (p) TimedOut(file, line); + return new TimedOut(file, line); } struct error * BuildChannelIsClosed(const char *file, unsigned line) { - BuildAlloc(ChannelIsClosed); - return new (p) ChannelIsClosed(file, line); + return new ChannelIsClosed(file, line); } struct error * BuildFiberIsCancelled(const char *file, unsigned line) { - BuildAlloc(FiberIsCancelled); - return new (p) FiberIsCancelled(file, line); + return new FiberIsCancelled(file, line); } struct error * BuildFiberSliceIsExceeded(const char *file, unsigned line) { - BuildAlloc(FiberSliceIsExceeded); - return new(p) FiberSliceIsExceeded(file, line); + return new FiberSliceIsExceeded(file, line); } struct error * BuildLuajitError(const char *file, unsigned line, const char *msg) { - BuildAlloc(LuajitError); - return new (p) LuajitError(file, line, msg); + return new LuajitError(file, line, msg); } struct error * BuildIllegalParams(const char *file, unsigned line, const char *format, ...) { - BuildAlloc(IllegalParams); - IllegalParams *e = new (p) IllegalParams(file, line, ""); + IllegalParams *e = new IllegalParams(file, line, ""); va_list ap; va_start(ap, format); error_vformat_msg(e, format, ap); @@ -371,8 +348,7 @@ BuildIllegalParams(const char *file, unsigned line, const char *format, ...) struct error * BuildSystemError(const char *file, unsigned line, const char *format, ...) { - BuildAlloc(SystemError); - SystemError *e = new (p) SystemError(file, line, ""); + SystemError *e = new SystemError(file, line, ""); va_list ap; va_start(ap, format); error_vformat_msg(e, format, ap); @@ -384,8 +360,7 @@ BuildSystemError(const char *file, unsigned line, const char *format, ...) struct error * BuildCollationError(const char *file, unsigned line, const char *format, ...) { - BuildAlloc(CollationError); - CollationError *e = new (p) CollationError(file, line, ""); + CollationError *e = new CollationError(file, line, ""); va_list ap; va_start(ap, format); error_vformat_msg(e, format, ap); @@ -396,8 +371,7 @@ BuildCollationError(const char *file, unsigned line, const char *format, ...) struct error * BuildSwimError(const char *file, unsigned line, const char *format, ...) { - BuildAlloc(SwimError); - SwimError *e = new (p) SwimError(file, line, ""); + SwimError *e = new SwimError(file, line, ""); va_list ap; va_start(ap, format); error_vformat_msg(e, format, ap); @@ -408,8 +382,7 @@ BuildSwimError(const char *file, unsigned line, const char *format, ...) struct error * BuildCryptoError(const char *file, unsigned line, const char *format, ...) { - BuildAlloc(CryptoError); - CryptoError *e = new (p) CryptoError(file, line, ""); + CryptoError *e = new CryptoError(file, line, ""); va_list ap; va_start(ap, format); error_vformat_msg(e, format, ap); @@ -421,8 +394,7 @@ struct error * BuildSocketError(const char *file, unsigned line, const char *socketname, const char *format, ...) { - BuildAlloc(SocketError); - SocketError *e = new (p) SocketError(file, line, socketname, ""); + SocketError *e = new SocketError(file, line, socketname, ""); va_list ap; va_start(ap, format); error_vformat_msg(e, format, ap); @@ -435,8 +407,7 @@ BuildSocketError(const char *file, unsigned line, const char *socketname, struct error * BuildRaftError(const char *file, unsigned line, const char *format, ...) { - BuildAlloc(RaftError); - RaftError *e = new (p) RaftError(file, line, ""); + RaftError *e = new RaftError(file, line, ""); va_list ap; va_start(ap, format); error_vformat_msg(e, format, ap); @@ -447,20 +418,10 @@ BuildRaftError(const char *file, unsigned line, const char *format, ...) struct error * BuildFileFormatError(const char *file, unsigned line, const char *format, ...) { - BuildAlloc(FileFormatError); - FileFormatError *e = new(p) FileFormatError(file, line, ""); + FileFormatError *e = new FileFormatError(file, line, ""); va_list ap; va_start(ap, format); error_vformat_msg(e, format, ap); va_end(ap); return e; } - -void -exception_init() -{ - /* A special workaround for out_of_memory static init */ - out_of_memory.refs = 1; -} - -#undef BuildAlloc diff --git a/src/lib/core/exception.h b/src/lib/core/exception.h index 51a36b98343bf0ff5df2a74fb65d737bfea6ad3a..1550afb5f10e69ce4f0cc0eabbc73ed1d8d093b2 100644 --- a/src/lib/core/exception.h +++ b/src/lib/core/exception.h @@ -271,12 +271,6 @@ class FileFormatError: public Exception { virtual void raise() { throw this; } }; -/** - * Initialize the exception subsystem. - */ -void -exception_init(); - #define tnt_error(class, ...) ({ \ say_debug("%s at %s:%i", #class, __FILE__, __LINE__); \ class *e = new class(__FILE__, __LINE__, ##__VA_ARGS__); \ diff --git a/src/main.cc b/src/main.cc index ca72f3e356301a69fc87bd8665e0720efbce0db0..98fb61f6bbc6526323e6e85dd1ddaad5c4d96fb1 100644 --- a/src/main.cc +++ b/src/main.cc @@ -865,8 +865,6 @@ main(int argc, char **argv) main_argc = argc; main_argv = argv; - exception_init(); - fiber_init(fiber_cxx_invoke); popen_init(); coio_init();