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.
25 #include "main/imports.h"
26 #include "main/context.h"
27 #include "slang_log.h"
28 #include "slang_utility.h"
32 static char *out_of_memory
= "Error: Out of memory.\n";
35 slang_info_log_construct(slang_info_log
* log
)
38 log
->dont_free_text
= GL_FALSE
;
39 log
->error_flag
= GL_FALSE
;
43 slang_info_log_destruct(slang_info_log
* log
)
45 if (!log
->dont_free_text
)
47 slang_alloc_free(log
->text
);
49 _mesa_free(log
->text
);
54 slang_info_log_message(slang_info_log
* log
, const char *prefix
,
59 if (log
->dont_free_text
)
61 size
= slang_string_length(msg
) + 2;
63 size
+= slang_string_length(prefix
) + 2;
64 if (log
->text
!= NULL
) {
65 GLuint old_len
= slang_string_length(log
->text
);
68 slang_alloc_realloc(log
->text
, old_len
+ 1, old_len
+ size
);
70 _mesa_realloc(log
->text
, old_len
+ 1, old_len
+ size
);
75 log
->text
= (char *) (slang_alloc_malloc(size
));
77 log
->text
= (char *) (_mesa_malloc(size
));
79 if (log
->text
!= NULL
)
82 if (log
->text
== NULL
)
85 slang_string_concat(log
->text
, prefix
);
86 slang_string_concat(log
->text
, ": ");
88 slang_string_concat(log
->text
, msg
);
89 slang_string_concat(log
->text
, "\n");
91 if (MESA_VERBOSE
& VERBOSE_GLSL
) {
92 _mesa_printf("Mesa: GLSL %s\n", log
->text
);
99 slang_info_log_print(slang_info_log
* log
, const char *msg
, ...)
105 _mesa_vsprintf(buf
, msg
, va
);
107 return slang_info_log_message(log
, NULL
, buf
);
111 slang_info_log_error(slang_info_log
* log
, const char *msg
, ...)
117 _mesa_vsprintf(buf
, msg
, va
);
119 log
->error_flag
= GL_TRUE
;
120 if (slang_info_log_message(log
, "Error", buf
))
122 slang_info_log_memory(log
);
127 slang_info_log_warning(slang_info_log
* log
, const char *msg
, ...)
133 _mesa_vsprintf(buf
, msg
, va
);
135 if (slang_info_log_message(log
, "Warning", buf
))
137 slang_info_log_memory(log
);
142 slang_info_log_memory(slang_info_log
* log
)
144 if (!slang_info_log_message(log
, "Error", "Out of memory.")) {
145 log
->dont_free_text
= GL_TRUE
;
146 log
->error_flag
= GL_TRUE
;
147 log
->text
= out_of_memory
;