Enlightenment CVS committal Author : cedric Project : e17 Module : proto/eina
Dir : e17/proto/eina/src/lib Modified Files: eina_stringshare.c eina_array.c Log Message: Fix and improvement for stringshare and array, thanks to the tests suite. =================================================================== RCS file: /cvs/e/e17/proto/eina/src/lib/eina_stringshare.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- eina_stringshare.c 30 Jul 2008 17:29:11 -0000 1.3 +++ eina_stringshare.c 1 Aug 2008 12:26:35 -0000 1.4 @@ -11,6 +11,7 @@ #include <string.h> #include "eina_stringshare.h" +#include "eina_error.h" typedef struct _Eina_Stringshare Eina_Stringshare; typedef struct _Eina_Stringshare_Node Eina_Stringshare_Node; @@ -69,7 +70,7 @@ * Initialize the eina stringshare internal structure. * @return Zero on failure, non-zero on successful initialization. */ -EAPI int +EAPI int eina_stringshare_init() { /* @@ -82,7 +83,6 @@ if (!share) return 0; } - eina_stringshare_init_count++; return 1; @@ -169,14 +169,14 @@ return; } } - printf("EEEK trying to del non-shared stringshare \"%s\"\n", str); - abort(); + EINA_ERROR_PWARN("EEEK trying to del non-shared stringshare \"%s\"\n", str); + if (getenv("EINA_ERROR_ABORT")) abort(); } /** * Shutdown the eina string internal structures */ -EAPI void +EAPI void eina_stringshare_shutdown() { --eina_stringshare_init_count; =================================================================== RCS file: /cvs/e/e17/proto/eina/src/lib/eina_array.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- eina_array.c 30 Jul 2008 16:34:54 -0000 1.1 +++ eina_array.c 1 Aug 2008 12:26:35 -0000 1.2 @@ -6,7 +6,9 @@ # include "config.h" #endif +#include <assert.h> #include <stdlib.h> +#include <string.h> #include "eina_array.h" #include "eina_inline_array.x" @@ -68,19 +70,58 @@ free(array); } +#include <stdio.h> + EAPI void eina_array_remove(Eina_Array *array, Eina_Bool (*keep)(void *data, void *gdata), void *gdata) { void **tmp; unsigned int total = 0; + unsigned int limit; unsigned int i; if (array->total == 0) return ; + for (i = 0; i < array->count; ++i) + { + void *data; + + data = _eina_array_get(array, i); + + if (keep(data, gdata) == EINA_FALSE) + break; + } + limit = i; + for (; i < array->count; ++i) + { + void *data; + + data = _eina_array_get(array, i); + + if (keep(data, gdata) == EINA_TRUE) + break; + } + /* Special case all objects that need to stay are at the beginning of the array. */ + if (i == array->count) + { + array->count = limit; + if (array->count == 0) + { + free(array->data); + array->total = 0; + array->data = NULL; + } + + return ; + } + tmp = malloc(sizeof (void*) * array->total); if (!tmp) return ; - for (i = 0; i < array->count; i++) + memcpy(tmp, array->data, limit * sizeof(void*)); + total = limit; + + for (; i < array->count; ++i) { void *data; @@ -95,16 +136,10 @@ free(array->data); - if (total == 0) - { - array->total = 0; - array->data = NULL; - free(tmp); - } - else - { - array->data = tmp; - } + /* If we do not keep any object in the array, we should have exited + earlier in test (i == array->count). */ + assert(total != 0); + array->data = tmp; array->count = total; } ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs