[babl/wip/msvc: 7/20] babl: Force USE_ALLOCA for MSVC builds



commit 91f127c4ba1b4fab79285d562ae95a1607f19f2b
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Jan 20 16:30:38 2020 +0800

    babl: Force USE_ALLOCA for MSVC builds
    
    This is because Visual Studio does not support C99 VLA's, so compensate this by
    using alloca() via _alloca()

 babl/babl-format.c | 8 ++++++++
 meson.build        | 2 ++
 2 files changed, 10 insertions(+)
---
diff --git a/babl/babl-format.c b/babl/babl-format.c
index 2e4e3d718..4892ed32c 100644
--- a/babl/babl-format.c
+++ b/babl/babl-format.c
@@ -260,9 +260,17 @@ babl_format_n (const Babl *btype,
   int            id         = 0;
   int            planar     = 0;
   BablModel     *model      = (BablModel *)babl_model ("Y");
+
+#ifdef USE_ALLOCA
+  BablComponent **component = alloca (sizeof (void *) *  components);
+  BablSampling  **sampling  = alloca (sizeof (void *) *  components);
+  const BablType **type     = alloca (sizeof (void *) *  components);
+#else
   BablComponent *component [components];
   BablSampling  *sampling  [components];
   const BablType *type      [components];
+#endif
+
   char          *name       = NULL;
 
   for (i = 0; i<components; i++)
diff --git a/meson.build b/meson.build
index 2f43ff641..2029abd33 100644
--- a/meson.build
+++ b/meson.build
@@ -176,6 +176,8 @@ if cc.get_id() == 'msvc'
     '-utf-8',              # Avoid C4819 (Unicode handling) compiler warnings
     '-D__WIN32__',         # MSVC does not define this by default
     '-D_USE_MATH_DEFINES', # Allow more math macro usage
+    '-DUSE_ALLOCA',        # Use alloca via _alloca()
+    '-Dalloca=_alloca',
     '-wd4244',             # Silence some unneeded compiler warnings
     '-wd4305'
   ]


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