[cogl/msvc-support-1.8] Use a wrapper for modff when compiling with Visual Studio
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cogl/msvc-support-1.8] Use a wrapper for modff when compiling with Visual Studio
- Date: Fri, 23 Sep 2011 09:02:28 +0000 (UTC)
commit 0073de9207ca384b407f0f01fc62ceb9fc03b38a
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 under 32-bit x86 compilation. 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 933a325..c3ba6bd 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 f800fcb..a9cef76 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 ca12fcb..9a6a30a 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 3551a9d..0f65439 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..3c93557 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 (this only applies for 32-bit x86 compilation, not x64):
+ *
+ * http://connect.microsoft.com/VisualStudio/feedback/details/ \
+ * 432366/modff-corrupts-stack
+ */
+#if (defined(_MSC_VER) && defined(_M_IX86))
+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 && _M_IX86 */
+#define cogl_modff modff
+#endif /* _MSC_VER && _M_IX86 */
+
#endif /* __COGL_UTIL_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]