On Mon, Aug 16, 2021 at 6:05 PM Henri Verbeet hverbeet@gmail.com wrote:
On Fri, 13 Aug 2021 at 16:15, Matteo Bruni mbruni@codeweavers.com wrote:
@@ -147,11 +143,6 @@ struct vkd3d_string_buffer *vkd3d_string_buffer_get(struct vkd3d_string_buffer_c if (!(buffer = vkd3d_malloc(sizeof(*buffer)))) return NULL; vkd3d_string_buffer_init(buffer);
if (!vkd3d_string_buffer_resize(buffer, 1))
{
vkd3d_free(buffer);
return NULL;
}
I think Zebediah successfully convinced me it's useful for vkd3d_string_buffer_get() to return empty but initialised buffers, like wined3d's string_buffer_get() does. Note that a consequence of not doing this is that we can no longer safely do something like the following:
buffer = vkd3d_string_buffer_get(...); if (flags & FLAT) vkd3d_string_buffer_printf(buffer, "flat "); if (flags & NOPERSPECTIVE) vkd3d_string_buffer_printf(buffer, "noperspective "); if (flags & CENTROID) vkd3d_string_buffer_printf(buffer, "centroid "); printf("%svec4 v;\n", buffer->buffer); vkd3d_string_buffer_release(..., buffer);
because now buffer->buffer is potentially NULL.
Makes sense (and I totally forgot, not surprising in the least). In that case though, I think it would be nicer to allocate the initial buffer in vkd3d_string_buffer_init(), like in wined3d, instead of having to handle it in two places (with different allocation sizes, and missing the case where you don't call vkd3d_string_buffer_get() at all).