[gtk/master.msvc.fix] gtk/gtkcssrgbavalue.c: Fix build on Visual Studio



commit a4f63b7cbe12d8a53851e4e5aa759a9ed7bffedd
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Wed Nov 13 17:14:31 2019 +0800

    gtk/gtkcssrgbavalue.c: Fix build on Visual Studio
    
    Visual Studio does not allow static or global variables to use
    non-constants in their aggregate initializers, so fix the build by
    doing such initializations as local and non-static initializations,
    which means some unavoidable duplication.
    
    It seems that the current code in this file inadvertently made use of
    something outside of C99 in this case, from [1] and [2].
    
    [1]: https://stackoverflow.com/questions/6131455/compile-error-c2099-initializer-is-not-a-constant
    [2]: https://www.drdobbs.com/the-new-c-declarations-initializations/184401377

 gtk/gtkcssrgbavalue.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkcssrgbavalue.c b/gtk/gtkcssrgbavalue.c
index a63f2803a3..5caf92c756 100644
--- a/gtk/gtkcssrgbavalue.c
+++ b/gtk/gtkcssrgbavalue.c
@@ -107,10 +107,6 @@ static const GtkCssValueClass GTK_CSS_VALUE_RGBA = {
   gtk_css_value_rgba_print
 };
 
-static GtkCssValue transparent_black_singleton = (GtkCssValue) { &GTK_CSS_VALUE_RGBA, 1, { 0, 0, 0, 0 }};
-static GtkCssValue transparent_white_singleton = (GtkCssValue) { &GTK_CSS_VALUE_RGBA, 1, { 1, 1, 1, 0 }};
-static GtkCssValue opaque_white_singleton      = (GtkCssValue) { &GTK_CSS_VALUE_RGBA, 1, { 1, 1, 1, 1 }};
-
 GtkCssValue *
 _gtk_css_rgba_value_new_from_rgba (const GdkRGBA *rgba)
 {
@@ -120,6 +116,11 @@ _gtk_css_rgba_value_new_from_rgba (const GdkRGBA *rgba)
 
   if (gdk_rgba_is_clear (rgba))
     {
+      GtkCssValue transparent_black_singleton = (GtkCssValue) { &GTK_CSS_VALUE_RGBA,
+                                                                1, { 0, 0, 0, 0 }};
+      GtkCssValue transparent_white_singleton = (GtkCssValue) { &GTK_CSS_VALUE_RGBA,
+                                                                1, { 1, 1, 1, 0 }};
+
       if (rgba->red == 1 &&
           rgba->green == 1 &&
           rgba->blue == 1)
@@ -132,6 +133,8 @@ _gtk_css_rgba_value_new_from_rgba (const GdkRGBA *rgba)
     }
   else if (gdk_rgba_is_opaque (rgba))
     {
+      GtkCssValue opaque_white_singleton = (GtkCssValue) { &GTK_CSS_VALUE_RGBA,
+                                                           1, { 1, 1, 1, 1 }};
       if (rgba->red == 1 &&
           rgba->green == 1 &&
           rgba->blue == 1)
@@ -147,12 +150,18 @@ _gtk_css_rgba_value_new_from_rgba (const GdkRGBA *rgba)
 GtkCssValue *
 _gtk_css_rgba_value_new_transparent (void)
 {
+  GtkCssValue transparent_black_singleton = (GtkCssValue) { &GTK_CSS_VALUE_RGBA,
+                                                            1, { 0, 0, 0, 0 }};
+
   return _gtk_css_value_ref (&transparent_black_singleton);
 }
 
 GtkCssValue *
 _gtk_css_rgba_value_new_white (void)
 {
+  GtkCssValue opaque_white_singleton = (GtkCssValue) { &GTK_CSS_VALUE_RGBA,
+                                                       1, { 1, 1, 1, 1 }};
+
   return _gtk_css_value_ref (&opaque_white_singleton);
 }
 


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