]> git.mdlowis.com Git - proto/labwc.git/commitdiff
src: avoid tentative definitions of static data
authorJohn Lindgren <john@jlindgren.net>
Fri, 4 Jul 2025 04:12:21 +0000 (00:12 -0400)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Mon, 21 Jul 2025 14:51:10 +0000 (16:51 +0200)
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.

src/buffer.c
src/osd-field.c

index 1faa4620f845abb3000a19a444ec2cfe36024b81..8a2aa20256909cd52f01e79d136e2f67116d4a32 100644 (file)
 #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)
 {
index 9eec0837f62d927e023f70a2db883600feb98fea..2885febe39e7c0cfaa0795b12a461a9408fe5172 100644 (file)
@@ -21,8 +21,6 @@ struct field_converter {
        field_conversion_type *fn;
 };
 
-static const struct field_converter field_converter[];
-
 /* Internal helpers */
 
 static const char *
@@ -200,6 +198,27 @@ field_set_title_short(struct buf *buf, struct view *view, const char *format)
        buf_add(buf, get_title_if_different(view));
 }
 
+static void field_set_custom(struct buf *buf, struct view *view,
+       const char *format);
+
+static const struct field_converter field_converter[LAB_FIELD_COUNT] = {
+       [LAB_FIELD_TYPE]               = { 'B', field_set_type },
+       [LAB_FIELD_TYPE_SHORT]         = { 'b', field_set_type_short },
+       [LAB_FIELD_WIN_STATE_ALL]      = { 'S', field_set_win_state_all },
+       [LAB_FIELD_WIN_STATE]          = { 's', field_set_win_state },
+       [LAB_FIELD_IDENTIFIER]         = { 'I', field_set_identifier },
+       [LAB_FIELD_TRIMMED_IDENTIFIER] = { 'i', field_set_identifier_trimmed },
+       [LAB_FIELD_DESKTOP_ENTRY_NAME] = { 'n', field_set_desktop_entry_name},
+       [LAB_FIELD_WORKSPACE]          = { 'W', field_set_workspace },
+       [LAB_FIELD_WORKSPACE_SHORT]    = { 'w', field_set_workspace_short },
+       [LAB_FIELD_OUTPUT]             = { 'O', field_set_output },
+       [LAB_FIELD_OUTPUT_SHORT]       = { 'o', field_set_output_short },
+       [LAB_FIELD_TITLE]              = { 'T', field_set_title },
+       [LAB_FIELD_TITLE_SHORT]        = { 't', field_set_title_short },
+       /* fmt_char can never be matched so prevents LAB_FIELD_CUSTOM recursion */
+       [LAB_FIELD_CUSTOM]             = { '\0', field_set_custom },
+};
+
 static void
 field_set_custom(struct buf *buf, struct view *view, const char *format)
 {
@@ -278,24 +297,6 @@ reset_format:
        buf_reset(&field_result);
 }
 
-static const struct field_converter field_converter[LAB_FIELD_COUNT] = {
-       [LAB_FIELD_TYPE]               = { 'B', field_set_type },
-       [LAB_FIELD_TYPE_SHORT]         = { 'b', field_set_type_short },
-       [LAB_FIELD_WIN_STATE_ALL]      = { 'S', field_set_win_state_all },
-       [LAB_FIELD_WIN_STATE]          = { 's', field_set_win_state },
-       [LAB_FIELD_IDENTIFIER]         = { 'I', field_set_identifier },
-       [LAB_FIELD_TRIMMED_IDENTIFIER] = { 'i', field_set_identifier_trimmed },
-       [LAB_FIELD_DESKTOP_ENTRY_NAME] = { 'n', field_set_desktop_entry_name},
-       [LAB_FIELD_WORKSPACE]          = { 'W', field_set_workspace },
-       [LAB_FIELD_WORKSPACE_SHORT]    = { 'w', field_set_workspace_short },
-       [LAB_FIELD_OUTPUT]             = { 'O', field_set_output },
-       [LAB_FIELD_OUTPUT_SHORT]       = { 'o', field_set_output_short },
-       [LAB_FIELD_TITLE]              = { 'T', field_set_title },
-       [LAB_FIELD_TITLE_SHORT]        = { 't', field_set_title_short },
-       /* fmt_char can never be matched so prevents LAB_FIELD_CUSTOM recursion */
-       [LAB_FIELD_CUSTOM]             = { '\0', field_set_custom },
-};
-
 struct window_switcher_field *
 osd_field_create(void)
 {