diff --git a/distrho/DistrhoUtils.hpp b/distrho/DistrhoUtils.hpp index 9a2e0248..7f65f523 100644 --- a/distrho/DistrhoUtils.hpp +++ b/distrho/DistrhoUtils.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2018 Filipe Coelho + * Copyright (C) 2012-2021 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -198,6 +198,16 @@ void d_safe_assert_uint2(const char* const assertion, const char* const file, d_stderr2("assertion failure: \"%s\" in file %s, line %i, v1 %u, v2 %u", assertion, file, line, v1, v2); } +/* + * Print a safe assertion error message, with a custom error message. + */ +static inline +void d_custom_safe_assert(const char* const message, const char* const assertion, const char* const file, + const int line) noexcept +{ + d_stderr2("assertion failure: %s, condition \"%s\" in file %s, line %i", message, assertion, file, line); +} + /* * Print a safe exception error message. */ diff --git a/distrho/src/DistrhoDefines.h b/distrho/src/DistrhoDefines.h index a30bc296..583c4468 100644 --- a/distrho/src/DistrhoDefines.h +++ b/distrho/src/DistrhoDefines.h @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2019 Filipe Coelho + * Copyright (C) 2012-2021 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -39,6 +39,10 @@ # define DISTRHO_OS_HAIKU 1 # elif defined(__linux__) || defined(__linux) # define DISTRHO_OS_LINUX 1 +# elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) +# define DISTRHO_OS_BSD 1 +# elif defined(__GNU__) +# define DISTRHO_OS_GNU_HURD 1 # endif #endif @@ -85,11 +89,25 @@ #endif /* Define DISTRHO_SAFE_ASSERT* */ -#define DISTRHO_SAFE_ASSERT(cond) if (! (cond)) d_safe_assert(#cond, __FILE__, __LINE__); +#define DISTRHO_SAFE_ASSERT(cond) if (! (cond)) d_safe_assert (#cond, __FILE__, __LINE__); +#define DISTRHO_SAFE_ASSERT_INT(cond, value) if (! (cond)) d_safe_assert_int (#cond, __FILE__, __LINE__, static_cast(value)); +#define DISTRHO_SAFE_ASSERT_INT2(cond, v1, v2) if (! (cond)) d_safe_assert_int2 (#cond, __FILE__, __LINE__, static_cast(v1), static_cast(v2)); +#define DISTRHO_SAFE_ASSERT_UINT(cond, value) if (! (cond)) d_safe_assert_uint (#cond, __FILE__, __LINE__, static_cast(value)); +#define DISTRHO_SAFE_ASSERT_UINT2(cond, v1, v2) if (! (cond)) d_safe_assert_uint2(#cond, __FILE__, __LINE__, static_cast(v1), static_cast(v2)); + #define DISTRHO_SAFE_ASSERT_BREAK(cond) if (! (cond)) { d_safe_assert(#cond, __FILE__, __LINE__); break; } #define DISTRHO_SAFE_ASSERT_CONTINUE(cond) if (! (cond)) { d_safe_assert(#cond, __FILE__, __LINE__); continue; } #define DISTRHO_SAFE_ASSERT_RETURN(cond, ret) if (! (cond)) { d_safe_assert(#cond, __FILE__, __LINE__); return ret; } +#define DISTRHO_CUSTOM_SAFE_ASSERT(msg, cond) if (! (cond)) d_custom_safe_assert(msg, #cond, __FILE__, __LINE__); +#define DISTRHO_CUSTOM_SAFE_ASSERT_BREAK(msg, cond) if (! (cond)) { d_custom_safe_assert(msg, #cond, __FILE__, __LINE__); break; } +#define DISTRHO_CUSTOM_SAFE_ASSERT_CONTINUE(msg, cond) if (! (cond)) { d_custom_safe_assert(msg, #cond, __FILE__, __LINE__); continue; } +#define DISTRHO_CUSTOM_SAFE_ASSERT_RETURN(msg, cond, ret) if (! (cond)) { d_custom_safe_assert(msg, #cond, __FILE__, __LINE__); return ret; } + +#define DISTRHO_CUSTOM_SAFE_ASSERT_ONCE_BREAK(msg, cond) if (! (cond)) { static bool _p; if (!_p) { _p = true; d_custom_safe_assert(msg, #cond, __FILE__, __LINE__); } break; } +#define DISTRHO_CUSTOM_SAFE_ASSERT_ONCE_CONTINUE(msg, cond) if (! (cond)) { static bool _p; if (!_p) { _p = true; d_custom_safe_assert(msg, #cond, __FILE__, __LINE__); } continue; } +#define DISTRHO_CUSTOM_SAFE_ASSERT_ONCE_RETURN(msg, cond, ret) if (! (cond)) { static bool _p; if (!_p) { _p = true; d_custom_safe_assert(msg, #cond, __FILE__, __LINE__); } return ret; } + #define DISTRHO_SAFE_ASSERT_INT_BREAK(cond, value) if (! (cond)) { d_safe_assert_int(#cond, __FILE__, __LINE__, static_cast(value); break; } #define DISTRHO_SAFE_ASSERT_INT_CONTINUE(cond, value) if (! (cond)) { d_safe_assert_int(#cond, __FILE__, __LINE__, static_cast(value)); continue; } #define DISTRHO_SAFE_ASSERT_INT_RETURN(cond, value, ret) if (! (cond)) { d_safe_assert_int(#cond, __FILE__, __LINE__, static_cast(value)); return ret; } @@ -112,39 +130,23 @@ #define DISTRHO_SAFE_EXCEPTION_CONTINUE(msg) catch(...) { d_safe_exception(msg, __FILE__, __LINE__); continue; } #define DISTRHO_SAFE_EXCEPTION_RETURN(msg, ret) catch(...) { d_safe_exception(msg, __FILE__, __LINE__); return ret; } -/* Define DISTRHO_DECLARE_NON_COPY_CLASS */ +/* Define DISTRHO_DECLARE_NON_COPYABLE */ #ifdef DISTRHO_PROPER_CPP11_SUPPORT -# define DISTRHO_DECLARE_NON_COPY_CLASS(ClassName) \ -private: \ - ClassName(ClassName&) = delete; \ - ClassName(const ClassName&) = delete; \ - ClassName& operator=(ClassName&) = delete ; \ +# define DISTRHO_DECLARE_NON_COPYABLE(ClassName) \ +private: \ + ClassName(ClassName&) = delete; \ + ClassName(const ClassName&) = delete; \ + ClassName& operator=(ClassName&) = delete; \ ClassName& operator=(const ClassName&) = delete; #else -# define DISTRHO_DECLARE_NON_COPY_CLASS(ClassName) \ -private: \ - ClassName(ClassName&); \ - ClassName(const ClassName&); \ - ClassName& operator=(ClassName&); \ +# define DISTRHO_DECLARE_NON_COPYABLE(ClassName) \ +private: \ + ClassName(ClassName&); \ + ClassName(const ClassName&); \ + ClassName& operator=(ClassName&); \ ClassName& operator=(const ClassName&); #endif -/* Define DISTRHO_DECLARE_NON_COPY_STRUCT */ -#ifdef DISTRHO_PROPER_CPP11_SUPPORT -# define DISTRHO_DECLARE_NON_COPY_STRUCT(StructName) \ - StructName(StructName&) = delete; \ - StructName(const StructName&) = delete; \ - StructName& operator=(StructName&) = delete; \ - StructName& operator=(const StructName&) = delete; -#else -# define DISTRHO_DECLARE_NON_COPY_STRUCT(StructName) \ -private: \ - StructName(StructName&); \ - StructName(const StructName&); \ - StructName& operator=(StructName&); \ - StructName& operator=(const StructName&); -#endif - /* Define DISTRHO_PREVENT_HEAP_ALLOCATION */ #ifdef DISTRHO_PROPER_CPP11_SUPPORT # define DISTRHO_PREVENT_HEAP_ALLOCATION \ @@ -166,10 +168,27 @@ private: \ #define END_NAMESPACE_DISTRHO } #define USE_NAMESPACE_DISTRHO using namespace DISTRHO_NAMESPACE; +/* Define DISTRHO_OS_SEP and DISTRHO_OS_SPLIT */ +#ifdef DISTRHO_OS_WINDOWS +# define DISTRHO_OS_SEP '\\' +# define DISTRHO_OS_SEP_STR "\\" +# define DISTRHO_OS_SPLIT ';' +# define DISTRHO_OS_SPLIT_STR ";" +#else +# define DISTRHO_OS_SEP '/' +# define DISTRHO_OS_SEP_STR "/" +# define DISTRHO_OS_SPLIT ':' +# define DISTRHO_OS_SPLIT_STR ":" +#endif + /* Useful typedefs */ typedef unsigned char uchar; typedef unsigned short int ushort; typedef unsigned int uint; typedef unsigned long int ulong; +/* Deprecated macros */ +#define DISTRHO_DECLARE_NON_COPY_CLASS(ClassName) DISTRHO_DECLARE_NON_COPYABLE(ClassName) +#define DISTRHO_DECLARE_NON_COPY_STRUCT(StructName) DISTRHO_DECLARE_NON_COPYABLE(StructName) + #endif // DISTRHO_DEFINES_H_INCLUDED