src: avoid tentative definitions of static data

Having multiple declarations of the same static data (where one is
considered "tentative") is kind of an obscure C feature -- I didn't
even know the name of it until today. It's also forbidden in C++.

In the case of circular dependencies between static data <-> function,
the more typical pattern is to forward-declare the function, then the
data, then provide the function definition. Let's follow that pattern.
This commit is contained in:
John Lindgren 2025-07-04 00:12:21 -04:00 committed by Consolatis
parent 407a29aa23
commit a802d6b20a
2 changed files with 30 additions and 28 deletions

View file

@ -33,14 +33,8 @@
#include "common/box.h"
#include "common/mem.h"
static const struct wlr_buffer_impl data_buffer_impl;
static struct lab_data_buffer *
data_buffer_from_buffer(struct wlr_buffer *buffer)
{
assert(buffer->impl == &data_buffer_impl);
return (struct lab_data_buffer *)buffer;
}
static struct lab_data_buffer *data_buffer_from_buffer(
struct wlr_buffer *buffer);
static void
data_buffer_destroy(struct wlr_buffer *wlr_buffer)
@ -80,6 +74,13 @@ static const struct wlr_buffer_impl data_buffer_impl = {
.end_data_ptr_access = data_buffer_end_data_ptr_access,
};
static struct lab_data_buffer *
data_buffer_from_buffer(struct wlr_buffer *buffer)
{
assert(buffer->impl == &data_buffer_impl);
return (struct lab_data_buffer *)buffer;
}
struct lab_data_buffer *
buffer_adopt_cairo_surface(cairo_surface_t *surface)
{