summaryrefslogtreecommitdiff
path: root/legacy/evas/src/lib/main.c
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2002-11-24 04:06:08 +0000
committerCarsten Haitzler <raster@rasterman.com>2002-11-24 04:06:08 +0000
commit35105b70d8538224791339d94d599fcdc85ae1c4 (patch)
tree5b2b93f839221e5f253906d0f4ba3f16e95cd059 /legacy/evas/src/lib/main.c
parentff53f700237baa9f0e57da08000605c16094d0b9 (diff)
docs... and memory error stuff... auditing memory allocs and making ti very
robust if allocs fail SVN revision: 6458
Diffstat (limited to '')
-rw-r--r--legacy/evas/src/lib/main.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/legacy/evas/src/lib/main.c b/legacy/evas/src/lib/main.c
index 823acfd88a..70caf5f724 100644
--- a/legacy/evas/src/lib/main.c
+++ b/legacy/evas/src/lib/main.c
@@ -2,6 +2,93 @@
2#include "evas_private.h" 2#include "evas_private.h"
3#include "Evas.h" 3#include "Evas.h"
4 4
5int _evas_alloc_error = 0;
6
7/**
8 * Return if any allocation errors have occured during the prior function
9 * @return The allocation error flag
10 *
11 * This function will return if any memory allocation errors occured during,
12 * and what kind they were. The return value will be one of
13 * EVAS_ALLOC_ERROR_NONE, EVAS_ALLOC_ERROR_FATAL or EVAS_ALLOC_ERROR_RECOVERED
14 * with each meaning something different.
15 *
16 * EVAS_ALLOC_ERROR_NONE means that no errors occured at all and the function
17 * worked as expected.
18 *
19 * EVAS_ALLOC_ERROR_FATAL means the function was completely unable to perform
20 * its job and will have exited as cleanly as possible. The programmer
21 * should consider this as a sign of very low memory and should try and safely
22 * recover from the prior functions failure (or try free up memory elsewhere
23 * and try again after more memory is freed).
24 *
25 * EVAS_ALLOC_ERROR_RECOVERED means that an allocation error occured, but was
26 * recovered from by evas finding memory of its own it has allocated and
27 * freeing what it sees as not really usefully allocated memory. What is freed
28 * may vary. Evas may reduce the resolution of images, free cached images or
29 * fonts, trhow out pre-rendered data, reduce the complexity of change lists
30 * etc. Evas and the program will function as per normal after this, but this
31 * is a sign of low memory, and it is suggested that the program try and
32 * identify memory it doesn't need, and free it.
33 *
34 * Example:
35 * @code
36 * extern Evas_Object *object;
37 * void callback (void *data, Evas *e, Evas_Object *obj, void *event_info);
38 *
39 * evas_object_event_callback_add(object, EVAS_CALLBACK_MOUSE_DOWN, callback, NULL);
40 * if (evas_alloc_error() == EVAS_ALLOC_ERROR_FATAL)
41 * {
42 * fprintf(stderr, "ERROR: Completely unable to attach callabck. Must\n");
43 * fprintf(stderr, " destroy object now as it cannot be used.\n");
44 * evas_object_del(object);
45 * object = NULL;
46 * fprintf(stderr, "WARNING: Memory is really low. Cleaning out RAM.\n");
47 * my_memory_cleanup();
48 * }
49 * if (evas_alloc_error() == EVAS_ALLOC_ERROR_RECOVERED)
50 * {
51 * fprintf(stderr, "WARNING: Memory is really low. Cleaning out RAM.\n");
52 * my_memory_cleanup();
53 * }
54 * @endcode
55 */
56int
57evas_alloc_error(void)
58{
59 return _evas_alloc_error;
60}
61
62/* free cached items only in ram for speed reasons. return 0 if cant free */
63int
64evas_mem_free(int mem_required)
65{
66 return 0;
67}
68
69/* start reducing quality of images etc. return 0 if cant free anything */
70int
71evas_mem_degrade(int mem_required)
72{
73 return 0;
74}
75
76void *
77evas_mem_calloc(int size)
78{
79 void *ptr;
80
81 ptr = calloc(1, size);
82 if (ptr) return ptr;
83 MERR_BAD();
84 while ((!ptr) && (evas_mem_free(size))) ptr = calloc(1, size);
85 if (ptr) return ptr;
86 while ((!ptr) && (evas_mem_degrade(size))) ptr = calloc(1, size);
87 if (ptr) return ptr;
88 MERR_FATAL();
89 return NULL;
90}
91
5void 92void
6evas_debug_error(void) 93evas_debug_error(void)
7{ 94{
@@ -63,6 +150,9 @@ evas_debug_magic_string_get(DATA32 magic)
63 case MAGIC_OBJ_TEXT: 150 case MAGIC_OBJ_TEXT:
64 return "Evas_Object (Text)"; 151 return "Evas_Object (Text)";
65 break; 152 break;
153 case MAGIC_OBJ_SMART:
154 return "Evas_Object (Smart)";
155 break;
66 default: 156 default:
67 return "<UNKNOWN>"; 157 return "<UNKNOWN>";
68 }; 158 };