[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r10489: Remove some UB, should fix b
From: |
Benjamin Wolsey |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r10489: Remove some UB, should fix behaviour on ARM platform. |
Date: |
Mon, 29 Dec 2008 19:26:51 +0100 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 10489
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Mon 2008-12-29 19:26:51 +0100
message:
Remove some UB, should fix behaviour on ARM platform.
modified:
libbase/utility.h
libcore/SWFMatrix.cpp
libcore/SWFMatrix.h
libcore/swf/DefineButtonCxformTag.cpp
libcore/swf/DefineButtonSoundTag.cpp
------------------------------------------------------------
revno: 10483.1.1
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Mon 2008-12-29 16:51:21 +0100
message:
Drop FloatToFixed16.
modified:
libcore/SWFMatrix.h
------------------------------------------------------------
revno: 10483.1.2
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Mon 2008-12-29 18:18:53 +0100
message:
Remove unreliable conversion from utility.h, move local functions from
SWFMatrix header to the cpp file. One unreliable conversion function
remains in SWFMatrix.cpp.
modified:
libbase/utility.h
libcore/SWFMatrix.cpp
libcore/SWFMatrix.h
libcore/swf/DefineButtonCxformTag.cpp
libcore/swf/DefineButtonSoundTag.cpp
=== modified file 'libbase/utility.h'
--- a/libbase/utility.h 2008-11-14 00:46:35 +0000
+++ b/libbase/utility.h 2008-12-29 17:18:53 +0000
@@ -16,8 +16,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#ifndef _GNASH_UTILITY_H
-#define _GNASH_UTILITY_H
+#ifndef GNASH_UTILITY_H
+#define GNASH_UTILITY_H
// HAVE_FINITE, HAVE_PTHREADS, WIN32, NDEBUG etc.
#ifdef HAVE_CONFIG_H
@@ -53,13 +53,6 @@
#endif // _WIN32
-// Define this to enable fast float&double to uint32 conversion.
-// If the behaviour is undefined when overflow occurs with your
-// compiler, disable this macro.
-#ifndef __APPLE__
- #define TRUST_FLOAT_TO_UINT32_CONVERSION 1
-#endif
-
namespace gnash {
// Using a possible built-in pi constant M_PI, which is not in
@@ -84,23 +77,28 @@
#endif
}
-inline double infinite_to_zero(double x)
+inline double
+infinite_to_zero(double x)
{
return utility::isFinite(x) ? x : 0.0;
}
-template <typename T> inline T clamp(T i, T min, T max)
+template <typename T>
+inline T
+clamp(T i, T min, T max)
{
assert( min <= max );
return std::max<T>(min, std::min<T>(i, max));
}
-inline float flerp(float a, float b, float f)
+inline float
+flerp(float a, float b, float f)
{
return (b - a) * f + a;
}
-inline int frnd(float f)
+inline int
+frnd(float f)
{
return static_cast<int>(f + 0.5f);
}
@@ -110,18 +108,16 @@
/// Some of these functions could also be in the gnash::utility namespace,
/// although some are used so often that it would get annoying.
-inline double TWIPS_TO_PIXELS(int i)
+inline double
+TWIPS_TO_PIXELS(int i)
{
return static_cast<double>(i / 20.0);
}
// truncate when overflow occurs.
-inline boost::int32_t PIXELS_TO_TWIPS(double a)
+inline boost::int32_t
+PIXELS_TO_TWIPS(double a)
{
-#ifdef TRUST_FLOAT_TO_UINT32_CONVERSION
- // truncate when overflow occurs.
- return static_cast<boost::int32_t>(static_cast<boost::uint32_t>(a * 20));
-#else
// This truncates large values without relying on undefined behaviour.
// For very large values of 'a' it is noticeably slower than the UB
@@ -143,15 +139,10 @@
}
// This slow truncation happens only in very unlikely cases.
- return a >= 0 ? static_cast<boost::uint32_t>(std::fmod(a * 20.0,
upperUnsignedLimit))
- : - static_cast<boost::uint32_t>(std::fmod( - a * 20.0,
upperUnsignedLimit));
-#endif
-}
-
-inline boost::int32_t Fixed16Mul(boost::int32_t a, boost::int32_t b)
-{
- // truncate when overflow occurs.
- return static_cast<boost::int32_t>((static_cast<boost::int64_t>(a) *
static_cast<boost::int64_t>(b) + 0x8000) >> 16);
+ return a >= 0 ?
+ static_cast<boost::uint32_t>(std::fmod(a * 20.0, upperUnsignedLimit))
+ :
+ -static_cast<boost::uint32_t>(std::fmod(-a * 20.0,
upperUnsignedLimit));
}
/// \brief
=== modified file 'libcore/SWFMatrix.cpp'
--- a/libcore/SWFMatrix.cpp 2008-11-28 08:23:30 +0000
+++ b/libcore/SWFMatrix.cpp 2008-12-29 17:18:53 +0000
@@ -28,12 +28,48 @@
#include "SWFMatrix.h"
#include "SWFStream.h" // for reading from SWF
#include "log.h"
+#include "utility.h"
#include <cmath>
#include <iomanip>
namespace gnash {
+#define TRUST_FLOAT_TO_UINT32_CONVERSION 1
+
+namespace {
+
+inline
+boost::int32_t DoubleToFixed16(double a)
+{
+#ifdef TRUST_FLOAT_TO_UINT32_CONVERSION
+ // truncate when overflow occurs.
+ return static_cast<boost::int32_t>(static_cast<boost::uint32_t>(a *
65536.0));
+#else
+ boost::int32_t b;
+ if (a >= 0)
+ {
+ b = static_cast<boost::uint32_t>(std::fmod(a * 65536.0, 4294967296.0));
+ }
+ else
+ {
+ b = -static_cast<boost::uint32_t>(std::fmod(-a * 65536.0,
4294967296.0));
+ }
+ return b;
+#endif
+}
+
+inline boost::int32_t
+Fixed16Mul(boost::int32_t a, boost::int32_t b)
+{
+ // truncate when overflow occurs.
+ return static_cast<boost::int32_t>(
+ (static_cast<boost::int64_t>(a) *
+ static_cast<boost::int64_t>(b) + 0x8000) >> 16);
+}
+
+} // anonymous namepace
+
SWFMatrix::SWFMatrix()
{
// Default to identity.
@@ -92,6 +128,24 @@
}
void
+SWFMatrix::transform(geometry::Point2d& p) const
+{
+ boost::int32_t t0 = Fixed16Mul(sx, p.x) + Fixed16Mul(shy, p.y) + tx;
+ boost::int32_t t1 = Fixed16Mul(shx,p.x) + Fixed16Mul(sy, p.y) + ty;
+ p.x = t0;
+ p.y = t1;
+}
+
+void
+SWFMatrix::transform(boost::int32_t& x, boost::int32_t& y) const
+{
+ boost::int32_t t0 = Fixed16Mul(sx, x) + Fixed16Mul(shy, y) + tx;
+ boost::int32_t t1 = Fixed16Mul(shx,x) + Fixed16Mul(sy, y) + ty;
+ x = t0;
+ y = t1;
+}
+
+void
SWFMatrix::set_identity()
// Set the SWFMatrix to identity.
{
=== modified file 'libcore/SWFMatrix.h'
--- a/libcore/SWFMatrix.h 2008-10-19 18:04:05 +0000
+++ b/libcore/SWFMatrix.h 2008-12-29 17:18:53 +0000
@@ -28,7 +28,6 @@
#include "Range2d.h" // for transforming Range2d<float>
#include "rect.h" // for rect
#include "Point2d.h" // for Point2d
-#include "utility.h" // for TRUST_FLOAT_TO_UINT32_CONVERSION
#include <iostream>
#include <boost/cstdint.hpp>
@@ -145,22 +144,10 @@
void read(SWFStream& in);
/// Transform a given point by our SWFMatrix
- void transform(geometry::Point2d& p) const
- {
- boost::int32_t t0 = Fixed16Mul(sx, p.x) + Fixed16Mul(shy, p.y) + tx;
- boost::int32_t t1 = Fixed16Mul(shx,p.x) + Fixed16Mul(sy, p.y) + ty;
- p.x = t0;
- p.y = t1;
- }
+ void transform(geometry::Point2d& p) const;
/// Transform the given point by our SWFMatrix.
- void transform(boost::int32_t& x, boost::int32_t& y) const
- {
- boost::int32_t t0 = Fixed16Mul(sx, x) + Fixed16Mul(shy, y) + tx;
- boost::int32_t t1 = Fixed16Mul(shx,x) + Fixed16Mul(sy, y) + ty;
- x = t0;
- y = t1;
- }
+ void transform(boost::int32_t& x, boost::int32_t& y) const;
/// Transform point 'p' by our SWFMatrix.
//
@@ -204,44 +191,6 @@
/// Return the determinant of this SWFMatrix in 32.32 fixed point format.
boost::int64_t determinant() const;
- inline boost::int32_t FloatToFixed16(float a)
- {
-#ifdef TRUST_FLOAT_TO_UINT32_CONVERSION
- // truncate when overflow occurs.
- return static_cast<boost::int32_t>(static_cast<boost::uint32_t>(a *
65536.0f));
-#else
- boost::int32_t b;
- if(a >= 0)
- {
- b = static_cast<boost::uint32_t>(std::fmod(a * 65536.0,
4294967296.0));
- }
- else
- {
- b = -static_cast<boost::uint32_t>(std::fmod(-a * 65536.0,
4294967296.0));
- }
- return b;
-#endif
- }
-
- inline boost::int32_t DoubleToFixed16(double a)
- {
-#ifdef TRUST_FLOAT_TO_UINT32_CONVERSION
- // truncate when overflow occurs.
- return static_cast<boost::int32_t>(static_cast<boost::uint32_t>(a *
65536.0));
-#else
- boost::int32_t b;
- if(a >= 0)
- {
- b = static_cast<boost::uint32_t>(std::fmod(a * 65536.0,
4294967296.0));
- }
- else
- {
- b = -static_cast<boost::uint32_t>(std::fmod(-a * 65536.0,
4294967296.0));
- }
- return b;
-#endif
- }
-
}; //end of SWFMatrix
inline bool operator== (const SWFMatrix& a, const SWFMatrix& b)
=== modified file 'libcore/swf/DefineButtonCxformTag.cpp'
--- a/libcore/swf/DefineButtonCxformTag.cpp 2008-11-07 16:05:23 +0000
+++ b/libcore/swf/DefineButtonCxformTag.cpp 2008-12-29 17:18:53 +0000
@@ -21,6 +21,7 @@
#include "movie_definition.h"
#include "DefineButtonTag.h"
#include "DefineButtonCxformTag.h"
+#include "utility.h"
namespace gnash {
namespace SWF {
=== modified file 'libcore/swf/DefineButtonSoundTag.cpp'
--- a/libcore/swf/DefineButtonSoundTag.cpp 2008-11-07 16:05:23 +0000
+++ b/libcore/swf/DefineButtonSoundTag.cpp 2008-12-29 17:18:53 +0000
@@ -18,12 +18,13 @@
//
#include "DefineButtonSoundTag.h"
-#include <vector>
#include "movie_definition.h"
#include "SoundInfoRecord.h"
#include "SWFStream.h"
#include "DefineButtonTag.h"
+#include "utility.h"
+#include <vector>
namespace gnash {
namespace SWF {
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r10489: Remove some UB, should fix behaviour on ARM platform.,
Benjamin Wolsey <=