aboutsummaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorMax Horn2010-10-30 21:27:42 +0000
committerMax Horn2010-10-30 21:27:42 +0000
commit44393b2dc8ba78342dcbb7df39eca2e9e1f6e429 (patch)
treeb5b2d7013d64ca317072453a7fbbc391174e2851 /sound
parentff34a778318355ffba2ee5700524fccba9fe5cf3 (diff)
downloadscummvm-rg350-44393b2dc8ba78342dcbb7df39eca2e9e1f6e429.tar.gz
scummvm-rg350-44393b2dc8ba78342dcbb7df39eca2e9e1f6e429.tar.bz2
scummvm-rg350-44393b2dc8ba78342dcbb7df39eca2e9e1f6e429.zip
ALL: Add code to help stop people from accidentally using "bad" APIs
A new header file common/forbidden.h is included by scummsys.h and it re-#defines numerous symbols like fopen(), fread(), system(), etc. with garbage, in order to provoke compile errors in any code using them. If a .cpp file really *must* use any of these (e.g. because it is a backend file), then these redefinitions can be disabled by #defining FORBIDDEN_SYMBOL_ALLOW_ALL as the first thing in the .cpp file. Whenever this is done, an explanatory comment should be added. Note that this system cannot catch all "bad" usages (notably the Lua code in the sword25 engine), as it can only work if scummsys.h is included. svn-id: r53961
Diffstat (limited to 'sound')
-rw-r--r--sound/decoders/flac.cpp3
-rw-r--r--sound/decoders/vorbis.cpp5
-rw-r--r--sound/softsynth/mt32/mt32_file.cpp18
-rw-r--r--sound/softsynth/mt32/mt32_file.h2
4 files changed, 21 insertions, 7 deletions
diff --git a/sound/decoders/flac.cpp b/sound/decoders/flac.cpp
index d01e0d0a79..65f3306106 100644
--- a/sound/decoders/flac.cpp
+++ b/sound/decoders/flac.cpp
@@ -23,6 +23,9 @@
*
*/
+// Disable symbol overrides for FILE as that is used in FLAC headers
+#define FORBIDDEN_SYMBOL_EXCEPTION_FILE
+
#include "sound/decoders/flac.h"
#ifdef USE_FLAC
diff --git a/sound/decoders/vorbis.cpp b/sound/decoders/vorbis.cpp
index 7673c53010..ee31bbc38d 100644
--- a/sound/decoders/vorbis.cpp
+++ b/sound/decoders/vorbis.cpp
@@ -23,6 +23,11 @@
*
*/
+// Disable symbol overrides for FILE and fseek as those are used in the
+// Vorbis headers.
+#define FORBIDDEN_SYMBOL_EXCEPTION_FILE
+#define FORBIDDEN_SYMBOL_EXCEPTION_fseek
+
#include "sound/decoders/vorbis.h"
#ifdef USE_VORBIS
diff --git a/sound/softsynth/mt32/mt32_file.cpp b/sound/softsynth/mt32/mt32_file.cpp
index f4eba73d33..ce5c2874c4 100644
--- a/sound/softsynth/mt32/mt32_file.cpp
+++ b/sound/softsynth/mt32/mt32_file.cpp
@@ -19,6 +19,12 @@
* IN THE SOFTWARE.
*/
+
+// FIXME: Disable symbol overrides so that we can use system headers.
+// But we *really* should get rid of this usage of FILE, fopen etc.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
+
#include <stdio.h>
#include "mt32emu.h"
@@ -37,15 +43,15 @@ namespace MT32Emu {
}
void ANSIFile::close() {
- fclose(fp);
+ fclose((FILE *)fp);
}
size_t ANSIFile::read(void *in, size_t size) {
- return fread(in, 1, size, fp);
+ return fread(in, 1, size, (FILE *)fp);
}
bool ANSIFile::readBit8u(Bit8u *in) {
- int c = fgetc(fp);
+ int c = fgetc((FILE *)fp);
if (c == EOF)
return false;
*in = (Bit8u)c;
@@ -69,11 +75,11 @@ namespace MT32Emu {
}
size_t ANSIFile::write(const void *out, size_t size) {
- return fwrite(out, 1, size, fp);
+ return fwrite(out, 1, size, (FILE *)fp);
}
bool ANSIFile::writeBit8u(Bit8u out) {
- return fputc(out, fp) != EOF;
+ return fputc(out, (FILE *)fp) != EOF;
}
bool File::writeBit16u(Bit16u out) {
@@ -103,6 +109,6 @@ namespace MT32Emu {
}
bool ANSIFile::isEOF() {
- return feof(fp) != 0;
+ return feof((FILE *)fp) != 0;
}
}
diff --git a/sound/softsynth/mt32/mt32_file.h b/sound/softsynth/mt32/mt32_file.h
index 27c8ccbe46..b311ad9626 100644
--- a/sound/softsynth/mt32/mt32_file.h
+++ b/sound/softsynth/mt32/mt32_file.h
@@ -49,7 +49,7 @@ public:
class ANSIFile: public File {
private:
- FILE *fp;
+ void *fp;
public:
bool open(const char *filename, OpenMode mode);
void close();