~ubuntu-branches/ubuntu/utopic/fceux/utopic

« back to all changes in this revision

Viewing changes to debian/patches/0001-Use-C-11-standard-static-assertion-functionality.patch

  • Committer: Package Import Robot
  • Author(s): Joe Nahmias
  • Date: 2014-03-02 19:22:04 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140302192204-9f0aehi5stfnhn7d
Tags: 2.2.2+dfsg0-1
* Imported Upstream version 2.2.2
  + remove patches merged upstream; refresh remaining
  + remove windows compiled help files and non-free Visual C files
* Use C++11 standard static assertion functionality
* fix upstream installation of support files
* New patch 0004-ignore-missing-windows-help-CHM-file.patch
* update d/copyright for new, renamed, deleted files
* d/control: bump std-ver to 3.9.5, no changes needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
From: Joe Nahmias <joe@nahmias.net>
 
2
Date: Sun, 2 Mar 2014 13:44:53 -0500
 
3
Subject: Use C++11 standard static assertion functionality
 
4
 
 
5
Use static_assert() provided by MSVC (>=2010) [released on 2010-04-12]
 
6
and gcc (>=4.3) [released on 2008-03-05].  See also:
 
7
<http://www.pixelbeat.org/programming/gcc/static_assert.html>
 
8
 
 
9
Change all callers to provide an error message if the assertion fails as
 
10
required by the standard.
 
11
---
 
12
 SConstruct         |  4 ++++
 
13
 src/lua-engine.cpp |  4 ++--
 
14
 src/types-des.h    |  4 ----
 
15
 src/types.h        | 13 +++++++++++--
 
16
 src/utils/endian.h |  4 ++--
 
17
 5 files changed, 19 insertions(+), 10 deletions(-)
 
18
 
 
19
diff --git a/SConstruct b/SConstruct
 
20
index 4d5b446..e834d71 100644
 
21
--- a/SConstruct
 
22
+++ b/SConstruct
 
23
@@ -77,6 +77,10 @@ if env['PLATFORM'] == 'cygwin':
 
24
   env.Append(LINKFLAGS = " -mno-cygwin")
 
25
   env['LIBS'] = ['wsock32'];
 
26
 
 
27
+# tell g++ to support c++0x, used for static_assert()
 
28
+if env['CXX'] == 'g++':
 
29
+  env.Append(CXXFLAGS = "-std=c++0x")
 
30
+
 
31
 if env['PLATFORM'] == 'win32':
 
32
   env.Append(CPPPATH = [".", "drivers/win/", "drivers/common/", "drivers/", "drivers/win/zlib", "drivers/win/directx", "drivers/win/lua/include"])
 
33
   env.Append(CPPDEFINES = ["PSS_STYLE=2", "WIN32", "_USE_SHARED_MEMORY_", "NETWORK", "FCEUDEF_DEBUGGER", "NOMINMAX", "NEED_MINGW_HACKS", "_WIN32_IE=0x0600"])
 
34
diff --git a/src/lua-engine.cpp b/src/lua-engine.cpp
 
35
index 53774f7..0d0fd0e 100644
 
36
--- a/src/lua-engine.cpp
 
37
+++ b/src/lua-engine.cpp
 
38
@@ -241,7 +241,7 @@ static const char* luaCallIDStrings [] =
 
39
 };
 
40
 
 
41
 //make sure we have the right number of strings
 
42
-CTASSERT(sizeof(luaCallIDStrings)/sizeof(*luaCallIDStrings) == LUACALL_COUNT)
 
43
+CTASSERT(sizeof(luaCallIDStrings)/sizeof(*luaCallIDStrings) == LUACALL_COUNT, "luaCallIDStrings doesn't have the correct number of strings");
 
44
 
 
45
 static const char* luaMemHookTypeStrings [] =
 
46
 {
 
47
@@ -255,7 +255,7 @@ static const char* luaMemHookTypeStrings [] =
 
48
 };
 
49
 
 
50
 //make sure we have the right number of strings
 
51
-CTASSERT(sizeof(luaMemHookTypeStrings)/sizeof(*luaMemHookTypeStrings) ==  LUAMEMHOOK_COUNT)
 
52
+CTASSERT(sizeof(luaMemHookTypeStrings)/sizeof(*luaMemHookTypeStrings) ==  LUAMEMHOOK_COUNT, "luaMemHookTypeStrings doesn't have the correct number of strings");
 
53
 
 
54
 static char* rawToCString(lua_State* L, int idx=0);
 
55
 static const char* toCString(lua_State* L, int idx=0);
 
56
diff --git a/src/types-des.h b/src/types-des.h
 
57
index e94536b..76cd2d9 100644
 
58
--- a/src/types-des.h
 
59
+++ b/src/types-des.h
 
60
@@ -442,10 +442,6 @@ char (*BLAHBLAHBLAH( UNALIGNED T (&)[N] ))[N];
 
61
 //B32(10000000,11111111,10101010,01010101) = 2164238933
 
62
 //---------------------------
 
63
 
 
64
-#ifndef CTASSERT
 
65
-#define        CTASSERT(x)             typedef char __assert ## y[(x) ? 1 : -1]
 
66
-#endif
 
67
-
 
68
 static const char hexValid[23] = {"0123456789ABCDEFabcdef"};
 
69
 
 
70
 
 
71
diff --git a/src/types.h b/src/types.h
 
72
index fca8d8f..d44730c 100644
 
73
--- a/src/types.h
 
74
+++ b/src/types.h
 
75
@@ -128,8 +128,17 @@ typedef uint32_t uint32;
 
76
 typedef void (*writefunc)(uint32 A, uint8 V);
 
77
 typedef uint8 (*readfunc)(uint32 A);
 
78
 
 
79
-#ifndef CTASSERT
 
80
-#define CTASSERT(x)  typedef char __assert ## y[(x) ? 1 : -1];
 
81
+// Use C++11 static_assert(), if available
 
82
+// See: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1720.html
 
83
+#if 1600 <= _MSC_VER
 
84
+   // Visual Studio >= 2010
 
85
+#  define CTASSERT(expr, msg) static_assert(expr, msg)
 
86
+#elif ( 4 < __GNUC__ || (4 == __GNUC__ && 3 <= __GNUC_MINOR__) ) \
 
87
+  && defined __GXX_EXPERIMENTAL_CXX0X__
 
88
+   // g++ >= 4.3  (with -std=c++0x)
 
89
+#  define CTASSERT(expr, msg) static_assert(expr, msg)
 
90
+#else
 
91
+#  define CTASSERT(expr,msg) typedef static char __assert_ ## msg[(expr) ? 1 : -1];
 
92
 #endif
 
93
 
 
94
 #include "utils/endian.h"
 
95
diff --git a/src/utils/endian.h b/src/utils/endian.h
 
96
index 5bdbcde..6928d1c 100644
 
97
--- a/src/utils/endian.h
 
98
+++ b/src/utils/endian.h
 
99
@@ -82,7 +82,7 @@ inline int read_double_le(double *Bufo, EMUFILE*is) { uint64 temp; int ret = rea
 
100
 template<typename T>
 
101
 int readle(T *Bufo, EMUFILE*is)
 
102
 {
 
103
-       CTASSERT(sizeof(T)==1||sizeof(T)==2||sizeof(T)==4||sizeof(T)==8);
 
104
+       CTASSERT(sizeof(T)==1||sizeof(T)==2||sizeof(T)==4||sizeof(T)==8, "readle() called with bad Bufo size");
 
105
        switch(sizeof(T)) {
 
106
                case 1: return read8le((uint8*)Bufo,is);
 
107
                case 2: return read16le((uint16*)Bufo,is);
 
108
@@ -96,7 +96,7 @@ int readle(T *Bufo, EMUFILE*is)
 
109
 template<typename T>
 
110
 int writele(T *Bufo, EMUFILE*os)
 
111
 {
 
112
-       CTASSERT(sizeof(T)==1||sizeof(T)==2||sizeof(T)==4||sizeof(T)==8);
 
113
+       CTASSERT(sizeof(T)==1||sizeof(T)==2||sizeof(T)==4||sizeof(T)==8, "writele() called with bad Bufo size");
 
114
        switch(sizeof(T)) {
 
115
                case 1: return write8le(*(uint8*)Bufo,os);
 
116
                case 2: return write16le(*(uint16*)Bufo,os);