diff --git a/moo/mooutils/moofileicon.c b/moo/mooutils/moofileicon.c index cfcd9d65..8ab7fef5 100644 --- a/moo/mooutils/moofileicon.c +++ b/moo/mooutils/moofileicon.c @@ -69,7 +69,7 @@ moo_file_icon_new (void) MooFileIcon * moo_file_icon_copy (MooFileIcon *icon) { - return icon ? moo_slice_dup (MooFileIcon, icon) : NULL; + return icon ? moo_obj_dup (MooFileIcon, icon) : NULL; } void diff --git a/moo/mooutils/mooutils-debug.h b/moo/mooutils/mooutils-debug.h index 4c9ed379..745fa597 100644 --- a/moo/mooutils/mooutils-debug.h +++ b/moo/mooutils/mooutils-debug.h @@ -22,13 +22,8 @@ G_BEGIN_DECLS -void moo_assert_message (const char *message, - const char *file, - int line, - int counter, - const char *func); - -#define moo_assert(cond) _MOO_ASSERT(cond, moo_assert_message) +#define moo_assert _MOO_DEBUG_ASSERT +#define moo_release_assert _MOO_RELEASE_ASSERT #ifdef DEBUG diff --git a/moo/mooutils/mooutils-macros.h b/moo/mooutils/mooutils-macros.h index 144db24e..ce5190b3 100644 --- a/moo/mooutils/mooutils-macros.h +++ b/moo/mooutils/mooutils-macros.h @@ -49,26 +49,57 @@ #define MOO_STRFUNC ((const char*) ("")) #endif -#ifdef __COUNTER__ -#define _MOO_CODE_LOCATION_ARGS __FILE__, __LINE__, __COUNTER__ -#else -#define _MOO_CODE_LOCATION_ARGS __FILE__, __LINE__, 0 +#ifdef __cplusplus +extern "C" { #endif -#define _MOO_ASSERT_CHECK(cond, func) \ -do { \ - if (cond) \ - ; \ - else \ - func("condition failed: " #cond, \ - _MOO_CODE_LOCATION_ARGS, \ - MOO_STRFUNC); \ +typedef struct MooCodeLoc +{ + const char *file; + const char *func; + int line; + int counter; +} MooCodeLoc; + +void moo_assert_message (const char *message, + const MooCodeLoc *loc); + +#ifdef __cplusplus +} // extern "C" +#endif + +#ifdef __COUNTER__ +#define _MOO_COUNTER __COUNTER__ +#else +#define _MOO_COUNTER 0 +#endif + +#define _MOO_ASSERT_MESSAGE(msg) \ +do { \ + const MooCodeLoc _moo_loc__ = { \ + __FILE__, MOO_STRFUNC, \ + __LINE__, _MOO_COUNTER \ + }; \ + moo_assert_message (msg, &_moo_loc__); \ +} while (0) + +#define _MOO_ASSERT_CHECK(cond) \ +do { \ + if (cond) \ + ; \ + else \ + _MOO_ASSERT_MESSAGE ( \ + "condition failed: " #cond); \ } while(0) +#define MOO_VOID_STMT do {} while (0) + +#define _MOO_RELEASE_ASSERT _MOO_ASSERT_CHECK + #ifdef DEBUG -#define _MOO_ASSERT _MOO_ASSERT_CHECK +#define _MOO_DEBUG_ASSERT _MOO_ASSERT_CHECK #else -#define _MOO_ASSERT(cond, func) do {} while(0) +#define _MOO_DEBUG_ASSERT(cond) MOO_VOID_STMT #endif #define _MOO_CONCAT_(a, b) a##b @@ -79,3 +110,4 @@ do { \ MOO_STATIC_ASSERT(sizeof(char) == 1, "test"); #endif /* MOO_UTILS_MACROS_H */ +/* -%- strip:true -%- */ diff --git a/moo/mooutils/mooutils-misc.c b/moo/mooutils/mooutils-misc.c index b436899b..a9b58d4b 100644 --- a/moo/mooutils/mooutils-misc.c +++ b/moo/mooutils/mooutils-misc.c @@ -1758,15 +1758,12 @@ _moo_widget_set_tooltip (GtkWidget *widget, */ void -moo_assert_message(const char *message, - const char *file, - int line, - int counter, - const char *func) +moo_assert_message (const char *message, const MooCodeLoc *loc) { - g_error("file '%s', function '%s', line %d: %s\n", file, func, line, message); + g_error("file '%s', function '%s', line %d: %s\n", loc->file, loc->func, loc->line, message); } + /******************************************************************************* * Former eggregex stuff */ @@ -1982,6 +1979,14 @@ _moo_strv_reverse (char **str_array) } +gboolean +_moo_str_equal (const char *s1, + const char *s2) +{ + return strcmp (s1 ? s1 : "", s2 ? s2 : "") == 0; +} + + #if defined(__WIN32__) && !defined(MOO_DEBUG) static guint saved_win32_error_mode; #endif diff --git a/moo/mooutils/mooutils-misc.h b/moo/mooutils/mooutils-misc.h index 7a05ae0a..7848bf1c 100644 --- a/moo/mooutils/mooutils-misc.h +++ b/moo/mooutils/mooutils-misc.h @@ -17,7 +17,7 @@ #define MOO_UTILS_MISC_H #include -#include +#include G_BEGIN_DECLS @@ -128,12 +128,8 @@ char **moo_splitlines (const char *string); char **_moo_strv_reverse (char **str_array); -static inline gboolean -_moo_str_equal (const char *s1, - const char *s2) -{ - return !strcmp (s1 ? s1 : "", s2 ? s2 : ""); -} +gboolean _moo_str_equal (const char *s1, + const char *s2); static inline void moo_assign_string (char **where, @@ -193,26 +189,45 @@ gboolean _moo_regex_escape (const char *string, #if GLIB_CHECK_VERSION(2,10,0) -#define moo_new g_slice_new -#define moo_new0 g_slice_new0 -#define moo_free g_slice_free +# define moo_alloc_block(sz) g_slice_alloc (sz) +# define moo_alloc0_block(sz) g_slice_alloc0 (sz) +# define moo_free_block(sz,p) g_slice_free1 (sz, p) #else -#define moo_new(type) g_new (type, 1) -#define moo_new0(type) g_new0 (type, 1) -#define moo_free(type,mem) g_free (mem) +# define moo_alloc_block(sz) g_malloc (sz) +# define moo_alloc0_block(sz) g_malloc0 (sz) +# define moo_free_block(sz,p) g_free (p) #endif -#if GLIB_CHECK_VERSION(2,14,0) -#define moo_slice_dup g_slice_dup +#ifdef g_slice_dup +# define moo_dup_block(sz,p) g_slice_copy (sz, p) #else -#define moo_slice_dup(type,mem) ((type*) g_memdup (mem, sizeof (type))) +# define moo_dup_block(sz,p) g_memdup (p, sz) #endif +#define moo_new_n(type, n) ((type*) moo_alloc_block (sizeof (type) * (n))) +#define moo_new0_n(type, n) ((type*) moo_alloc0_block (sizeof (type) * (n))) +#define moo_free_n(type, n, p) do { type *p__ = p; moo_free_block (sizeof (type) * n, p__); } while (0) + +#define moo_new(type) moo_new_n (type, 1) +#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) +#define moo_obj_dup(type,p) ({ type const *cp__ = p; type *p__ = moo_dup_block (sizeof (type), p); p__; }) +#else +#define moo_obj_dup(type, p) ((type*) moo_dup_block (sizeof (type), p)) +#endif + +#define MOO_OBJECT_REF_SINK moo_object_ref_sink +static inline gpointer moo_object_ref_sink (gpointer obj) +{ #if GLIB_CHECK_VERSION(2,10,0) -#define MOO_OBJECT_REF_SINK(obj) (void) g_object_ref_sink (obj) + g_object_ref_sink (obj); #else -#define MOO_OBJECT_REF_SINK(obj) gtk_object_sink (g_object_ref (obj)) + gtk_object_sink (g_object_ref (obj)); #endif + return obj; +} #define MOO_UNUSED(x) (void)x;