EINA API BREAK: no more individual modules init/shutdown.

Being able to indivually initialize individual modules was initially
"good", but at end it's putting complexities on users that would try
to "optimize" by doing just what they used, but in the end most people
would get them wrong, users would have to do lots of code and etc. At
the end it does not worth.

Most module init just register handful errors and log domains, so are
cheap. The exception is mempool users, that would dlopen() stuff, but
people that are concerned (embedded) can just compile those statically
in eina.

Since at the end any real application would use most of modules, we
actually end saving lots of function calls that would do nothing other
than increment a global counter.

I also did the init/shutdown use an array, making it easier to
maintain. The inital dependencies were analysed by a script I wrote, I
hope it's all right.

Please fix any breakages you find!



SVN revision: 42300
This commit is contained in:
Gustavo Sverzut Barbieri 2009-09-06 22:21:56 +00:00
parent 718873e00c
commit e4af7c100c
65 changed files with 766 additions and 1770 deletions

View File

@ -73,9 +73,6 @@ struct _Eina_Array
EINA_MAGIC
};
EAPI int eina_array_init (void);
EAPI int eina_array_shutdown (void);
EAPI Eina_Array *eina_array_new (unsigned int step) EINA_WARN_UNUSED_RESULT EINA_MALLOC EINA_WARN_UNUSED_RESULT;
EAPI void eina_array_free (Eina_Array *array) EINA_ARG_NONNULL(1);
EAPI void eina_array_step_set (Eina_Array *array, unsigned int step) EINA_ARG_NONNULL(1);

View File

@ -55,9 +55,6 @@ typedef void (*Eina_Benchmark_Specimens)(int request);
*/
#define EINA_BENCHMARK(function) ((Eina_Benchmark_Specimens)function)
EAPI int eina_benchmark_init(void);
EAPI int eina_benchmark_shutdown(void);
EAPI Eina_Benchmark *eina_benchmark_new(const char *name, const char *run);
EAPI void eina_benchmark_free(Eina_Benchmark *bench);

View File

@ -52,9 +52,6 @@ EAPI extern Eina_Error EINA_ERROR_CONVERT_0X_NOT_FOUND;
*/
EAPI extern Eina_Error EINA_ERROR_CONVERT_OUTRUN_STRING_LENGTH;
EAPI int eina_convert_init(void);
EAPI int eina_convert_shutdown(void);
EAPI int eina_convert_itoa(int n, char *s) EINA_ARG_NONNULL(2);
EAPI int eina_convert_xtoa(unsigned int n, char *s) EINA_ARG_NONNULL(2);
EAPI int eina_convert_dtoa(double d, char *des) EINA_ARG_NONNULL(2);

View File

@ -39,9 +39,6 @@
*/
typedef struct _Eina_Counter Eina_Counter;
EAPI int eina_counter_init(void);
EAPI int eina_counter_shutdown(void);
EAPI Eina_Counter *eina_counter_new(const char *name) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
EAPI void eina_counter_free(Eina_Counter *counter) EINA_ARG_NONNULL(1);

View File

@ -89,8 +89,6 @@ typedef int Eina_Error;
*/
EAPI extern Eina_Error EINA_ERROR_OUT_OF_MEMORY;
EAPI int eina_error_init(void);
EAPI int eina_error_shutdown(void);
EAPI Eina_Error eina_error_msg_register(const char *msg) EINA_ARG_NONNULL(1);
EAPI Eina_Error eina_error_get(void);
EAPI void eina_error_set(Eina_Error err);

View File

@ -60,9 +60,6 @@ typedef int (*Eina_Key_Cmp)(const void *key1, int key1_length,
typedef int (*Eina_Key_Hash)(const void *key, int key_length);
#define EINA_KEY_HASH(Function) ((Eina_Key_Hash)Function)
EAPI int eina_hash_init(void);
EAPI int eina_hash_shutdown(void);
EAPI Eina_Hash * eina_hash_new(Eina_Key_Length key_length_cb,
Eina_Key_Cmp key_cmp_cb,
Eina_Key_Hash key_hash_cb,

View File

@ -75,9 +75,6 @@ struct _Eina_List_Accounting
EINA_MAGIC
};
EAPI int eina_list_init(void);
EAPI int eina_list_shutdown(void);
EAPI Eina_List *eina_list_append (Eina_List *list, const void *data) EINA_ARG_NONNULL(2) EINA_WARN_UNUSED_RESULT;
EAPI Eina_List *eina_list_prepend (Eina_List *list, const void *data) EINA_ARG_NONNULL(2) EINA_WARN_UNUSED_RESULT;
EAPI Eina_List *eina_list_append_relative (Eina_List *list, const void *data, const void *relative) EINA_ARG_NONNULL(2) EINA_WARN_UNUSED_RESULT;

View File

@ -162,10 +162,7 @@ struct _Eina_Log_Domain
Eina_Bool deleted:1; /**< Flags deletion of domain, a free slot */
};
/**
* @typedef Eina_Log_Level
* List of available logging levels.
*/
EAPI void eina_log_threads_enable(void);
/**
* @enum _Eina_Log_Level
@ -190,15 +187,6 @@ typedef void (*Eina_Log_Print_Cb)(const Eina_Log_Domain *d, Eina_Log_Level level
const char *file, const char *fnc, int line,
const char *fmt, void *data, va_list args);
/**
* @var EINA_LOG_OUT_OF_MEMORY
* Log identifier corresponding to a lack of memory.
*/
EAPI int eina_log_init(void);
EAPI int eina_log_shutdown(void);
EAPI void eina_log_threads_enable(void);
/*
* Customization
*/

View File

@ -37,9 +37,6 @@
typedef unsigned int Eina_Magic;
EAPI int eina_magic_string_init(void);
EAPI int eina_magic_string_shutdown(void);
/**
* @typedef Eina_Magic
* An abstract type for a magic number.

View File

@ -67,10 +67,6 @@ typedef struct _Eina_Matrixsparse_Item_Cell Eina_Matrixsparse_Item_Cell;
typedef struct _Eina_Matrixsparse_Item_Row Eina_Matrixsparse_Item_Row;
/* init */
EAPI int eina_matrixsparse_init(void);
EAPI int eina_matrixsparse_shutdown(void);
/* constructors and destructors */
EAPI Eina_Matrixsparse *eina_matrixsparse_new(unsigned long rows, unsigned long cols, void (*free_func)(void *user_data, void *cell_data), const void *user_data);
EAPI void eina_matrixsparse_free(Eina_Matrixsparse *m);

View File

@ -49,9 +49,6 @@ typedef struct _Eina_Mempool_Backend Eina_Mempool_Backend;
EAPI extern Eina_Error EINA_ERROR_NOT_MEMPOOL_MODULE;
EAPI int eina_mempool_init(void);
EAPI int eina_mempool_shutdown(void);
EAPI Eina_Mempool * eina_mempool_add(const char *module, const char *context, const char *options, ...) EINA_MALLOC EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
EAPI void eina_mempool_del(Eina_Mempool *mp) EINA_ARG_NONNULL(1);

View File

@ -56,9 +56,6 @@ extern EAPI Eina_Error EINA_ERROR_WRONG_MODULE;
*/
extern EAPI Eina_Error EINA_ERROR_MODULE_INIT_FAILED;
EAPI int eina_module_init(void);
EAPI int eina_module_shutdown(void);
EAPI Eina_Module * eina_module_new(const char *file) EINA_MALLOC EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
EAPI Eina_Bool eina_module_free(Eina_Module *m) EINA_ARG_NONNULL(1);
EAPI Eina_Bool eina_module_load(Eina_Module *module) EINA_ARG_NONNULL(1);

View File

@ -59,9 +59,6 @@ static inline Eina_Bool eina_rectangle_intersection(Eina_Rectangle *dst, const E
static inline void eina_rectangle_rescale_in(const Eina_Rectangle *out, const Eina_Rectangle *in, Eina_Rectangle *res) EINA_ARG_NONNULL(1, 2, 3);
static inline void eina_rectangle_rescale_out(const Eina_Rectangle *out, const Eina_Rectangle *in, Eina_Rectangle *res) EINA_ARG_NONNULL(1, 2, 3);
EAPI int eina_rectangle_init(void);
EAPI int eina_rectangle_shutdown(void);
EAPI Eina_Rectangle_Pool *eina_rectangle_pool_new(int w, int h) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
EAPI Eina_Rectangle_Pool *eina_rectangle_pool_get(Eina_Rectangle *rect) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
EAPI Eina_Bool eina_rectangle_pool_geometry_get(Eina_Rectangle_Pool *pool, int *w, int *h) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;

View File

@ -68,9 +68,6 @@
#include "eina_config.h"
#include "eina_error.h"
EAPI int eina_safety_checks_init(void);
EAPI int eina_safety_checks_shutdown(void);
/**
* @var EINA_ERROR_SAFETY_FAILED
* Error identifier corresponding to safety check failure.

View File

@ -65,8 +65,6 @@
* @{
*/
EAPI int eina_stringshare_init(void);
EAPI int eina_stringshare_shutdown(void);
EAPI const char *eina_stringshare_add_length(const char *str, unsigned int slen) EINA_WARN_UNUSED_RESULT;
EAPI const char *eina_stringshare_add(const char *str) EINA_WARN_UNUSED_RESULT;
EAPI const char *eina_stringshare_ref(const char *str);

View File

@ -27,6 +27,8 @@
#include "eina_config.h"
#include "eina_private.h"
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h"
#include "eina_accessor.h"

View File

@ -31,39 +31,7 @@
*
* @section tutorial_error_basic_usage Basic Usage
*
* The first thing to do when using arrays is to initialize the array
* module with eina_array_init() and, when no more arrays are used, the
* module is shut down with eina_array_shutdown(). So a basic program
* would look like that:
*
* @code
* #include <stdlib.h>
* #include <stdio.h>
*
* #include <eina_array.h>
*
* int main(void)
* {
* if (!eina_array_init())
* {
* printf ("Error during the initialization of eina_error module\n");
* return EXIT_FAILURE;
* }
*
* eina_array_shutdown();
*
* return EXIT_SUCCESS;
* }
* @endcode
*
* All program using any module of eina must be compiled with the
* following command:
*
* @code
* gcc -o my_bin my_source.c `pkg-config --cflags --libs eina-0`
* @endcode
*
* Then, an array must created with eina_array_new(). That function
* An array must created with eina_array_new(). That function
* takes an integer as parameter, which is the count of pointers to
* add when increasing the array size. Once the array is not used
* anymore, it must be destroyed with eina_array_free().
@ -97,15 +65,15 @@
* Eina_Array_Iterator iterator;
* unsigned int i;
*
* if (!eina_array_init())
* if (!eina_init())
* {
* printf ("Error during the initialization of eina_error module\n");
* printf ("Error during the initialization of eina\n");
* return EXIT_FAILURE;
* }
*
* array = eina_array_new(16);
* if (!array)
* goto shutdown_array;
* goto shutdown;
*
* for (i = 0; i < 4; i++)
* {
@ -127,12 +95,12 @@
* }
*
* eina_array_free(array);
* eina_array_shutdown();
* eina_shutdown();
*
* return EXIT_SUCCESS;
*
* shutdown_array:
* eina_array_shutdown();
* shutdown:
* eina_shutdown();
*
* return EXIT_FAILURE;
* }
@ -152,10 +120,11 @@
#include "eina_config.h"
#include "eina_private.h"
#include "eina_safety_checks.h"
#include "eina_error.h"
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h"
#include "eina_array.h"
#include "eina_inline_array.x"
/*============================================================================*
* Local *
@ -209,7 +178,6 @@ struct _Eina_Accessor_Array
EINA_MAGIC
};
static int _eina_array_init_count = 0;
static int _eina_array_log_dom = -1;
#define ERR(...) EINA_LOG_DOM_ERR(_eina_array_log_dom, __VA_ARGS__)
#define DBG(...) EINA_LOG_DOM_DBG(_eina_array_log_dom, __VA_ARGS__)
@ -322,9 +290,9 @@ eina_array_grow(Eina_Array *array)
* data at any place, the Eina @ref Eina_List_Group is the correct container
* to use.
*
* To use the array data type, eina_array_init() must be called before
* any other array functions. When no more array function is used,
* eina_array_shutdown() must be called to free all the resources.
* To use the array data type, eina_init() must be called before any
* other array functions. When eina is no more array function is used,
* eina_shutdown() must be called to free all the resources.
*
* An array must be created with eina_array_new(). It allocated all
* the necessary data for an array. When not needed anymore, an array
@ -350,117 +318,51 @@ eina_array_grow(Eina_Array *array)
*/
/**
* @internal
* @brief Initialize the array module.
*
* @return 1 or greater on success, 0 on error.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function sets up the error and magic modules or Eina. It is
* also called by eina_init(). It returns 0 on failure, otherwise it
* returns the number of times it has already been called. See
* eina_error_init() and eina_magic_string_init() for the
* documentation of the initialisation of the dependency modules.
* called by eina_init().
*
* When no more Eina arrays are used, call eina_array_shutdown() to shut
* down the array module.
*
* @see eina_error_init()
* @see eina_magic_string_init()
* @see eina_init()
*/
EAPI int
Eina_Bool
eina_array_init(void)
{
if (!_eina_array_init_count)
_eina_array_log_dom = eina_log_domain_register("eina_array", EINA_LOG_COLOR_DEFAULT);
if (_eina_array_log_dom < 0)
{
if (!eina_log_init())
{
fprintf(stderr, "Could not initialize eina logging system.\n");
return 0;
}
_eina_array_log_dom = eina_log_domain_register("eina_array", EINA_LOG_COLOR_DEFAULT);
if (_eina_array_log_dom < 0)
{
EINA_LOG_ERR("Could not register log domain: eina_array");
eina_log_shutdown();
return 0;
}
if (!eina_error_init())
{
ERR("Could not initialize eina error module.");
goto error_init_error;
}
if (!eina_safety_checks_init())
{
ERR("Could not initialize eina safety checks.");
goto safety_checks_init_error;
}
if (!eina_magic_string_init())
{
ERR("ERROR: Could not initialize eina magic string module.");
goto magic_string_init_error;
}
eina_magic_string_set(EINA_MAGIC_ITERATOR,
"Eina Iterator");
eina_magic_string_set(EINA_MAGIC_ACCESSOR,
"Eina Accessor");
eina_magic_string_set(EINA_MAGIC_ARRAY,
"Eina Array");
eina_magic_string_set(EINA_MAGIC_ARRAY_ITERATOR,
"Eina Array Iterator");
eina_magic_string_set(EINA_MAGIC_ARRAY_ACCESSOR,
"Eina Array Accessor");
EINA_LOG_ERR("Could not register log domain: eina_array");
return EINA_FALSE;
}
return ++_eina_array_init_count;
magic_string_init_error:
eina_safety_checks_shutdown();
safety_checks_init_error:
eina_error_shutdown();
error_init_error:
eina_log_domain_unregister(_eina_array_log_dom);
_eina_array_log_dom = -1;
eina_log_shutdown();
return 0;
eina_magic_string_set(EINA_MAGIC_ITERATOR, "Eina Iterator");
eina_magic_string_set(EINA_MAGIC_ACCESSOR, "Eina Accessor");
eina_magic_string_set(EINA_MAGIC_ARRAY, "Eina Array");
eina_magic_string_set(EINA_MAGIC_ARRAY_ITERATOR, "Eina Array Iterator");
eina_magic_string_set(EINA_MAGIC_ARRAY_ACCESSOR, "Eina Array Accessor");
return EINA_TRUE;
}
/**
* @internal
* @brief Shut down the array module.
*
* @return 0 when the list module is completely shut down, 1 or
* greater otherwise.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function shuts down the array module. It returns 0 when it has
* been called the same number of times than eina_array_init(). In
* that case it shut down the magic and error modules. This function
* is also called by eina_shutdown(). See eina_error_shutdown() and
* eina_magic_string_shutdown() for the documentation of the
* shutting down of the dependency modules.
* This function shuts down the array module set up by
* eina_array_init(). It is called by eina_shutdown().
*
* @see eina_error_shutdown()
* @see eina_magic_string_shutdown()
* @see eina_shutdown()
*/
EAPI int
Eina_Bool
eina_array_shutdown(void)
{
--_eina_array_init_count;
if (!_eina_array_init_count)
{
eina_magic_string_shutdown();
eina_safety_checks_shutdown();
eina_error_shutdown();
eina_log_domain_unregister(_eina_array_log_dom);
_eina_array_log_dom = -1;
eina_log_shutdown();
}
return _eina_array_init_count;
eina_log_domain_unregister(_eina_array_log_dom);
_eina_array_log_dom = -1;
return EINA_TRUE;
}
/**

View File

@ -91,7 +91,6 @@ struct _Eina_Benchmark
Eina_Inlist *runs;
};
static int _eina_benchmark_count = 0;
static int _log_dom = -1;
#define ERR(...) EINA_LOG_DOM_ERR(_log_dom, __VA_ARGS__)
@ -117,9 +116,9 @@ static int _log_dom = -1;
* in Eina to compare the time used by eina, glib, evas and ecore data
* types.
*
* The benchmark module must be initialized with eina_benchmark_init()
* and shut down with eina_benchmark_shutdown(). A benchmark is
* created with eina_benchmark_new() and freed with
* To use the benchmark module, Eina must be initialized with
* eina_init() and later shut down with eina_shutdown(). A benchmark
* is created with eina_benchmark_new() and freed with
* eina_benchmark_free().
*
* eina_benchmark_register() adds a test to a benchmark. That test can
@ -137,103 +136,46 @@ static int _log_dom = -1;
*/
/**
* @internal
* @brief Initialize the benchmark module.
*
* @return 1 or greater on success, 0 on error.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function sets up the error, array and counter modules or
* Eina. It is also called by eina_init(). It returns 0 on failure,
* otherwise it returns the number of times it has already been
* called. See eina_error_init(), eina_array_init() and
* eina_counter_init() for the documentation of the initialisation of
* the dependency modules.
* This function sets up the benchmark module of Eina. It is called by
* eina_init().
*
* When no more Eina benchmarks are used, call
* eina_benchmark_shutdown() to shut down the benchmark module.
*
* @see eina_error_init()
* @see eina_array_init()
* @see eina_counter_init()
* @see eina_init()
*/
EAPI int
Eina_Bool
eina_benchmark_init(void)
{
_eina_benchmark_count++;
if (_eina_benchmark_count > 1) return _eina_benchmark_count;
if (!eina_log_init())
{
fprintf(stderr, "Could not initialize eina logging system.\n");
return 0;
}
_log_dom = eina_log_domain_register("eina_benchmark", EINA_LOG_COLOR_DEFAULT);
if (_log_dom < 0)
{
EINA_LOG_ERR("Could not register log domain: eina_benchmark");
eina_log_shutdown();
return 0;
return EINA_FALSE;
}
if (!eina_error_init())
{
ERR("Could not initialize eina error module.");
goto error_init_error;
}
if (!eina_array_init())
{
ERR("Could not initialize eina array module.");
goto array_init_error;
}
if (!eina_counter_init())
{
ERR("Could not initialize eina counter module.");
goto counter_init_error;
}
return _eina_benchmark_count;
counter_init_error:
eina_array_shutdown();
array_init_error:
eina_error_shutdown();
error_init_error:
eina_log_domain_unregister(_log_dom);
eina_log_shutdown();
return 0;
return EINA_TRUE;
}
/**
* @internal
* @brief Shut down the benchmark module.
*
* @return 0 when the error module is completely shut down, 1 or
* greater otherwise.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function shut down the error, array and counter modules set up
* by eina_array_init(). It is also called by eina_shutdown(). It returns
* 0 when it is called the same number of times than eina_benchmark_init().
* This function shuts down the benchmark module set up by
* eina_benchmark_init(). It is called by eina_shutdown().
*
* @see eina_error_shutdown()
* @see eina_array_shutdown()
* @see eina_counter_shutdown()
* @see eina_shutdown()
*/
EAPI int
Eina_Bool
eina_benchmark_shutdown(void)
{
_eina_benchmark_count--;
if (_eina_benchmark_count != 0) return _eina_benchmark_count;
eina_counter_shutdown();
eina_array_shutdown();
eina_error_shutdown();
eina_log_domain_unregister(_log_dom);
eina_log_shutdown();
return 0;
_log_dom = -1;
return EINA_TRUE;
}
/**

View File

@ -28,6 +28,8 @@
#include "eina_config.h"
#include "eina_private.h"
#include "eina_log.h"
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h"
#include "eina_convert.h"
@ -42,7 +44,6 @@
static const char look_up_table[] = {'0', '1', '2', '3', '4',
'5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f'};
static int _eina_convert_init_count = 0;
static int _eina_convert_log_dom = -1;
#define ERR(...) EINA_LOG_DOM_ERR(_eina_convert_log_dom, __VA_ARGS__)
@ -93,8 +94,8 @@ EAPI Eina_Error EINA_ERROR_CONVERT_OUTRUN_STRING_LENGTH = 0;
* These functions allow you to convert integer or real numbers to
* string or conversely.
*
* To use these function, you have to call eina_convert_init()
* first, and eina_convert_shutdown() when they are not used anymore.
* To use these functions, you have to call eina_init()
* first, and eina_shutdown() when eina is not used anymore.
*
* @section Eina_Convert_From_Integer_To_Sring Conversion from integer to string
*
@ -115,9 +116,9 @@ EAPI Eina_Error EINA_ERROR_CONVERT_OUTRUN_STRING_LENGTH = 0;
* {
* char *tmp[128];
*
* if (!eina_convert_init())
* if (!eina_init())
* {
* printf ("Error during the initialization of eina_convert module\n");
* printf ("Error during the initialization of eina.\n");
* return EXIT_FAILURE;
* }
*
@ -127,7 +128,7 @@ EAPI Eina_Error EINA_ERROR_CONVERT_OUTRUN_STRING_LENGTH = 0;
* eina_convert_xtoa(0xA1, tmp);
* printf("value: %s\n", tmp);
*
* eina_convert_shutdown();
* eina_shutdown();
*
* return EXIT_SUCCESS;
* }
@ -181,9 +182,9 @@ EAPI Eina_Error EINA_ERROR_CONVERT_OUTRUN_STRING_LENGTH = 0;
* long int e = 0;
* doule r;
*
* if (!eina_convert_init())
* if (!eina_init())
* {
* printf ("Error during the initialization of eina_convert module\n");
* printf ("Error during the initialization of eina.\n");
* return EXIT_FAILURE;
* }
*
@ -194,7 +195,7 @@ EAPI Eina_Error EINA_ERROR_CONVERT_OUTRUN_STRING_LENGTH = 0;
* r = ldexp((double)m, e);
* printf("value: %s\n", tmp);
*
* eina_convert_shutdown();
* eina_shutdown();
*
* return EXIT_SUCCESS;
* }
@ -206,81 +207,55 @@ EAPI Eina_Error EINA_ERROR_CONVERT_OUTRUN_STRING_LENGTH = 0;
*/
/**
* @brief Initialize the eina convert internal structure.
* @internal
* @brief Initialize the convert module.
*
* @return 1 or greater on success, 0 on error.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function sets up the convert module of Eina. It is called by
* eina_init().
*
* This function sets up the error module of Eina and registers the
* errors #EINA_ERROR_CONVERT_0X_NOT_FOUND,
* #EINA_ERROR_CONVERT_P_NOT_FOUND and
* #EINA_ERROR_CONVERT_OUTRUN_STRING_LENGTH. It is also called by
* eina_init(). It returns 0 on failure, otherwise it returns the
* number of times it has already been called.
* #EINA_ERROR_CONVERT_OUTRUN_STRING_LENGTH.
*
* @see eina_init()
*/
EAPI int
Eina_Bool
eina_convert_init(void)
{
_eina_convert_init_count++;
if (_eina_convert_init_count > 1) goto init_out;
eina_error_init();
EINA_ERROR_CONVERT_0X_NOT_FOUND = eina_error_msg_register("Error during string convertion to float, First '0x' was not found.");
EINA_ERROR_CONVERT_P_NOT_FOUND = eina_error_msg_register("Error during string convertion to float, First 'p' was not found.");
EINA_ERROR_CONVERT_OUTRUN_STRING_LENGTH = eina_error_msg_register("Error outrun string limit during convertion string convertion to float.");
if (!eina_log_init())
{
fprintf(stderr, "Could not initialize eina logging system.\n");
eina_error_shutdown();
return 0;
}
_eina_convert_log_dom = eina_log_domain_register("eina_convert", EINA_LOG_COLOR_DEFAULT);
if (_eina_convert_log_dom < 0)
{
EINA_LOG_ERR("Could not register log domain: eina_convert");
eina_log_shutdown();
eina_error_shutdown();
return 0;
return EINA_FALSE;
}
if (!eina_safety_checks_init())
{
ERR("Could not initialize eina safety checks.");
eina_log_shutdown();
eina_error_shutdown();
return 0;
}
EINA_ERROR_CONVERT_0X_NOT_FOUND = eina_error_msg_register("Error during string convertion to float, First '0x' was not found.");
EINA_ERROR_CONVERT_P_NOT_FOUND = eina_error_msg_register("Error during string convertion to float, First 'p' was not found.");
EINA_ERROR_CONVERT_OUTRUN_STRING_LENGTH = eina_error_msg_register("Error outrun string limit during convertion string convertion to float.");
init_out:
return _eina_convert_init_count;
return EINA_TRUE;
}
/**
* @brief Shut down the eina convert internal structures
* @internal
* @brief Shut down the convert module.
*
* @return 0 when the convert module is completely shut down, 1 or
* greater otherwise.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function just shuts down the error module. It is also called by
* eina_shutdown(). It returns 0 when it is called the same number of
* times than eina_convert_init().
* This function shuts down the convert module set up by
* eina_convert_init(). It is called by eina_shutdown().
*
* @see eina_shutdown()
*/
EAPI int
Eina_Bool
eina_convert_shutdown(void)
{
_eina_convert_init_count--;
if (_eina_convert_init_count > 0) goto shutdown_out;
eina_safety_checks_shutdown();
eina_log_domain_unregister(_eina_convert_log_dom);
eina_log_shutdown();
eina_error_shutdown();
shutdown_out:
return _eina_convert_init_count;
_eina_convert_log_dom = -1;
return EINA_TRUE;
}
/*

View File

@ -34,11 +34,13 @@
#include "eina_config.h"
#include "eina_private.h"
#include "eina_safety_checks.h"
#include "eina_counter.h"
#include "eina_inlist.h"
#include "eina_error.h"
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h"
#include "eina_counter.h"
/*============================================================================*
* Local *
*============================================================================*/
@ -74,8 +76,6 @@ struct _Eina_Clock
Eina_Bool valid;
};
static int _eina_counter_init_count = 0;
#ifndef _WIN32
static inline int
_eina_counter_time_get(Eina_Nano_Time *tp)
@ -152,9 +152,10 @@ _eina_counter_asiprintf(char *base, int *position, const char *format, ...)
*
* @brief These functions allow you to get the time spent in a part of a code.
*
* The counter system must be initialized with eina_counter_init() and
* shut down with eina_counter_shutdown(). The create a counter, use
* eina_counter_new(). To free it, use eina_counter_free().
* Before using the counter system, Eina must be initialized with
* eina_init() and later shut down with eina_shutdown(). The create a
* counter, use eina_counter_new(). To free it, use
* eina_counter_free().
*
* To time a part of a code, call eina_counter_start() just before it,
* and eina_counter_stop() just after it. Each time you start to time
@ -188,9 +189,9 @@ _eina_counter_asiprintf(char *base, int *position, const char *format, ...)
* {
* Eina_Counter *counter;
*
* if (!eina_counter_init())
* if (!eina_init())
* {
* printf("Error during the initialization of eina_counter module\n");
* printf("Error during the initialization of eina\n");
* return EXIT_FAILURE;
* }
*
@ -203,7 +204,7 @@ _eina_counter_asiprintf(char *base, int *position, const char *format, ...)
* eina_counter_dump(counter);
*
* eina_counter_free(counter);
* eina_counter_shutdown();
* eina_shutdown();
*
* return EXIT_SUCCESS;
* }
@ -228,85 +229,51 @@ _eina_counter_asiprintf(char *base, int *position, const char *format, ...)
*/
/**
* @internal
* @brief Initialize the eina counter internal structure.
*
* @return 1 or greater on success, 0 on error.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function shuts down the counter module set up by
* eina_counter_init(). It is called by eina_init().
*
* This function sets up the error module of Eina and only on Windows,
* it initializes the high precision timer. It also registers, only on
* Windows, the error #EINA_ERROR_COUNTER_WINDOWS. It is also called
* by eina_init(). It returns 0 on failure, otherwise it returns the
* number of times it has already been called. See eina_error_init()
* for the documentation of the initialisation of the dependency
* modules.
* number of times it has already been called.
*
* Once the counter module is not used anymore, then
* eina_counter_shutdown() must be called to shut down the counter
* module.
*
* @see eina_error_init()
* @see eina_init()
*/
EAPI int
Eina_Bool
eina_counter_init(void)
{
_eina_counter_init_count++;
if (_eina_counter_init_count == 1)
{
if (!eina_error_init())
{
fprintf(stderr, "Could not initialize eina error module.\n");
return 0;
}
#ifdef _WIN32
EINA_ERROR_COUNTER_WINDOWS = eina_error_msg_register("Change your OS, you moron !");
if (!QueryPerformanceFrequency(&_eina_counter_frequency))
{
eina_error_set(EINA_ERROR_COUNTER_WINDOWS);
eina_error_shutdown();
return 0;
}
#endif /* _WIN2 */
if (!eina_safety_checks_init())
{
fprintf(stderr, "Could not initialize eina safety checks.\n");
eina_error_shutdown();
return 0;
}
EINA_ERROR_COUNTER_WINDOWS = eina_error_msg_register("Change your OS, you moron !");
if (!QueryPerformanceFrequency(&_eina_counter_frequency))
{
eina_error_set(EINA_ERROR_COUNTER_WINDOWS);
return EINA_FALSE;
}
return _eina_counter_init_count;
#endif /* _WIN2 */
return EINA_TRUE;
}
/**
* @brief Shut down the eina counter internal structures
* @internal
* @brief Shut down the counter module.
*
* @return 0 when the counter module is completely shut down, 1 or
* greater otherwise.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function shuts down the counter module set up by
* eina_counter_init(). It is called by eina_shutdown(). It
* returns 0 when it is called the same number of times than
* eina_counter_init().
* eina_counter_init(). It is called by eina_shutdown().
*
* @see eina_error_shutdown()
* @see eina_shutdown()
*/
EAPI int
Eina_Bool
eina_counter_shutdown(void)
{
_eina_counter_init_count--;
if (_eina_counter_init_count == 0)
{
eina_error_shutdown();
eina_safety_checks_shutdown();
}
return _eina_counter_init_count;
return EINA_TRUE;
}
/**

View File

@ -27,41 +27,6 @@
* itself. Similar to libC's @c errno and strerror() facilities, this
* is extensible and recommended for other libraries and applications.
*
* @section tutorial_error_basic_usage Basic Usage
*
* The first thing to do when using the error module is to initialize
* it with eina_error_init() and, when the error module is not used
* anymore, to shut down it with eina_error_shutdown(). So a basic
* program would look like that:
*
* @code
* #include <stdlib.h>
* #include <stdio.h>
*
* #include <eina_error.h>
*
* int main(void)
* {
* if (!eina_error_init())
* {
* printf ("Error during the initialization of eina_error module\n");
* return EXIT_FAILURE;
* }
*
* eina_error_shutdown();
*
* return EXIT_SUCCESS;
* }
* @endcode
*
* All program using any module of eina must be compiled with the
* following command:
*
* @code
* gcc -Wall -o my_exe my_source.c `pkg-config --cflags --libs eina`
* @endcode
*
*
* @section tutorial_error_registering_msg Registering messages
*
* The error module can provide a system that mimic the errno system
@ -115,7 +80,7 @@
* {
* void *data;
*
* if (!eina_error_init())
* if (!eina_init())
* {
* printf ("Error during the initialization of eina_error module\n");
* return EXIT_FAILURE;
@ -155,7 +120,7 @@
* eina_error_msg_get(err));
* }
*
* eina_error_shutdown();
* eina_shutdown();
*
* return EXIT_SUCCESS;
* }
@ -179,11 +144,14 @@
#include "eina_config.h"
#include "eina_private.h"
#include "eina_safety_checks.h"
#include "eina_error.h"
#include "eina_inlist.h"
#include "eina_log.h" /* remove me when eina_error_print is removed! */
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h"
#include "eina_error.h"
/* TODO
* + printing errors to stdout or stderr can be implemented
* using a queue, useful for multiple threads printing
@ -201,7 +169,6 @@
* @cond LOCAL
*/
static int _eina_error_init_count = 0;
static Eina_Inlist *_error_list = NULL;
static int _error_list_count = 0;
static Eina_Error _err;
@ -224,10 +191,10 @@ static Eina_Error _err;
*
* @brief These functions provide error management for projects.
*
* The error system must be initialized with eina_error_init() and
* shut down with eina_error_shutdown(). Error codes are registered
* with eina_error_msg_register() and converted from identifier to
* original message string with eina_error_msg_get().
* To use the error system Eina must be initialized with eina_init()
* and later shut down with eina_shutdown(). Error codes are
* registered with eina_error_msg_register() and converted from
* identifier to original message string with eina_error_msg_get().
*
* Logging functions are not in eina_error anymore, see
* eina_log_print() instead.
@ -247,84 +214,49 @@ EAPI Eina_Error EINA_ERROR_OUT_OF_MEMORY = 0;
*/
/**
* @internal
* @brief Initialize the error module.
*
* @return 1 or greater on success, 0 on error.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function sets up the error module of Eina. It is called by
* eina_init() and by all modules initialization functions. It returns
* @c 0 on failure, otherwise it returns the number of times it is
* called.
*
* The default error level value is set by default to
* #EINA_ERROR_LEVEL_DBG if Eina is compiled with debug mode, or to
* #EINA_ERROR_LEVEL_ERR otherwise. That value can be overwritten by
* setting the environment variable EINA_ERROR_LEVEL. This function
* checks the value of that environment variable in the first
* call. Its value must be a number between 0 and 3, to match the
* error levels #EINA_ERROR_LEVEL_ERR, #EINA_ERROR_LEVEL_WARN,
* #EINA_ERROR_LEVEL_INFO and #EINA_ERROR_LEVEL_DBG. That value can
* also be set later with eina_error_log_level_set().
* eina_init().
*
* This function registers the error #EINA_ERROR_OUT_OF_MEMORY.
*
* Once the error module is not used anymore, then
* eina_error_shutdown() must be called to shut down the error
* module.
*
* @see eina_init()
*/
EAPI int eina_error_init(void)
Eina_Bool
eina_error_init(void)
{
_eina_error_init_count++;
if (_eina_error_init_count != 1)
return _eina_error_init_count;
/* TODO register the eina's basic errors */
EINA_ERROR_OUT_OF_MEMORY = eina_error_msg_register("Out of memory");
if (!eina_safety_checks_init())
{
fprintf(stderr, "Could not initialize eina safety checks.\n");
_eina_error_init_count = 0;
return 0;
}
return 1;
return EINA_TRUE;
}
/**
* @internal
* @brief Shut down the error module.
*
* @return 0 when the error module is completely shut down, 1 or
* greater otherwise.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function shuts down the error module set up by
* eina_error_init(). It is called by eina_shutdown() and by all
* modules shutdown functions. It returns 0 when it is called the
* same number of times than eina_error_init(). In that case it clears
* the error list.
* eina_error_init(). It is called by eina_shutdown().
*
* @see eina_shutdown()
*/
EAPI int eina_error_shutdown(void)
Eina_Bool
eina_error_shutdown(void)
{
Eina_Inlist *tmp;
_eina_error_init_count--;
if (!_eina_error_init_count)
{
/* remove the error strings */
while (_error_list)
{
tmp = _error_list;
_error_list = _error_list->next;
free(tmp);
}
_error_list_count = 0;
eina_safety_checks_shutdown();
}
return _eina_error_init_count;
/* remove the error strings */
while (_error_list)
{
Eina_Inlist *tmp = _error_list;
_error_list = _error_list->next;
free(tmp);
}
_error_list_count = 0;
return EINA_TRUE;
}
/**

View File

@ -63,6 +63,8 @@ void *alloca (size_t);
#include "eina_config.h"
#include "eina_private.h"
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h"
#include "eina_file.h"
@ -85,10 +87,6 @@ void *alloca (size_t);
* @li eina_file_split() split a path into all the subdirectories that
* compose it, according to the separator of the file system.
*
* @warning eina_file_split() uses the @ref Eina_Array_Group module
* but does not initialize it. eina_array_init() and
* eina_array_shutdown() must be called if this function is used.
*
* @{
*/
@ -238,10 +236,6 @@ eina_file_dir_list(const char *dir, Eina_Bool recursive, Eina_File_Dir_List_Cb c
* filesystem. If @p path is @c NULL or if the array can not be
* created, @c NULL is returned, otherwise, an array with the
* different parts of @p path is returned.
*
* @warning This function uses the @ref Eina_Array_Group module but
* does not initialize it. eina_array_init() and eina_array_shutdown()
* must be called if this function is used.
*/
EAPI Eina_Array *
eina_file_split(char *path)

View File

@ -32,11 +32,13 @@
#include "eina_config.h"
#include "eina_private.h"
#include "eina_safety_checks.h"
#include "eina_hash.h"
#include "eina_rbtree.h"
#include "eina_error.h"
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h"
#include "eina_hash.h"
/*============================================================================*
* Local *
*============================================================================*/
@ -136,8 +138,6 @@ struct _Eina_Hash_Each
const void *data;
};
static int _eina_hash_init_count = 0;
#undef get16bits
#if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \
|| defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)
@ -638,66 +638,6 @@ _eina_hash_iterator_free(Eina_Iterator_Hash *it)
* @{
*/
/**
* @brief Initialize the hash table module.
*
* @return 1 or greater on success, 0 on error.
*
* This function sets up the error module of Eina. It is also called
* by eina_init(). It returns 0 on failure, otherwise it returns the
* number of times it has already been called. See eina_error_init()
* for the documentation of the initialisation of the dependency
* module.
*
* When no more Eina hash tables are used, call eina_hash_shutdown()
* to shut down the array module.
*
* @see eina_error_init()
*/
EAPI int
eina_hash_init(void)
{
if (!_eina_hash_init_count)
{
if (!eina_error_init())
{
fprintf(stderr, "Could not initialize eina error module\n");
return 0;
}
if (!eina_safety_checks_init())
{
fprintf(stderr, "Could not initialize eina safety checks.\n");
eina_error_shutdown();
return 0;
}
}
return ++_eina_hash_init_count;
}
/**
* @brief Shut down the hash table module.
*
* @return 0 when the error module is completely shut down, 1 or
* greater otherwise.
*
* This function just shut down the error module set up by
* eina_hash_init(). It is also called by eina_shutdown(). It returns
* 0 when it is called the same number of times than
* eina_error_init().
*/
EAPI int
eina_hash_shutdown(void)
{
if (_eina_hash_init_count == 1)
{
eina_safety_checks_shutdown();
eina_error_shutdown();
}
return --_eina_hash_init_count;
}
EAPI Eina_Hash *
eina_hash_new(Eina_Key_Length key_length_cb,
Eina_Key_Cmp key_cmp_cb,

View File

@ -25,9 +25,11 @@
#include "eina_config.h"
#include "eina_private.h"
#include "eina_error.h"
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h"
#include "eina_inlist.h"
#include "eina_error.h"
/* FIXME: TODO please, refactor this :) */

View File

@ -27,6 +27,8 @@
#include "eina_config.h"
#include "eina_private.h"
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h"
#include "eina_iterator.h"

View File

@ -24,6 +24,8 @@
#include "eina_config.h"
#include "eina_private.h"
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h"
#include "eina_lalloc.h"

View File

@ -74,11 +74,13 @@
#include "eina_config.h"
#include "eina_private.h"
#include "eina_safety_checks.h"
#include "eina_error.h"
#include "eina_list.h"
#include "eina_mempool.h"
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h"
#include "eina_list.h"
/*============================================================================*
* Local *
@ -151,7 +153,6 @@ struct _Eina_Accessor_List
EINA_MAGIC
};
static int _eina_list_init_count = 0;
static Eina_Mempool *_eina_list_mp = NULL;
static Eina_Mempool *_eina_list_accounting_mp = NULL;
static int _eina_list_log_dom = -1;
@ -435,160 +436,92 @@ eina_list_sort_merge(Eina_List *a, Eina_List *b, Eina_Compare_Cb func)
*/
/**
* @internal
* @brief Initialize the list module.
*
* @return 1 or greater on success, 0 on error.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function sets up the error, magic and mempool modules of
* Eina. It is also called by eina_init(). It returns 0 on failure,
* otherwise it returns the number of times it has already been
* called. If Eina has been configured with the default memory pool,
* then the memory pool used in an Eina list will be
* "pass_through". Otherwise, the environment variable EINA_MEMPOOL is
* read and its value is chosen as memory pool ; if EINA_MEMPOOL is
* not defined, then the "chained_mempool" memory pool is chosen. If
* the memory pool is not found, then eina_list_init() return @c 0.
* See eina_error_init(), eina_magic_string_init() and
* eina_mempool_init() for the documentation of the initialisation of
* the dependency modules.
* This function sets up the list module of Eina. It is called by
* eina_init().
*
* When no more Eina lists are used, call eina_list_shutdown() to shut
* down the list module.
* This function creates mempool to speed up list node and accounting
* management, using EINA_MEMPOOL environment variable if it is set to
* choose the memory pool type to use.
*
* @see eina_error_init()
* @see eina_magic_string_init()
* @see eina_mempool_init()
* @see eina_init()
*/
EAPI int
Eina_Bool
eina_list_init(void)
{
const char *choice;
const char *choice, *tmp;
if (!_eina_list_init_count)
_eina_list_log_dom = eina_log_domain_register("eina_list", EINA_LOG_COLOR_DEFAULT);
if (_eina_list_log_dom < 0)
{
if (!eina_log_init())
{
fprintf(stderr, "Could not initialize eina logging system.\n");
return 0;
}
_eina_list_log_dom = eina_log_domain_register("eina_list", EINA_LOG_COLOR_DEFAULT);
if (_eina_list_log_dom < 0)
{
EINA_LOG_ERR("Could not register log domain: eina_list");
eina_log_shutdown();
return 0;
}
if (!eina_error_init())
{
ERR("Could not initialize eina error module.");
goto on_error_fail;
}
if (!eina_safety_checks_init())
{
ERR("Could not initialize eina safety checks.");
goto on_safety_checks_fail;
}
if (!eina_magic_string_init())
{
ERR("ERROR: Could not initialize eina magic string module.");
goto on_magic_string_fail;
}
if (!eina_mempool_init())
{
ERR("ERROR: Could not initialize eina mempool module.");
goto on_mempool_fail;
}
#ifdef EINA_DEFAULT_MEMPOOL
choice = "pass_through";
#else
if (!(choice = getenv("EINA_MEMPOOL")))
choice = "chained_mempool";
#endif
_eina_list_mp = eina_mempool_add(choice, "list", NULL,
sizeof (Eina_List), 320);
if (!_eina_list_mp)
{
ERR("ERROR: Mempool for list cannot be allocated in list init.");
goto on_init_fail;
}
_eina_list_accounting_mp = eina_mempool_add(choice, "list_accounting", NULL,
sizeof (Eina_List_Accounting), 80);
if (!_eina_list_accounting_mp)
{
ERR("ERROR: Mempool for list accounting cannot be allocated in list init.");
eina_mempool_del(_eina_list_mp);
goto on_init_fail;
}
eina_magic_string_set(EINA_MAGIC_ITERATOR,
"Eina Iterator");
eina_magic_string_set(EINA_MAGIC_ACCESSOR,
"Eina Accessor");
eina_magic_string_set(EINA_MAGIC_LIST,
"Eina List");
eina_magic_string_set(EINA_MAGIC_LIST_ITERATOR,
"Eina List Iterator");
eina_magic_string_set(EINA_MAGIC_LIST_ACCESSOR,
"Eina List Accessor");
eina_magic_string_set(EINA_MAGIC_LIST_ACCOUNTING,
"Eina List Accounting");
EINA_LOG_ERR("Could not register log domain: eina_list");
return EINA_FALSE;
}
return ++_eina_list_init_count;
#ifdef EINA_DEFAULT_MEMPOOL
choice = "pass_through";
#else
choice = "chained_mempool";
#endif
tmp = getenv("EINA_MEMPOOL");
if (tmp && tmp[0])
choice = tmp;
_eina_list_mp = eina_mempool_add
(choice, "list", NULL, sizeof(Eina_List), 320);
if (!_eina_list_mp)
{
ERR("ERROR: Mempool for list cannot be allocated in list init.");
goto on_init_fail;
}
_eina_list_accounting_mp = eina_mempool_add
(choice, "list_accounting", NULL, sizeof(Eina_List_Accounting), 80);
if (!_eina_list_accounting_mp)
{
ERR("ERROR: Mempool for list accounting cannot be allocated in list init.");
eina_mempool_del(_eina_list_mp);
goto on_init_fail;
}
eina_magic_string_set(EINA_MAGIC_ITERATOR, "Eina Iterator");
eina_magic_string_set(EINA_MAGIC_ACCESSOR, "Eina Accessor");
eina_magic_string_set(EINA_MAGIC_LIST, "Eina List");
eina_magic_string_set(EINA_MAGIC_LIST_ITERATOR, "Eina List Iterator");
eina_magic_string_set(EINA_MAGIC_LIST_ACCESSOR, "Eina List Accessor");
eina_magic_string_set(EINA_MAGIC_LIST_ACCOUNTING, "Eina List Accounting");
return EINA_TRUE;
on_init_fail:
eina_mempool_shutdown();
on_mempool_fail:
eina_magic_string_shutdown();
on_magic_string_fail:
eina_safety_checks_shutdown();
on_safety_checks_fail:
eina_error_shutdown();
on_error_fail:
eina_log_domain_unregister(_eina_list_log_dom);
_eina_list_log_dom = -1;
eina_log_shutdown();
return 0;
return EINA_FALSE;
}
/**
* @internal
* @brief Shut down the list module.
*
* @return 0 when the list module is completely shut down, 1 or
* greater otherwise.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function shuts down the mempool, magic and error modules set
* up by eina_list_init(). It is also called by eina_shutdown(). It
* returns 0 when it is called the same number of times than
* eina_list_init().
* This function shuts down the list module set up by
* eina_list_init(). It is called by eina_shutdown().
*
* @see eina_shutdown()
*/
EAPI int
Eina_Bool
eina_list_shutdown(void)
{
--_eina_list_init_count;
eina_mempool_del(_eina_list_accounting_mp);
eina_mempool_del(_eina_list_mp);
if (!_eina_list_init_count)
{
eina_mempool_del(_eina_list_accounting_mp);
eina_mempool_del(_eina_list_mp);
eina_mempool_shutdown();
eina_magic_string_shutdown();
eina_safety_checks_shutdown();
eina_error_shutdown();
eina_log_domain_unregister(_eina_list_log_dom);
_eina_list_log_dom = -1;
eina_log_shutdown();
}
return _eina_list_init_count;
eina_log_domain_unregister(_eina_list_log_dom);
_eina_list_log_dom = -1;
return EINA_TRUE;
}
/**

View File

@ -30,39 +30,7 @@
*
* @section tutorial_log_basic_usage Basic Usage
*
* The first thing to do when using the log module is to initialize
* it with eina_log_init() and when the log module is not used
* anymore, shut it down with eina_log_shutdown(). Here's a basic example:
*
* @code
* #include <stdlib.h>
* #include <stdio.h>
*
* #include <eina_log.h>
*
* int main(void)
* {
* if (!eina_log_init())
* {
* printf ("Error initializing Eina Log module\n");
* return EXIT_FAILURE;
* }
*
* eina_log_shutdown();
*
* return EXIT_SUCCESS;
* }
* @endcode
*
* Every program using any module of eina must be compiled with the
* following command:
*
* @code
* gcc -Wall -o my_exe my_source.c `pkg-config --cflags --libs eina`
* @endcode
*
* After the module has been initialized, log messages can be displayed using
* the following macros:
* Log messages can be displayed using the following macros:
*
* @li EINA_LOG_ERR(),
* @li EINA_LOG_INFO(),
@ -75,35 +43,35 @@
* #include <stdlib.h>
* #include <stdio.h>
*
* #include <eina_log.h>
* #include <Eina.h>
*
* void test(int i)
* {
* EINA_LOG_DBG("Entering test\n");
* EINA_LOG_DBG("Entering test");
*
* if (i < 0)
* {
* EINA_LOG_ERR("Argument is negative\n");
* EINA_LOG_ERR("Argument is negative");
* return;
* }
*
* EINA_LOG_INFO("argument non negative\n");
* EINA_LOG_INFO("argument non negative");
*
* EINA_LOG_DBG("Exiting test\n");
* EINA_LOG_DBG("Exiting test");
* }
*
* int main(void)
* {
* if (!eina_log_init())
* if (!eina_init())
* {
* printf ("log during the initialization of Eina_Log module\n");
* printf("log during the initialization of Eina_Log module\n");
* return EXIT_FAILURE;
* }
*
* test(-1);
* test(0);
*
* eina_log_shutdown();
* eina_shutdown();
*
* return EXIT_SUCCESS;
* }
@ -173,7 +141,6 @@
* The global level (EINA_LOG_LEVEL) can also be set through code, using
* eina_log_level_set() function.
*
* // TODO rewrite this section
* @section tutorial_log_advanced_display Advanced usage of print callbacks
*
* The log module allows the user to change the way
@ -206,7 +173,8 @@
* int to_stderr;
* };
*
* void print_cb(Eina_Log_Level level,
* void print_cb(const Eina_Log_Domain *domain,
* Eina_Log_Level level,
* const char *file,
* const char *fnc,
* int line,
@ -230,8 +198,10 @@
* str = "stdout";
* }
*
* fprintf(output, "%s:%s (%d) %s: ", file, fnc, line, str);
* fprintf(output, "%s:%s:%s (%d) %s: ",
* domain->domain_str, file, fnc, line, str);
* vfprintf(output, fmt, args);
* putc('\n', output);
* }
*
* void test(Data *data, int i)
@ -241,40 +211,59 @@
* else
* data->to_stderr = 1;
*
* log("log message...\n");
* log("log message...");
* }
*
* int main(void)
* {
* Data *data;
* Data data;
*
* if (!eina_log_init())
* if (!eina_init())
* {
* printf ("log during the initialization of Eina_Log module\n");
* printf("log during the initialization of Eina_Log module\n");
* return EXIT_FAILURE;
* }
*
* data = (Data *)malloc(sizeof(Data));
* if (!data)
* {
* printf ("log during memory allocation\n");
* eina_log_shutdown();
* return EXIT_FAILURE;
* }
* eina_log_print_cb_set(print_cb, &data);
*
* eina_log_print_cb_set(print_cb, data);
* test(&data, -1);
* test(&data, 0);
*
* test(data, -1);
* test(data, 0);
*
* eina_log_shutdown();
* eina_shutdown();
*
* return EXIT_SUCCESS;
* }
* @endcode
*
* Of course, instead of printf(), eina_log_print() can be used to
* have beautiful log messages.
* @addtogroup Eina_Log_Group Log
*
* @{
*
* The default log level value is set by default to
* #EINA_LOG_LEVEL_DBG if Eina is compiled with debug mode, or to
* #EINA_LOG_LEVEL_ERR otherwise. That value can be overwritten by
* setting the environment variable EINA_LOG_LEVEL. This function
* checks the value of that environment variable in the first
* call. Its value must be a number between 0 and 4, to match the log
* levels #EINA_LOG_LEVEL_CRITICAL, #EINA_LOG_LEVEL_ERR,
* #EINA_LOG_LEVEL_WARN, #EINA_LOG_LEVEL_INFO and
* #EINA_LOG_LEVEL_DBG. That value can also be set later with
* eina_log_log_level_set(). When logging domains are created, they
* will get either this value or specific value given with
* EINA_LOG_LEVELS that takes the format
* 'domain_name:level,another_name:other_level'.
*
* Format and verbosity of messages depend on the logging method, see
* eina_log_print_cb_set(). The default logging method is
* eina_log_print_cb_stderr(), which will output fancy colored
* messages to standard error stream. See its documentation on how to
* disable coloring, function or file/line print.
*
* This module will optionally abort program execution if message
* level is below or equal to @c EINA_LOG_LEVEL_CRITICAL and
* @c EINA_LOG_ABORT=1.
*
* @}
*/
#ifdef HAVE_CONFIG_H
@ -291,9 +280,11 @@
#include "eina_config.h"
#include "eina_private.h"
#include "eina_inlist.h"
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h"
#include "eina_log.h"
#include "eina_inlist.h"
#include <assert.h>
@ -301,7 +292,6 @@
* + printing logs to stdout or stderr can be implemented
* using a queue, useful for multiple threads printing
* + add a wrapper for assert?
* + improve doc
*/
/*============================================================================*
@ -336,9 +326,6 @@ struct _Eina_Log_Domain_Level_Pending
*/
static Eina_Inlist *_pending_list = NULL;
// Initialization counter
static int _eina_log_init_count = 0;
// Disable color flag (can be changed through the env var
// EINA_LOG_ENV_COLOR_DISABLE).
static Eina_Bool _disable_color = EINA_FALSE;
@ -810,11 +797,11 @@ eina_log_domain_parse_pendings(void)
*
* @brief These functions provide log management for projects.
*
* The log system must be initialized with eina_log_init() and
* shut down with eina_log_shutdown(). The most generic way to print
* To use the log system Eina must be initialized with eina_init() and
* later shut down with eina_shutdown(). The most generic way to print
* logs is to use eina_log_print() but the helper macros
* EINA_LOG_ERR(), EINA_LOG_INFO(), EINA_LOG_WARN() and
* EINA_LOG_DBG() should be used instead.
* EINA_LOG_ERR(), EINA_LOG_INFO(), EINA_LOG_WARN() and EINA_LOG_DBG()
* should be used instead.
*
* Here is a straightforward example:
*
@ -826,20 +813,20 @@ eina_log_domain_parse_pendings(void)
*
* void test_warn(void)
* {
* EINA_LOG_WARN("Here is a warning message\n");
* EINA_LOG_WARN("Here is a warning message");
* }
*
* int main(void)
* {
* if (!eina_log_init())
* if (!eina_init())
* {
* printf ("log during the initialization of Eina_Log module\n");
* printf("log during the initialization of Eina_Log module\n");
* return EXIT_FAILURE;
* }
*
* test_warn();
*
* eina_log_shutdown();
* eina_shutdown();
*
* return EXIT_SUCCESS;
* }
@ -859,7 +846,7 @@ eina_log_domain_parse_pendings(void)
* with:
*
* @code
* EINA_log_LEVEL=2 ./test_eina_log
* EINA_LOG_LEVEL=2 ./test_eina_log
* @endcode
*
* You should see a message displayed in the terminal.
@ -881,38 +868,13 @@ EAPI int EINA_LOG_DOMAIN_GLOBAL = 0;
*/
/**
* @internal
* @brief Initialize the log module.
*
* @return 1 or greater on success, 0 on log.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function sets up the log module of Eina. It is called by
* eina_init() and by all modules initialization functions. It returns
* @c 0 on failure, otherwise it returns the number of times it is
* called.
*
* The default log level value is set by default to
* #EINA_LOG_LEVEL_DBG if Eina is compiled with debug mode, or to
* #EINA_LOG_LEVEL_ERR otherwise. That value can be overwritten by
* setting the environment variable EINA_log_LEVEL. This function
* checks the value of that environment variable in the first
* call. Its value must be a number between 0 and 3, to match the
* log levels #EINA_LOG_LEVEL_ERR, #EINA_LOG_LEVEL_WARN,
* #EINA_LOG_LEVEL_INFO and #EINA_LOG_LEVEL_DBG. That value can
* also be set later with eina_log_log_level_set().
*
* Once the log module is not used anymore, then
* eina_log_shutdown() must be called to shut down the log
* module.
*
* Format and verbosity of messages depend on the logging method, see
* eina_log_print_cb_set(). The default logging method is
* eina_log_print_cb_stderr(), which will output fancy colored
* messages to standard error stream. See its documentation on how to
* disable coloring, function or file/line print.
*
* This module will optionally abort program execution if message
* level is below or equal to @c EINA_LOG_LEVEL_CRITICAL and
* @c EINA_LOG_ABORT=1.
* eina_init().
*
* @see eina_init()
*
@ -920,15 +882,11 @@ EAPI int EINA_LOG_DOMAIN_GLOBAL = 0;
* place where this function was called the first time is
* considered the main thread.
*/
EAPI int
Eina_Bool
eina_log_init(void)
{
const char *level, *tmp;
_eina_log_init_count++;
if (_eina_log_init_count != 1)
return _eina_log_init_count;
assert((sizeof(_names)/sizeof(_names[0])) == EINA_LOG_LEVELS);
assert((sizeof(_colors)/sizeof(_colors[0])) == EINA_LOG_LEVELS + 1);
@ -955,8 +913,6 @@ eina_log_init(void)
// Global log level
if ((level = getenv(EINA_LOG_ENV_LEVEL)))
_log_level = atoi(level);
else
_log_level = EINA_LOG_LEVEL_ERR;
// Register UNKNOWN domain, the default logger
EINA_LOG_DOMAIN_GLOBAL = eina_log_domain_register("", NULL);
@ -964,52 +920,37 @@ eina_log_init(void)
if (EINA_LOG_DOMAIN_GLOBAL < 0)
{
fprintf(stderr, "Failed to create global logging domain.\n");
_eina_log_init_count = 0;
return 0;
return EINA_FALSE;
}
// Parse pending domains passed through EINA_LOG_LEVELS
eina_log_domain_parse_pendings();
if (!eina_safety_checks_init())
{
fprintf(stderr, "Could not initialize eina safety checks.\n");
eina_log_shutdown(); /* zero _eina_log_init_count and free stuff */
return 0;
}
return 1;
return EINA_TRUE;
}
/**
* @internal
* @brief Shut down the log module.
*
* @return 0 when the log module is completely shut down, 1 or
* greater otherwise.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function shuts down the log module set up by
* eina_log_init(). It is called by eina_shutdown() and by all
* modules shutdown functions. It returns 0 when it is called the
* same number of times than eina_log_init(). In that case it clears
* the log list.
* eina_log_init(). It is called by eina_shutdown().
*
* @see eina_shutdown()
*
* @warning Not-MT: just call this function from main thread! The
* place where eina_log_init() was called the first time is
* considered the main thread.
* place where eina_log_init() (eina_init()) was called the
* first time is considered the main thread.
*/
EAPI int
Eina_Bool
eina_log_shutdown(void)
{
Eina_Inlist *tmp;
CHECK_MAIN(0);
if (_eina_log_init_count != 1) return --_eina_log_init_count;
eina_safety_checks_shutdown();
while (_log_domains_count--)
{
if (_log_domains[_log_domains_count].deleted)
@ -1033,14 +974,14 @@ eina_log_shutdown(void)
_threads_enabled = 0;
#endif
return --_eina_log_init_count;
return EINA_TRUE;
}
/**
* Enable logging module to handle threads.
*
* There is no disable option on purpose, if it is enabled, there is
* no way back until you call the last eina_log_shutdown().
* no way back until you call the last eina_shutdown().
*
* There is no function to retrieve if threads are enabled as one is
* not supposed to know this from outside.
@ -1051,7 +992,7 @@ eina_log_shutdown(void)
* printed.
*
* The main thread is considered the thread where the first
* eina_log_init() was called.
* eina_init() was called.
*/
EAPI void
eina_log_threads_enable(void)

View File

@ -51,7 +51,6 @@ struct _Eina_Magic_String
Eina_Magic magic;
};
static int _eina_magic_string_count = 0;
static Eina_Inlist *strings = NULL;
/**
@ -75,63 +74,47 @@ static Eina_Inlist *strings = NULL;
*/
/**
* @brief Initialize the magic module.
* @internal
* @brief Initialize the magic string module.
*
* @return 1 or greater.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function just increases a reference counter. If the magic
* module is disabled at configure time, then it always returns @c 1.
*
* Once the magic module is not used anymore, then
* eina_magic_shutdown() must be called to shut down the magic
* module.
* This function sets up the magic string module of Eina. It is called by
* eina_init().
*
* @see eina_init()
*/
EAPI int
Eina_Bool
eina_magic_string_init(void)
{
++_eina_magic_string_count;
return _eina_magic_string_count;
return EINA_TRUE;
}
/**
* @brief Shut down the magic module.
* @internal
* @brief Shut down the magic string module.
*
* @return 0 when the magic module is completely shut down, 1 or
* greater otherwise.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function shuts down the magic module set up by
* eina_magic_string_init(). It is called by eina_shutdown() and by
* all modules shutdown functions. It returns 0 when it is called the
* same number of times than eina_magic_string_init(). In that case it
* clears the magic list and return @c 0. If the magic module is
* disabled at configure time, then it always returns @c 0.
* This function shuts down the magic string module set up by
* eina_magic string_init(). It is called by eina_shutdown().
*
* @see eina_shutdown()
*/
EAPI int
Eina_Bool
eina_magic_string_shutdown(void)
{
--_eina_magic_string_count;
if (_eina_magic_string_count == 0)
/* Free all strings. */
while (strings)
{
/* Free all strings. */
while (strings)
{
Eina_Magic_String *tmp;
Eina_Magic_String *tmp = (Eina_Magic_String*) strings;
strings = eina_inlist_remove(strings, strings);
tmp = (Eina_Magic_String*) strings;
strings = eina_inlist_remove(strings, strings);
free(tmp->string);
free(tmp);
}
free(tmp->string);
free(tmp);
}
return _eina_magic_string_count;
return EINA_TRUE;
}
/**

View File

@ -52,6 +52,68 @@ static int _eina_log_dom = -1;
#define ERR(...) EINA_LOG_DOM_ERR(_eina_log_dom, __VA_ARGS__)
#define DBG(...) EINA_LOG_DOM_DBG(_eina_log_dom, __VA_ARGS__)
/* place module init/shutdown functions here to avoid other modules
* calling them by mistake.
*/
#define S(x) extern Eina_Bool eina_##x##_init(void); extern Eina_Bool eina_##x##_shutdown(void)
S(log);
S(error);
S(safety_checks);
S(magic_string);
S(array);
S(module);
S(mempool);
S(list);
S(stringshare);
S(matrixsparse);
S(convert);
S(counter);
S(benchmark);
S(rectangle);
#undef S
struct eina_desc_setup
{
const char *name;
Eina_Bool (*init)(void);
Eina_Bool (*shutdown)(void);
};
static const struct eina_desc_setup _eina_desc_setup[] = {
#define S(x) {#x, eina_##x##_init, eina_##x##_shutdown}
/* log is a special case as it needs printf */
S(error),
S(safety_checks),
S(magic_string),
S(array),
S(module),
S(mempool),
S(list),
S(stringshare),
S(matrixsparse),
S(convert),
S(counter),
S(benchmark),
S(rectangle)
#undef S
};
static const size_t _eina_desc_setup_len = sizeof(_eina_desc_setup) / sizeof(_eina_desc_setup[0]);
static void
_eina_shutdown_from_desc(const struct eina_desc_setup *itr)
{
for (itr--; itr >= _eina_desc_setup; itr--)
{
if (!itr->shutdown())
ERR("Problems shutting down eina module '%s', ignored.", itr->name);
}
eina_log_domain_unregister(_eina_log_dom);
_eina_log_dom = -1;
eina_log_shutdown();
}
/**
* @endcond
*/
@ -81,21 +143,7 @@ static int _eina_log_dom = -1;
* This function sets up all the eina modules. It returns 0 on
* failure (that is, when one of the module fails to initialize),
* otherwise it returns the number of times it has already been
* called. The list of initialisation functions that are called are
* (in that order):
*
* @li eina_log_init()
* @li eina_error_init()
* @li eina_safety_checks_init()
* @li eina_hash_init()
* @li eina_stringshare_init()
* @li eina_list_init()
* @li eina_matrixsparse_init()
* @li eina_array_init()
* @li eina_counter_init()
* @li eina_benchmark_init()
* @li eina_magic_string_init()
* @li eina_rectangle_init()
* called.
*
* When Eina is not used anymore, call eina_shutdown() to shut down
* the Eina library.
@ -103,14 +151,16 @@ static int _eina_log_dom = -1;
EAPI int
eina_init(void)
{
if (_eina_main_count) goto finish_init;
const struct eina_desc_setup *itr, *itr_end;
if (EINA_LIKELY(_eina_main_count > 0))
return ++_eina_main_count;
if (!eina_log_init())
{
fprintf(stderr, "Could not initialize eina logging system.\n");
return 0;
}
_eina_log_dom = eina_log_domain_register("eina", EINA_LOG_COLOR_DEFAULT);
if (_eina_log_dom < 0)
{
@ -119,92 +169,20 @@ eina_init(void)
return 0;
}
if (!eina_error_init())
itr = _eina_desc_setup;
itr_end = itr + _eina_desc_setup_len;
for (; itr < itr_end; itr++)
{
ERR("Could not initialize eina error module.");
goto eina_init_error;
if (!itr->init())
{
ERR("Could not initialize eina module '%s'.", itr->name);
_eina_shutdown_from_desc(itr);
return 0;
}
}
if (!eina_safety_checks_init())
{
ERR("Could not initialize eina safety checks module.");
goto safety_checks_init_error;
}
if (!eina_hash_init())
{
ERR("Could not initialize eina hash module.");
goto hash_init_error;
}
if (!eina_stringshare_init())
{
ERR("Could not initialize eina stringshare module.");
goto stringshare_init_error;
}
if (!eina_list_init())
{
ERR("Could not initialize eina list module.");
goto list_init_error;
}
if (!eina_matrixsparse_init())
{
ERR("Could not initialize eina matrixsparse module.");
goto matrixsparse_init_error;
}
if (!eina_array_init())
{
ERR("Could not initialize eina array module.");
goto array_init_error;
}
if (!eina_counter_init())
{
ERR("Could not initialize eina counter module.");
goto counter_init_error;
}
if (!eina_benchmark_init())
{
ERR("Could not initialize eina benchmark module.");
goto benchmark_init_error;
}
if (!eina_magic_string_init())
{
ERR("Could not initialize eina magic string module.");
goto magic_string_init_error;
}
if (!eina_rectangle_init())
{
ERR("Could not initialize eina rectangle module.");
goto rectangle_init_error;
}
finish_init:
return ++_eina_main_count;
rectangle_init_error:
eina_magic_string_shutdown();
magic_string_init_error:
eina_benchmark_shutdown();
benchmark_init_error:
eina_counter_shutdown();
counter_init_error:
eina_array_shutdown();
array_init_error:
eina_matrixsparse_shutdown();
matrixsparse_init_error:
eina_list_shutdown();
list_init_error:
eina_stringshare_shutdown();
stringshare_init_error:
eina_hash_shutdown();
hash_init_error:
eina_safety_checks_shutdown();
safety_checks_init_error:
eina_error_shutdown();
eina_init_error:
_eina_log_dom = -1;
eina_log_shutdown();
return 0;
_eina_main_count = 1;
return 1;
}
/**
@ -215,21 +193,7 @@ eina_init(void)
*
* This function shuts down the Eina library. It returns 0 when it has
* been called the same number of times than eina_init(). In that case
* it shut down all the Eina modules. The list of shut down functions
* that are called are (in that order):
*
* @li eina_rectangle_shutdown()
* @li eina_magic_string_shutdown()
* @li eina_benchmark_shutdown()
* @li eina_counter_shutdown()
* @li eina_array_shutdown()
* @li eina_matrixsparse_shutdown()
* @li eina_list_shutdown()
* @li eina_stringshare_shutdown()
* @li eina_hash_shutdown()
* @li eina_safety_checks_shutdown()
* @li eina_error_shutdown()
* @li eina_log_shutdown()
* it shut down all the Eina modules.
*
* Once this function succeeds (that is, @c 0 is returned), you must
* not call any of the Eina function anymore. You must call
@ -238,25 +202,10 @@ eina_init(void)
EAPI int
eina_shutdown(void)
{
if (_eina_main_count != 1) goto finish_shutdown;
eina_rectangle_shutdown();
eina_magic_string_shutdown();
eina_benchmark_shutdown();
eina_counter_shutdown();
eina_array_shutdown();
eina_matrixsparse_shutdown();
eina_list_shutdown();
eina_stringshare_shutdown();
eina_hash_shutdown();
eina_safety_checks_shutdown();
eina_error_shutdown();
eina_log_domain_unregister(_eina_log_dom);
_eina_log_dom = -1;
eina_log_shutdown();
finish_shutdown:
return --_eina_main_count;
_eina_main_count--;
if (EINA_UNLIKELY(_eina_main_count == 0))
_eina_shutdown_from_desc(_eina_desc_setup + _eina_desc_setup_len);
return _eina_main_count;
}
/**

View File

@ -38,12 +38,14 @@
#endif
#include "eina_config.h"
#include "eina_private.h"
#include "eina_error.h"
#include "eina_matrixsparse.h"
#include "eina_magic.h"
#include "eina_mempool.h"
#include "eina_private.h"
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h"
#include "eina_matrixsparse.h"
/*============================================================================*
@ -182,7 +184,6 @@ struct _Eina_Matrixsparse_Iterator_Complete
* @todo Eina_Matrixsparse_Cell_Accessor: accessor over cells in row
*/
static int _eina_matrixsparse_init_count = 0;
static int _eina_matrixsparse_log_dom = -1;
#define ERR(...) EINA_LOG_DOM_ERR(_eina_matrixsparse_log_dom, __VA_ARGS__)
@ -757,160 +758,96 @@ _eina_matrixsparse_iterator_complete_free(Eina_Matrixsparse_Iterator_Complete *i
*
* @{
*/
/**
* @internal
* @brief Initialize the matrixsparse module.
*
* @return 1 or greater on success, 0 on error.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function sets up the error, magic and mempool modules of
* Eina. It is also called by eina_init(). It returns 0 on failure,
* otherwise it returns the number of times it has already been
* called. If Eina has been configured with the default memory pool,
* then the memory pool used in an Eina matrixsparse will be
* "pass_through". Otherwise, the environment variable EINA_MEMPOOL is
* read and its value is chosen as memory pool ; if EINA_MEMPOOL is
* not defined, then the "chained_mempool" memory pool is chosen. If
* the memory pool is not found, then eina_matrixsparse_init() return @c 0.
* See eina_error_init(), eina_magic_string_init() and
* eina_mempool_init() for the documentation of the initialisation of
* the dependency modules.
* This function sets up the matrixsparse module of Eina. It is called by
* eina_init().
*
* When no more Eina matrixsparse are used, call eina_matrixsparse_shutdown()
* to shut down the matrixsparse module.
* This function creates mempool to speed up matrix rows and cells
* management, using EINA_MEMPOOL environment variable if it is set to
* choose the memory pool type to use.
*
* @see eina_error_init()
* @see eina_magic_string_init()
* @see eina_mempool_init()
* @see eina_init()
*/
EAPI int
Eina_Bool
eina_matrixsparse_init(void)
{
const char *choice;
const char *choice, *tmp;
if (!_eina_matrixsparse_init_count)
_eina_matrixsparse_log_dom = eina_log_domain_register("eina_matrixsparse", EINA_LOG_COLOR_DEFAULT);
if (_eina_matrixsparse_log_dom < 0)
{
if (!eina_log_init())
{
fprintf(stderr, "Could not initialize eina logging system.");
return 0;
}
_eina_matrixsparse_log_dom = eina_log_domain_register("eina_matrixsparse", EINA_LOG_COLOR_DEFAULT);
if (_eina_matrixsparse_log_dom < 0)
{
EINA_LOG_ERR("Could not register log domain: eina_matrixsparse");
eina_log_shutdown();
return 0;
}
if (!eina_error_init())
{
ERR("Could not initialize eina error module.");
goto on_eina_error_fail;
}
if (!eina_magic_string_init())
{
ERR("Could not initialize eina magic string module.");
goto on_magic_string_fail;
}
if (!eina_mempool_init())
{
ERR("Could not initialize eina mempool module.");
goto on_mempool_fail;
}
#ifdef EINA_DEFAULT_MEMPOOL
choice = "pass_through";
#else
if (!(choice = getenv("EINA_MEMPOOL")))
choice = "chained_mempool";
#endif
_eina_matrixsparse_cell_mp = eina_mempool_add
(choice, "matrixsparse_cell", NULL, sizeof (Eina_Matrixsparse_Cell), 120);
if (!_eina_matrixsparse_cell_mp)
{
ERR("Mempool for matrixsparse_cell cannot be allocated in matrixsparse init.");
goto on_init_fail;
}
_eina_matrixsparse_row_mp = eina_mempool_add
(choice, "matrixsparse_row", NULL, sizeof (Eina_Matrixsparse_Row), 120);
if (!_eina_matrixsparse_row_mp)
{
ERR("Mempool for matrixsparse_row cannot be allocated in matrixsparse init.");
goto on_init_fail;
}
eina_magic_string_set(EINA_MAGIC_MATRIXSPARSE,
"Eina Matrixsparse");
eina_magic_string_set(EINA_MAGIC_MATRIXSPARSE_ROW,
"Eina Matrixsparse Row");
eina_magic_string_set(EINA_MAGIC_MATRIXSPARSE_CELL,
"Eina Matrixsparse Cell");
eina_magic_string_set(EINA_MAGIC_MATRIXSPARSE_ITERATOR,
"Eina Matrixsparse Iterator");
eina_magic_string_set(EINA_MAGIC_MATRIXSPARSE_ROW_ACCESSOR,
"Eina Matrixsparse Row Accessor");
eina_magic_string_set(EINA_MAGIC_MATRIXSPARSE_ROW_ITERATOR,
"Eina Matrixsparse Row Iterator");
eina_magic_string_set(EINA_MAGIC_MATRIXSPARSE_CELL_ACCESSOR,
"Eina Matrixsparse Cell Accessor");
eina_magic_string_set(EINA_MAGIC_MATRIXSPARSE_CELL_ITERATOR,
"Eina Matrixsparse Cell Iterator");
EINA_LOG_ERR("Could not register log domain: eina_matrixsparse");
return EINA_FALSE;
}
return ++_eina_matrixsparse_init_count;
#ifdef EINA_DEFAULT_MEMPOOL
choice = "pass_through";
#else
choice = "chained_mempool";
#endif
tmp = getenv("EINA_MEMPOOL");
if (tmp && tmp[0])
choice = tmp;
_eina_matrixsparse_cell_mp = eina_mempool_add
(choice, "matrixsparse_cell", NULL, sizeof (Eina_Matrixsparse_Cell), 120);
if (!_eina_matrixsparse_cell_mp)
{
ERR("Mempool for matrixsparse_cell cannot be allocated in matrixsparse init.");
goto on_init_fail;
}
_eina_matrixsparse_row_mp = eina_mempool_add
(choice, "matrixsparse_row", NULL, sizeof (Eina_Matrixsparse_Row), 120);
if (!_eina_matrixsparse_row_mp)
{
ERR("Mempool for matrixsparse_row cannot be allocated in matrixsparse init.");
goto on_init_fail;
}
eina_magic_string_set(EINA_MAGIC_MATRIXSPARSE, "Eina Matrixsparse");
eina_magic_string_set(EINA_MAGIC_MATRIXSPARSE_ROW, "Eina Matrixsparse Row");
eina_magic_string_set(EINA_MAGIC_MATRIXSPARSE_CELL, "Eina Matrixsparse Cell");
eina_magic_string_set(EINA_MAGIC_MATRIXSPARSE_ITERATOR, "Eina Matrixsparse Iterator");
eina_magic_string_set(EINA_MAGIC_MATRIXSPARSE_ROW_ACCESSOR, "Eina Matrixsparse Row Accessor");
eina_magic_string_set(EINA_MAGIC_MATRIXSPARSE_ROW_ITERATOR, "Eina Matrixsparse Row Iterator");
eina_magic_string_set(EINA_MAGIC_MATRIXSPARSE_CELL_ACCESSOR, "Eina Matrixsparse Cell Accessor");
eina_magic_string_set(EINA_MAGIC_MATRIXSPARSE_CELL_ITERATOR, "Eina Matrixsparse Cell Iterator");
return EINA_TRUE;
on_init_fail:
eina_mempool_shutdown();
on_mempool_fail:
eina_magic_string_shutdown();
on_magic_string_fail:
eina_error_shutdown();
on_eina_error_fail:
eina_log_domain_unregister(_eina_matrixsparse_log_dom);
_eina_matrixsparse_log_dom = -1;
eina_log_shutdown();
return 0;
return EINA_FALSE;
}
/**
* @internal
* @brief Shut down the matrixsparse module.
*
* @return 0 when the matrixsparse module is completely shut down, 1 or
* greater otherwise.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function shuts down the mempool, magic and error modules set
* up by eina_matrixsparse_init(). It is also called by eina_shutdown(). It
* returns 0 when it is called the same number of times than
* eina_matrixsparse_init().
* This function shuts down the matrixsparse module set up by
* eina_matrixsparse_init(). It is called by eina_shutdown().
*
* @see eina_shutdown()
*/
EAPI int
Eina_Bool
eina_matrixsparse_shutdown(void)
{
--_eina_matrixsparse_init_count;
eina_mempool_del(_eina_matrixsparse_row_mp);
eina_mempool_del(_eina_matrixsparse_cell_mp);
if (!_eina_matrixsparse_init_count)
{
eina_mempool_del(_eina_matrixsparse_row_mp);
eina_mempool_del(_eina_matrixsparse_cell_mp);
eina_mempool_shutdown();
eina_magic_string_shutdown();
eina_error_shutdown();
eina_log_domain_unregister(_eina_matrixsparse_log_dom);
_eina_matrixsparse_log_dom = -1;
eina_log_shutdown();
}
return _eina_matrixsparse_init_count;
eina_log_domain_unregister(_eina_matrixsparse_log_dom);
_eina_matrixsparse_log_dom = -1;
return EINA_TRUE;
}
/**

View File

@ -30,6 +30,9 @@
#include "eina_hash.h"
#include "eina_module.h"
#include "eina_log.h"
#include "eina_main.h"
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h"
#include "eina_mempool.h"
@ -43,7 +46,6 @@
static Eina_Hash *_backends;
static Eina_Array *_modules;
static int _init_count = 0;
static int _log_dom = -1;
#define ERR(...) EINA_LOG_DOM_ERR(_log_dom, __VA_ARGS__)
@ -142,140 +144,100 @@ eina_mempool_unregister(Eina_Mempool_Backend *be)
EAPI Eina_Error EINA_ERROR_NOT_MEMPOOL_MODULE = 0;
EAPI int
Eina_Bool
eina_mempool_init(void)
{
if (!_init_count)
{
char *path;
char *path;
if (!eina_log_init())
{
fprintf(stderr, "Could not initialize eina logging system.\n");
return 0;
}
_log_dom = eina_log_domain_register("eina_mempool", EINA_LOG_COLOR_DEFAULT);
if (_log_dom < 0)
{
EINA_LOG_ERR("Could not register log domain: eina_mempool");
return 0;
}
_log_dom = eina_log_domain_register("eina_mempool", EINA_LOG_COLOR_DEFAULT);
if (_log_dom < 0)
{
EINA_LOG_ERR("Could not register log domain: eina_mempool");
eina_log_shutdown();
return 0;
}
EINA_ERROR_NOT_MEMPOOL_MODULE = eina_error_msg_register("Not a memory pool module.");
_backends = eina_hash_string_superfast_new(NULL);
if (!eina_safety_checks_init())
{
ERR("Could not initialize eina safety checks.");
goto safety_checks_init_error;
}
/* dynamic backends */
_modules = eina_module_list_get(NULL, PACKAGE_LIB_DIR "/eina/mp/", 0, NULL, NULL);
if (!eina_hash_init())
{
ERR("Could not initialize eina hash module.");
goto hash_init_error;
}
if (!eina_module_init())
{
ERR("Could not initialize eina module module.");
goto module_init_error;
}
path = eina_module_environment_path_get("HOME", "/.eina/mp/");
_modules = eina_module_list_get(_modules, path, 0, NULL, NULL);
if (path) free(path);
EINA_ERROR_NOT_MEMPOOL_MODULE = eina_error_msg_register("Not a memory pool module.");
_backends = eina_hash_string_superfast_new(NULL);
path = eina_module_environment_path_get("EINA_MODULES_MEMPOOL_DIR", "/eina/mp/");
_modules = eina_module_list_get(_modules, path, 0, NULL, NULL);
if (path) free(path);
/* dynamic backends */
_modules = eina_module_list_get(NULL, PACKAGE_LIB_DIR "/eina/mp/", 0, NULL, NULL);
path = eina_module_symbol_path_get(eina_init, "/eina/mp/");
_modules = eina_module_list_get(_modules, path, 0, NULL, NULL);
if (path) free(path);
path = eina_module_environment_path_get("HOME", "/.eina/mp/");
_modules = eina_module_list_get(_modules, path, 0, NULL, NULL);
if (path) free(path);
path = eina_module_environment_path_get("EINA_MODULES_MEMPOOL_DIR", "/eina/mp/");
_modules = eina_module_list_get(_modules, path, 0, NULL, NULL);
if (path) free(path);
path = eina_module_symbol_path_get(eina_mempool_init, "/eina/mp/");
_modules = eina_module_list_get(_modules, path, 0, NULL, NULL);
if (path) free(path);
if (!_modules)
{
ERR("no mempool modules able to be loaded.");
eina_hash_free(_backends);
goto mempool_init_error;
}
eina_module_list_load(_modules);
/* builtin backends */
if (!_modules)
{
ERR("no mempool modules able to be loaded.");
eina_hash_free(_backends);
goto mempool_init_error;
}
eina_module_list_load(_modules);
/* builtin backends */
#ifdef EINA_STATIC_BUILD_CHAINED_POOL
chained_init();
chained_init();
#endif
#ifdef EINA_STATIC_BUILD_PASS_THROUGH
pass_through_init();
pass_through_init();
#endif
#ifdef EINA_STATIC_BUILD_EMEMOA_UNKNOWN
ememoa_unknown_init();
ememoa_unknown_init();
#endif
#ifdef EINA_STATIC_BUILD_EMEMOA_FIXED
ememoa_fixed_init();
ememoa_fixed_init();
#endif
#ifdef EINA_STATIC_BUILD_FIXED_BITMAP
fixed_bitmap_init();
fixed_bitmap_init();
#endif
}
return ++_init_count;
mempool_init_error:
eina_module_shutdown();
module_init_error:
eina_hash_shutdown();
hash_init_error:
eina_safety_checks_shutdown();
safety_checks_init_error:
eina_log_domain_unregister(_log_dom);
eina_log_shutdown();
return EINA_TRUE;
return 0;
mempool_init_error:
eina_log_domain_unregister(_log_dom);
_log_dom = -1;
return EINA_FALSE;
}
EAPI int
Eina_Bool
eina_mempool_shutdown(void)
{
_init_count--;
if (_init_count != 0) return _init_count;
/* builtin backends */
/* builtin backends */
#ifdef EINA_STATIC_BUILD_CHAINED_POOL
chained_shutdown();
chained_shutdown();
#endif
#ifdef EINA_STATIC_BUILD_PASS_THROUGH
pass_through_shutdown();
pass_through_shutdown();
#endif
#ifdef EINA_STATIC_BUILD_EMEMOA_UNKNOWN
ememoa_unknown_shutdown();
ememoa_unknown_shutdown();
#endif
#ifdef EINA_STATIC_BUILD_EMEMOA_FIXED
ememoa_fixed_shutdown();
ememoa_fixed_shutdown();
#endif
#ifdef EINA_STATIC_BUILD_FIXED_BITMAP
fixed_bitmap_shutdown();
fixed_bitmap_shutdown();
#endif
/* dynamic backends */
eina_module_list_flush(_modules);
if (_modules)
eina_array_free(_modules);
/* dynamic backends */
eina_module_list_flush(_modules);
if (_modules)
eina_array_free(_modules);
eina_module_shutdown();
if (_backends)
eina_hash_free(_backends);
if (_backends)
eina_hash_free(_backends);
eina_log_domain_unregister(_log_dom);
_log_dom = -1;
eina_hash_shutdown();
eina_safety_checks_shutdown();
eina_log_domain_unregister(_log_dom);
eina_log_shutdown();
return 0;
return EINA_TRUE;
}
EAPI Eina_Mempool *

View File

@ -54,12 +54,14 @@ void *alloca (size_t);
#include "eina_config.h"
#include "eina_private.h"
#include "eina_safety_checks.h"
#include "eina_error.h"
#include "eina_module.h"
#include "eina_file.h"
#include "eina_log.h"
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h"
#include "eina_module.h"
/*============================================================================*
* Local *
*============================================================================*/
@ -147,7 +149,6 @@ static void _dir_list_cb(const char *name, const char *path, void *data)
eina_module_free(m);
}
}
static int _eina_module_count = 0;
/**
* @endcond
@ -182,120 +183,58 @@ EAPI Eina_Error EINA_ERROR_MODULE_INIT_FAILED = 0;
*/
/**
* @brief Initialize the eina module internal structure.
* @internal
* @brief Initialize the module loader module.
*
* @return 1 or greater on success, 0 on error.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function sets up the module loader module of Eina. It is
* called by eina_init().
*
* This function sets up the module module of Eina. It also registers
* the errors #EINA_ERROR_WRONG_MODULE and
* #EINA_ERROR_MODULE_INIT_FAILED. It is also called by
* eina_init(). It returns 0 on failure, otherwise it returns the
* number of times it has already been called. See eina_error_init()
* for the documentation of the initialisation of the dependency
* modules.
* #EINA_ERROR_MODULE_INIT_FAILED.
*
* Once the module module is not used anymore, then
* eina_module_shutdown() must be called to shut down the module
* module.
*
* @see eina_error_init()
* @see eina_init()
*/
EAPI int
Eina_Bool
eina_module_init(void)
{
_eina_module_count++;
if (_eina_module_count != 1)
goto end_init;
if (!eina_log_init())
{
fprintf(stderr, "Could not initialize eina logging module.\n");
return 0;
}
if (!eina_safety_checks_init())
{
EINA_LOG_ERR("Could not initialize eina safety checks.");
eina_log_shutdown();
return 0;
}
EINA_MODULE_LOG_DOM = eina_log_domain_register
("eina_module", EINA_LOG_COLOR_DEFAULT);
if (EINA_MODULE_LOG_DOM < 0)
{
EINA_LOG_ERR("Could not register log domain: eina_module");
eina_safety_checks_shutdown();
eina_log_shutdown();
return 0;
}
if (!eina_error_init())
{
ERR("Could not initialize eina error module.");
goto error_init_error;
return EINA_FALSE;
}
EINA_ERROR_WRONG_MODULE = eina_error_msg_register("Wrong file format or no file module found");
EINA_ERROR_MODULE_INIT_FAILED = eina_error_msg_register("Module initialisation function failed");
if (!eina_array_init())
{
ERR("Could not initialize eina array module.");
goto array_init_error;
}
end_init:
return _eina_module_count;
array_init_error:
eina_error_shutdown();
error_init_error:
eina_safety_checks_shutdown();
eina_log_domain_unregister(EINA_MODULE_LOG_DOM);
EINA_MODULE_LOG_DOM = -1;
eina_log_shutdown();
return 0;
return EINA_TRUE;
}
/**
* @brief Shut down the eina module internal structures
* @internal
* @brief Shut down the module loader module.
*
* @return 0 when the module module is completely shut down, 1 or
* greater otherwise.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function shuts down the module module set up by
* eina_module_init(). It is called by eina_shutdown(). It
* returns 0 when it is called the same number of times than
* eina_module_init().
* This function shuts down the module loader module set up by
* eina_module_init(). It is called by eina_shutdown().
*
* @see eina_error_shutdown()
* @see eina_shutdown()
*/
EAPI int
Eina_Bool
eina_module_shutdown(void)
{
_eina_module_count--;
if (_eina_module_count != 0)
goto end_shutdown;
eina_array_shutdown();
eina_error_shutdown();
/* TODO should we store every module when "new" is called and
* delete the list of modules here
*/
eina_safety_checks_shutdown();
eina_log_domain_unregister(EINA_MODULE_LOG_DOM);
EINA_MODULE_LOG_DOM = -1;
eina_log_shutdown();
end_shutdown:
return _eina_module_count;
return EINA_TRUE;
}
/**

View File

@ -26,9 +26,11 @@
#include "eina_config.h"
#include "eina_private.h"
#include "eina_array.h"
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h"
#include "eina_rbtree.h"
#include "eina_array.h"
/*============================================================================*
* Local *

View File

@ -25,14 +25,16 @@
#include "eina_config.h"
#include "eina_private.h"
#include "eina_safety_checks.h"
#include "eina_rectangle.h"
#include "eina_magic.h"
#include "eina_inlist.h"
#include "eina_mempool.h"
#include "eina_list.h"
#include "eina_trash.h"
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h"
#include "eina_rectangle.h"
/*============================================================================*
* Local *
*============================================================================*/
@ -84,7 +86,6 @@ struct _Eina_Rectangle_Alloc
EINA_MAGIC_FAIL((d), EINA_RECTANGLE_ALLOC_MAGIC); \
} while (0);
static int _eina_rectangle_init_count = 0;
static Eina_Mempool *_eina_rectangle_alloc_mp = NULL;
static Eina_Mempool *_eina_rectangle_mp = NULL;
@ -235,102 +236,58 @@ _eina_rectangle_empty_space_find(Eina_List *empty, int w, int h, int *x, int *y)
* API *
*============================================================================*/
EAPI int
Eina_Bool
eina_rectangle_init(void)
{
const char *choice;
_eina_rectangle_init_count++;
if (_eina_rectangle_init_count > 1) return _eina_rectangle_init_count;
if (!eina_log_init())
{
fprintf(stderr, "Could not initialize eina logging system.\n");
return 0;
}
const char *choice, *tmp;
_eina_rectangle_log_dom = eina_log_domain_register("eina_rectangle", EINA_LOG_COLOR_DEFAULT);
if (_eina_rectangle_log_dom < 0)
{
EINA_LOG_ERR("Could not register log domain: eina_rectangle");
eina_log_shutdown();
return 0;
}
if (!eina_error_init())
{
ERR("Could not initialize eina error module.");
goto error_init_error;
}
if (!eina_safety_checks_init())
{
fprintf(stderr, "Could not initialize eina safety checks.");
goto safety_checks_init_error;
}
if (!eina_mempool_init())
{
ERR("Could not initialize eina mempool module.");
goto mempool_init_error;
}
if (!eina_list_init())
{
ERR("Could not initialize eina list module.");
goto list_init_error;
return EINA_FALSE;
}
#ifdef EINA_DEFAULT_MEMPOOL
choice = "pass_through";
#else
if (!(choice = getenv("EINA_MEMPOOL")))
choice = "chained_mempool";
choice = "chained_mempool";
#endif
tmp = getenv("EINA_MEMPOOL");
if (tmp && tmp[0])
choice = tmp;
_eina_rectangle_alloc_mp = eina_mempool_add(choice, "rectangle-alloc", NULL,
sizeof (Eina_Rectangle_Alloc) + sizeof (Eina_Rectangle), 1024);
_eina_rectangle_alloc_mp = eina_mempool_add
(choice, "rectangle-alloc", NULL,
sizeof(Eina_Rectangle_Alloc) + sizeof(Eina_Rectangle), 1024);
if (!_eina_rectangle_alloc_mp)
{
ERR("Mempool for rectangle cannot be allocated in rectangle init.");
goto init_error;
}
_eina_rectangle_mp = eina_mempool_add(choice, "rectangle", NULL, sizeof (Eina_Rectangle), 256);
_eina_rectangle_mp = eina_mempool_add
(choice, "rectangle", NULL, sizeof(Eina_Rectangle), 256);
if (!_eina_rectangle_mp)
{
ERR("Mempool for rectangle cannot be allocated in rectangle init.");
goto init_error;
}
return _eina_rectangle_init_count;
return EINA_TRUE;
init_error:
eina_list_shutdown();
list_init_error:
eina_mempool_shutdown();
mempool_init_error:
eina_safety_checks_shutdown();
safety_checks_init_error:
eina_error_shutdown();
error_init_error:
eina_log_domain_unregister(_eina_rectangle_log_dom);
_eina_rectangle_log_dom = -1;
eina_log_shutdown();
return 0;
return EINA_FALSE;
}
EAPI int
Eina_Bool
eina_rectangle_shutdown(void)
{
Eina_Rectangle *del;
--_eina_rectangle_init_count;
if (_eina_rectangle_init_count) return _eina_rectangle_init_count;
eina_list_shutdown();
while ((del = eina_trash_pop(&_eina_rectangles)))
eina_mempool_free(_eina_rectangle_mp, del);
_eina_rectangles_count = 0;
@ -338,14 +295,10 @@ eina_rectangle_shutdown(void)
eina_mempool_del(_eina_rectangle_alloc_mp);
eina_mempool_del(_eina_rectangle_mp);
eina_mempool_shutdown();
eina_safety_checks_shutdown();
eina_error_shutdown();
eina_log_domain_unregister(_eina_rectangle_log_dom);
_eina_rectangle_log_dom = -1;
eina_log_shutdown();
return 0;
return EINA_TRUE;
}
EAPI Eina_Rectangle *

View File

@ -54,70 +54,43 @@
EAPI Eina_Error EINA_ERROR_SAFETY_FAILED = 0;
static int _eina_safety_checks_init_count = 0;
/**
* @endcond
*/
/**
* @internal
* @brief Initialize the safety checks module.
*
* @return 1 or greater on success, 0 on error.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function sets up the safety checks module of Eina. It is
* called by eina_init() and by all modules initialization
* functions. It returns @c 0 on failure, otherwise it returns the
* number of times it is called.
* called by eina_init().
*
* @see eina_init()
*/
EAPI int
Eina_Bool
eina_safety_checks_init(void)
{
if (_eina_safety_checks_init_count > 0)
return ++_eina_safety_checks_init_count;
#ifdef EINA_SAFETY_CHECKS
if (!eina_log_init())
return 0;
#endif
if (!eina_error_init())
{
eina_log_shutdown();
return 0;
}
EINA_ERROR_SAFETY_FAILED = eina_error_msg_register("Safety check failed.");
_eina_safety_checks_init_count = 1;
return 1;
return EINA_TRUE;
}
/**
* @internal
* @brief Shut down the safety checks module.
*
* @return 0 when the error module is completely shut down, 1 or
* greater otherwise.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function shuts down the error module set up by
* eina_safety_checks_init(). It is called by eina_shutdown() and by
* all modules shutdown functions. It returns 0 when it is called the
* same number of times than eina_safety_checks_init(). In that case
* it clears the error list.
* eina_safety_checks_init(). It is called by eina_shutdown().
*
* @see eina_shutdown()
*/
EAPI int
Eina_Bool
eina_safety_checks_shutdown(void)
{
_eina_safety_checks_init_count--;
if (_eina_safety_checks_init_count != 0)
return _eina_safety_checks_init_count;
eina_error_shutdown();
#ifdef EINA_SAFETY_CHECKS
eina_log_shutdown();
#endif
return 0;
return EINA_TRUE;
}
/**

View File

@ -76,12 +76,14 @@
#include "eina_config.h"
#include "eina_private.h"
#include "eina_safety_checks.h"
#include "eina_stringshare.h"
#include "eina_hash.h"
#include "eina_rbtree.h"
#include "eina_error.h"
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
#include "eina_safety_checks.h"
#include "eina_stringshare.h"
/*============================================================================*
* Local *
*============================================================================*/
@ -146,7 +148,6 @@ struct _Eina_Stringshare_Head
};
static Eina_Stringshare *share = NULL;
static int _eina_stringshare_init_count = 0;
static int _eina_stringshare_log_dom = -1;
#define CRITICAL(...) EINA_LOG_DOM_CRIT(_eina_stringshare_log_dom, __VA_ARGS__)
@ -806,125 +807,75 @@ _eina_stringshare_node_alloc(int slen)
*/
/**
* @brief Initialize the eina stringshare internal structure.
* @internal
* @brief Initialize the stringshare module.
*
* @return 1 or greater on success, 0 on error.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function allocates the memory needed by the stringshare
* internal structure and sets up the error module of Eina. It is also
* called by eina_init(). It returns 0 on failure, otherwise it
* returns the number of times it has already been called.
* This function sets up the stringshare module of Eina. It is called by
* eina_init().
*
* @see eina_init()
*/
EAPI int
Eina_Bool
eina_stringshare_init(void)
{
/*
* No strings have been loaded at this point, so create the hash
* table for storing string info for later.
*/
if (!_eina_stringshare_init_count)
_eina_stringshare_log_dom = eina_log_domain_register("eina_stringshare", EINA_LOG_COLOR_DEFAULT);
if (_eina_stringshare_log_dom < 0)
{
if (!eina_log_init())
{
fprintf(stderr, "Could not initialize eina logging system.\n");
return 0;
}
_eina_stringshare_log_dom = eina_log_domain_register("eina_stringshare", EINA_LOG_COLOR_DEFAULT);
if (_eina_stringshare_log_dom < 0)
{
EINA_LOG_ERR("Could not register log domain: eina_stringshare");
eina_log_shutdown();
return 0;
}
share = calloc(1, sizeof(Eina_Stringshare));
if (!share)
return 0;
if (!eina_error_init())
{
ERR("Could not initialize eina error module.");
goto error_init_error;
}
if (!eina_safety_checks_init())
{
ERR("Could not initialize eina safety checks.");
goto safety_checks_init_error;
}
if (!eina_magic_string_init())
{
ERR("ERROR: Could not initialize eina magic string module.");
goto magic_string_init_error;
}
eina_magic_string_set(EINA_MAGIC_STRINGSHARE,
"Eina Stringshare");
eina_magic_string_set(EINA_MAGIC_STRINGSHARE_HEAD,
"Eina Stringshare Head");
eina_magic_string_set(EINA_MAGIC_STRINGSHARE_NODE,
"Eina Stringshare Node");
EINA_MAGIC_SET(share, EINA_MAGIC_STRINGSHARE);
_eina_stringshare_small_init();
_eina_stringshare_population_init();
EINA_LOG_ERR("Could not register log domain: eina_stringshare");
return EINA_FALSE;
}
return ++_eina_stringshare_init_count;
share = calloc(1, sizeof(Eina_Stringshare));
if (!share)
{
eina_log_domain_unregister(_eina_stringshare_log_dom);
_eina_stringshare_log_dom = -1;
return EINA_FALSE;
}
magic_string_init_error:
eina_safety_checks_shutdown();
safety_checks_init_error:
eina_error_shutdown();
error_init_error:
eina_log_domain_unregister(_eina_stringshare_log_dom);
_eina_stringshare_log_dom = -1;
eina_log_shutdown();
return 0;
eina_magic_string_set(EINA_MAGIC_STRINGSHARE, "Eina Stringshare");
eina_magic_string_set(EINA_MAGIC_STRINGSHARE_HEAD, "Eina Stringshare Head");
eina_magic_string_set(EINA_MAGIC_STRINGSHARE_NODE, "Eina Stringshare Node");
EINA_MAGIC_SET(share, EINA_MAGIC_STRINGSHARE);
_eina_stringshare_small_init();
_eina_stringshare_population_init();
return EINA_TRUE;
}
/**
* @brief Shut down the eina stringshare internal structures
* @internal
* @brief Shut down the stringshare module.
*
* @return 0 when the stringshare module is completely shut down, 1 or
* greater otherwise.
* @return #EINA_TRUE on success, #EINA_FALSE on failure.
*
* This function frees the memory allocated by eina_stringshare_init()
* and shuts down the error module. It is also called by
* eina_shutdown(). It returns 0 when it is called the same number of
* times than eina_stringshare_init().
* This function shuts down the stringshare module set up by
* eina_stringshare_init(). It is called by eina_shutdown().
*
* @see eina_shutdown()
*/
EAPI int
Eina_Bool
eina_stringshare_shutdown(void)
{
unsigned int i;
_eina_stringshare_population_stats();
--_eina_stringshare_init_count;
if (!_eina_stringshare_init_count)
/* remove any string still in the table */
for (i = 0; i < EINA_STRINGSHARE_BUCKETS; i++)
{
/* remove any string still in the table */
for (i = 0; i < EINA_STRINGSHARE_BUCKETS; i++)
{
eina_rbtree_delete(EINA_RBTREE_GET(share->buckets[i]), EINA_RBTREE_FREE_CB(_eina_stringshare_head_free), NULL);
share->buckets[i] = NULL;
}
MAGIC_FREE(share);
_eina_stringshare_population_shutdown();
_eina_stringshare_small_shutdown();
eina_magic_string_shutdown();
eina_safety_checks_shutdown();
eina_error_shutdown();
eina_log_domain_unregister(_eina_stringshare_log_dom);
_eina_stringshare_log_dom = -1;
eina_log_shutdown();
eina_rbtree_delete(EINA_RBTREE_GET(share->buckets[i]), EINA_RBTREE_FREE_CB(_eina_stringshare_head_free), NULL);
share->buckets[i] = NULL;
}
MAGIC_FREE(share);
return _eina_stringshare_init_count;
_eina_stringshare_population_shutdown();
_eina_stringshare_small_shutdown();
eina_log_domain_unregister(_eina_stringshare_log_dom);
_eina_stringshare_log_dom = -1;
return EINA_TRUE;
}
/**

View File

@ -51,7 +51,7 @@ static const Eina_Benchmark_Case etc[] = {
static Eina_Array *_modules;
static void _mempool_init(void)
{
eina_mempool_init();
eina_init();
/* force modules to be loaded in case they are not installed */
_modules = eina_module_list_get(NULL, PACKAGE_BUILD_DIR"/src/modules", 1, NULL, NULL);
eina_module_list_load(_modules);
@ -61,7 +61,7 @@ static void _mempool_shutdown(void)
{
eina_module_list_flush(_modules);
/* TODO delete the list */
eina_mempool_shutdown();
eina_shutdown();
}
int
@ -75,7 +75,7 @@ main(int argc, char **argv)
_mempool_init();
eina_benchmark_init();
eina_init();
for (i = 0; etc[i].bench_case != NULL; ++i)
{
@ -102,7 +102,7 @@ main(int argc, char **argv)
eina_bench_e17();
eina_benchmark_shutdown();
eina_shutdown();
_mempool_shutdown();
return 0;

View File

@ -72,7 +72,7 @@ eina_bench_array_4evas_render_inline(int request)
srand(time(NULL));
eina_array_init();
eina_init();
array = eina_array_new(64);
@ -106,7 +106,7 @@ eina_bench_array_4evas_render_inline(int request)
eina_array_free(array);
eina_array_shutdown();
eina_shutdown();
}
static Eina_Bool
@ -136,7 +136,7 @@ eina_bench_array_4evas_render_iterator(int request)
srand(time(NULL));
eina_array_init();
eina_init();
array = eina_array_new(64);
@ -173,7 +173,7 @@ eina_bench_array_4evas_render_iterator(int request)
eina_array_free(array);
eina_array_shutdown();
eina_shutdown();
}
static void
@ -185,7 +185,7 @@ eina_bench_list_4evas_render(int request)
int i;
int j;
eina_list_init();
eina_init();
for (i = 0; i < 1000; ++i)
{
@ -242,7 +242,7 @@ eina_bench_list_4evas_render(int request)
list = eina_list_remove_list(list, list);
}
eina_list_shutdown();
eina_shutdown();
}
static void
@ -255,7 +255,7 @@ eina_bench_list_4evas_render_iterator(int request)
int i;
int j;
eina_list_init();
eina_init();
for (i = 0; i < 1000; ++i)
{
@ -309,7 +309,7 @@ eina_bench_list_4evas_render_iterator(int request)
list = eina_list_remove_list(list, list);
}
eina_list_shutdown();
eina_shutdown();
}
static void

View File

@ -35,7 +35,7 @@ _eina_mempool_bench(Eina_Mempool *mp, int request)
int i;
int j;
eina_array_init();
eina_init();
array = eina_array_new(32);
for (i = 0; i < 100; ++i)
@ -52,7 +52,7 @@ _eina_mempool_bench(Eina_Mempool *mp, int request)
}
eina_array_free(array);
eina_array_shutdown();
eina_shutdown();
}
static void
@ -115,7 +115,7 @@ eina_mempool_glib(int request)
int i;
int j;
eina_array_init();
eina_init();
array = eina_array_new(32);
for (i = 0; i < 100; ++i)
@ -132,7 +132,7 @@ eina_mempool_glib(int request)
}
eina_array_free(array);
eina_array_shutdown();
eina_shutdown();
}
#endif

View File

@ -32,8 +32,8 @@ eina_bench_eina_rectangle_pool(int request)
Eina_List *list = NULL;
int i;
eina_list_init();
eina_rectangle_init();
eina_init();
eina_init();
pool = eina_rectangle_pool_new(2048, 2048);
if (!pool) return ;
@ -63,8 +63,8 @@ eina_bench_eina_rectangle_pool(int request)
eina_rectangle_pool_free(pool);
eina_list_free(list);
eina_rectangle_shutdown();
eina_list_shutdown();
eina_shutdown();
eina_shutdown();
}
void eina_bench_rectangle_pool(Eina_Benchmark *bench)

View File

@ -37,8 +37,7 @@
#endif
#include "eina_bench.h"
#include "eina_list.h"
#include "eina_convert.h"
#include "Eina.h"
static int
_eina_cmp_str(const char *a, const char *b)
@ -52,7 +51,7 @@ eina_bench_sort_eina(int request)
Eina_List *list = NULL;
int i;
eina_list_init();
eina_init();
srand(time(NULL));
@ -73,7 +72,7 @@ eina_bench_sort_eina(int request)
list = eina_list_remove_list(list, list);
}
eina_list_shutdown();
eina_shutdown();
}
#ifdef EINA_BENCH_HAVE_EVAS

View File

@ -47,7 +47,7 @@ eina_bench_stringshare_job(int request)
unsigned int j;
int i;
eina_stringshare_init();
eina_init();
for (i = 0; i < request; ++i)
{
@ -68,7 +68,7 @@ eina_bench_stringshare_job(int request)
tmp = eina_stringshare_add(build);
}
eina_stringshare_shutdown();
eina_shutdown();
}
#ifdef EINA_BENCH_HAVE_GLIB

View File

@ -36,8 +36,7 @@
# include <Ecore_Data.h>
#endif
#include "eina_stringshare.h"
#include "eina_counter.h"
#include "Eina.h"
#if EINA_ENABLE_BENCH_E17
@ -55,10 +54,10 @@ struct _Eina_Stringshare_Test
static const char *strings[30000];
static Eina_Stringshare_Test eina_str = {
"eina",
eina_stringshare_init,
eina_init,
eina_stringshare_add,
eina_stringshare_del,
eina_stringshare_shutdown
eina_shutdown
};
#ifdef EINA_BENCH_HAVE_EVAS
@ -122,11 +121,11 @@ eina_bench_e17(void)
#if EINA_ENABLE_BENCH_E17
int i;
eina_counter_init();
eina_init();
for (i = 0; str[i]; ++i)
eina_bench_e17_stringshare(str[i]);
eina_counter_shutdown();
eina_shutdown();
#endif
}

View File

@ -21,7 +21,7 @@
#endif
#include "eina_suite.h"
#include "eina_mempool.h"
#include "Eina.h"
#include <stdio.h>
#include <string.h>
@ -106,7 +106,7 @@ eina_build_suite(int argc, const char **argv)
static Eina_Array *_modules;
static void _mempool_init(void)
{
eina_mempool_init();
eina_init();
/* force modules to be loaded in case they are not installed */
_modules = eina_module_list_get(NULL, PACKAGE_BUILD_DIR"/src/modules", 1, NULL, NULL);
eina_module_list_load(_modules);
@ -116,7 +116,7 @@ static void _mempool_shutdown(void)
{
eina_module_list_flush(_modules);
/* TODO delete the list */
eina_mempool_shutdown();
eina_shutdown();
}
int

View File

@ -23,10 +23,7 @@
#include <stdio.h>
#include "eina_suite.h"
#include "eina_array.h"
#include "eina_inlist.h"
#include "eina_list.h"
#include "eina_private.h"
#include "Eina.h"
static Eina_Bool
eina_accessor_check(__UNUSED__ const Eina_Array *array,
@ -45,7 +42,7 @@ START_TEST(eina_accessor_array_simple)
int *tmp;
int i;
eina_array_init();
eina_init();
ea = eina_array_new(11);
fail_if(!ea);
@ -76,7 +73,7 @@ START_TEST(eina_accessor_array_simple)
eina_array_free(ea);
eina_array_shutdown();
eina_shutdown();
}
END_TEST
@ -187,7 +184,7 @@ START_TEST(eina_accessor_list_simple)
int *j;
int i = 0;
eina_list_init();
eina_init();
list = eina_list_append(list, &data[0]);
fail_if(list == NULL);

View File

@ -23,8 +23,7 @@
#include <stdio.h>
#include "eina_suite.h"
#include "eina_array.h"
#include "eina_convert.h"
#include "Eina.h"
START_TEST(eina_array_simple)
{
@ -33,7 +32,7 @@ START_TEST(eina_array_simple)
Eina_Array_Iterator it;
unsigned int i;
eina_array_init();
eina_init();
ea = eina_array_new(11);
fail_if(!ea);
@ -66,7 +65,7 @@ START_TEST(eina_array_simple)
eina_array_flush(ea);
eina_array_free(ea);
eina_array_shutdown();
eina_shutdown();
}
END_TEST
@ -77,7 +76,7 @@ START_TEST(eina_array_static)
Eina_Array_Iterator it;
unsigned int i;
eina_array_init();
eina_init();
eina_array_step_set(&sea, 10);
@ -104,7 +103,7 @@ START_TEST(eina_array_static)
eina_array_clean(&sea);
eina_array_flush(&sea);
eina_array_shutdown();
eina_shutdown();
}
END_TEST
@ -127,7 +126,7 @@ START_TEST(eina_array_remove_stuff)
Eina_Array_Iterator it;
unsigned int i;
eina_array_init();
eina_init();
ea = eina_array_new(64);
fail_if(!ea);
@ -177,7 +176,7 @@ START_TEST(eina_array_remove_stuff)
eina_array_free(ea);
eina_array_shutdown();
eina_shutdown();
}
END_TEST

View File

@ -25,8 +25,8 @@
#include <math.h>
#include <float.h>
#include "eina_convert.h"
#include "eina_suite.h"
#include "Eina.h"
START_TEST(eina_convert_simple)
{
@ -83,7 +83,7 @@ START_TEST(eina_convert_double)
long long int m = 0;
long e = 0;
eina_convert_init();
eina_init();
_eina_convert_check(EET_TEST_DOUBLE0, 20);
_eina_convert_check(-EET_TEST_DOUBLE0, 21);
@ -96,7 +96,7 @@ START_TEST(eina_convert_double)
fail_if(eina_convert_atod("0xjo", 8, &m, &e) != EINA_FALSE);
fail_if(eina_convert_atod("0xp", 8, &m, &e) != EINA_FALSE);
eina_convert_shutdown();
eina_shutdown();
}
END_TEST

View File

@ -23,21 +23,8 @@
#include <stdio.h>
#include <stdlib.h>
#include "eina_counter.h"
#include "eina_suite.h"
START_TEST(eina_counter_init_shutdown)
{
eina_counter_init();
eina_counter_init();
eina_counter_shutdown();
eina_counter_init();
eina_counter_init();
eina_counter_shutdown();
eina_counter_shutdown();
eina_counter_shutdown();
}
END_TEST
#include "Eina.h"
START_TEST(eina_counter_simple)
{
@ -45,7 +32,7 @@ START_TEST(eina_counter_simple)
char *dump;
int i;
eina_counter_init();
eina_init();
cnt = eina_counter_new("eina_test");
fail_if(!cnt);
@ -73,7 +60,7 @@ START_TEST(eina_counter_simple)
eina_counter_free(cnt);
eina_counter_shutdown();
eina_shutdown();
}
END_TEST
@ -82,7 +69,7 @@ START_TEST(eina_counter_break)
Eina_Counter *cnt;
char *dump;
eina_counter_init();
eina_init();
cnt = eina_counter_new("eina_test");
fail_if(!cnt);
@ -96,13 +83,12 @@ START_TEST(eina_counter_break)
free(dump);
eina_counter_shutdown();
eina_shutdown();
}
END_TEST
void eina_test_counter(TCase *tc)
{
tcase_add_test(tc, eina_counter_init_shutdown);
tcase_add_test(tc, eina_counter_simple);
tcase_add_test(tc, eina_counter_break);
}

View File

@ -25,20 +25,7 @@
#include <string.h>
#include "eina_suite.h"
#include "eina_error.h"
START_TEST(eina_error_init_shutdown)
{
eina_error_init();
eina_error_init();
eina_error_shutdown();
eina_error_init();
eina_error_init();
eina_error_shutdown();
eina_error_shutdown();
eina_error_shutdown();
}
END_TEST
#include "Eina.h"
#define TEST_TEXT "The big test\n"
@ -48,7 +35,7 @@ START_TEST(eina_error_errno)
setenv("EINA_ERROR_LEVEL", "1", 0);
eina_error_init();
eina_init();
test = eina_error_msg_register(TEST_TEXT);
fail_if(!eina_error_msg_get(test));
@ -57,13 +44,12 @@ START_TEST(eina_error_errno)
eina_error_set(test);
fail_if(eina_error_get() != test);
eina_error_shutdown();
eina_shutdown();
}
END_TEST
void
eina_test_error(TCase *tc)
{
tcase_add_test(tc, eina_error_init_shutdown);
tcase_add_test(tc, eina_error_errno);
}

View File

@ -24,13 +24,13 @@
#include <string.h>
#include "eina_suite.h"
#include "eina_file.h"
#include "Eina.h"
START_TEST(eina_file_split_simple)
{
Eina_Array *ea;
eina_array_init();
eina_init();
ea = eina_file_split(NULL);
fail_if(ea);
@ -60,7 +60,7 @@ START_TEST(eina_file_split_simple)
eina_array_free(ea);
eina_array_shutdown();
eina_shutdown();
}
END_TEST

View File

@ -24,22 +24,8 @@
#include <stdio.h>
#include <string.h>
#include "eina_hash.h"
#include "eina_convert.h"
#include "eina_suite.h"
START_TEST(eina_hash_init_shutdown)
{
eina_hash_init();
eina_hash_init();
eina_hash_shutdown();
eina_hash_init();
eina_hash_init();
eina_hash_shutdown();
eina_hash_shutdown();
eina_hash_shutdown();
}
END_TEST
#include "Eina.h"
static Eina_Bool
eina_foreach_check(__UNUSED__ const Eina_Hash *hash, const void *key, void *data, __UNUSED__ void *fdata)
@ -62,7 +48,7 @@ START_TEST(eina_hash_simple)
int array[] = { 1, 42, 4, 5, 6 };
/* As mempool is already initialized and it use hash, we should have 2 init. */
fail_if(eina_hash_init() != 2);
fail_if(eina_init() != 2);
hash = eina_hash_string_superfast_new(NULL);
fail_if(hash == NULL);
@ -108,8 +94,8 @@ START_TEST(eina_hash_simple)
eina_hash_free(hash);
/* Same comment as eina_hash_init */
fail_if(eina_hash_shutdown() != 1);
/* Same comment as eina_init */
fail_if(eina_shutdown() != 1);
}
END_TEST
@ -118,7 +104,7 @@ START_TEST(eina_hash_extended)
Eina_Hash *hash = NULL;
int i;
fail_if(eina_hash_init() != 2);
fail_if(eina_init() != 2);
hash = eina_hash_string_djb2_new(NULL);
fail_if(hash == NULL);
@ -137,7 +123,7 @@ START_TEST(eina_hash_extended)
eina_hash_free(hash);
fail_if(eina_hash_shutdown() != 1);
fail_if(eina_shutdown() != 1);
}
END_TEST
@ -147,7 +133,7 @@ START_TEST(eina_hash_double_item)
int i[] = { 7, 7 };
int *test;
fail_if(eina_hash_init() != 2);
fail_if(eina_init() != 2);
hash = eina_hash_string_superfast_new(NULL);
fail_if(hash == NULL);
@ -161,13 +147,12 @@ START_TEST(eina_hash_double_item)
eina_hash_free(hash);
fail_if(eina_hash_shutdown() != 1);
fail_if(eina_shutdown() != 1);
}
END_TEST
void eina_test_hash(TCase *tc)
{
tcase_add_test(tc, eina_hash_init_shutdown);
tcase_add_test(tc, eina_hash_simple);
tcase_add_test(tc, eina_hash_extended);
tcase_add_test(tc, eina_hash_double_item);

View File

@ -23,7 +23,7 @@
#include <stdlib.h>
#include "eina_suite.h"
#include "eina_inlist.h"
#include "Eina.h"
typedef struct _Eina_Test_Inlist Eina_Test_Inlist;
struct _Eina_Test_Inlist

View File

@ -23,12 +23,7 @@
#include <stdio.h>
#include "eina_suite.h"
#include "eina_array.h"
#include "eina_hash.h"
#include "eina_inlist.h"
#include "eina_list.h"
#include "eina_rbtree.h"
#include "eina_private.h"
#include "Eina.h"
static Eina_Bool
eina_iterator_array_check(__UNUSED__ const Eina_Array *array,
@ -47,7 +42,7 @@ START_TEST(eina_iterator_array_simple)
int *tmp;
int i;
eina_array_init();
eina_init();
ea = eina_array_new(11);
fail_if(!ea);
@ -75,7 +70,7 @@ START_TEST(eina_iterator_array_simple)
eina_array_free(ea);
eina_array_shutdown();
eina_shutdown();
}
END_TEST
@ -110,7 +105,7 @@ START_TEST(eina_iterator_hash_simple)
Eina_Hash *hash;
int array[] = { 1, 42, 7, 8, 6 };
eina_hash_init();
eina_init();
hash = eina_hash_string_superfast_new(NULL);
fail_if(hash == NULL);
@ -135,7 +130,7 @@ START_TEST(eina_iterator_hash_simple)
eina_hash_free(hash);
eina_hash_shutdown();
eina_shutdown();
}
END_TEST
@ -240,7 +235,7 @@ START_TEST(eina_iterator_list_simple)
int data[] = { 6, 9, 42, 1, 7, 1337, 81, 1664 };
int i = 0;
eina_list_init();
eina_init();
list = eina_list_append(list, &data[0]);
fail_if(list == NULL);

View File

@ -24,7 +24,7 @@
#include <stdio.h>
#include "eina_suite.h"
#include "eina_lalloc.h"
#include "Eina.h"
typedef struct _Eina_Lazy_Allocator_Test Eina_Lazy_Allocator_Test;
struct _Eina_Lazy_Allocator_Test

View File

@ -22,8 +22,8 @@
#include <stdio.h>
#include "eina_list.h"
#include "eina_suite.h"
#include "Eina.h"
static Eina_Bool eina_list_sorted_check(const Eina_List *list)
{
@ -65,7 +65,7 @@ START_TEST(eina_test_simple)
int result[] = { 81, 9, 9, 7, 1 };
int i;
eina_list_init();
eina_init();
list = eina_list_append(list, &data[0]);
fail_if(list == NULL);
@ -205,7 +205,7 @@ START_TEST(eina_test_simple)
list = eina_list_free(list);
fail_if(list != NULL);
eina_list_shutdown();
eina_shutdown();
}
END_TEST
@ -219,7 +219,7 @@ START_TEST(eina_test_merge)
int data[] = { 6, 9, 42, 1, 7, 9, 81, 1664, 1337, 3, 21, 10, 0, 5, 2008 };
int i;
eina_list_init();
eina_init();
l1 = eina_list_append(NULL, &data[0]);
l1 = eina_list_append(l1, &data[1]);
@ -290,7 +290,7 @@ START_TEST(eina_test_merge)
fail_if(!eina_list_sorted_check(l1));
eina_list_shutdown();
eina_shutdown();
}
END_TEST
@ -302,7 +302,7 @@ START_TEST(eina_test_sorted_insert)
Eina_List *l1, *l2, *itr;
void *d;
eina_list_init();
eina_init();
count = sizeof(data)/sizeof(data[0]);
@ -339,7 +339,7 @@ START_TEST(eina_test_sorted_insert)
fail_if(!eina_list_sorted_check(l1));
eina_list_free(l1);
eina_list_shutdown();
eina_shutdown();
}
END_TEST

View File

@ -25,27 +25,11 @@
#include <string.h>
#include "eina_suite.h"
#include "eina_log.h"
START_TEST(eina_log_init_shutdown)
{
int initial_level = eina_log_init() - 1;
fail_if(!(initial_level+1));
fail_if(!eina_log_init());
fail_if(!eina_log_shutdown());
fail_if(!eina_log_init());
fail_if(!eina_log_init());
fail_if(!eina_log_shutdown());
fail_if(!eina_log_shutdown());
fail_if(initial_level != eina_log_shutdown());
}
END_TEST
#include "Eina.h"
START_TEST(eina_log_macro)
{
fail_if(!eina_log_init());
fail_if(!eina_init());
eina_log_level_set(EINA_LOG_LEVEL_DBG);
eina_log_print_cb_set(eina_log_print_cb_file, stderr);
@ -56,13 +40,13 @@ START_TEST(eina_log_macro)
EINA_LOG_WARN("A warning\n");
EINA_LOG_DBG("A debug\n");
eina_log_shutdown();
eina_shutdown();
}
END_TEST
START_TEST(eina_log_domains_macros)
{
fail_if(!eina_log_init());
fail_if(!eina_init());
int d = eina_log_domain_register("MyDomain", EINA_COLOR_GREEN);
fail_if(d < 0);
@ -73,13 +57,13 @@ START_TEST(eina_log_domains_macros)
EINA_LOG_DOM_DBG(d, "A debug\n");
EINA_LOG_DOM_INFO(d, "An info\n");
eina_log_shutdown();
eina_shutdown();
}
END_TEST
START_TEST(eina_log_domains_registry)
{
fail_if(!eina_log_init());
fail_if(!eina_init());
int i;
int d[50];
@ -93,13 +77,13 @@ START_TEST(eina_log_domains_registry)
for (i = 0; i < 50; i++)
eina_log_domain_unregister(d[i]);
eina_log_shutdown();
eina_shutdown();
}
END_TEST
START_TEST(eina_log_domains_slot_reuse)
{
fail_if(!eina_log_init());
fail_if(!eina_init());
// Create 9 domains
int idx[9];
@ -128,13 +112,13 @@ START_TEST(eina_log_domains_slot_reuse)
// Check for slot reuse
fail_if(new != removed);
eina_log_shutdown();
eina_shutdown();
}
END_TEST
START_TEST(eina_log_level_indexes)
{
fail_if(!eina_log_init());
fail_if(!eina_init());
int d = eina_log_domain_register("Levels", EINA_COLOR_GREEN);
fail_if(d < 0);
@ -145,7 +129,7 @@ START_TEST(eina_log_level_indexes)
// Displayed only if user sets level 6 or higher
EINA_LOG(d, 6, "Higher level debug\n");
eina_log_shutdown();
eina_shutdown();
}
END_TEST
@ -153,7 +137,6 @@ END_TEST
void
eina_test_log(TCase *tc)
{
tcase_add_test(tc, eina_log_init_shutdown);
tcase_add_test(tc, eina_log_macro);
tcase_add_test(tc, eina_log_domains_macros);
tcase_add_test(tc, eina_log_domains_registry);

View File

@ -26,20 +26,7 @@
#define EINA_MAGIC_DEBUG
#include "eina_suite.h"
#include "eina_magic.h"
START_TEST(eina_magic_string_init_shutdown)
{
eina_magic_string_init();
eina_magic_string_init();
eina_magic_string_shutdown();
eina_magic_string_init();
eina_magic_string_init();
eina_magic_string_shutdown();
eina_magic_string_shutdown();
eina_magic_string_shutdown();
}
END_TEST
#include "Eina.h"
#define EINA_MAGIC_TEST 0x7781fee7
#define EINA_MAGIC_TEST2 0x42241664
@ -55,7 +42,7 @@ START_TEST(eina_magic_simple)
{
Eina_Magic_Struct *ems = NULL;
eina_magic_string_init();
eina_init();
eina_magic_string_set(EINA_MAGIC_TEST, EINA_MAGIC_STRING);
eina_magic_string_set(EINA_MAGIC_TEST2, NULL);
@ -82,13 +69,12 @@ START_TEST(eina_magic_simple)
EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST);
#endif
eina_magic_string_shutdown();
eina_shutdown();
}
END_TEST
void eina_test_magic(TCase *tc)
{
tcase_add_test(tc, eina_magic_string_init_shutdown);
tcase_add_test(tc, eina_magic_simple);
}

View File

@ -22,13 +22,13 @@
#include <stdio.h>
#include "Eina.h"
#include "eina_suite.h"
#include "Eina.h"
START_TEST(eina_simple)
{
fail_if(eina_init() != 1);
fail_if(eina_shutdown() != 0);
fail_if(eina_init() != 2); /* one init by test suite */
fail_if(eina_shutdown() != 1);
}
END_TEST

View File

@ -4,8 +4,8 @@
#include <stdio.h>
#include "eina_matrixsparse.h"
#include "eina_suite.h"
#include "Eina.h"
#define MAX_ROWS 10
#define MAX_COLS 10
@ -98,7 +98,7 @@ START_TEST(eina_test_simple)
value3 = -3;
value4 = -4;
eina_matrixsparse_init();
eina_init();
matrix = eina_matrixsparse_new(MAX_ROWS, MAX_COLS,
eina_matrixsparse_free_cell_cb, data);
@ -255,7 +255,7 @@ START_TEST(eina_test_simple)
matrixsparse_check(matrix, data, MAX_ROWS, MAX_COLS);
eina_matrixsparse_free(matrix);
eina_matrixsparse_shutdown();
eina_shutdown();
}
END_TEST
@ -274,7 +274,7 @@ START_TEST(eina_test_resize)
for (j = 0; j < MAX_COLS; j++)
data[i][j] = 0;
eina_matrixsparse_init();
eina_init();
matrix = eina_matrixsparse_new(MAX_ROWS, MAX_COLS,
eina_matrixsparse_free_cell_cb, data);
@ -369,7 +369,7 @@ START_TEST(eina_test_resize)
eina_matrixsparse_free(matrix);
eina_matrixsparse_shutdown();
eina_shutdown();
}
END_TEST
@ -396,7 +396,7 @@ START_TEST(eina_test_iterators)
printf("\n");
}
eina_matrixsparse_init();
eina_init();
matrix = eina_matrixsparse_new(MAX_ROWS, MAX_COLS,
eina_matrixsparse_free_cell_cb, data);
@ -468,7 +468,7 @@ START_TEST(eina_test_iterators)
eina_matrixsparse_free(matrix);
eina_matrixsparse_shutdown();
eina_shutdown();
}
END_TEST

View File

@ -21,14 +21,14 @@
#endif
#include "eina_suite.h"
#include "eina_mempool.h"
#include "Eina.h"
static Eina_Array *_modules;
static void
_mempool_init(void)
{
eina_mempool_init();
eina_init();
/* force modules to be loaded in case they are not installed */
_modules = eina_module_list_get(NULL, PACKAGE_BUILD_DIR"/src/modules", 1, NULL, NULL);
eina_module_list_load(_modules);
@ -39,7 +39,7 @@ _mempool_shutdown(void)
{
eina_module_list_flush(_modules);
/* TODO delete the list */
eina_mempool_shutdown();
eina_shutdown();
}
static void
@ -77,19 +77,6 @@ _eina_mempool_test(Eina_Mempool *mp, Eina_Bool with_realloc, Eina_Bool with_gc)
eina_mempool_del(mp);
}
START_TEST(eina_mempool_init_shutdown)
{
Eina_Mempool *mp;
_mempool_init();
mp = eina_mempool_add("test", "test", NULL);
fail_if(mp != NULL);
_mempool_shutdown();
}
END_TEST
START_TEST(eina_mempool_chained_mempool)
{
Eina_Mempool *mp;
@ -160,7 +147,6 @@ END_TEST
void
eina_test_mempool(TCase *tc)
{
tcase_add_test(tc, eina_mempool_init_shutdown);
tcase_add_test(tc, eina_mempool_chained_mempool);
tcase_add_test(tc, eina_mempool_pass_through);
tcase_add_test(tc, eina_mempool_fixed_bitmap);

View File

@ -23,24 +23,7 @@
#include <stdio.h>
#include "eina_suite.h"
#include "eina_module.h"
START_TEST(eina_module_init_shutdown)
{
eina_module_init();
eina_module_shutdown();
eina_module_init();
eina_module_init();
eina_module_init();
eina_module_shutdown();
eina_module_init();
eina_module_init();
eina_module_shutdown();
eina_module_shutdown();
eina_module_shutdown();
eina_module_shutdown();
}
END_TEST
#include "Eina.h"
static Eina_Bool list_cb(Eina_Module *m, void *data)
{
@ -65,20 +48,19 @@ START_TEST(eina_module_load_unload)
{
Eina_Array *_modules;
eina_module_init();
eina_init();
_modules = eina_module_list_get(NULL, PACKAGE_BUILD_DIR"/src/tests/", 1, &list_cb, NULL);
fail_if(!_modules);
eina_module_list_load(_modules);
eina_module_list_unload(_modules);
eina_module_list_flush(_modules);
/* TODO delete the list */
eina_module_shutdown();
eina_shutdown();
}
END_TEST
void
eina_test_module(TCase *tc)
{
tcase_add_test(tc, eina_module_init_shutdown);
tcase_add_test(tc, eina_module_load_unload);
}

View File

@ -24,9 +24,8 @@
#include <stdio.h>
#include <time.h>
#include "eina_array.h"
#include "eina_suite.h"
#include "eina_rbtree.h"
#include "Eina.h"
static inline Eina_Bool
_eina_rbtree_is_red(Eina_Rbtree *tree)
@ -160,7 +159,7 @@ START_TEST(eina_rbtree_remove)
Eina_Array_Iterator it;
unsigned int i;
eina_array_init();
eina_init();
ea = eina_array_new(11);
fail_if(!ea);
@ -184,7 +183,7 @@ START_TEST(eina_rbtree_remove)
fail_if(root != NULL);
eina_array_shutdown();
eina_shutdown();
}
END_TEST

View File

@ -22,8 +22,8 @@
#include <stdio.h>
#include "eina_rectangle.h"
#include "eina_suite.h"
#include "Eina.h"
START_TEST(eina_rectangle_pool)
{
@ -34,7 +34,7 @@ START_TEST(eina_rectangle_pool)
int w;
int h;
fail_if(!eina_rectangle_init());
fail_if(!eina_init());
pool = eina_rectangle_pool_new(256, 256);
fail_if(pool == NULL);
@ -68,7 +68,7 @@ START_TEST(eina_rectangle_pool)
eina_rectangle_pool_free(pool);
eina_rectangle_shutdown();
eina_shutdown();
}
END_TEST

View File

@ -26,22 +26,7 @@
#include <time.h>
#include "eina_suite.h"
#include "eina_stringshare.h"
#include "eina_array.h"
#include "eina_convert.h"
START_TEST(eina_stringshare_init_shutdown)
{
eina_stringshare_init();
eina_stringshare_init();
eina_stringshare_shutdown();
eina_stringshare_init();
eina_stringshare_init();
eina_stringshare_shutdown();
eina_stringshare_shutdown();
eina_stringshare_shutdown();
}
END_TEST
#include "Eina.h"
#define TEST0 "test/0"
#define TEST1 "test/1"
@ -51,7 +36,7 @@ START_TEST(eina_stringshare_simple)
const char *t0;
const char *t1;
eina_stringshare_init();
eina_init();
t0 = eina_stringshare_add(TEST0);
t1 = eina_stringshare_add(TEST1);
@ -64,7 +49,7 @@ START_TEST(eina_stringshare_simple)
eina_stringshare_del(t0);
eina_stringshare_del(t1);
eina_stringshare_shutdown();
eina_shutdown();
}
END_TEST
@ -73,7 +58,7 @@ START_TEST(eina_stringshare_small)
char buf[4];
int i;
eina_stringshare_init();
eina_init();
for (i = 0; i < 3; i++)
{
@ -99,7 +84,7 @@ START_TEST(eina_stringshare_small)
eina_stringshare_del(t1);
}
eina_stringshare_shutdown();
eina_shutdown();
}
END_TEST
@ -109,7 +94,7 @@ START_TEST(eina_stringshare_test_share)
const char *t0;
const char *t1;
eina_stringshare_init();
eina_init();
t0 = eina_stringshare_add(TEST0);
t1 = eina_stringshare_add(TEST0);
@ -123,7 +108,7 @@ START_TEST(eina_stringshare_test_share)
eina_stringshare_del(t0);
eina_stringshare_del(t1);
eina_stringshare_shutdown();
eina_shutdown();
}
END_TEST
@ -132,7 +117,7 @@ START_TEST(eina_stringshare_putstuff)
const char *tmp;
int i;
eina_stringshare_init();
eina_init();
for (i = 10000; i > 0; --i)
{
@ -143,7 +128,7 @@ START_TEST(eina_stringshare_putstuff)
fail_if(tmp != eina_stringshare_add(build));
}
eina_stringshare_shutdown();
eina_shutdown();
}
END_TEST
@ -155,7 +140,7 @@ START_TEST(eina_stringshare_collision)
srand(time(NULL));
eina_stringshare_init();
eina_init();
ea = eina_array_new(256);
fail_if(!ea);
@ -180,7 +165,7 @@ START_TEST(eina_stringshare_collision)
for (i = 0; i < 1000; ++i)
eina_stringshare_del(eina_array_pop(ea));
eina_stringshare_shutdown();
eina_shutdown();
eina_array_free(ea);
}
@ -189,7 +174,6 @@ END_TEST
void
eina_test_stringshare(TCase *tc)
{
tcase_add_test(tc, eina_stringshare_init_shutdown);
tcase_add_test(tc, eina_stringshare_simple);
tcase_add_test(tc, eina_stringshare_small);
tcase_add_test(tc, eina_stringshare_test_share);