Cedric BAIL <cedric.b...@free.fr> writes:
>>>> - *_foreach():
>>>> One could argue that passing NULL should be equivalent to an empty
>>>> loop. For example, right now
>>>> eina_iterator_foreach(NULL, ..., ...)
>>>> generates a magic check error message, while
>>>> EINA_ITERATOR_FOREACH(NULL, ...)
>>>> does not.
>
> There is valid use case for when an iterator could be NULL. If you do :
> it = eina_file_stat_ls("/plop");
> EINA_ITERATOR_FOREACH(it, ...)
> {
> ....
> }
> eina_iterator_free(it);
>
> It cleary simplify the code in my opinion without impacting speed at
> all if we do handle it == NULL case. So for this one I would like to
> have it handle.
That's exactly what caused me to look into this :-) I've changed
eina_iterator_foreach() so that it just returns early without
complaining if a NULL iterator is passed to it, so both
eina_iterator_free() and EINA_ITERATOR_FREE() should have a more similar
behavior now.
Index: src/lib/eina_hash.c
===================================================================
--- src/lib/eina_hash.c (revision 73186)
+++ src/lib/eina_hash.c (working copy)
@@ -485,13 +485,10 @@ _eina_hash_del_by_key(Eina_Hash *hash, const void
{
int key_length, key_hash;
+ EINA_SAFETY_ON_NULL_RETURN_VAL(hash, EINA_FALSE);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(key, EINA_FALSE);
EINA_MAGIC_CHECK_HASH(hash);
- if (!hash)
- return EINA_FALSE;
- if (!key)
- return EINA_FALSE;
-
if (!hash->buckets)
return EINA_FALSE;
Index: src/lib/eina_accessor.c
===================================================================
--- src/lib/eina_accessor.c (revision 73186)
+++ src/lib/eina_accessor.c (working copy)
@@ -95,8 +95,10 @@ eina_accessor_shutdown(void)
EAPI void
eina_accessor_free(Eina_Accessor *accessor)
{
+ if (!accessor)
+ return;
+
EINA_MAGIC_CHECK_ACCESSOR(accessor);
- EINA_SAFETY_ON_NULL_RETURN(accessor);
EINA_SAFETY_ON_NULL_RETURN(accessor->free);
accessor->free(accessor);
}
Index: src/lib/eina_inarray.c
===================================================================
--- src/lib/eina_inarray.c (revision 73186)
+++ src/lib/eina_inarray.c (working copy)
@@ -355,6 +355,9 @@ eina_inarray_new(unsigned int member_size, unsigne
EAPI void
eina_inarray_free(Eina_Inarray *array)
{
+ if (!inarray)
+ return;
+
EINA_MAGIC_CHECK_INARRAY(array);
free(array->members);
free(array);
Index: src/lib/eina_matrixsparse.c
===================================================================
--- src/lib/eina_matrixsparse.c (revision 73186)
+++ src/lib/eina_matrixsparse.c (working copy)
@@ -971,6 +971,10 @@ eina_matrixsparse_free(Eina_Matrixsparse *m)
void *user_data;
Eina_Matrixsparse_Row *r;
+
+ if (!m)
+ return;
+
EINA_MAGIC_CHECK_MATRIXSPARSE(m);
free_func = m->free.func;
Index: src/lib/eina_model.c
===================================================================
--- src/lib/eina_model.c (revision 73186)
+++ src/lib/eina_model.c (working copy)
@@ -3527,6 +3527,9 @@ _eina_model_unref(Eina_Model *model)
EAPI void
eina_model_del(Eina_Model *model)
{
+ if (!model)
+ return;
+
EINA_MODEL_INSTANCE_CHECK(model);
_eina_model_del(model);
_eina_model_unref(model);
Index: src/lib/eina_tiler.c
===================================================================
--- src/lib/eina_tiler.c (revision 73186)
+++ src/lib/eina_tiler.c (working copy)
@@ -1127,6 +1127,9 @@ EAPI Eina_Tiler *eina_tiler_new(int w, int h)
EAPI void eina_tiler_free(Eina_Tiler *t)
{
+ if (!t)
+ return;
+
EINA_MAGIC_CHECK_TILER(t);
_splitter_del(t);
free(t);
@@ -1165,6 +1168,9 @@ EAPI void eina_tiler_rect_del(Eina_Tiler *t, const
{
Eina_Rectangle tmp;
+ if (!t)
+ return;
+
EINA_MAGIC_CHECK_TILER(t);
if ((r->w <= 0) || (r->h <= 0))
return;
Index: src/lib/eina_simple_xml_parser.c
===================================================================
--- src/lib/eina_simple_xml_parser.c (revision 73186)
+++ src/lib/eina_simple_xml_parser.c (working copy)
@@ -585,6 +585,9 @@ eina_simple_xml_attribute_new(Eina_Simple_XML_Node
EAPI void
eina_simple_xml_attribute_free(Eina_Simple_XML_Attribute *attr)
{
+ if (!attr)
+ return;
+
EINA_MAGIC_CHECK_ATTRIBUTE(attr);
if (attr->parent)
@@ -669,6 +672,9 @@ _eina_simple_xml_node_tag_free(Eina_Simple_XML_Nod
EAPI void
eina_simple_xml_node_tag_free(Eina_Simple_XML_Node_Tag *tag)
{
+ if (!tag)
+ return;
+
EINA_MAGIC_CHECK_TAG(&tag->base);
if (tag->base.type != EINA_SIMPLE_XML_NODE_TAG)
{
@@ -716,6 +722,9 @@ eina_simple_xml_node_data_new(Eina_Simple_XML_Node
EAPI void
eina_simple_xml_node_data_free(Eina_Simple_XML_Node_Data *node)
{
+ if (!node)
+ return;
+
EINA_MAGIC_CHECK_DATA(&node->base);
if (node->base.type != EINA_SIMPLE_XML_NODE_DATA)
{
@@ -735,6 +744,9 @@ eina_simple_xml_node_cdata_new(Eina_Simple_XML_Nod
EAPI void
eina_simple_xml_node_cdata_free(Eina_Simple_XML_Node_Data *node)
{
+ if (!node)
+ return;
+
EINA_MAGIC_CHECK_DATA(&node->base);
if (node->base.type != EINA_SIMPLE_XML_NODE_CDATA)
{
@@ -754,6 +766,9 @@ eina_simple_xml_node_processing_new(Eina_Simple_XM
EAPI void
eina_simple_xml_node_processing_free(Eina_Simple_XML_Node_Data *node)
{
+ if (!node)
+ return;
+
EINA_MAGIC_CHECK_DATA(&node->base);
if (node->base.type != EINA_SIMPLE_XML_NODE_PROCESSING)
{
@@ -773,6 +788,9 @@ eina_simple_xml_node_doctype_new(Eina_Simple_XML_N
EAPI void
eina_simple_xml_node_doctype_free(Eina_Simple_XML_Node_Data *node)
{
+ if (!node)
+ return;
+
EINA_MAGIC_CHECK_DATA(&node->base);
if (node->base.type != EINA_SIMPLE_XML_NODE_DOCTYPE)
{
@@ -792,6 +810,9 @@ eina_simple_xml_node_comment_new(Eina_Simple_XML_N
EAPI void
eina_simple_xml_node_comment_free(Eina_Simple_XML_Node_Data *node)
{
+ if (!node)
+ return;
+
EINA_MAGIC_CHECK_DATA(&node->base);
if (node->base.type != EINA_SIMPLE_XML_NODE_COMMENT)
{
Index: src/lib/eina_iterator.c
===================================================================
--- src/lib/eina_iterator.c (revision 73186)
+++ src/lib/eina_iterator.c (working copy)
@@ -95,8 +95,10 @@ eina_iterator_shutdown(void)
EAPI void
eina_iterator_free(Eina_Iterator *iterator)
{
+ if (!iterator)
+ return;
+
EINA_MAGIC_CHECK_ITERATOR(iterator);
- EINA_SAFETY_ON_NULL_RETURN(iterator);
EINA_SAFETY_ON_NULL_RETURN(iterator->free);
iterator->free(iterator);
}
@@ -117,7 +119,6 @@ eina_iterator_next(Eina_Iterator *iterator, void *
return EINA_FALSE;
EINA_MAGIC_CHECK_ITERATOR(iterator);
- EINA_SAFETY_ON_NULL_RETURN_VAL(iterator, EINA_FALSE);
EINA_SAFETY_ON_NULL_RETURN_VAL(iterator->next, EINA_FALSE);
EINA_SAFETY_ON_NULL_RETURN_VAL(data, EINA_FALSE);
return iterator->next(iterator, data);
@@ -131,8 +132,10 @@ eina_iterator_foreach(Eina_Iterator *iterator,
const void *container;
void *data;
+ if (!iterator)
+ return;
+
EINA_MAGIC_CHECK_ITERATOR(iterator);
- EINA_SAFETY_ON_NULL_RETURN(iterator);
EINA_SAFETY_ON_NULL_RETURN(iterator->get_container);
EINA_SAFETY_ON_NULL_RETURN(iterator->next);
EINA_SAFETY_ON_NULL_RETURN(cb);
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel