@@ -66,9 +66,9 @@ void error_init(ERROR_T* error, const error_type_T type, position_T start, posit
6666 if (truncated_c_string_<%= i %> ) { free(truncated_c_string_<%= i %> ); }
6767 <%- end -%>
6868 <%- end -%>
69- <%= error . human %> -> base.message = hb_allocator_strdup(allocator, message );
69+ <%= error . human %> -> base.message = hb_string_copy(hb_string(message), allocator );
7070 <%- else -%>
71- <%= error . human %> -> base.message = hb_allocator_strdup(allocator, "<%= error . message_template %> ");
71+ <%= error . human %> -> base.message = hb_string_copy(hb_string( "<%= error . message_template %> "), allocator );
7272 <%- end -%>
7373
7474 <%- error . fields . each do |field | -%>
@@ -95,30 +95,30 @@ void append_<%= error.human %>(<%= (arguments + ["hb_array_T* errors"]).join(",
9595}
9696<%- end -%>
9797
98- const char* error_type_to_string(ERROR_T* error) {
98+ hb_string_T error_type_to_string(ERROR_T* error) {
9999 switch (error-> type) {
100100 <%- errors . each do |error | -%>
101- case <%= error . type %> : return "<%= error . type %> ";
101+ case <%= error . type %> : return hb_string( "<%= error . type %> ") ;
102102 <%- end -%>
103103 }
104104
105- return "Unknown error_type_T";
105+ return hb_string( "Unknown error_type_T") ;
106106}
107107
108- const char* error_human_type(ERROR_T* error) {
108+ hb_string_T error_human_type(ERROR_T* error) {
109109 switch (error-> type) {
110110 <%- errors . each do |error | -%>
111- case <%= error . type %> : return "<%= error . name %> ";
111+ case <%= error . type %> : return hb_string( "<%= error . name %> ") ;
112112 <%- end -%>
113113 }
114114
115- return "Unknown error_type_T";
115+ return hb_string( "Unknown error_type_T") ;
116116}
117117
118118void error_free_base_error(ERROR_T* error, hb_allocator_T* allocator) {
119119 if (error == NULL) { return; }
120120
121- if (error-> message != NULL) { hb_allocator_dealloc(allocator, error-> message); }
121+ if (!hb_string_is_null( error-> message)) { hb_allocator_dealloc(allocator, error-> message.data ); }
122122
123123 hb_allocator_dealloc(allocator, error);
124124}
@@ -210,13 +210,13 @@ static void error_pretty_print_<%= error.human %>(<%= error.struct_type %>* erro
210210 if (!error) { return; }
211211
212212 hb_buffer_append(buffer, "@ ");
213- hb_buffer_append (buffer, error_human_type((ERROR_T*) error));
213+ hb_buffer_append_string (buffer, error_human_type((ERROR_T*) error));
214214 hb_buffer_append(buffer, " ");
215215
216216 pretty_print_location(error-> base.location, buffer);
217217 hb_buffer_append(buffer, "\n");
218218
219- pretty_print_quoted_property(hb_string("message"), hb_string( error-> base.message) , indent, relative_indent, <%= error . fields . none? %> , buffer);
219+ pretty_print_quoted_property(hb_string("message"), error-> base.message, indent, relative_indent, <%= error . fields . none? %> , buffer);
220220 <%- error . fields . each_with_index do |field , index | -%>
221221 <%- case field -%>
222222 <%- when Herb ::Template ::PositionField -%>
0 commit comments