diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index e8cb94d5081188d233c47c6a4eb807c38afd8197..4c8feca999745a5a06336e117a6bb5430b43a65b 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -56,7 +56,7 @@ set (recompiled_core_sources set (common_sources tbuf.m palloc.m util.m diagnostics.m salloc.m pickle.m coro.m stat.m log_io.m - log_io_remote.m iproto.m exceptions.m errcode.c latch.m) + log_io_remote.m iproto.m exception.m errcode.c latch.m) if (ENABLE_TRACE) set (common_sources ${common_sources} trace.m) diff --git a/core/exception.m b/core/exception.m new file mode 100644 index 0000000000000000000000000000000000000000..debb381c807d293a6fe41ef78723810b50138329 --- /dev/null +++ b/core/exception.m @@ -0,0 +1,63 @@ +/* + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#include "exception.h" +#include "say.h" + +@implementation tnt_Exception ++ alloc +{ + static __thread tnt_Exception *e = nil; + + if (![e isKindOf:self]) { + [e free]; + e = [super alloc]; + } + + return e; +} + +- init:(const char *)p_file:(unsigned)p_line reason:(const char *)p_reason +{ + [super init]; + + file = p_file; + line = p_line; + + reason = p_reason; + + return self; +} + +- init:(const char *)p_file:(unsigned)p_line +{ + return [self init:p_file:p_line reason:"unknown"]; +} + +@end + diff --git a/core/exceptions.m b/core/exceptions.m deleted file mode 100644 index 2db8c416a0f0e106823526a8d78b105ca8d25c8b..0000000000000000000000000000000000000000 --- a/core/exceptions.m +++ /dev/null @@ -1,35 +0,0 @@ -#include <exceptions.h> -#include <say.h> - -@implementation tnt_Exception -+ alloc -{ - static __thread tnt_Exception *e = nil; - - if (![e isKindOf:self]) { - [e free]; - e = [super alloc]; - } - - return e; -} - -- init:(const char *)p_file:(unsigned)p_line reason:(const char *)p_reason -{ - [super init]; - - file = p_file; - line = p_line; - - reason = p_reason; - - return self; -} - -- init:(const char *)p_file:(unsigned)p_line -{ - return [self init:p_file:p_line reason:"unknown"]; -} - -@end - diff --git a/include/exception.h b/include/exception.h new file mode 100644 index 0000000000000000000000000000000000000000..f99fd034ba039417d844f22d1680844bf2193610 --- /dev/null +++ b/include/exception.h @@ -0,0 +1,57 @@ +#ifndef TARANTOOL_EXCEPTION_H_INCLUDED +#define TARANTOOL_EXCEPTION_H_INCLUDED +/* + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#import <objc/Object.h> + +/** The base class for all exceptions. + * + * Note: implements garbage collection (see +alloc + * implementation). + */ + +@interface tnt_Exception: Object { + @public + const char *file; + unsigned line; + const char *reason; +} + ++ alloc; + +- init:(const char *)p_file:(unsigned)p_line reason:(const char*)p_reason; +- init:(const char *)p_file:(unsigned)p_line; +@end + +#define tnt_raise(class, message) { \ + say_debug("tnt_raise %s at %s:%i", #class, __FILE__, __LINE__); \ + @throw [[class alloc] init:__FILE__:__LINE__ message]; \ +} + +#endif /* TARANTOOL_EXCEPTION_H_INCLUDED */ diff --git a/include/exceptions.h b/include/exceptions.h deleted file mode 100644 index 52dc6eee54d7dfb9822b7c9b08cb3a381eb99ea2..0000000000000000000000000000000000000000 --- a/include/exceptions.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef TARANTOOL_EXCEPTIONS_H -#define TARANTOOL_EXCEPTIONS_H - -#include <objc/Object.h> - -/** The base class for all exceptions. - * - * Note: implements garbage collection (see +alloc - * implementation). - */ - -@interface tnt_Exception: Object { - @public - const char *file; - unsigned line; - const char *reason; -} - -+ alloc; - -- init:(const char *)p_file:(unsigned)p_line reason:(const char*)p_reason; -- init:(const char *)p_file:(unsigned)p_line; -@end - -#define tnt_raise(class, message) { \ - say_debug("tnt_raise %s at %s:%i", #class, __FILE__, __LINE__); \ - @throw [[class alloc] init:__FILE__:__LINE__ message]; \ -} - -#endif diff --git a/include/fiber.h b/include/fiber.h index 08f259eb90fbe23ec52bedf18c6dd18e7bf8079f..189b440a702ed21a96db32a41f07c40e28a9ba4d 100644 --- a/include/fiber.h +++ b/include/fiber.h @@ -40,7 +40,7 @@ #include <util.h> #include "third_party/queue.h" -#include <exceptions.h> +#include "exception.h" #define FIBER_NAME_MAXLEN 16 diff --git a/include/pickle.h b/include/pickle.h index 6e2a9ec4a1a84c87429a4c3e0c4765b9bc9bbccf..34d7d3640f7fa2e3833d63d4ca706bc44bbf3636 100644 --- a/include/pickle.h +++ b/include/pickle.h @@ -28,7 +28,7 @@ #include <stdbool.h> #include <util.h> -#include <exceptions.h> +#include "exception.h" @interface tnt_PickleException: tnt_Exception @end diff --git a/mod/box/box.h b/mod/box/box.h index b68c6134177e0c6d0b19c474af0010f6ceca24be..2141f651643f540699da6de2cce9d7b39b3a1ea2 100644 --- a/mod/box/box.h +++ b/mod/box/box.h @@ -27,7 +27,7 @@ */ #include <mod/box/index.h> -#include <exceptions.h> +#include "exception.h" #include <tbuf.h> @interface tnt_BoxException: tnt_Exception {