1 #include "evas_common.h"
2 #include "evas_private.h"
4 int _evas_alloc_error = 0;
5 static int _evas_debug_init = 0;
6 static int _evas_debug_show = 0;
7 static int _evas_debug_abort = 0;
10 * Return if any allocation errors have occured during the prior function
11 * @return The allocation error flag
13 * This function will return if any memory allocation errors occured during,
14 * and what kind they were. The return value will be one of
15 * EVAS_ALLOC_ERROR_NONE, EVAS_ALLOC_ERROR_FATAL or EVAS_ALLOC_ERROR_RECOVERED
16 * with each meaning something different.
18 * EVAS_ALLOC_ERROR_NONE means that no errors occured at all and the function
21 * EVAS_ALLOC_ERROR_FATAL means the function was completely unable to perform
22 * its job and will have exited as cleanly as possible. The programmer
23 * should consider this as a sign of very low memory and should try and safely
24 * recover from the prior functions failure (or try free up memory elsewhere
25 * and try again after more memory is freed).
27 * EVAS_ALLOC_ERROR_RECOVERED means that an allocation error occured, but was
28 * recovered from by evas finding memory of its own it has allocated and
29 * freeing what it sees as not really usefully allocated memory. What is freed
30 * may vary. Evas may reduce the resolution of images, free cached images or
31 * fonts, trhow out pre-rendered data, reduce the complexity of change lists
32 * etc. Evas and the program will function as per normal after this, but this
33 * is a sign of low memory, and it is suggested that the program try and
34 * identify memory it doesn't need, and free it.
38 * extern Evas_Object *object;
39 * void callback (void *data, Evas *e, Evas_Object *obj, void *event_info);
41 * evas_object_event_callback_add(object, EVAS_CALLBACK_MOUSE_DOWN, callback, NULL);
42 * if (evas_alloc_error() == EVAS_ALLOC_ERROR_FATAL)
44 * fprintf(stderr, "ERROR: Completely unable to attach callabck. Must\n");
45 * fprintf(stderr, " destroy object now as it cannot be used.\n");
46 * evas_object_del(object);
48 * fprintf(stderr, "WARNING: Memory is really low. Cleaning out RAM.\n");
49 * my_memory_cleanup();
51 * if (evas_alloc_error() == EVAS_ALLOC_ERROR_RECOVERED)
53 * fprintf(stderr, "WARNING: Memory is really low. Cleaning out RAM.\n");
54 * my_memory_cleanup();
59 evas_alloc_error(void)
61 return _evas_alloc_error;
64 /* free cached items only in ram for speed reasons. return 0 if cant free */
66 evas_mem_free(int mem_required)
71 /* start reducing quality of images etc. return 0 if cant free anything */
73 evas_mem_degrade(int mem_required)
79 evas_mem_calloc(int size)
83 ptr = calloc(1, size);
86 while ((!ptr) && (evas_mem_free(size))) ptr = calloc(1, size);
88 while ((!ptr) && (evas_mem_degrade(size))) ptr = calloc(1, size);
95 evas_debug_error(void)
97 if (!_evas_debug_init)
99 if (getenv("EVAS_DEBUG_SHOW")) _evas_debug_show = 1;
100 if (getenv("EVAS_DEBUG_ABORT")) _evas_debug_abort = 1;
101 _evas_debug_init = 1;
103 if (_evas_debug_show)
105 "*** EVAS ERROR: Evas Magic Check Failed!!!\n");
109 evas_debug_input_null(void)
111 if (!_evas_debug_init)
113 if (getenv("EVAS_DEBUG_SHOW")) _evas_debug_show = 1;
114 if (getenv("EVAS_DEBUG_ABORT")) _evas_debug_abort = 1;
115 _evas_debug_init = 1;
117 if (_evas_debug_show)
119 " Input object pointer is NULL!\n");
120 if (_evas_debug_abort) abort();
124 evas_debug_magic_null(void)
126 if (!_evas_debug_init)
128 if (getenv("EVAS_DEBUG_SHOW")) _evas_debug_show = 1;
129 if (getenv("EVAS_DEBUG_ABORT")) _evas_debug_abort = 1;
130 _evas_debug_init = 1;
132 if (_evas_debug_show)
134 " Input object is zero'ed out (maybe a freed object or zero-filled RAM)!\n");
135 if (_evas_debug_abort) abort();
139 evas_debug_magic_wrong(DATA32 expected, DATA32 supplied)
141 if (!_evas_debug_init)
143 if (getenv("EVAS_DEBUG_SHOW")) _evas_debug_show = 1;
144 if (getenv("EVAS_DEBUG_ABORT")) _evas_debug_abort = 1;
145 _evas_debug_init = 1;
147 if (_evas_debug_show)
149 " Input object is wrong type\n"
150 " Expected: %08x - %s\n"
151 " Supplied: %08x - %s\n",
152 expected, evas_debug_magic_string_get(expected),
153 supplied, evas_debug_magic_string_get(supplied));
154 if (_evas_debug_abort) abort();
158 evas_debug_generic(const char *str)
160 if (!_evas_debug_init)
162 if (getenv("EVAS_DEBUG_SHOW")) _evas_debug_show = 1;
163 if (getenv("EVAS_DEBUG_ABORT")) _evas_debug_abort = 1;
164 _evas_debug_init = 1;
166 if (_evas_debug_show)
170 if (_evas_debug_abort) abort();
174 evas_debug_magic_string_get(DATA32 magic)
182 return "Evas_Object";
184 case MAGIC_OBJ_RECTANGLE:
185 return "Evas_Object (Rectangle)";
188 return "Evas_Object (Line)";
190 case MAGIC_OBJ_GRADIENT:
191 return "Evas_Object (Gradient)";
193 case MAGIC_OBJ_POLYGON:
194 return "Evas_Object (Polygon)";
196 case MAGIC_OBJ_IMAGE:
197 return "Evas_Object (Image)";
200 return "Evas_Object (Text)";
202 case MAGIC_OBJ_SMART:
203 return "Evas_Object (Smart)";