[PATCH] compositor-drm: pass only const strings as backend parameters

Giulio Camuffo giuliocamuffo at gmail.com
Tue May 24 16:50:05 UTC 2016


This makes more clear that the backend doesn't take ownership
of the data and it makes the API more usable.

Signed-off-by: Giulio Camuffo <giuliocamuffo at gmail.com>
---
 src/compositor-drm.h | 10 +++++-----
 src/main.c           | 18 ++++++++++++------
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/src/compositor-drm.h b/src/compositor-drm.h
index 3f150db..24f60f8 100644
--- a/src/compositor-drm.h
+++ b/src/compositor-drm.h
@@ -58,13 +58,13 @@ struct weston_drm_backend_output_config {
 	 * - "rgb565"
 	 * - "xrgb2101010"
 	 */
-	char *gbm_format;
+	const char *gbm_format;
 	/** The seat to be used by the output. Set to NULL to use the
 	 * default seat. */
-	char *seat;
+	const char *seat;
 	/** The modeline to be used by the output. Refer to the documentation
 	 * of WESTON_DRM_BACKEND_OUTPUT_PREFERRED for details. */
-	char *modeline;
+	const char *modeline;
 };
 
 /** The backend configuration struct.
@@ -93,7 +93,7 @@ struct weston_drm_backend_config {
 	 * take ownership of the seat_id pointer and will free it on
 	 * backend destruction.
 	 */
-	char *seat_id;
+	const char *seat_id;
 
 	/** The pixel format of the framebuffer to be used.
 	 *
@@ -105,7 +105,7 @@ struct weston_drm_backend_config {
 	 * The backend will take ownership of the format pointer and will free
 	 * it on backend destruction.
 	 */
-	char *gbm_format;
+	const char *gbm_format;
 
 	/** Callback used to configure the outputs.
 	 *
diff --git a/src/main.c b/src/main.c
index d1c569d..c3d0d0b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -972,6 +972,7 @@ drm_configure_output(struct weston_compositor *c,
 	struct weston_config *wc = weston_compositor_get_user_data(c);
 	struct weston_config_section *section;
 	char *s;
+	char *seat, *gbm_format;
 	int scale;
 	enum weston_drm_backend_output_mode mode =
 		WESTON_DRM_BACKEND_OUTPUT_PREFERRED;
@@ -1000,8 +1001,10 @@ drm_configure_output(struct weston_compositor *c,
 	free(s);
 
 	weston_config_section_get_string(section,
-					 "gbm-format", &config->gbm_format, NULL);
-	weston_config_section_get_string(section, "seat", &config->seat, "");
+					 "gbm-format", &gbm_format, NULL);
+	weston_config_section_get_string(section, "seat", &seat, "");
+	config->gbm_format = gbm_format;
+	config->seat = seat;
 	return mode;
 }
 
@@ -1012,10 +1015,11 @@ load_drm_backend(struct weston_compositor *c, const char *backend,
 	struct weston_drm_backend_config config = {{ 0, }};
 	struct weston_config_section *section;
 	int ret = 0;
+	char *gbm_format, *seat_id;
 
 	const struct weston_option options[] = {
 		{ WESTON_OPTION_INTEGER, "connector", 0, &config.connector },
-		{ WESTON_OPTION_STRING, "seat", 0, &config.seat_id },
+		{ WESTON_OPTION_STRING, "seat", 0, &seat_id },
 		{ WESTON_OPTION_INTEGER, "tty", 0, &config.tty },
 		{ WESTON_OPTION_BOOLEAN, "current-mode", 0, &config.use_current_mode },
 		{ WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
@@ -1025,17 +1029,19 @@ load_drm_backend(struct weston_compositor *c, const char *backend,
 
 	section = weston_config_get_section(wc, "core", NULL, NULL);
 	weston_config_section_get_string(section,
-					 "gbm-format", &config.gbm_format,
+					 "gbm-format", &gbm_format,
 					 NULL);
 
 	config.base.struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION;
 	config.base.struct_size = sizeof(struct weston_drm_backend_config);
 	config.configure_output = drm_configure_output;
+	config.gbm_format = gbm_format;
+	config.seat_id = seat_id;
 
 	ret = load_backend_new(c, backend, &config.base);
 
-	free(config.gbm_format);
-	free(config.seat_id);
+	free(gbm_format);
+	free(seat_id);
 
 	return ret;
 }
-- 
2.8.3



More information about the wayland-devel mailing list