[cogl/msvc-support] Use a wrapper for modff when compiling with Visual Studio



commit 8f8b43dbb3dc55052f90b6d1e1e3ca4f4de5a13e
Author: Neil Roberts <neil linux intel com>
Date:   Tue Jul 19 10:43:30 2011 +0100

    Use a wrapper for modff when compiling with Visual Studio
    
    Visual Studio appears to have a broken macro implementation of modff
    in its headers. This patch adds a wrapper in cogl-util.h to make it
    use modf instead.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=650833
    
    Signed-off-by: Chun-wei Fan <fanchunwei src gnome org>

 cogl/cogl-sub-texture.c       |    6 +++---
 cogl/cogl-texture-2d.c        |    2 +-
 cogl/cogl-texture-3d.c        |    2 +-
 cogl/cogl-texture-rectangle.c |    2 +-
 cogl/cogl-texture.c           |    2 +-
 cogl/cogl-util.h              |   20 ++++++++++++++++++++
 6 files changed, 27 insertions(+), 7 deletions(-)
---
diff --git a/cogl/cogl-sub-texture.c b/cogl/cogl-sub-texture.c
index d00dcd5..b49b759 100644
--- a/cogl/cogl-sub-texture.c
+++ b/cogl/cogl-sub-texture.c
@@ -54,8 +54,8 @@ _cogl_sub_texture_map_range (float *t1, float *t2,
 {
   float t1_frac, t1_int, t2_frac, t2_int;
 
-  t1_frac = modff (*t1, &t1_int);
-  t2_frac = modff (*t2, &t2_int);
+  t1_frac = cogl_modff (*t1, &t1_int);
+  t2_frac = cogl_modff (*t2, &t2_int);
 
   if (t1_frac < 0.0f)
     {
@@ -122,7 +122,7 @@ _cogl_sub_texture_unmap_coord (float t,
   float frac_part, int_part;
 
   /* Convert the fractional part leaving the integer part in tact */
-  frac_part = modff (t, &int_part);
+  frac_part = cogl_modff (t, &int_part);
 
   if (cogl_util_float_signbit (frac_part))
     frac_part = ((1.0f + frac_part) * full_size -
diff --git a/cogl/cogl-texture-2d.c b/cogl/cogl-texture-2d.c
index 71ff44a..abf5380 100644
--- a/cogl/cogl-texture-2d.c
+++ b/cogl/cogl-texture-2d.c
@@ -69,7 +69,7 @@ _cogl_texture_2d_wrap_coords (float t_1, float t_2,
 
   /* Wrap t_1 and t_2 to the range [0,1] */
 
-  modff (t_1 < t_2 ? t_1 : t_2, &int_part);
+  cogl_modff (t_1 < t_2 ? t_1 : t_2, &int_part);
   t_1 -= int_part;
   t_2 -= int_part;
   if (cogl_util_float_signbit (int_part))
diff --git a/cogl/cogl-texture-3d.c b/cogl/cogl-texture-3d.c
index a64c3d2..e9f0dd6 100644
--- a/cogl/cogl-texture-3d.c
+++ b/cogl/cogl-texture-3d.c
@@ -70,7 +70,7 @@ _cogl_texture_3d_wrap_coords (float t_1, float t_2,
 
   /* Wrap t_1 and t_2 to the range [0,1] */
 
-  modff (t_1 < t_2 ? t_1 : t_2, &int_part);
+  cogl_modff (t_1 < t_2 ? t_1 : t_2, &int_part);
   t_1 -= int_part;
   t_2 -= int_part;
   if (cogl_util_float_signbit (int_part))
diff --git a/cogl/cogl-texture-rectangle.c b/cogl/cogl-texture-rectangle.c
index e98be8d..b6e456f 100644
--- a/cogl/cogl-texture-rectangle.c
+++ b/cogl/cogl-texture-rectangle.c
@@ -74,7 +74,7 @@ _cogl_texture_rectangle_wrap_coords (float t_1, float t_2,
 
   /* Wrap t_1 and t_2 to the range [0,1] */
 
-  modff (t_1 < t_2 ? t_1 : t_2, &int_part);
+  cogl_modff (t_1 < t_2 ? t_1 : t_2, &int_part);
   t_1 -= int_part;
   t_2 -= int_part;
   if (cogl_util_float_signbit (int_part))
diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c
index 134e5f5..dd1cc77 100644
--- a/cogl/cogl-texture.c
+++ b/cogl/cogl-texture.c
@@ -309,7 +309,7 @@ _cogl_texture_iter_update (CoglTextureIter *iter)
   float t_2;
   float frac_part;
 
-  frac_part = modff (iter->pos, &iter->next_pos);
+  frac_part = cogl_modff (iter->pos, &iter->next_pos);
 
   /* modff rounds the int part towards zero so we need to add one if
      we're meant to be heading away from zero */
diff --git a/cogl/cogl-util.h b/cogl/cogl-util.h
index e32fcd6..7345607 100644
--- a/cogl/cogl-util.h
+++ b/cogl/cogl-util.h
@@ -103,4 +103,24 @@ int
 _cogl_util_ffs (int num);
 #endif
 
+/* MSVC appears to have a bug in its implementation of modff so we
+ * instead use the double version there. There is a comment about this
+ * bug here:
+ *
+ * http://connect.microsoft.com/VisualStudio/feedback/details/ \
+ *       432366/modff-corrupts-stack
+ */
+#ifdef _MSC_VER
+static inline float
+cogl_modff (float value, float *int_part)
+{
+  double frac_part_double, int_part_double;
+  frac_part_double = modf (value, &int_part_double);
+  *int_part = int_part_double;
+  return frac_part_double;
+}
+#else /* _MSC_VER */
+#define cogl_modff modff
+#endif /* _MSC_VER */
+
 #endif /* __COGL_UTIL_H */



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