On 10/4/21 3:32 AM, Giovanni Mascellani wrote:
Semantically, a NULL buffer is considered equivalent to the empty string. The accessor vkd3d_string_buffer_data implements this equivalence.
The reason for this change is to avoid asserting the result of a memory allocation in vkd3d_string_buffer_init, while at the same time keeping it always successful.
Well, I guess this is one alternative to 216057. I don't dislike it.
@@ -855,7 +856,7 @@ struct vkd3d_string_buffer *hlsl_type_to_string(struct hlsl_ctx *ctx, const stru
if ((inner_string = hlsl_type_to_string(ctx, t))) {
vkd3d_string_buffer_printf(string, "%s", inner_string->buffer);
vkd3d_string_buffer_printf(string, "%s", vkd3d_string_buffer_data(inner_string)); hlsl_release_string_buffer(ctx, inner_string); }
This means that here, and everywhere else, you can get rid of the NULL check.
diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index ef9eaef5..8a2dd0e3 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -25,11 +25,9 @@ VKD3D_DEBUG_ENV_NAME("VKD3D_SHADER_DEBUG");
void vkd3d_string_buffer_init(struct vkd3d_string_buffer *buffer) {
- buffer->buffer_size = 16;
- buffer->buffer_size = 0; buffer->content_size = 0;
- buffer->buffer = vkd3d_malloc(buffer->buffer_size);
- assert(buffer->buffer);
- memset(buffer->buffer, 0, buffer->buffer_size);
- buffer->buffer = NULL; }
I'm assuming this was accidental.
void vkd3d_string_buffer_cleanup(struct vkd3d_string_buffer *buffer) @@ -37,20 +35,29 @@ void vkd3d_string_buffer_cleanup(struct vkd3d_string_buffer *buffer) vkd3d_free(buffer->buffer); }
+const char *vkd3d_string_buffer_data(const struct vkd3d_string_buffer *buffer) +{
- return buffer->buffer ? buffer->buffer : "";
+}
Should this be defined in vkd3d_shader_private.h as an inline function?