Re: [PATCH 1/8] Constify event_loop_core

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2016-06-20 at 10:15 +0100, Frediano Ziglio wrote:
> Was used as write variable only for testing.
> Avoid usage of not constant globals.

It'd be nice to expand just a little bit more on the how this change benefits
us. 

> 
> Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
> ---
>  server/event-loop.c             |  6 +++---
>  server/red-common.h             |  2 +-
>  server/tests/basic_event_loop.c | 20 +++++++++++---------
>  3 files changed, 15 insertions(+), 13 deletions(-)
> 
> diff --git a/server/event-loop.c b/server/event-loop.c
> index 4738ed9..d16aca1 100644
> --- a/server/event-loop.c
> +++ b/server/event-loop.c
> @@ -17,9 +17,9 @@
>  */
>  
>  /*
> - *This file export a global variable:
> + * This file export a global variable:

As long as your changing this line: export -> exports?

>   *
> - * SpiceCoreInterfaceInternal event_loop_core;
> + * const SpiceCoreInterfaceInternal event_loop_core;
>   */
>  
>  #include "red-common.h"
> @@ -168,7 +168,7 @@ static void watch_remove(SpiceWatch *watch)
>      free(watch);
>  }
>  
> -SpiceCoreInterfaceInternal event_loop_core = {
> +const SpiceCoreInterfaceInternal event_loop_core = {
>      .timer_add = timer_add,
>      .timer_start = timer_start,
>      .timer_cancel = timer_cancel,
> diff --git a/server/red-common.h b/server/red-common.h
> index 7add3d0..7ab7e15 100644
> --- a/server/red-common.h
> +++ b/server/red-common.h
> @@ -58,7 +58,7 @@ struct SpiceCoreInterfaceInternal {
>      GMainContext *main_context;
>  };
>  
> -extern SpiceCoreInterfaceInternal event_loop_core;
> +extern const SpiceCoreInterfaceInternal event_loop_core;
>  
>  typedef struct RedsState RedsState;
>  
> diff --git a/server/tests/basic_event_loop.c b/server/tests/basic_event_loop.c
> index b9e1b9c..4820387 100644
> --- a/server/tests/basic_event_loop.c
> +++ b/server/tests/basic_event_loop.c
> @@ -36,6 +36,7 @@ int debug = 0;
>      } \
>  }
>  
> +static SpiceCoreInterfaceInternal base_core_interface;
>  static GMainContext *main_context = NULL;
>  
>  GMainContext *basic_event_loop_get_context(void)
> @@ -69,12 +70,12 @@ static void ignore_sigpipe(void)
>  
>  static SpiceTimer* base_timer_add(SpiceTimerFunc func, void *opaque)
>  {
> -    return event_loop_core.timer_add(&event_loop_core, func, opaque);
> +    return base_core_interface.timer_add(&base_core_interface, func, opaque);
>  }
>  
>  static SpiceWatch *base_watch_add(int fd, int event_mask, SpiceWatchFunc
> func, void *opaque)
>  {
> -    return event_loop_core.watch_add(&event_loop_core, fd, event_mask, func,
> opaque);
> +    return base_core_interface.watch_add(&base_core_interface, fd,
> event_mask, func, opaque);
>  }
>  
>  static SpiceCoreInterface core = {
> @@ -91,13 +92,14 @@ SpiceCoreInterface *basic_event_loop_init(void)
>      ignore_sigpipe();
>      spice_assert(main_context == NULL);
>      main_context = g_main_context_new();
> -    core.timer_start = event_loop_core.timer_start;
> -    core.timer_cancel = event_loop_core.timer_cancel;
> -    core.timer_remove = event_loop_core.timer_remove;
> -    core.watch_update_mask = event_loop_core.watch_update_mask;
> -    core.watch_remove = event_loop_core.watch_remove;
> -    event_loop_core.channel_event = core.channel_event =
> event_loop_channel_event;
> -    event_loop_core.main_context = main_context;
> +    base_core_interface = event_loop_core;
> +    core.timer_start = base_core_interface.timer_start;
> +    core.timer_cancel = base_core_interface.timer_cancel;
> +    core.timer_remove = base_core_interface.timer_remove;
> +    core.watch_update_mask = base_core_interface.watch_update_mask;
> +    core.watch_remove = base_core_interface.watch_remove;
> +    base_core_interface.channel_event = core.channel_event =
> event_loop_channel_event;
> +    base_core_interface.main_context = main_context;
>  
>      return &core;
>  }

Acked-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]