[PATCH 2/6] text-backend: minor fixes
Kristian Høgsberg
hoegsberg at gmail.com
Sun Jul 22 08:56:43 PDT 2012
On Wed, Jul 11, 2012 at 10:25:30PM +0200, Philipp Brüschweiler wrote:
> * make sure deactivation is done consistently when a text_model
> is destroyed
> * zero out allocated objects
Sure. I followed up with a few whitespace fixes to keep lines under
80 characters. For stuff like
wl_signal_emit(&text_model->input_method->ec->hide_input_panel_signal, text_model->input_method->ec);
I like adding a temp ec variable, to make it shorter, but more
importantly make the expression simpler and easier to read. For
expressions like
struct text_model *text_model = container_of(resource,
struct text_model, resource);
I prefer breaking after the '=':
struct text_model *text_model =
container_of(resource, struct text_model, resource);
which again keeps the line under 80 characters and makes the code
easier to read, since we break after the lower-precedence operator
(assignment) and avoid breaking up the macro call.
Anyway, just guidelines.
Kristian
> ---
> src/text-backend.c | 29 +++++++++++++++++------------
> 1 Datei geändert, 17 Zeilen hinzugefügt(+), 12 Zeilen entfernt(-)
>
> diff --git a/src/text-backend.c b/src/text-backend.c
> index 1d2c2b7..5104686 100644
> --- a/src/text-backend.c
> +++ b/src/text-backend.c
> @@ -46,14 +46,22 @@ struct input_method {
> };
>
> static void
> +deactivate_text_model(struct text_model *text_model)
> +{
> +
> + if (text_model->input_method->active_model == text_model) {
> + text_model->input_method->active_model = NULL;
> + wl_signal_emit(&text_model->input_method->ec->hide_input_panel_signal, text_model->input_method->ec);
> + }
> +}
> +
> +static void
> destroy_text_model(struct wl_resource *resource)
> {
> struct text_model *text_model = container_of(resource,
> struct text_model, resource);
>
> - if (text_model->input_method->active_model == text_model) {
> - text_model->input_method->active_model = 0;
> - }
> + deactivate_text_model(text_model);
>
> wl_list_remove(&text_model->link);
> free(text_model);
> @@ -90,10 +98,7 @@ text_model_deactivate(struct wl_client *client,
> {
> struct text_model *text_model = resource->data;
>
> - if (text_model->input_method->active_model == text_model) {
> - text_model->input_method->active_model = NULL;
> - wl_signal_emit(&text_model->input_method->ec->hide_input_panel_signal, text_model->input_method->ec);
> - }
> + deactivate_text_model(text_model);
> }
>
> static void
> @@ -145,13 +150,13 @@ static void input_method_create_text_model(struct wl_client *client,
> struct input_method *input_method = resource->data;
> struct text_model *text_model;
>
> - text_model = malloc(sizeof *text_model);
> + text_model = calloc(1, sizeof *text_model);
>
> text_model->resource.destroy = destroy_text_model;
> -
> +
> text_model->resource.object.id = id;
> text_model->resource.object.interface = &text_model_interface;
> - text_model->resource.object.implementation =
> + text_model->resource.object.implementation =
> (void (**)(void)) &text_model_implementation;
> text_model->resource.data = text_model;
>
> @@ -204,7 +209,7 @@ input_method_create(struct weston_compositor *ec)
> {
> struct input_method *input_method;
>
> - input_method = malloc(sizeof *input_method);
> + input_method = calloc(1, sizeof *input_method);
>
> input_method->base.interface = &input_method_interface;
> input_method->base.implementation = (void(**)(void)) &input_method_implementation;
> @@ -218,5 +223,5 @@ input_method_create(struct weston_compositor *ec)
> input_method, bind_input_method);
>
> input_method->destroy_listener.notify = input_method_notifier_destroy;
> - wl_signal_add(&ec->destroy_signal, &input_method->destroy_listener);
> + wl_signal_add(&ec->destroy_signal, &input_method->destroy_listener);
> }
> --
> 1.7.11.1
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
More information about the wayland-devel
mailing list