2 * Mesa 3-D graphics library
5 * Copyright (C) 2005-2007 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #include "slang_log.h"
27 #include "slang_utility.h"
31 static char *out_of_memory
= "Error: Out of memory.\n";
34 slang_info_log_construct(slang_info_log
* log
)
37 log
->dont_free_text
= GL_FALSE
;
38 log
->error_flag
= GL_FALSE
;
42 slang_info_log_destruct(slang_info_log
* log
)
44 if (!log
->dont_free_text
)
46 slang_alloc_free(log
->text
);
48 _mesa_free(log
->text
);
53 slang_info_log_message(slang_info_log
* log
, const char *prefix
,
58 if (log
->dont_free_text
)
60 size
= slang_string_length(msg
) + 2;
62 size
+= slang_string_length(prefix
) + 2;
63 if (log
->text
!= NULL
) {
64 GLuint old_len
= slang_string_length(log
->text
);
67 slang_alloc_realloc(log
->text
, old_len
+ 1, old_len
+ size
);
69 _mesa_realloc(log
->text
, old_len
+ 1, old_len
+ size
);
74 log
->text
= (char *) (slang_alloc_malloc(size
));
76 log
->text
= (char *) (_mesa_malloc(size
));
78 if (log
->text
!= NULL
)
81 if (log
->text
== NULL
)
84 slang_string_concat(log
->text
, prefix
);
85 slang_string_concat(log
->text
, ": ");
87 slang_string_concat(log
->text
, msg
);
88 slang_string_concat(log
->text
, "\n");
90 _mesa_printf("Mesa GLSL error/warning: %s\n", log
->text
);
96 slang_info_log_print(slang_info_log
* log
, const char *msg
, ...)
102 _mesa_vsprintf(buf
, msg
, va
);
104 return slang_info_log_message(log
, NULL
, buf
);
108 slang_info_log_error(slang_info_log
* log
, const char *msg
, ...)
114 _mesa_vsprintf(buf
, msg
, va
);
116 log
->error_flag
= GL_TRUE
;
117 if (slang_info_log_message(log
, "Error", buf
))
119 slang_info_log_memory(log
);
124 slang_info_log_warning(slang_info_log
* log
, const char *msg
, ...)
130 _mesa_vsprintf(buf
, msg
, va
);
132 if (slang_info_log_message(log
, "Warning", buf
))
134 slang_info_log_memory(log
);
139 slang_info_log_memory(slang_info_log
* log
)
141 if (!slang_info_log_message(log
, "Error", "Out of memory.")) {
142 log
->dont_free_text
= GL_TRUE
;
143 log
->error_flag
= GL_TRUE
;
144 log
->text
= out_of_memory
;