forked from enlightenment/efl
parent
7473953e3e
commit
e04f59c7b0
|
@ -27,6 +27,7 @@ extern "C" {
|
|||
#include "eina_error.h"
|
||||
#include "eina_array.h"
|
||||
#include "eina_stringshare.h"
|
||||
#include "eina_magic.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ eina_rectangle.h \
|
|||
eina_types.h \
|
||||
eina_array.h \
|
||||
eina_inline_array.x \
|
||||
eina_magic.h \
|
||||
eina_stringshare.h
|
||||
|
||||
installed_mainheaderdir = $(prefix)/include/eina-@VMAJ@
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
#ifndef EINA_MAGIC_H_
|
||||
#define EINA_MAGIC_H_
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#define EINA_MAGIC_NONE 0x1234fedc
|
||||
|
||||
#define EINA_MAGIC Eina_Magic __magic;
|
||||
|
||||
#define EINA_MAGIC_SET(d, m) (d)->__magic = (m)
|
||||
#define EINA_MAGIC_CHECK(d, m) ((d) && ((d)->__magic == (m)))
|
||||
#define EINA_MAGIC_FAIL(d, m, fn) _eina_magic_fail((d), (d) ? (d)->__magic : 0, (m), (__FUNCTION__));
|
||||
|
||||
typedef unsigned int Eina_Magic;
|
||||
|
||||
EAPI int eina_magic_string_init();
|
||||
EAPI int eina_magic_string_shutdown();
|
||||
|
||||
EAPI const char* eina_magic_string_get(Eina_Magic magic);
|
||||
EAPI void eina_magic_string_set(Eina_Magic magic, const char *magic_name);
|
||||
EAPI void eina_magic_fail(void *d, Eina_Magic m, Eina_Magic req_m,
|
||||
const char *file, const char *fnc, int line);
|
||||
|
||||
#else
|
||||
|
||||
#define EINA_MAGIC_NONE (void)
|
||||
#define EINA_MAGIC
|
||||
#define EINA_MAGIC_SET(d, m) (void)
|
||||
#define EINA_MAGIC_CHECK(d, m) (1)
|
||||
#define EINA_MAGIC_FAIL(d, m, fn) (void)
|
||||
|
||||
#define eina_magic_string_get(Magic) (NULL)
|
||||
#define eina_magic_string_set(Magic, Magic_Name) (void)
|
||||
#define eina_magic_fail(d, m, req_m, file, fnx, line) (void)
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* EINA_MAGIC_H_ */
|
|
@ -16,6 +16,7 @@ eina_list.c \
|
|||
eina_module.c \
|
||||
eina_value.c \
|
||||
eina_array.c \
|
||||
eina_magic.c \
|
||||
eina_stringshare.c
|
||||
|
||||
libeina_la_LIBADD = -ldl
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
#include "eina_array.h"
|
||||
#include "eina_error.h"
|
||||
|
||||
#include "eina_private.h"
|
||||
|
||||
#ifndef DEBUG
|
||||
#define DEBUG
|
||||
#endif
|
||||
#include "eina_magic.h"
|
||||
|
||||
typedef struct _Eina_Magic_String Eina_Magic_String;
|
||||
struct _Eina_Magic_String
|
||||
{
|
||||
char *string;
|
||||
Eina_Magic magic;
|
||||
};
|
||||
|
||||
static int _eina_magic_string_count = 0;
|
||||
static Eina_Array *strings = NULL;
|
||||
|
||||
EAPI int
|
||||
eina_magic_string_init()
|
||||
{
|
||||
++_eina_magic_string_count;
|
||||
|
||||
if (_eina_magic_string_count == 1)
|
||||
strings = eina_array_new(8);
|
||||
|
||||
return _eina_magic_string_count;
|
||||
}
|
||||
|
||||
EAPI int
|
||||
eina_magic_string_shutdown()
|
||||
{
|
||||
--_eina_magic_string_count;
|
||||
|
||||
if (_eina_magic_string_count == 0)
|
||||
{
|
||||
eina_array_free(strings);
|
||||
strings = NULL;
|
||||
}
|
||||
|
||||
return _eina_magic_string_count;
|
||||
}
|
||||
|
||||
|
||||
EAPI const char*
|
||||
eina_magic_string_get(Eina_Magic magic)
|
||||
{
|
||||
Eina_Magic_String *ems;
|
||||
unsigned int i;
|
||||
|
||||
if (!strings) return NULL;
|
||||
|
||||
EINA_ARRAY_ITER_NEXT(strings, i, ems)
|
||||
if (ems->magic == magic)
|
||||
return ems->string;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
EAPI void
|
||||
eina_magic_string_set(Eina_Magic magic, const char *magic_name)
|
||||
{
|
||||
Eina_Magic_String *ems;
|
||||
unsigned int i;
|
||||
|
||||
if (!strings) return ;
|
||||
|
||||
EINA_ARRAY_ITER_NEXT(strings, i, ems)
|
||||
if (ems->magic == magic)
|
||||
{
|
||||
free(ems->string);
|
||||
if (magic_name)
|
||||
ems->string = strdup(magic_name);
|
||||
else
|
||||
ems->string = NULL;
|
||||
return ;
|
||||
}
|
||||
|
||||
ems = malloc(sizeof (Eina_Magic_String));
|
||||
ems->magic = magic;
|
||||
if (magic_name)
|
||||
ems->string = strdup(magic_name);
|
||||
else
|
||||
ems->string = NULL;
|
||||
|
||||
_eina_array_append(strings, ems);
|
||||
}
|
||||
|
||||
EAPI void
|
||||
eina_magic_fail(void *d, Eina_Magic m, Eina_Magic req_m, const char *file, const char *fnc, int line)
|
||||
{
|
||||
if (!d)
|
||||
eina_error_print(EINA_ERROR_LEVEL_ERR, file, fnc, line,
|
||||
"*** Eina Magic Check Failed !!!\n"
|
||||
" Input handle pointer is NULL !\n"
|
||||
"*** NAUGHTY PROGRAMMER!!!\n"
|
||||
"*** SPANK SPANK SPANK!!!\n"
|
||||
"*** Now go fix your code. Tut tut tut!\n"
|
||||
"\n");
|
||||
else
|
||||
if (m == EINA_MAGIC_NONE)
|
||||
eina_error_print(EINA_ERROR_LEVEL_ERR, file, fnc, line,
|
||||
"*** Eina Magic Check Failed !!!\n"
|
||||
" Input handle has already been freed!\n"
|
||||
"*** NAUGHTY PROGRAMMER!!!\n"
|
||||
"*** SPANK SPANK SPANK!!!\n"
|
||||
"*** Now go fix your code. Tut tut tut!\n"
|
||||
"\n");
|
||||
else
|
||||
if (m != req_m)
|
||||
eina_error_print(EINA_ERROR_LEVEL_ERR, file, fnc, line,
|
||||
"*** Eina Magic Check Failed !!!\n"
|
||||
" Input handle is wrong type\n"
|
||||
" Expected: %08x - %s\n"
|
||||
" Supplied: %08x - %s\n"
|
||||
"*** NAUGHTY PROGRAMMER!!!\n"
|
||||
"*** SPANK SPANK SPANK!!!\n"
|
||||
"*** Now go fix your code. Tut tut tut!\n"
|
||||
"\n",
|
||||
req_m, eina_magic_string_get(req_m),
|
||||
m, eina_magic_string_get(m));
|
||||
else
|
||||
eina_error_print(EINA_ERROR_LEVEL_ERR, file, fnc, line,
|
||||
"*** Eina Magic Check Failed !!!\n"
|
||||
" Why did you call me !\n"
|
||||
"*** NAUGHTY PROGRAMMER!!!\n"
|
||||
"*** SPANK SPANK SPANK!!!\n"
|
||||
"*** Now go fix your code. Tut tut tut!\n"
|
||||
"\n");
|
||||
if (getenv("EINA_ERROR_ABORT")) abort();
|
||||
}
|
||||
|
Loading…
Reference in New Issue