f9998898a878c31ab1f0845fc24e9de5faec9fb3
[framework/uifw/evas.git] / src / lib / main.c
1 #include "evas_common.h"
2 #include "evas_private.h"
3
4 static Evas_Version _version = { VMAJ, VMIN, VMIC, VREV };
5 EAPI Evas_Version *evas_version = &_version;
6
7 int _evas_alloc_error = 0;
8 static int _evas_debug_init = 0;
9 static int _evas_debug_show = 0;
10 static int _evas_debug_abort = 0;
11
12 EAPI Evas_Alloc_Error
13 evas_alloc_error(void)
14 {
15    return _evas_alloc_error;
16 }
17
18 /* free cached items only in ram for speed reasons. return 0 if can't free */
19 int
20 evas_mem_free(int mem_required __UNUSED__)
21 {
22    return 0;
23 }
24
25 /* start reducing quality of images etc. return 0 if can't free anything */
26 int
27 evas_mem_degrade(int mem_required __UNUSED__)
28 {
29    return 0;
30 }
31
32 void *
33 evas_mem_calloc(int size)
34 {
35    void *ptr;
36
37    ptr = calloc(1, size);
38    if (ptr) return ptr;
39    MERR_BAD();
40    while ((!ptr) && (evas_mem_free(size))) ptr = calloc(1, size);
41    if (ptr) return ptr;
42    while ((!ptr) && (evas_mem_degrade(size))) ptr = calloc(1, size);
43    if (ptr) return ptr;
44    MERR_FATAL();
45    return NULL;
46 }
47
48 void
49 evas_debug_error(void)
50 {
51    if (!_evas_debug_init)
52      {
53         if (getenv("EVAS_DEBUG_SHOW")) _evas_debug_show = 1;
54         if (getenv("EVAS_DEBUG_ABORT")) _evas_debug_abort = 1;
55         _evas_debug_init = 1;
56      }
57    if (_evas_debug_show)
58      CRIT("Evas Magic Check Failed!!!");
59 }
60
61 void
62 evas_debug_input_null(void)
63 {
64    if (!_evas_debug_init)
65      {
66         if (getenv("EVAS_DEBUG_SHOW")) _evas_debug_show = 1;
67         if (getenv("EVAS_DEBUG_ABORT")) _evas_debug_abort = 1;
68         _evas_debug_init = 1;
69      }
70    if (_evas_debug_show)
71      CRIT("Input object pointer is NULL!");
72    if (_evas_debug_abort) abort();
73 }
74
75 void
76 evas_debug_magic_null(void)
77 {
78    if (!_evas_debug_init)
79      {
80         if (getenv("EVAS_DEBUG_SHOW")) _evas_debug_show = 1;
81         if (getenv("EVAS_DEBUG_ABORT")) _evas_debug_abort = 1;
82         _evas_debug_init = 1;
83      }
84    if (_evas_debug_show)
85      CRIT("Input object is zero'ed out (maybe a freed object or zero-filled RAM)!");
86    if (_evas_debug_abort) abort();
87 }
88
89 void
90 evas_debug_magic_wrong(DATA32 expected, DATA32 supplied)
91 {
92    if (!_evas_debug_init)
93      {
94         if (getenv("EVAS_DEBUG_SHOW")) _evas_debug_show = 1;
95         if (getenv("EVAS_DEBUG_ABORT")) _evas_debug_abort = 1;
96         _evas_debug_init = 1;
97      }
98    if (_evas_debug_show)
99      CRIT("Input object is wrong type\n"
100           "    Expected: %08x - %s\n"
101           "    Supplied: %08x - %s",
102           expected, evas_debug_magic_string_get(expected),
103           supplied, evas_debug_magic_string_get(supplied));
104    if (_evas_debug_abort) abort();
105 }
106
107 void
108 evas_debug_generic(const char *str)
109 {
110    if (!_evas_debug_init)
111      {
112         if (getenv("EVAS_DEBUG_SHOW")) _evas_debug_show = 1;
113         if (getenv("EVAS_DEBUG_ABORT")) _evas_debug_abort = 1;
114         _evas_debug_init = 1;
115      }
116    if (_evas_debug_show)
117      CRIT("%s", str);
118    if (_evas_debug_abort) abort();
119 }
120
121 const char *
122 evas_debug_magic_string_get(DATA32 magic)
123 {
124    switch (magic)
125      {
126       case MAGIC_EVAS:
127         return "Evas";
128       case MAGIC_OBJ:
129         return "Evas_Object";
130       case MAGIC_OBJ_RECTANGLE:
131         return "Evas_Object (Rectangle)";
132       case MAGIC_OBJ_LINE:
133         return "Evas_Object (Line)";
134       case MAGIC_OBJ_POLYGON:
135         return "Evas_Object (Polygon)";
136       case MAGIC_OBJ_IMAGE:
137         return "Evas_Object (Image)";
138       case MAGIC_OBJ_TEXT:
139         return "Evas_Object (Text)";
140       case MAGIC_OBJ_SMART:
141         return "Evas_Object (Smart)";
142       case MAGIC_EVAS_GL:
143         return "Evas_GL";
144       case MAGIC_MAP:
145         return "Evas_Map";
146       default:
147         return "<UNKNOWN>";
148      };
149    return "<UNKNOWN>";
150 }