2008-09-12 17:06:58 +02:00
|
|
|
/* $Id$
|
add a new headers <lasso/utils.h> with macros to handle memory like assigning a
gobject field (work flow, is you augment ref of the new value, decrease the one
from the old, and then assign), assigning strings, releasing lists of strings, of
gobjects,etc..
the free macros are all called g_release_somehting and they set the released
variable to NULL.
add a macro to validate GObject parameter types
This header is intended to concentre every bit of wisdom for handling pointers
and memory, try to use thoses macros in your code.
They are not intended to work with weak references (references you do not own),
so always g_object_ref in this case (or use g_assign_gobject that does it,
when your variable is not needed anymore to g_assign_gobject(var, NULL));
2008-05-22 16:54:13 +02:00
|
|
|
*
|
|
|
|
* Lasso - A free implementation of the Liberty Alliance specifications.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2007 Entr'ouvert
|
|
|
|
* http://lasso.entrouvert.org
|
2008-09-12 17:06:58 +02:00
|
|
|
*
|
add a new headers <lasso/utils.h> with macros to handle memory like assigning a
gobject field (work flow, is you augment ref of the new value, decrease the one
from the old, and then assign), assigning strings, releasing lists of strings, of
gobjects,etc..
the free macros are all called g_release_somehting and they set the released
variable to NULL.
add a macro to validate GObject parameter types
This header is intended to concentre every bit of wisdom for handling pointers
and memory, try to use thoses macros in your code.
They are not intended to work with weak references (references you do not own),
so always g_object_ref in this case (or use g_assign_gobject that does it,
when your variable is not needed anymore to g_assign_gobject(var, NULL));
2008-05-22 16:54:13 +02:00
|
|
|
* Authors: See AUTHORS file in top-level directory.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2008-09-12 17:06:58 +02:00
|
|
|
*
|
add a new headers <lasso/utils.h> with macros to handle memory like assigning a
gobject field (work flow, is you augment ref of the new value, decrease the one
from the old, and then assign), assigning strings, releasing lists of strings, of
gobjects,etc..
the free macros are all called g_release_somehting and they set the released
variable to NULL.
add a macro to validate GObject parameter types
This header is intended to concentre every bit of wisdom for handling pointers
and memory, try to use thoses macros in your code.
They are not intended to work with weak references (references you do not own),
so always g_object_ref in this case (or use g_assign_gobject that does it,
when your variable is not needed anymore to g_assign_gobject(var, NULL));
2008-05-22 16:54:13 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2008-09-12 17:06:58 +02:00
|
|
|
*
|
add a new headers <lasso/utils.h> with macros to handle memory like assigning a
gobject field (work flow, is you augment ref of the new value, decrease the one
from the old, and then assign), assigning strings, releasing lists of strings, of
gobjects,etc..
the free macros are all called g_release_somehting and they set the released
variable to NULL.
add a macro to validate GObject parameter types
This header is intended to concentre every bit of wisdom for handling pointers
and memory, try to use thoses macros in your code.
They are not intended to work with weak references (references you do not own),
so always g_object_ref in this case (or use g_assign_gobject that does it,
when your variable is not needed anymore to g_assign_gobject(var, NULL));
2008-05-22 16:54:13 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __LASSO_UTILS_H__
|
|
|
|
#define __LASSO_UTILS_H__
|
|
|
|
|
2008-11-05 15:38:00 +01:00
|
|
|
#include <glib.h>
|
2009-03-27 16:06:34 +01:00
|
|
|
#include "debug.h"
|
2008-11-05 15:38:00 +01:00
|
|
|
|
2009-01-24 10:33:20 +01:00
|
|
|
#ifdef LASSO_DEBUG
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define lasso_check_type_equality(a,b) \
|
|
|
|
{ \
|
|
|
|
enum { TYPE_MISMATCH = (1 / __builtin_types_compatible_p(typeof(a), typeof(b))) }; \
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define lasso_check_type_equality(a,b)
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#define lasso_check_type_equality(a,b)
|
|
|
|
#endif
|
|
|
|
|
2009-01-24 10:33:21 +01:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#define lasso_check_type_equality2(a,b,c) \
|
2008-05-30 14:41:11 +02:00
|
|
|
{ \
|
2009-01-24 10:33:21 +01:00
|
|
|
enum { TYPE_MISMATCH = (1 / (__builtin_types_compatible_p(typeof(a), typeof(b))+__builtin_types_compatible_p(typeof(a), typeof(c)))) }; \
|
2008-05-30 14:41:11 +02:00
|
|
|
}
|
2009-01-24 10:33:21 +01:00
|
|
|
#else
|
|
|
|
#define lasso_check_type_equality2(a,b,c)
|
|
|
|
#endif
|
add a new headers <lasso/utils.h> with macros to handle memory like assigning a
gobject field (work flow, is you augment ref of the new value, decrease the one
from the old, and then assign), assigning strings, releasing lists of strings, of
gobjects,etc..
the free macros are all called g_release_somehting and they set the released
variable to NULL.
add a macro to validate GObject parameter types
This header is intended to concentre every bit of wisdom for handling pointers
and memory, try to use thoses macros in your code.
They are not intended to work with weak references (references you do not own),
so always g_object_ref in this case (or use g_assign_gobject that does it,
when your variable is not needed anymore to g_assign_gobject(var, NULL));
2008-05-22 16:54:13 +02:00
|
|
|
|
|
|
|
/* Freeing */
|
2008-08-05 16:52:20 +02:00
|
|
|
#define lasso_release(dest) \
|
2008-05-30 14:41:11 +02:00
|
|
|
{ \
|
|
|
|
if (dest) { \
|
|
|
|
g_free(dest); dest = NULL; \
|
|
|
|
} \
|
|
|
|
}
|
2008-08-01 16:10:34 +02:00
|
|
|
|
2008-08-05 16:52:31 +02:00
|
|
|
#define lasso_release_full(dest, free_function) \
|
2008-05-30 14:41:11 +02:00
|
|
|
{ \
|
|
|
|
if (dest) { \
|
2008-08-05 16:52:31 +02:00
|
|
|
free_function(dest); dest = NULL; \
|
2008-05-30 14:41:11 +02:00
|
|
|
} \
|
|
|
|
}
|
2008-08-01 16:10:34 +02:00
|
|
|
|
2009-01-24 10:33:20 +01:00
|
|
|
#define lasso_release_full2(dest, free_function, type) \
|
|
|
|
{ \
|
|
|
|
lasso_check_type_equality(dest, type); \
|
|
|
|
if (dest) { \
|
|
|
|
free_function(dest); dest = NULL; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2008-08-05 16:52:31 +02:00
|
|
|
#define lasso_release_gobject(dest) \
|
2009-01-24 10:33:20 +01:00
|
|
|
{ \
|
|
|
|
if (G_IS_OBJECT(dest) || dest == NULL) { \
|
|
|
|
lasso_release_full(dest, g_object_unref); \
|
|
|
|
} else { \
|
|
|
|
g_critical("Trying to unref a non GObject pointer dest=%s", #dest); \
|
|
|
|
} \
|
|
|
|
}
|
2008-08-05 16:52:31 +02:00
|
|
|
|
|
|
|
#define lasso_release_string(dest) \
|
2008-08-05 16:52:48 +02:00
|
|
|
lasso_release_full(dest, g_free)
|
|
|
|
|
|
|
|
#define lasso_release_list(dest) \
|
2009-01-24 10:33:20 +01:00
|
|
|
lasso_release_full2(dest, g_list_free, GList*)
|
2008-08-05 16:52:31 +02:00
|
|
|
|
2008-08-05 16:52:48 +02:00
|
|
|
#define lasso_release_list_of_full(dest, free_function) \
|
2008-05-30 14:41:11 +02:00
|
|
|
{ \
|
|
|
|
if (dest) { \
|
2008-08-05 16:52:48 +02:00
|
|
|
g_list_foreach(dest, (GFunc)free_function, NULL); \
|
2009-01-24 10:33:20 +01:00
|
|
|
lasso_release_list(dest); \
|
2008-05-30 14:41:11 +02:00
|
|
|
} \
|
|
|
|
}
|
2008-08-01 16:10:34 +02:00
|
|
|
|
2008-08-05 16:52:48 +02:00
|
|
|
#define lasso_release_list_of_strings(dest) \
|
|
|
|
lasso_release_list_of_full(dest, g_free)
|
|
|
|
|
2008-08-05 16:52:20 +02:00
|
|
|
#define lasso_release_list_of_gobjects(dest) \
|
2008-08-05 16:52:48 +02:00
|
|
|
lasso_release_list_of_full(dest, g_object_unref)
|
2008-08-01 16:10:34 +02:00
|
|
|
|
2008-08-05 16:52:29 +02:00
|
|
|
#define lasso_unlink_and_release_node(node) \
|
2008-08-05 16:52:48 +02:00
|
|
|
lasso_release_list_of_full(dest, xmlFreeNode)
|
add a new headers <lasso/utils.h> with macros to handle memory like assigning a
gobject field (work flow, is you augment ref of the new value, decrease the one
from the old, and then assign), assigning strings, releasing lists of strings, of
gobjects,etc..
the free macros are all called g_release_somehting and they set the released
variable to NULL.
add a macro to validate GObject parameter types
This header is intended to concentre every bit of wisdom for handling pointers
and memory, try to use thoses macros in your code.
They are not intended to work with weak references (references you do not own),
so always g_object_ref in this case (or use g_assign_gobject that does it,
when your variable is not needed anymore to g_assign_gobject(var, NULL));
2008-05-22 16:54:13 +02:00
|
|
|
|
2009-01-24 10:33:21 +01:00
|
|
|
#define lasso_release_xml_node(node) \
|
2009-01-24 10:33:20 +01:00
|
|
|
lasso_release_full2(node, xmlFreeNode, xmlNodePtr)
|
2008-08-01 16:10:34 +02:00
|
|
|
|
2008-08-05 16:52:20 +02:00
|
|
|
#define lasso_release_doc(doc) \
|
2009-01-24 10:33:20 +01:00
|
|
|
lasso_release_full2(doc, xmlFreeDoc, xmlDocPtr)
|
2008-08-05 16:52:31 +02:00
|
|
|
|
2009-03-27 16:05:37 +01:00
|
|
|
#define lasso_release_xml_string(dest) \
|
2009-01-24 10:33:20 +01:00
|
|
|
lasso_release_full2(dest, xmlFree, xmlChar*)
|
2008-08-01 16:10:34 +02:00
|
|
|
|
2008-08-05 16:52:32 +02:00
|
|
|
#define lasso_release_encrypt_context(dest) \
|
2009-01-24 10:33:20 +01:00
|
|
|
lasso_release_full2(dest, xmlSecEncCtxDestroy, xmlSecEncCtxPtr)
|
2008-08-05 16:52:32 +02:00
|
|
|
|
|
|
|
#define lasso_release_signature_context(dest) \
|
2009-01-24 10:33:20 +01:00
|
|
|
lasso_release_full2(dest, xmlSecDSigCtxDestroy,xmlSecDSigCtxPtr)
|
2008-08-05 16:52:32 +02:00
|
|
|
|
|
|
|
#define lasso_release_key_manager(dest) \
|
2009-01-24 10:33:20 +01:00
|
|
|
lasso_release_full2(dest, xmlSecKeysMngrDestroy, xmlSecKeysMngrPtr)
|
2008-08-05 16:52:32 +02:00
|
|
|
|
2008-11-04 02:58:42 +01:00
|
|
|
#define lasso_release_output_buffer(dest) \
|
2009-01-24 10:33:20 +01:00
|
|
|
lasso_release_full2(dest, xmlOutputBufferClose, xmlOutputBufferPtr)
|
|
|
|
|
|
|
|
#define lasso_release_xpath_object(dest) \
|
|
|
|
lasso_release_full2(dest, xmlXPathFreeObject, xmlXPathObjectPtr)
|
|
|
|
|
|
|
|
#define lasso_release_xpath_context(dest) \
|
|
|
|
lasso_release_full2(dest, xmlXPathFreeContext, xmlXPathContextPtr)
|
|
|
|
|
|
|
|
#define lasso_release_xpath_job(xpathObject, xpathContext, xmlDocument) \
|
|
|
|
lasso_release_xpath_object(xpathObject); \
|
|
|
|
lasso_release_xpath_context(xpathContext); \
|
|
|
|
lasso_release_doc(xmlDocument)
|
|
|
|
|
2009-03-27 16:06:32 +01:00
|
|
|
#define lasso_release_sec_key(dest) \
|
|
|
|
lasso_release_full2(dest, xmlSecKeyDestroy, xmlSecKeyPtr)
|
|
|
|
|
2009-01-24 10:33:21 +01:00
|
|
|
/* Assignment and list appending */
|
|
|
|
#define lasso_assign_string(dest,src) \
|
|
|
|
{ \
|
|
|
|
char *__tmp = g_strdup(src);\
|
|
|
|
lasso_release_string(dest); \
|
|
|
|
dest = __tmp; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define lasso_assign_xml_string(dest,src) \
|
|
|
|
{ \
|
|
|
|
xmlChar *__tmp = g_strdup(src); \
|
|
|
|
lasso_release_xml_string(dest); \
|
|
|
|
dest = __tmp; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define lasso_assign_new_string(dest,src) \
|
|
|
|
{ \
|
2009-03-27 16:05:35 +01:00
|
|
|
char *__tmp = src; \
|
|
|
|
if (dest != __tmp) \
|
2009-03-27 16:05:34 +01:00
|
|
|
lasso_release_string(dest); \
|
2009-03-27 16:05:35 +01:00
|
|
|
dest = __tmp; \
|
2009-01-24 10:33:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define lasso_assign_gobject(dest,src) \
|
|
|
|
{ \
|
2009-03-27 16:05:35 +01:00
|
|
|
GObject *__tmp = G_OBJECT(src); \
|
|
|
|
if (__tmp) \
|
|
|
|
g_object_ref(__tmp); \
|
|
|
|
lasso_release_gobject(dest); \
|
|
|
|
dest = (void*)(__tmp); \
|
2009-01-24 10:33:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define lasso_assign_new_gobject(dest,src) \
|
|
|
|
{ \
|
2009-03-27 16:05:35 +01:00
|
|
|
GObject *__tmp = G_OBJECT(src); \
|
|
|
|
if (dest != (void*)__tmp) \
|
|
|
|
lasso_release_gobject(dest); \
|
|
|
|
dest = (void*)(__tmp); \
|
2009-01-24 10:33:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define lasso_assign_xml_node(dest,src) \
|
|
|
|
{ \
|
2009-03-27 16:05:35 +01:00
|
|
|
xmlNode *__tmp = (src); \
|
2009-01-24 10:33:21 +01:00
|
|
|
lasso_check_type_equality(dest, src); \
|
|
|
|
if (dest) \
|
|
|
|
xmlFreeNode(dest); \
|
2009-03-27 16:05:35 +01:00
|
|
|
dest = xmlCopyNode(__tmp, 1); \
|
2009-01-24 10:33:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define lasso_assign_new_list_of_gobjects(dest, src) \
|
|
|
|
{ \
|
|
|
|
GList *__tmp = (src); \
|
|
|
|
lasso_release_gobject_list(dest); \
|
|
|
|
dest = __tmp; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define lasso_assign_list_of_gobjects(dest, src) \
|
|
|
|
{ \
|
|
|
|
GList *__tmp = (src); \
|
|
|
|
lasso_release_list_of_gobjects(dest); \
|
|
|
|
dest = g_list_copy(__tmp); \
|
|
|
|
for (;__tmp != NULL; __tmp = g_list_next(__tmp)) { \
|
|
|
|
if (G_IS_OBJECT(__tmp->data)) { \
|
|
|
|
g_object_ref(__tmp->data); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define lasso_assign_list_of_strings(dest, src) \
|
|
|
|
{ \
|
|
|
|
GList *__tmp = src; \
|
|
|
|
GList *__iter_dest; \
|
|
|
|
lasso_release_list_of_strings(dest); \
|
|
|
|
dest = g_list_copy(__tmp); \
|
|
|
|
for (__iter_dest = dest ; __iter_dest != NULL ; __iter_dest = g_list_next(__iter_dest)) { \
|
|
|
|
__iter_dest->data = g_strdup(__iter_dest->data); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2009-03-27 16:06:32 +01:00
|
|
|
#define lasso_assign_new_sec_key(dest, src) \
|
|
|
|
{ \
|
|
|
|
xmlSecKey *__tmp = (src); \
|
|
|
|
if (dest) \
|
|
|
|
lasso_release_sec_key(dest); \
|
|
|
|
dest = __tmp; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define lasso_assign_sec_key(dest, src) \
|
|
|
|
{ \
|
|
|
|
xmlSecKey *__tmp = xmlSecKeyDup(src); \
|
|
|
|
if (dest) \
|
|
|
|
lasso_release_sec_key(dest); \
|
|
|
|
dest = __tmp; \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-24 10:33:21 +01:00
|
|
|
|
|
|
|
/* List appending */
|
|
|
|
#define lasso_list_add(dest, src) \
|
|
|
|
{ \
|
|
|
|
lasso_check_type_equality((src), void*); \
|
|
|
|
dest = g_list_append(dest, (src)); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define lasso_list_add_non_null(dest, src) \
|
|
|
|
{ \
|
|
|
|
void *__tmp_non_null_src = (src); \
|
|
|
|
if (__tmp_non_null_src != NULL) { \
|
|
|
|
dest = g_list_append(dest, __tmp_non_null_src); \
|
|
|
|
} else { \
|
|
|
|
g_critical("Adding a NULL value to a non-NULL content list: dest=%s src=%s", #dest, #src); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define lasso_list_add_string(dest, src) \
|
|
|
|
{ \
|
|
|
|
lasso_list_add_non_null(dest, g_strdup(src));\
|
|
|
|
}
|
|
|
|
|
|
|
|
#define lasso_list_add_new_string(dest, src) \
|
|
|
|
{ \
|
|
|
|
gchar *__tmp = src; \
|
|
|
|
lasso_list_add_non_null(dest, __tmp); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define lasso_list_add_xml_string(dest, src) \
|
|
|
|
{\
|
|
|
|
xmlChar *__tmp_src = (src);\
|
|
|
|
lasso_list_add_non_null(dest, (void*)g_strdup((char*)__tmp_src));\
|
|
|
|
}
|
|
|
|
|
|
|
|
#define lasso_list_add_gobject(dest, src) \
|
|
|
|
{ \
|
|
|
|
void *__tmp_src = (src); \
|
|
|
|
if (G_IS_OBJECT(__tmp_src)) { \
|
|
|
|
dest = g_list_append(dest, g_object_ref(__tmp_src)); \
|
|
|
|
} else { \
|
|
|
|
g_critical("Trying to add to a GList* a non GObject pointer dest=%s src=%s", #dest, #src); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define lasso_list_add_new_gobject(dest, src) \
|
|
|
|
{ \
|
|
|
|
void *__tmp_src = (src); \
|
|
|
|
if (G_IS_OBJECT(__tmp_src)) { \
|
|
|
|
dest = g_list_append(dest, __tmp_src); \
|
|
|
|
} else { \
|
|
|
|
g_critical("Trying to add to a GList* a non GObject pointer dest=%s src=%s", #dest, #src); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define lasso_list_add_xml_node(dest, src) \
|
|
|
|
{ \
|
|
|
|
xmlNode *__tmp_src = src; \
|
|
|
|
lasso_list_add_non_null(dest, __tmp_src); \
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pointer ownership transfer */
|
2009-01-24 10:33:20 +01:00
|
|
|
#define lasso_transfer_full(dest, src, kind) \
|
|
|
|
{\
|
|
|
|
lasso_release_##kind((dest)); \
|
|
|
|
lasso_check_type_equality(dest, src); \
|
|
|
|
(dest) = (void*)(src); \
|
|
|
|
(src) = NULL; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define lasso_transfer_xpath_object(dest, src) \
|
|
|
|
lasso_transfer_full(dest, src, xpath_object)
|
|
|
|
|
|
|
|
#define lasso_transfer_string(dest, src) \
|
|
|
|
lasso_transfer_full(dest, src, string)
|
|
|
|
|
|
|
|
#define lasso_transfer_gobject(dest, src) \
|
|
|
|
lasso_transfer_full(dest, src, gobject)
|
2008-11-04 02:58:42 +01:00
|
|
|
|
2009-03-27 16:05:06 +01:00
|
|
|
/* Node extraction */
|
|
|
|
#define lasso_extract_node_or_fail(to, from, kind, error) \
|
|
|
|
if (LASSO_IS_##kind(from)) { \
|
|
|
|
to = LASSO_##kind(from); \
|
|
|
|
} else { \
|
|
|
|
rc = error; \
|
|
|
|
goto cleanup; \
|
|
|
|
}
|
|
|
|
|
add a new headers <lasso/utils.h> with macros to handle memory like assigning a
gobject field (work flow, is you augment ref of the new value, decrease the one
from the old, and then assign), assigning strings, releasing lists of strings, of
gobjects,etc..
the free macros are all called g_release_somehting and they set the released
variable to NULL.
add a macro to validate GObject parameter types
This header is intended to concentre every bit of wisdom for handling pointers
and memory, try to use thoses macros in your code.
They are not intended to work with weak references (references you do not own),
so always g_object_ref in this case (or use g_assign_gobject that does it,
when your variable is not needed anymore to g_assign_gobject(var, NULL));
2008-05-22 16:54:13 +02:00
|
|
|
/* Bad param handling */
|
2008-08-05 16:52:26 +02:00
|
|
|
#define lasso_return_val_if_invalid_param(kind, name, val) \
|
|
|
|
g_return_val_if_fail(LASSO_IS_##kind(name), val)
|
add a new headers <lasso/utils.h> with macros to handle memory like assigning a
gobject field (work flow, is you augment ref of the new value, decrease the one
from the old, and then assign), assigning strings, releasing lists of strings, of
gobjects,etc..
the free macros are all called g_release_somehting and they set the released
variable to NULL.
add a macro to validate GObject parameter types
This header is intended to concentre every bit of wisdom for handling pointers
and memory, try to use thoses macros in your code.
They are not intended to work with weak references (references you do not own),
so always g_object_ref in this case (or use g_assign_gobject that does it,
when your variable is not needed anymore to g_assign_gobject(var, NULL));
2008-05-22 16:54:13 +02:00
|
|
|
|
2008-08-05 16:52:26 +02:00
|
|
|
#define lasso_bad_param(kind, name) \
|
|
|
|
lasso_return_val_if_invalid_param(kind, name, \
|
2008-08-01 16:10:34 +02:00
|
|
|
LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ);
|
|
|
|
|
2008-08-05 16:52:26 +02:00
|
|
|
#define lasso_null_param(name) \
|
2008-08-01 16:10:34 +02:00
|
|
|
g_return_val_if_fail(name != NULL, LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ);
|
|
|
|
|
2008-11-04 02:58:42 +01:00
|
|
|
#define goto_exit_with_rc(rc_value) \
|
|
|
|
{\
|
|
|
|
rc = (rc_value); \
|
|
|
|
goto exit; \
|
|
|
|
}
|
|
|
|
|
2008-08-01 16:10:34 +02:00
|
|
|
#define goto_exit_if_fail(condition, rc_value) \
|
|
|
|
{\
|
|
|
|
if (! (condition) ) {\
|
|
|
|
rc = (rc_value); \
|
|
|
|
goto exit; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2009-01-24 10:33:18 +01:00
|
|
|
#define goto_exit_if_fail_with_warning(condition, rc_value) \
|
|
|
|
{\
|
|
|
|
if (! (condition) ) {\
|
|
|
|
g_warning("%s %s", __STRING(condition), __STRING(rc_value));\
|
|
|
|
rc = (rc_value); \
|
|
|
|
goto exit; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2009-03-27 16:06:34 +01:00
|
|
|
#define lasso_mem_debug(who, what, where) \
|
|
|
|
{ \
|
|
|
|
if (lasso_flag_memory_debug) \
|
|
|
|
fprintf(stdout, " freeing %s/%s (at %p)\n", who, what, (void*)where); \
|
|
|
|
}
|
|
|
|
|
2008-11-05 12:23:27 +01:00
|
|
|
/* Declare type of element in a container */
|
2009-01-24 10:34:30 +01:00
|
|
|
#ifndef OFTYPE
|
2008-09-12 17:06:58 +02:00
|
|
|
#define OFTYPE(x)
|
2009-01-24 10:34:30 +01:00
|
|
|
#endif
|
2008-08-05 16:53:18 +02:00
|
|
|
|
2008-11-05 12:23:27 +01:00
|
|
|
/* Get a printable extract for error messages */
|
|
|
|
char* lasso_safe_prefix_string(const char *str, gsize length);
|
|
|
|
|
2009-04-02 19:16:05 +02:00
|
|
|
/* GLIB bacward-compatibility */
|
|
|
|
#if (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 16)
|
|
|
|
int g_strcmp0 (const char *str1,
|
|
|
|
const char *str2);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
add a new headers <lasso/utils.h> with macros to handle memory like assigning a
gobject field (work flow, is you augment ref of the new value, decrease the one
from the old, and then assign), assigning strings, releasing lists of strings, of
gobjects,etc..
the free macros are all called g_release_somehting and they set the released
variable to NULL.
add a macro to validate GObject parameter types
This header is intended to concentre every bit of wisdom for handling pointers
and memory, try to use thoses macros in your code.
They are not intended to work with weak references (references you do not own),
so always g_object_ref in this case (or use g_assign_gobject that does it,
when your variable is not needed anymore to g_assign_gobject(var, NULL));
2008-05-22 16:54:13 +02:00
|
|
|
#endif /* __LASSO_UTILS_H__ */
|