diff --git a/cmake/modules/FindMooCmake.cmake b/cmake/modules/FindMooCmake.cmake index df766b76..dbe0bdcb 100644 --- a/cmake/modules/FindMooCmake.cmake +++ b/cmake/modules/FindMooCmake.cmake @@ -143,10 +143,6 @@ IF(MOO_OS_BSD OR MOO_OS_LINUX) SET(MOO_OS_UNIX TRUE) ENDIF(MOO_OS_BSD OR MOO_OS_LINUX) -FOREACH(_moo_os ${_MOO_KNOWN_PLATFORMS}) - MOO_DEFINE_H(MOO_OS_${_moo_os}) -ENDFOREACH(_moo_os) - ########################################################################### # # Installation dirs @@ -348,7 +344,7 @@ MACRO(MOO_CHECK_OPTION variable) ENDIF(NOT DEFINED __MOO_OPTION_SET_${variable}) ENDMACRO(MOO_CHECK_OPTION) -MOO_OPTION(MOO_DEV_MODE FALSE "Enable developer mode - bunch of checks, warnings, etc.") +MOO_OPTION(MOO_DEV_MODE FALSE "Enable developer mode - bunch of checks, warnings, etc." DEFINE 1) FIND_PACKAGE(MooCompilers) FIND_PACKAGE(MooCmakeUtils) diff --git a/cmake/modules/FindMooCompilers.cmake b/cmake/modules/FindMooCompilers.cmake index aa0c32b1..f8738e2c 100644 --- a/cmake/modules/FindMooCompilers.cmake +++ b/cmake/modules/FindMooCompilers.cmake @@ -174,17 +174,18 @@ IF(MOO_DEV_MODE) ENDIF(MOO_DEV_MODE) MOO_ADD_COMPILER_FLAGS(GCC -Wall -Wextra) -MOO_CHECK_COMPILER_FLAGS(GCC -fexceptions -fno-strict-aliasing -fno-strict-overflow -Wno-missing-field-initializers) +MOO_CHECK_COMPILER_FLAGS(GCC -fexceptions -fno-strict-aliasing -fno-strict-overflow -Wno-missing-field-initializers -Wnonnull) MOO_CHECK_COMPILER_FLAGS(GCC DEBUG -ftrapv) MOO_ADD_COMPILER_FLAGS(GCC CXX -std=c++98 -pedantic) +MOO_CHECK_COMPILER_FLAGS(GCC CXX -fno-rtti) MOO_CHECK_COMPILER_FLAGS(GCC CXX RELEASE -fno-enforce-eh-specs) IF(MOO_DEV_MODE) MOO_CHECK_COMPILER_FLAGS(GCC CXX -fno-nonansi-builtins -fno-gnu-keywords) MOO_CHECK_COMPILER_FLAGS(GCC CXX - -Wctor-dtor-privacy -Wnon-virtual-dtor + -Wctor-dtor-privacy -Wnon-virtual-dtor -Wabi -Wstrict-null-sentinel -Woverloaded-virtual -Wsign-promo ) ENDIF(MOO_DEV_MODE) diff --git a/config.h.in b/config.h.in index c02d6657..ece6330d 100644 --- a/config.h.in +++ b/config.h.in @@ -1,3 +1,5 @@ +#include + #define MOO_BUILD_APP 1 #define MOO_BUILD_EDIT 1 #define MOO_BUILD_LUA 1 diff --git a/moo/moo-config.h b/moo/moo-config.h new file mode 100644 index 00000000..7b39288e --- /dev/null +++ b/moo/moo-config.h @@ -0,0 +1,63 @@ +#ifndef MOO_CONFIG_H +#define MOO_CONFIG_H + +#undef MOO_CL_GCC +#undef MOO_CL_MINGW +#undef MOO_CL_MSVC +#define MOO_GCC_CHECK_VERSION(maj,min) (0) + +#if defined(_MSC_VER) +# define MOO_CL_MSVC 1 +#elif defined(__GNUC__) +# define MOO_CL_GCC 1 +# ifdef __GNUC_MINOR__ +# undef MOO_GCC_CHECK_VERSION +# define MOO_GCC_CHECK_VERSION(maj,min) (((__GNUC__ << 16) + __GNUC_MINOR__) >= (((maj) << 16) + (min))) +# endif +# if defined(__MINGW32__) +# define MOO_CL_MINGW 1 +# endif +#endif + +#undef MOO_OS_WIN32 +#undef MOO_OS_WIN64 +#undef MOO_OS_UNIX +#undef MOO_OS_DARWIN + +#if defined(__APPLE__) +# define MOO_OS_DARWIN 1 +#endif + +#if defined(_WIN32) +# if !defined(UNICODE) || !defined(_UNICODE) +# error "UNICODE and _UNICODE must be defined on windows" +# endif +# ifndef __WIN32__ +# error "__WIN32__ must be defined on windows" +# endif +# define MOO_OS_WIN32 1 +#else +# ifdef __WIN32__ +# error "__WIN32__ defined but _WIN32 is not" +# endif +#endif +#if defined(_WIN64) +# ifndef _WIN32 +# error "_WIN64 defined but _WIN32 is not" +# endif +# define MOO_OS_WIN64 1 +#endif + +#ifndef MOO_OS_WIN32 +# define MOO_OS_UNIX 1 +#endif + +#ifndef MOO_OS_WIN32 +# define MOO_CDECL +# define MOO_STDCALL +#else +# define MOO_CDECL __cdecl +# define MOO_STDCALL __stdcall +#endif + +#endif /* MOO_CONFIG_H */ diff --git a/moo/mooutils/moo-test-utils.c b/moo/mooutils/moo-test-utils.c index 489b9d4c..60e8d1a4 100644 --- a/moo/mooutils/moo-test-utils.c +++ b/moo/mooutils/moo-test-utils.c @@ -412,7 +412,7 @@ moo_test_load_data_file (const char *basename) return contents; } -MOO_NORETURN void +NORETURN void moo_abort (void) { abort (); diff --git a/moo/mooutils/moo-test-utils.h b/moo/mooutils/moo-test-utils.h index 4eac1fe0..0fd973a9 100644 --- a/moo/mooutils/moo-test-utils.h +++ b/moo/mooutils/moo-test-utils.h @@ -53,7 +53,7 @@ void moo_test_run_tests (const char *single_test, void moo_test_cleanup (void); gboolean moo_test_get_result (void); -MOO_NORETURN void moo_abort (void); +NORETURN void moo_abort (void); void moo_test_assert_impl (gboolean passed, const char *text, diff --git a/moo/mooutils/moocpp-exc.h b/moo/mooutils/moocpp-exc.h index 2945fe74..e4e70a4b 100644 --- a/moo/mooutils/moocpp-exc.h +++ b/moo/mooutils/moocpp-exc.h @@ -20,27 +20,21 @@ namespace moo { -#if defined(MOO_COMPILER_MSVC) -#define MOO_NOTHROW __declspec(nothrow) -#else -#define MOO_NOTHROW throw() -#endif - class Exception { protected: - Exception(const char *what, const MooCodeLoc *loc) MOO_NOTHROW + NOTHROW Exception(const char *what, const MooCodeLoc *loc) : m_what(what ? what : "") , m_loc(loc ? *loc : moo_default_code_loc ()) { } - virtual ~Exception() MOO_NOTHROW + virtual NOTHROW ~Exception() { } public: - const char *what() const MOO_NOTHROW { return m_what; } + const char * NOTHROW what() const { return m_what; } private: const char *m_what; @@ -52,19 +46,19 @@ private: class ExcUnexpected : public Exception { protected: - ExcUnexpected(const char *msg, const MooCodeLoc &loc) MOO_NOTHROW + NOTHROW ExcUnexpected(const char *msg, const MooCodeLoc &loc) : Exception(msg, &loc) { } - virtual ~ExcUnexpected() MOO_NOTHROW + virtual NOTHROW ~ExcUnexpected() { } MOO_DISABLE_COPY_AND_ASSIGN(ExcUnexpected) public: - MOO_NORETURN static void raise(const char *msg, const MooCodeLoc &loc) + NORETURN static void raise(const char *msg, const MooCodeLoc &loc) { moo_assert_message(msg, loc); throw ExcUnexpected(msg, loc); diff --git a/moo/mooutils/moocpp-gobject.h b/moo/mooutils/moocpp-gobject.h index 010aa737..03d5b8c4 100644 --- a/moo/mooutils/moocpp-gobject.h +++ b/moo/mooutils/moocpp-gobject.h @@ -35,7 +35,7 @@ static void c_type##_init(CType *obj) \ MOO_END_NO_EXCEPTIONS \ } \ \ -static void c_type##_finalize(GObject *gobj) MOO_NOTHROW \ +static void NOTHROW c_type##_finalize(GObject *gobj) \ { \ ImplType *p = G_TYPE_INSTANCE_GET_PRIVATE(gobj, \ c_type##_get_type(), ImplType); \ @@ -43,7 +43,7 @@ static void c_type##_finalize(GObject *gobj) MOO_NOTHROW \ G_OBJECT_CLASS(c_type##_parent_class)->finalize(gobj); \ } \ \ -static ImplType *getPriv(CType *obj) MOO_NOTHROW \ +static ImplType * NOTHROW getPriv(CType *obj) \ { \ return G_TYPE_INSTANCE_GET_PRIVATE(obj, \ c_type##_get_type(), ImplType); \ @@ -58,21 +58,21 @@ template class GWeakPtr { public: - GWeakPtr(GObjType *gobj = 0) MOO_NOTHROW : m_p(0) { set(gobj); } - ~GWeakPtr() MOO_NOTHROW { unset(); } + NOTHROW GWeakPtr(GObjType *gobj = 0) : m_p(0) { set(gobj); } + NOTHROW ~GWeakPtr() { unset(); } - GWeakPtr(const GWeakPtr &wp) MOO_NOTHROW : m_p(0) { set(wp.get()); } - GWeakPtr &operator=(const GWeakPtr &wp) MOO_NOTHROW { set(wp.get()); } - GWeakPtr &operator=(GObjType *gobj) MOO_NOTHROW { set(gobj); } + NOTHROW GWeakPtr(const GWeakPtr &wp) : m_p(0) { set(wp.get()); } + GWeakPtr & NOTHROW operator=(const GWeakPtr &wp) { set(wp.get()); } + GWeakPtr & NOTHROW operator=(GObjType *gobj) { set(gobj); } - operator bool () const MOO_NOTHROW { return m_p; } - bool operator ! () const MOO_NOTHROW { return !m_p; } + NOTHROW operator bool () const { return m_p; } + bool NOTHROW operator ! () const { return !m_p; } - operator GObjType* () const MOO_NOTHROW { return get(); } + NOTHROW operator GObjType* () const { return get(); } GObjType *operator -> () const { return checkPtr(get()); } - GObjType *get() const MOO_NOTHROW { return static_cast(m_p); } + GObjType * NOTHROW get() const { return static_cast(m_p); } - void set(GObjType *gobj) MOO_NOTHROW + void NOTHROW set(GObjType *gobj) { if (m_p != gobj) { @@ -83,7 +83,7 @@ public: } } - void unset() MOO_NOTHROW + void NOTHROW unset() { if (m_p) g_object_remove_weak_pointer(G_OBJECT(m_p), &m_p); diff --git a/moo/mooutils/moocpp-macros.h b/moo/mooutils/moocpp-macros.h index 467b3e8d..cea28dcf 100644 --- a/moo/mooutils/moocpp-macros.h +++ b/moo/mooutils/moocpp-macros.h @@ -26,50 +26,60 @@ #define mooStaticAssert MOO_STATIC_ASSERT -#ifdef DEBUG -mooStaticAssert(sizeof(char) == 1, "test"); -inline void _moo_dummy_test_func() -{ - mooCheck(false); - mooAssert(false); - mooAssertNotReached(); - mooCheckNotReached(); -} -#endif - namespace moo { template -inline void checkCanCast() +inline void MOO_FUNC_DEV_MODE checkCanCast() { FromClass *p = 0; ToClass &q = *p; (void) q; } -#ifdef DEBUG +#ifdef MOO_DEV_MODE #define mooCheckCanCast(FromClass, ToClass) moo::checkCanCast() #else // !DEBUG #define mooCheckCanCast(FromClass, ToClass) MOO_VOID_STMT #endif // !DEBUG +#define MOO_DISABLE_COPY_AND_ASSIGN(Class) \ +private: \ + Class(const Class&) MOO_FA_MISSING; \ + Class &operator=(const Class&) MOO_FA_MISSING; + +#ifdef MOO_DEV_MODE + +namespace _test { + +mooStaticAssert(sizeof(char) == 1, "test"); + +inline void __moo_test_func() +{ + mooCheck(false); + mooAssert(false); + mooAssertNotReached(); + mooCheckNotReached(); +} + +class Foo1 { +public: + Foo1() {} + + void meth1() NOTHROW; + void NOTHROW meth2() {} + + MOO_DISABLE_COPY_AND_ASSIGN(Foo1) +}; + +inline void NOTHROW Foo1::meth1() +{ +} + +} // namespace _test + +#endif // MOO_DEV_MODE + } // namespace moo -#define MOO_DISABLE_COPY_AND_ASSIGN(Class) \ -private: \ - Class(const Class&); \ - Class &operator=(const Class&); - -#define MOO_DO_ONCE_BEGIN \ -do { \ - static bool _moo_beenHere = false; \ - if (!_moo_beenHere) \ - { \ - _moo_beenHere = true; - -#define MOO_DO_ONCE_END \ - } \ -} while (0); - #endif /* MOO_CPP_MACROS_H */ /* -%- strip:true -%- */ diff --git a/moo/mooutils/moocpp-types.h b/moo/mooutils/moocpp-types.h index ab259b7a..bed1cd28 100644 --- a/moo/mooutils/moocpp-types.h +++ b/moo/mooutils/moocpp-types.h @@ -49,9 +49,9 @@ public: CheckedPtr(T *p) : m_p(p) { mooThrowIfFalse(p); } CheckedPtr(T *p, const char *msg, const MooCodeLoc &loc) : m_p(p) { if (!p) ExcUnexpected::raise(msg, loc); } - operator T*() const MOO_NOTHROW { return m_p; } - T &operator*() const MOO_NOTHROW { return *m_p; } - T *operator->() const MOO_NOTHROW { return m_p; } + NOTHROW operator T*() const { return m_p; } + T & NOTHROW operator*() const { return *m_p; } + T * NOTHROW operator->() const { return m_p; } private: T *m_p; diff --git a/moo/mooutils/mooonce.h b/moo/mooutils/mooonce.h index 2f5ba29a..5d1fffca 100644 --- a/moo/mooutils/mooonce.h +++ b/moo/mooutils/mooonce.h @@ -2,6 +2,7 @@ #define MOO_ONCE_H #include +#include #if !GLIB_CHECK_VERSION(2,14,0) inline static gboolean @@ -35,15 +36,28 @@ moo_once_init_leave (volatile gsize *value_location, #define moo_once_init_leave g_once_init_leave #endif -#define MOO_BEGIN_DO_ONCE \ +#define MOO_DO_ONCE_BEGIN \ do { \ static gsize _moo_do_once = 0; \ if (moo_once_init_enter (&_moo_do_once)) \ { -#define MOO_END_DO_ONCE \ +#define MOO_DO_ONCE_END \ moo_once_init_leave (&_moo_do_once, 1); \ } \ } while (0); +#ifdef MOO_DEV_MODE + +inline static gboolean __moo_test_func() +{ + gboolean value; + MOO_DO_ONCE_BEGIN + value = TRUE; + MOO_DO_ONCE_END + return value; +} + +#endif + #endif /* MOO_ONCE_H */ diff --git a/moo/mooutils/mootype-macros.h b/moo/mooutils/mootype-macros.h index 5203ad37..50053cfe 100644 --- a/moo/mooutils/mootype-macros.h +++ b/moo/mooutils/mootype-macros.h @@ -67,12 +67,12 @@ type_name##_get_type (void) { \ static GType g_define_type_id; \ \ - MOO_BEGIN_DO_ONCE \ + MOO_DO_ONCE_BEGIN \ \ _MOO_REGISTER_TYPE(TypeName,type_name,TYPE_PARENT,0) \ code \ \ - MOO_END_DO_ONCE \ + MOO_DO_ONCE_END \ \ return g_define_type_id; \ } @@ -85,14 +85,14 @@ type_name##_get_type (void) { \ static GType g_define_type_id; \ \ - MOO_BEGIN_DO_ONCE \ + MOO_DO_ONCE_BEGIN \ \ g_define_type_id = \ g_boxed_type_register_static (#TypeName, \ (GBoxedCopyFunc) copy_func, \ (GBoxedFreeFunc) free_func); \ \ - MOO_END_DO_ONCE \ + MOO_DO_ONCE_END \ \ return g_define_type_id; \ } @@ -123,9 +123,9 @@ static GType type_name##_get_type (void) GType type_name##_get_type (void) \ { \ static GType g_define_type_id; \ - MOO_BEGIN_DO_ONCE \ + MOO_DO_ONCE_BEGIN \ g_define_type_id = g_pointer_type_register_static (#TypeName); \ - MOO_END_DO_ONCE \ + MOO_DO_ONCE_END \ return g_define_type_id; \ } @@ -133,9 +133,9 @@ GType type_name##_get_type (void) #define MOO_DEFINE_QUARK__(QuarkName) \ { \ static GQuark q; \ - MOO_BEGIN_DO_ONCE \ + MOO_DO_ONCE_BEGIN \ q = g_quark_from_static_string (#QuarkName); \ - MOO_END_DO_ONCE \ + MOO_DO_ONCE_END \ return q; \ } diff --git a/moo/mooutils/mooutils-debug.h b/moo/mooutils/mooutils-debug.h index 745fa597..aa453675 100644 --- a/moo/mooutils/mooutils-debug.h +++ b/moo/mooutils/mooutils-debug.h @@ -88,7 +88,7 @@ gboolean moo_debug_enabled (const char *var, gboolean def_enabled); void _moo_set_debug (const char *domains); -#elif defined(MOO_COMPILER_GCC) +#elif defined(MOO_CL_GCC) #define MOO_DEBUG_INIT(domain, def_enabled) #define moo_dmsg(format, args...) G_STMT_START {} G_STMT_END diff --git a/moo/mooutils/mooutils-macros.h b/moo/mooutils/mooutils-macros.h index 8c6cf03e..76174e32 100644 --- a/moo/mooutils/mooutils-macros.h +++ b/moo/mooutils/mooutils-macros.h @@ -16,23 +16,11 @@ #ifndef MOO_UTILS_MACROS_H #define MOO_UTILS_MACROS_H -#if defined(__GNUC__) -# undef MOO_COMPILER_MSVC -# define MOO_COMPILER_GCC 1 -# define MOO_GCC_VERSION(maj,min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) -#elif defined(_MSC_VER) -# define MOO_COMPILER_MSVC 1 -# undef MOO_COMPILER_GCC -# define MOO_GCC_VERSION(maj,min) (0) -#else /* not gcc, not visual studio */ -# undef MOO_COMPILER_MSVC -# undef MOO_COMPILER_GCC -# define MOO_GCC_VERSION(maj,min) (0) -#endif /* gcc or visual studio */ +#include -#if defined(MOO_COMPILER_GCC) +#if defined(MOO_CL_GCC) # define MOO_STRFUNC ((const char*) (__PRETTY_FUNCTION__)) -#elif defined(MOO_COMPILER_MSVC) +#elif defined(MOO_CL_MSVC) # define MOO_STRFUNC ((const char*) (__FUNCTION__)) #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L # define MOO_STRFUNC ((const char*) (__func__)) @@ -40,7 +28,7 @@ # define MOO_STRFUNC ((const char*) ("")) #endif -#if defined(MOO_COMPILER_MSVC) +#if defined(MOO_CL_MSVC) #define MOO_MSVC_WARNING_PUSH __pragma(warning(push)) #define MOO_MSVC_WARNING_POP __pragma(warning(push)) #define MOO_MSVC_WARNING_DISABLE(N) __pragma(warning(disable:N)) @@ -52,12 +40,12 @@ #define MOO_MSVC_WARNING_PUSH_DISABLE(N) #endif -#if defined(MOO_COMPILER_GCC) +#if defined(MOO_CL_GCC) #define _MOO_GCC_PRAGMA(x) _Pragma (#x) #define MOO_COMPILER_MESSAGE(x) _MOO_GCC_PRAGMA(message (#x)) #define MOO_TODO(x) _MOO_GCC_PRAGMA(message ("TODO: " #x)) #define MOO_IMPLEMENT_ME _MOO_GCC_PRAGMA(message ("IMPLEMENT ME")) -#elif defined(MOO_COMPILER_MSVC) +#elif defined(MOO_CL_MSVC) #define _MOO_MESSAGE_LINE(line) #line #define _MOO_MESSAGE_LOC __FILE__ "(" _MOO_MESSAGE_LINE(__LINE__) ") : " #define MOO_COMPILER_MESSAGE(x) __pragma(message(_MOO_MESSAGE_LOC #x)) @@ -69,12 +57,131 @@ #define MOO_IMPLEMENT_ME #endif -#if defined(MOO_COMPILER_MSVC) -#define MOO_NORETURN __declspec(noreturn) -#elif defined(__GNUC__) -#define MOO_NORETURN __attribute__((noreturn)) +#define MOO_CONCAT__(a, b) a##b +#define MOO_CONCAT(a, b) MOO_CONCAT__(a, b) + +#define MOO_UNUSED(x) (void)(x) +#ifdef MOO_CL_GCC +# define MOO_UNUSED_ARG(x) x __attribute__ ((__unused__)) #else -#define MOO_NORETURN +# define MOO_UNUSED_ARG(x) x +#endif + +#if defined(MOO_CL_GCC) +# define MOO_FA_ERROR(msg) __attribute__((error(msg))) +# define MOO_FA_WARNING(msg) __attribute__((warning(msg))) +# define MOO_FA_NORETURN __attribute__((noreturn)) +# define MOO_FA_CONST __attribute__((const)) +# define MOO_FA_UNUSED __attribute__((unused)) +# define MOO_FA_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) +# define MOO_FA_MALLOC __attribute__((malloc)) +# if MOO_GCC_CHECK_VERSION(3, 3) +# define MOO_FA_DEPRECATED __attribute__((deprecated)) +# else +# define MOO_FA_DEPRECATED +# endif +# if MOO_GCC_CHECK_VERSION(3, 3) +# define MOO_FA_NONNULL(indices) __attribute__((nonnull indices)) +# define MOO_FA_NOTHROW __attribute__((nothrow)) +# else +# define MOO_FA_NONNULL(indices) +# define MOO_FA_NOTHROW +# endif +#else /* !MOO_CL_GCC */ +# define MOO_FA_ERROR(msg) +# define MOO_FA_WARNING(msg) +# define MOO_FA_MALLOC +# define MOO_FA_UNUSED +# define MOO_FA_WARN_UNUSED_RESULT +# define MOO_FA_CONST +# define MOO_FA_DEPRECATED +# define MOO_FA_NONNULL(indices) +# if defined(MOO_CL_MSVC) +# define MOO_FA_NORETURN __declspec(noreturn) +# define MOO_FA_NOTHROW __declspec(nothrow) +# else +# define MOO_FA_NORETURN +# define MOO_FA_NOTHROW +# endif +#endif /* !MOO_CL_GCC */ + +#define MOO_NORETURN MOO_FA_NORETURN +#define MOO_NOTHROW MOO_FA_NOTHROW +#define NORETURN MOO_NORETURN +#define NOTHROW MOO_NOTHROW + +#define MOO_FA_MISSING MOO_FA_ERROR("This function must not be used") + +#if !defined(MOO_DEV_MODE) +# define MOO_FUNC_DEV_MODE MOO_FA_ERROR("This function must be used only in dev mode") +#else +# define MOO_FUNC_DEV_MODE +#endif + +#if defined(MOO_CL_GCC) +# define MOO_VA_CLEANUP(func) __attribute__((cleanup(func))) +# define _MOO_VA_CLEANUP_DEFINED 1 +# define MOO_VA_DEPRECATED __attribute__((deprecated)) +# define MOO_VA_UNUSED __attribute__((unused)) +#else /* !MOO_CL_GCC */ +# define MOO_VA_CLEANUP(func) +# undef _MOO_VA_CLEANUP_DEFINED +# define MOO_VA_DEPRECATED +# define MOO_VA_UNUSED +#endif /* !MOO_CL_GCC */ + +#define MOO_VAR_CLEANUP_CHECK(func) +#define MOO_VAR_CLEANUP_CHECKD(func) +#undef MOO_VAR_CLEANUP_CHECK_ENABLED +#undef MOO_VAR_CLEANUP_CHECKD_ENABLED + +#if defined(_MOO_VA_CLEANUP_DEFINED) +# undef MOO_VAR_CLEANUP_CHECK +# define MOO_VAR_CLEANUP_CHECK(func) MOO_VA_CLEANUP(func) +# define MOO_VAR_CLEANUP_CHECK_ENABLED 1 +# ifdef DEBUG +# undef MOO_VAR_CLEANUP_CHECKD +# define MOO_VAR_CLEANUP_CHECKD(func) MOO_VA_CLEANUP(func) +# define MOO_VAR_CLEANUP_CHECKD_ENABLED 1 +# endif +#endif + +#ifdef __COUNTER__ +#define _MOO_COUNTER __COUNTER__ +#else +#define _MOO_COUNTER 0 +#endif + +#define MOO_CODE_LOC (moo_make_code_loc (__FILE__, MOO_STRFUNC, __LINE__, _MOO_COUNTER)) + +#define _MOO_STATIC_ASSERT_MACRO(cond) enum { MOO_CONCAT(_MooStaticAssert_, __LINE__) = 1 / ((cond) ? 1 : 0) } +#define MOO_STATIC_ASSERT(cond, message) _MOO_STATIC_ASSERT_MACRO(cond) + +#define _MOO_ASSERT_MESSAGE(msg) moo_assert_message (msg, MOO_CODE_LOC) + +#define _MOO_ASSERT_CHECK_MSG(cond, msg) \ +do { \ + if (cond) \ + ; \ + else \ + _MOO_ASSERT_MESSAGE (msg); \ +} while(0) + +#define _MOO_ASSERT_CHECK(cond) \ + _MOO_ASSERT_CHECK_MSG(cond, \ + "condition failed: " #cond) + +#define MOO_VOID_STMT do {} while (0) + +#define _MOO_RELEASE_ASSERT _MOO_ASSERT_CHECK +#define _MOO_RELEASE_ASSERT_NOT_REACHED() _MOO_ASSERT_MESSAGE ("should not be reached") + +#ifdef DEBUG +#define _MOO_DEBUG_ASSERT _MOO_ASSERT_CHECK +#define _MOO_DEBUG_ASSERT_NOT_REACHED() _MOO_ASSERT_MESSAGE ("should not be reached") +#else +#define _MOO_DEBUG_ASSERT(cond) MOO_VOID_STMT +#define _MOO_DEBUG_ASSERT_NOT_REACHED() MOO_VOID_STMT #endif #ifdef __cplusplus @@ -107,8 +214,8 @@ moo_make_code_loc (const char *file, const char *func, int line, int counter) return loc; } -#ifndef DEBUG -MOO_NORETURN +#ifndef MOO_DEV_MODE +NORETURN #endif void moo_assert_message(const char *message, MooCodeLoc loc); @@ -116,49 +223,91 @@ void moo_assert_message(const char *message, MooCodeLoc loc); } // extern "C" #endif -#ifdef __COUNTER__ -#define _MOO_COUNTER __COUNTER__ -#else -#define _MOO_COUNTER 0 -#endif +#define __moo_test_func_name MOO_CONCAT(__moo_test_func_, __LINE__) +#define __moo_test_func __moo_test_func_name +#define __moo_test_func_a(args) __moo_test_func_name args -#define MOO_CODE_LOC (moo_make_code_loc (__FILE__, MOO_STRFUNC, __LINE__, _MOO_COUNTER)) +#ifdef MOO_DEV_MODE -#define _MOO_ASSERT_MESSAGE(msg) moo_assert_message (msg, MOO_CODE_LOC) +MOO_STATIC_ASSERT(sizeof(char) == 1, "test"); -#define _MOO_ASSERT_CHECK_MSG(cond, msg) \ -do { \ - if (cond) \ - ; \ - else \ - _MOO_ASSERT_MESSAGE (msg); \ -} while(0) +inline static void __moo_test_func(void) +{ + _MOO_RELEASE_ASSERT(0); + _MOO_RELEASE_ASSERT_NOT_REACHED(); + _MOO_DEBUG_ASSERT(0); + _MOO_DEBUG_ASSERT_NOT_REACHED(); +} -#define _MOO_ASSERT_CHECK(cond) \ - _MOO_ASSERT_CHECK_MSG(cond, \ - "condition failed: " #cond) +int __moo_test_func_name(void) MOO_FA_MISSING; +void __moo_test_func_name(void) MOO_FA_ERROR("test"); +void MOO_FA_ERROR("test") __moo_test_func_name(void); +void __moo_test_func_name(void) MOO_FUNC_DEV_MODE; +void MOO_FUNC_DEV_MODE __moo_test_func_name(void); +void __moo_test_func(void); +void __moo_test_func(void) MOO_FA_WARNING("warning"); +void MOO_FA_WARNING("warning") __moo_test_func(void); +void __moo_test_func(void) MOO_FA_DEPRECATED; +void MOO_FA_DEPRECATED __moo_test_func(void); +void *__moo_test_func(void) MOO_FA_MALLOC; +void * MOO_FA_MALLOC __moo_test_func(void); +void * MOO_FA_NONNULL(()) __moo_test_func_a((void *p)); +void * __moo_test_func_a((void *p)) MOO_FA_NONNULL(()); +void * MOO_FA_NONNULL((1)) __moo_test_func_a((void *p)); +void * __moo_test_func_a((void *p)) MOO_FA_NONNULL((1)); +void * MOO_FA_NONNULL((1,2)) __moo_test_func_a((void *p1, void *p2)); +void * __moo_test_func_a((void *p1, void *p2)) MOO_FA_NONNULL((1,2)); -#define MOO_VOID_STMT do {} while (0) +void MOO_NORETURN __moo_test_func_name(void); +void MOO_NOTHROW __moo_test_func_name(void); -#define _MOO_RELEASE_ASSERT _MOO_ASSERT_CHECK -#define _MOO_RELEASE_ASSERT_NOT_REACHED() _MOO_ASSERT_MESSAGE ("should not be reached") +inline static void MOO_NOTHROW __moo_test_func_name(void) +{ +} -#ifdef DEBUG -#define _MOO_DEBUG_ASSERT _MOO_ASSERT_CHECK -#define _MOO_DEBUG_ASSERT_NOT_REACHED() _MOO_ASSERT_MESSAGE ("should not be reached") -#else -#define _MOO_DEBUG_ASSERT(cond) MOO_VOID_STMT -#define _MOO_DEBUG_ASSERT_NOT_REACHED() MOO_VOID_STMT -#endif +void __moo_test_func(void) MOO_FA_NORETURN; +void MOO_FA_NORETURN __moo_test_func(void); -#define _MOO_CONCAT_(a, b) a##b -#define _MOO_CONCAT(a, b) _MOO_CONCAT_(a, b) -#define __MOO_STATIC_ASSERT_MACRO(cond, counter) enum { _MOO_CONCAT(_MooStaticAssert_##counter##_, __LINE__) = 1 / ((cond) ? 1 : 0) } -#define _MOO_STATIC_ASSERT_MACRO(cond) __MOO_STATIC_ASSERT_MACRO(cond, 0) -#define MOO_STATIC_ASSERT(cond, message) _MOO_STATIC_ASSERT_MACRO(cond) +void __moo_test_func(void) MOO_FA_NOTHROW; +void MOO_FA_NOTHROW __moo_test_func(void); -#ifdef DEBUG -inline static void _moo_test_asserts_dummy(void *p) +void __moo_test_func(void) MOO_FA_UNUSED; +void MOO_FA_UNUSED __moo_test_func(void); + +int __moo_test_func(void) MOO_FA_WARN_UNUSED_RESULT; +int MOO_FA_WARN_UNUSED_RESULT __moo_test_func(void); + +inline static void __moo_test_dummy1(void *p) +{ + MOO_UNUSED(p); +} + +inline static void __moo_test_func(void) +{ + char *p MOO_VA_CLEANUP(__moo_test_dummy1) = 0; + MOO_UNUSED(p); +} + +inline static void __moo_test_func(void) +{ + char *p MOO_VAR_CLEANUP_CHECK(__moo_test_dummy1) = 0; + MOO_UNUSED(p); +} + +inline static void __moo_test_func(void) +{ + char *p MOO_VAR_CLEANUP_CHECKD(__moo_test_dummy1) = 0; + MOO_UNUSED(p); +} + +inline static void __moo_test_func_a((MOO_VA_UNUSED MOO_VA_DEPRECATED int var)) +{ + MOO_VA_UNUSED MOO_VA_DEPRECATED int var2; + MOO_VA_UNUSED int MOO_VA_DEPRECATED var3; + MOO_VA_UNUSED int var4 MOO_VA_DEPRECATED; +} + +inline static void __moo_test_func(void *p) { MOO_STATIC_ASSERT (sizeof(char) == 1, "test"); _MOO_ASSERT_CHECK (p != (void*)0); @@ -167,7 +316,12 @@ inline static void _moo_test_asserts_dummy(void *p) _MOO_RELEASE_ASSERT_NOT_REACHED (); _MOO_DEBUG_ASSERT_NOT_REACHED (); } -#endif + +inline static void __moo_test_dummy2(void) NOTHROW; +inline static void NOTHROW __moo_test_dummy2(void) +{ +} + +#endif /* MOO_DEV_MODE */ #endif /* MOO_UTILS_MACROS_H */ -/* -%- strip:true -%- */ diff --git a/moo/mooutils/mooutils-misc.c b/moo/mooutils/mooutils-misc.c index e85f7e5e..58fab83c 100644 --- a/moo/mooutils/mooutils-misc.c +++ b/moo/mooutils/mooutils-misc.c @@ -1154,7 +1154,7 @@ _moo_get_pid_string (void) { static char *moo_pid_string; - MOO_BEGIN_DO_ONCE + MOO_DO_ONCE_BEGIN #ifdef __WIN32__ moo_pid_string = g_strdup_printf ("%ld", GetCurrentProcessId ()); @@ -1162,7 +1162,7 @@ _moo_get_pid_string (void) moo_pid_string = g_strdup_printf ("%ld", (long) getpid ()); #endif - MOO_END_DO_ONCE + MOO_DO_ONCE_END return moo_pid_string; } @@ -1193,7 +1193,7 @@ moo_tempnam (void) static int counter; G_LOCK_DEFINE_STATIC (counter); - MOO_BEGIN_DO_ONCE + MOO_DO_ONCE_BEGIN { char *dirname = NULL; const char *short_name; @@ -1218,7 +1218,7 @@ moo_tempnam (void) moo_temp_dir = dirname; moo_install_atexit (); } - MOO_END_DO_ONCE + MOO_DO_ONCE_END g_return_val_if_fail (moo_temp_dir != NULL, NULL); diff --git a/moo/mooutils/mooutils-misc.h b/moo/mooutils/mooutils-misc.h index c6778308..7ac4bf62 100644 --- a/moo/mooutils/mooutils-misc.h +++ b/moo/mooutils/mooutils-misc.h @@ -212,7 +212,7 @@ gboolean _moo_regex_escape (const char *string, #define moo_new0(type) moo_new0_n (type, 1) #define moo_free(type,p) moo_free_n (type, 1, p) -#if defined(MOO_COMPILER_GCC) +#if defined(MOO_CL_GCC) #define moo_obj_dup(type,p) ({ type const *cp__ = p; type *p__ = moo_dup_block (sizeof (type), cp__); p__; }) #else #define moo_obj_dup(type, p) ((type*) moo_dup_block (sizeof (type), p)) @@ -229,8 +229,6 @@ static inline gpointer moo_object_ref_sink (gpointer obj) return obj; } -#define MOO_UNUSED(x) (void)x; - G_END_DECLS