diff options
Diffstat (limited to 'mesalib/src/glsl')
-rw-r--r-- | mesalib/src/glsl/glcpp/glcpp-parse.y | 50 | ||||
-rw-r--r-- | mesalib/src/glsl/glcpp/glcpp.h | 2 | ||||
-rw-r--r-- | mesalib/src/glsl/link_uniforms.cpp | 15 | ||||
-rw-r--r-- | mesalib/src/glsl/linker.h | 2 | ||||
-rw-r--r-- | mesalib/src/glsl/ralloc.c | 11 | ||||
-rw-r--r-- | mesalib/src/glsl/ralloc.h | 6 |
6 files changed, 46 insertions, 40 deletions
diff --git a/mesalib/src/glsl/glcpp/glcpp-parse.y b/mesalib/src/glsl/glcpp/glcpp-parse.y index efcc205c2..47ba54ddf 100644 --- a/mesalib/src/glsl/glcpp/glcpp-parse.y +++ b/mesalib/src/glsl/glcpp/glcpp-parse.y @@ -184,11 +184,11 @@ input: line: control_line { - ralloc_strcat (&parser->output, "\n"); + ralloc_asprintf_rewrite_tail (&parser->output, &parser->output_length, "\n"); } | text_line { _glcpp_parser_print_expanded_token_list (parser, $1); - ralloc_strcat (&parser->output, "\n"); + ralloc_asprintf_rewrite_tail (&parser->output, &parser->output_length, "\n"); ralloc_free ($1); } | expanded_line @@ -320,7 +320,7 @@ control_line: if ($2 >= 130 || $2 == 100) add_builtin_define (parser, "GL_FRAGMENT_PRECISION_HIGH", 1); - ralloc_asprintf_append (&parser->output, "#version %" PRIiMAX, $2); + ralloc_asprintf_rewrite_tail (&parser->output, &parser->output_length, "#version %" PRIiMAX, $2); } | HASH NEWLINE ; @@ -903,54 +903,54 @@ _token_list_equal_ignoring_space (token_list_t *a, token_list_t *b) } static void -_token_print (char **out, token_t *token) +_token_print (char **out, size_t *len, token_t *token) { if (token->type < 256) { - ralloc_asprintf_append (out, "%c", token->type); + ralloc_asprintf_rewrite_tail (out, len, "%c", token->type); return; } switch (token->type) { case INTEGER: - ralloc_asprintf_append (out, "%" PRIiMAX, token->value.ival); + ralloc_asprintf_rewrite_tail (out, len, "%" PRIiMAX, token->value.ival); break; case IDENTIFIER: case INTEGER_STRING: case OTHER: - ralloc_strcat (out, token->value.str); + ralloc_asprintf_rewrite_tail (out, len, "%s", token->value.str); break; case SPACE: - ralloc_strcat (out, " "); + ralloc_asprintf_rewrite_tail (out, len, " "); break; case LEFT_SHIFT: - ralloc_strcat (out, "<<"); + ralloc_asprintf_rewrite_tail (out, len, "<<"); break; case RIGHT_SHIFT: - ralloc_strcat (out, ">>"); + ralloc_asprintf_rewrite_tail (out, len, ">>"); break; case LESS_OR_EQUAL: - ralloc_strcat (out, "<="); + ralloc_asprintf_rewrite_tail (out, len, "<="); break; case GREATER_OR_EQUAL: - ralloc_strcat (out, ">="); + ralloc_asprintf_rewrite_tail (out, len, ">="); break; case EQUAL: - ralloc_strcat (out, "=="); + ralloc_asprintf_rewrite_tail (out, len, "=="); break; case NOT_EQUAL: - ralloc_strcat (out, "!="); + ralloc_asprintf_rewrite_tail (out, len, "!="); break; case AND: - ralloc_strcat (out, "&&"); + ralloc_asprintf_rewrite_tail (out, len, "&&"); break; case OR: - ralloc_strcat (out, "||"); + ralloc_asprintf_rewrite_tail (out, len, "||"); break; case PASTE: - ralloc_strcat (out, "##"); + ralloc_asprintf_rewrite_tail (out, len, "##"); break; case COMMA_FINAL: - ralloc_strcat (out, ","); + ralloc_asprintf_rewrite_tail (out, len, ","); break; case PLACEHOLDER: /* Nothing to print. */ @@ -1040,11 +1040,11 @@ _token_paste (glcpp_parser_t *parser, token_t *token, token_t *other) } glcpp_error (&token->location, parser, ""); - ralloc_strcat (&parser->info_log, "Pasting \""); - _token_print (&parser->info_log, token); - ralloc_strcat (&parser->info_log, "\" and \""); - _token_print (&parser->info_log, other); - ralloc_strcat (&parser->info_log, "\" does not give a valid preprocessing token.\n"); + ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "Pasting \""); + _token_print (&parser->info_log, &parser->info_log_length, token); + ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "\" and \""); + _token_print (&parser->info_log, &parser->info_log_length, other); + ralloc_asprintf_rewrite_tail (&parser->info_log, &parser->info_log_length, "\" does not give a valid preprocessing token.\n"); return token; } @@ -1058,7 +1058,7 @@ _token_list_print (glcpp_parser_t *parser, token_list_t *list) return; for (node = list->head; node; node = node->next) - _token_print (&parser->output, node->token); + _token_print (&parser->output, &parser->output_length, node->token); } void @@ -1104,7 +1104,9 @@ glcpp_parser_create (const struct gl_extensions *extensions, int api) parser->lex_from_node = NULL; parser->output = ralloc_strdup(parser, ""); + parser->output_length = 0; parser->info_log = ralloc_strdup(parser, ""); + parser->info_log_length = 0; parser->error = 0; /* Add pre-defined macros. */ diff --git a/mesalib/src/glsl/glcpp/glcpp.h b/mesalib/src/glsl/glcpp/glcpp.h index dc816e90e..2d7cad2e6 100644 --- a/mesalib/src/glsl/glcpp/glcpp.h +++ b/mesalib/src/glsl/glcpp/glcpp.h @@ -174,6 +174,8 @@ struct glcpp_parser { token_node_t *lex_from_node; char *output; char *info_log; + size_t output_length; + size_t info_log_length; int error; }; diff --git a/mesalib/src/glsl/link_uniforms.cpp b/mesalib/src/glsl/link_uniforms.cpp index 296e4e20c..bd2c10d75 100644 --- a/mesalib/src/glsl/link_uniforms.cpp +++ b/mesalib/src/glsl/link_uniforms.cpp @@ -67,7 +67,7 @@ uniform_field_visitor::process(ir_variable *var) void uniform_field_visitor::recursion(const glsl_type *t, char **name, - unsigned name_length) + size_t name_length) { /* Records need to have each field processed individually. * @@ -78,22 +78,21 @@ uniform_field_visitor::recursion(const glsl_type *t, char **name, if (t->is_record()) { for (unsigned i = 0; i < t->length; i++) { const char *field = t->fields.structure[i].name; + size_t new_length = name_length; /* Append '.field' to the current uniform name. */ - ralloc_asprintf_rewrite_tail(name, name_length, ".%s", field); + ralloc_asprintf_rewrite_tail(name, &new_length, ".%s", field); - recursion(t->fields.structure[i].type, name, - name_length + 1 + strlen(field)); + recursion(t->fields.structure[i].type, name, new_length); } } else if (t->is_array() && t->fields.array->is_record()) { for (unsigned i = 0; i < t->length; i++) { - char subscript[13]; + size_t new_length = name_length; /* Append the subscript to the current uniform name */ - const unsigned subscript_length = snprintf(subscript, 13, "[%u]", i); - ralloc_asprintf_rewrite_tail(name, name_length, "%s", subscript); + ralloc_asprintf_rewrite_tail(name, &new_length, "[%u]", i); - recursion(t->fields.array, name, name_length + subscript_length); + recursion(t->fields.array, name, new_length); } } else { this->visit_field(t, *name); diff --git a/mesalib/src/glsl/linker.h b/mesalib/src/glsl/linker.h index 433c63be2..0b4c001f7 100644 --- a/mesalib/src/glsl/linker.h +++ b/mesalib/src/glsl/linker.h @@ -76,7 +76,7 @@ private: * \param name_length Length of the current name \b not including the * terminating \c NUL character. */ - void recursion(const glsl_type *t, char **name, unsigned name_length); + void recursion(const glsl_type *t, char **name, size_t name_length); }; #endif /* GLSL_LINKER_H */ diff --git a/mesalib/src/glsl/ralloc.c b/mesalib/src/glsl/ralloc.c index 91e4bab2e..2f93dcdea 100644 --- a/mesalib/src/glsl/ralloc.c +++ b/mesalib/src/glsl/ralloc.c @@ -448,11 +448,11 @@ ralloc_vasprintf_append(char **str, const char *fmt, va_list args) size_t existing_length; assert(str != NULL); existing_length = *str ? strlen(*str) : 0; - return ralloc_vasprintf_rewrite_tail(str, existing_length, fmt, args); + return ralloc_vasprintf_rewrite_tail(str, &existing_length, fmt, args); } bool -ralloc_asprintf_rewrite_tail(char **str, size_t start, const char *fmt, ...) +ralloc_asprintf_rewrite_tail(char **str, size_t *start, const char *fmt, ...) { bool success; va_list args; @@ -463,7 +463,7 @@ ralloc_asprintf_rewrite_tail(char **str, size_t start, const char *fmt, ...) } bool -ralloc_vasprintf_rewrite_tail(char **str, size_t start, const char *fmt, +ralloc_vasprintf_rewrite_tail(char **str, size_t *start, const char *fmt, va_list args) { size_t new_length; @@ -479,11 +479,12 @@ ralloc_vasprintf_rewrite_tail(char **str, size_t start, const char *fmt, new_length = printf_length(fmt, args); - ptr = resize(*str, start + new_length + 1); + ptr = resize(*str, *start + new_length + 1); if (unlikely(ptr == NULL)) return false; - vsnprintf(ptr + start, new_length + 1, fmt, args); + vsnprintf(ptr + *start, new_length + 1, fmt, args); *str = ptr; + *start += new_length; return true; } diff --git a/mesalib/src/glsl/ralloc.h b/mesalib/src/glsl/ralloc.h index 1324f3466..86306b1f5 100644 --- a/mesalib/src/glsl/ralloc.h +++ b/mesalib/src/glsl/ralloc.h @@ -329,10 +329,11 @@ char *ralloc_vasprintf(const void *ctx, const char *fmt, va_list args); * \param fmt A printf-style formatting string * * \p str will be updated to the new pointer unless allocation fails. + * \p start will be increased by the length of the newly formatted text. * * \return True unless allocation failed. */ -bool ralloc_asprintf_rewrite_tail(char **str, size_t start, +bool ralloc_asprintf_rewrite_tail(char **str, size_t *start, const char *fmt, ...); /** @@ -352,10 +353,11 @@ bool ralloc_asprintf_rewrite_tail(char **str, size_t start, * \param args A va_list containing the data to be formatted * * \p str will be updated to the new pointer unless allocation fails. + * \p start will be increased by the length of the newly formatted text. * * \return True unless allocation failed. */ -bool ralloc_vasprintf_rewrite_tail(char **str, size_t start, const char *fmt, +bool ralloc_vasprintf_rewrite_tail(char **str, size_t *start, const char *fmt, va_list args); /** |