[Scummvm-cvs-logs] SF.net SVN: scummvm:[53961] scummvm/trunk

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sat Oct 30 23:27:43 CEST 2010


Revision: 53961
          http://scummvm.svn.sourceforge.net/scummvm/?rev=53961&view=rev
Author:   fingolfin
Date:     2010-10-30 21:27:42 +0000 (Sat, 30 Oct 2010)

Log Message:
-----------
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.

Modified Paths:
--------------
    scummvm/trunk/backends/fs/stdiostream.cpp
    scummvm/trunk/backends/midi/alsa.cpp
    scummvm/trunk/backends/midi/camd.cpp
    scummvm/trunk/backends/midi/coreaudio.cpp
    scummvm/trunk/backends/midi/coremidi.cpp
    scummvm/trunk/backends/midi/dmedia.cpp
    scummvm/trunk/backends/midi/seq.cpp
    scummvm/trunk/backends/midi/stmidi.cpp
    scummvm/trunk/backends/midi/timidity.cpp
    scummvm/trunk/backends/midi/windows.cpp
    scummvm/trunk/backends/platform/sdl/main.cpp
    scummvm/trunk/backends/platform/sdl/sdl.cpp
    scummvm/trunk/common/scummsys.h
    scummvm/trunk/engines/sword25/gfx/image/pngloader.cpp
    scummvm/trunk/engines/sword25/gfx/screenshot.cpp
    scummvm/trunk/gui/browser_osx.mm
    scummvm/trunk/sound/decoders/flac.cpp
    scummvm/trunk/sound/decoders/vorbis.cpp
    scummvm/trunk/sound/softsynth/mt32/mt32_file.cpp
    scummvm/trunk/sound/softsynth/mt32/mt32_file.h

Added Paths:
-----------
    scummvm/trunk/common/forbidden.h

Modified: scummvm/trunk/backends/fs/stdiostream.cpp
===================================================================
--- scummvm/trunk/backends/fs/stdiostream.cpp	2010-10-30 21:26:32 UTC (rev 53960)
+++ scummvm/trunk/backends/fs/stdiostream.cpp	2010-10-30 21:27:42 UTC (rev 53961)
@@ -23,6 +23,9 @@
  *
  */
 
+// Disable symbol overrides so that we can use FILE, fopen etc.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
 #include "backends/fs/stdiostream.h"
 
 StdioStream::StdioStream(void *handle) : _handle(handle) {

Modified: scummvm/trunk/backends/midi/alsa.cpp
===================================================================
--- scummvm/trunk/backends/midi/alsa.cpp	2010-10-30 21:26:32 UTC (rev 53960)
+++ scummvm/trunk/backends/midi/alsa.cpp	2010-10-30 21:27:42 UTC (rev 53961)
@@ -22,6 +22,9 @@
  * $Id$
  */
 
+// Disable symbol overrides so that we can use system headers.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
 #include "common/scummsys.h"
 
 #if defined(USE_ALSA)

Modified: scummvm/trunk/backends/midi/camd.cpp
===================================================================
--- scummvm/trunk/backends/midi/camd.cpp	2010-10-30 21:26:32 UTC (rev 53960)
+++ scummvm/trunk/backends/midi/camd.cpp	2010-10-30 21:27:42 UTC (rev 53961)
@@ -22,6 +22,9 @@
  * $Id$
  */
 
+// Disable symbol overrides so that we can use system headers.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
 #include "common/scummsys.h"
 
 #if defined(__amigaos4__)

Modified: scummvm/trunk/backends/midi/coreaudio.cpp
===================================================================
--- scummvm/trunk/backends/midi/coreaudio.cpp	2010-10-30 21:26:32 UTC (rev 53960)
+++ scummvm/trunk/backends/midi/coreaudio.cpp	2010-10-30 21:27:42 UTC (rev 53961)
@@ -24,6 +24,9 @@
 
 #ifdef MACOSX
 
+// Disable symbol overrides so that we can use system headers.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
 // HACK to disable deprecated warnings under Mac OS X 10.5.
 // Apple depracted the AUGraphNewNode & AUGraphGetNodeInfo APIs
 // in favor of the new AUGraphAddNode & AUGraphNodeInfo APIs.

Modified: scummvm/trunk/backends/midi/coremidi.cpp
===================================================================
--- scummvm/trunk/backends/midi/coremidi.cpp	2010-10-30 21:26:32 UTC (rev 53960)
+++ scummvm/trunk/backends/midi/coremidi.cpp	2010-10-30 21:27:42 UTC (rev 53961)
@@ -24,6 +24,9 @@
 
 #ifdef MACOSX
 
+// Disable symbol overrides so that we can use system headers.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
 #include "common/config-manager.h"
 #include "common/util.h"
 #include "sound/musicplugin.h"

Modified: scummvm/trunk/backends/midi/dmedia.cpp
===================================================================
--- scummvm/trunk/backends/midi/dmedia.cpp	2010-10-30 21:26:32 UTC (rev 53960)
+++ scummvm/trunk/backends/midi/dmedia.cpp	2010-10-30 21:27:42 UTC (rev 53961)
@@ -29,6 +29,9 @@
 
 #if defined(IRIX)
 
+// Disable symbol overrides so that we can use system headers.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
 #include "common/scummsys.h"
 #include "common/util.h"
 #include "common/config-manager.h"

Modified: scummvm/trunk/backends/midi/seq.cpp
===================================================================
--- scummvm/trunk/backends/midi/seq.cpp	2010-10-30 21:26:32 UTC (rev 53960)
+++ scummvm/trunk/backends/midi/seq.cpp	2010-10-30 21:27:42 UTC (rev 53961)
@@ -28,6 +28,9 @@
  *    both the QuickTime support and (vkeybd http://www.alsa-project.org/~iwai/alsa.html)
  */
 
+// Disable symbol overrides so that we can use system headers.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
 #include "common/scummsys.h"
 
 #if defined(USE_SEQ_MIDI)

Modified: scummvm/trunk/backends/midi/stmidi.cpp
===================================================================
--- scummvm/trunk/backends/midi/stmidi.cpp	2010-10-30 21:26:32 UTC (rev 53960)
+++ scummvm/trunk/backends/midi/stmidi.cpp	2010-10-30 21:27:42 UTC (rev 53961)
@@ -36,6 +36,9 @@
 
 #if defined __MINT__
 
+// Disable symbol overrides so that we can use system headers.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
 #include <osbind.h>
 #include "sound/mpu401.h"
 #include "common/util.h"

Modified: scummvm/trunk/backends/midi/timidity.cpp
===================================================================
--- scummvm/trunk/backends/midi/timidity.cpp	2010-10-30 21:26:32 UTC (rev 53960)
+++ scummvm/trunk/backends/midi/timidity.cpp	2010-10-30 21:27:42 UTC (rev 53961)
@@ -34,6 +34,9 @@
  *
  */
 
+// Disable symbol overrides so that we can use system headers.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
 #include "common/scummsys.h"
 
 #if defined(USE_TIMIDITY)

Modified: scummvm/trunk/backends/midi/windows.cpp
===================================================================
--- scummvm/trunk/backends/midi/windows.cpp	2010-10-30 21:26:32 UTC (rev 53960)
+++ scummvm/trunk/backends/midi/windows.cpp	2010-10-30 21:27:42 UTC (rev 53961)
@@ -24,6 +24,9 @@
 
 #if defined(WIN32) && !defined(_WIN32_WCE)
 
+// Disable symbol overrides so that we can use system headers.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 // winnt.h defines ARRAYSIZE, but we want our own one...

Modified: scummvm/trunk/backends/platform/sdl/main.cpp
===================================================================
--- scummvm/trunk/backends/platform/sdl/main.cpp	2010-10-30 21:26:32 UTC (rev 53960)
+++ scummvm/trunk/backends/platform/sdl/main.cpp	2010-10-30 21:27:42 UTC (rev 53961)
@@ -23,6 +23,8 @@
  *
  */
 
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
 // Fix for bug #2895217 "MSVC compilation broken with r47595":
 // We need to keep this on top of the "common/scummsys.h" include,
 // otherwise we will get errors about the windows headers redefining

Modified: scummvm/trunk/backends/platform/sdl/sdl.cpp
===================================================================
--- scummvm/trunk/backends/platform/sdl/sdl.cpp	2010-10-30 21:26:32 UTC (rev 53960)
+++ scummvm/trunk/backends/platform/sdl/sdl.cpp	2010-10-30 21:27:42 UTC (rev 53961)
@@ -23,6 +23,9 @@
  *
  */
 
+// Disable symbol overrides so that we can use system headers.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
 #if defined(WIN32)
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
@@ -79,7 +82,7 @@
 #endif
 
 #if defined(MACOSX) || defined(IPHONE)
-#include "CoreFoundation/CoreFoundation.h"
+#include <CoreFoundation/CoreFoundation.h>
 #endif
 
 

Added: scummvm/trunk/common/forbidden.h
===================================================================
--- scummvm/trunk/common/forbidden.h	                        (rev 0)
+++ scummvm/trunk/common/forbidden.h	2010-10-30 21:27:42 UTC (rev 53961)
@@ -0,0 +1,147 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef COMMON_FORBIDDEN_H
+#define COMMON_FORBIDDEN_H
+
+
+//
+// Backend files may #define FORBIDDEN_SYMBOL_ALLOW_ALL if they
+// have to access functions like fopen, fread etc.
+// Regular code, esp. code in engines/, should never do that.
+//
+
+#ifndef FORBIDDEN_SYMBOL_ALLOW_ALL
+
+#define FORBIDDEN_SYMBOL_REPLACEMENT	FORBIDDEN SYMBOL!
+
+
+/*
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_printf
+#undef printf
+#define printf	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fprintf
+#undef fprintf
+#define fprintf	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+*/
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_FILE
+#undef FILE
+#define FILE	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fopen
+#undef fopen
+#define fopen(a,b)	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fclose
+#undef fclose
+#define fclose(a)	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fread
+#undef fread
+#define fread(a,b,c,d)	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fwrite
+#undef fwrite
+#define fwrite(a,b,c,d)	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fseek
+#undef fseek
+#define fseek(a,b,c)	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_ftell
+#undef ftell
+#define ftell(a)	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_feof
+#undef feof
+#define feof(a)	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fgetc
+#undef fgetc
+#define fgetc(a)	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_fputc
+#undef fputc
+#define fputc(a,b)	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_setjmp
+#undef setjmp
+#define setjmp(a)	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_longjmp
+#undef longjmp
+#define longjmp(a,b)	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_system
+#undef system
+#define system(a)	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+
+/*
+time_t
+
+time
+
+difftime
+
+mktime
+
+localtime
+
+clock
+
+gmtime
+
+system
+
+remove
+
+setlocale
+
+setvbuf
+*/
+
+#endif
+
+
+#endif


Property changes on: scummvm/trunk/common/forbidden.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Modified: scummvm/trunk/common/scummsys.h
===================================================================
--- scummvm/trunk/common/scummsys.h	2010-10-30 21:26:32 UTC (rev 53960)
+++ scummvm/trunk/common/scummsys.h	2010-10-30 21:27:42 UTC (rev 53961)
@@ -437,5 +437,6 @@
 	typedef uint16 OverlayColor;
 #endif
 
+#include <common/forbidden.h>
 
 #endif

Modified: scummvm/trunk/engines/sword25/gfx/image/pngloader.cpp
===================================================================
--- scummvm/trunk/engines/sword25/gfx/image/pngloader.cpp	2010-10-30 21:26:32 UTC (rev 53960)
+++ scummvm/trunk/engines/sword25/gfx/image/pngloader.cpp	2010-10-30 21:27:42 UTC (rev 53961)
@@ -32,6 +32,9 @@
  *
  */
 
+// Disable symbol overrides so that we can use png.h
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
 #include "sword25/gfx/image/image.h"
 #include "sword25/gfx/image/pngloader.h"
 #include <png.h>

Modified: scummvm/trunk/engines/sword25/gfx/screenshot.cpp
===================================================================
--- scummvm/trunk/engines/sword25/gfx/screenshot.cpp	2010-10-30 21:26:32 UTC (rev 53960)
+++ scummvm/trunk/engines/sword25/gfx/screenshot.cpp	2010-10-30 21:27:42 UTC (rev 53961)
@@ -32,6 +32,9 @@
  *
  */
 
+// Disable symbol overrides so that we can use png.h
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
 #define BS_LOG_PREFIX "SCREENSHOT"
 
 #include "common/system.h"

Modified: scummvm/trunk/gui/browser_osx.mm
===================================================================
--- scummvm/trunk/gui/browser_osx.mm	2010-10-30 21:26:32 UTC (rev 53960)
+++ scummvm/trunk/gui/browser_osx.mm	2010-10-30 21:27:42 UTC (rev 53961)
@@ -22,6 +22,9 @@
  * $Id$
  */
 
+// Disable symbol overrides so that we can use system headers
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
 #include "gui/browser.h"
 #include "gui/GuiManager.h"
 #include "gui/ListWidget.h"

Modified: scummvm/trunk/sound/decoders/flac.cpp
===================================================================
--- scummvm/trunk/sound/decoders/flac.cpp	2010-10-30 21:26:32 UTC (rev 53960)
+++ scummvm/trunk/sound/decoders/flac.cpp	2010-10-30 21:27:42 UTC (rev 53961)
@@ -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

Modified: scummvm/trunk/sound/decoders/vorbis.cpp
===================================================================
--- scummvm/trunk/sound/decoders/vorbis.cpp	2010-10-30 21:26:32 UTC (rev 53960)
+++ scummvm/trunk/sound/decoders/vorbis.cpp	2010-10-30 21:27:42 UTC (rev 53961)
@@ -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

Modified: scummvm/trunk/sound/softsynth/mt32/mt32_file.cpp
===================================================================
--- scummvm/trunk/sound/softsynth/mt32/mt32_file.cpp	2010-10-30 21:26:32 UTC (rev 53960)
+++ scummvm/trunk/sound/softsynth/mt32/mt32_file.cpp	2010-10-30 21:27:42 UTC (rev 53961)
@@ -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 @@
 	}
 
 	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 @@
 	}
 
 	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 @@
 	}
 
 	bool ANSIFile::isEOF() {
-		return feof(fp) != 0;
+		return feof((FILE *)fp) != 0;
 	}
 }

Modified: scummvm/trunk/sound/softsynth/mt32/mt32_file.h
===================================================================
--- scummvm/trunk/sound/softsynth/mt32/mt32_file.h	2010-10-30 21:26:32 UTC (rev 53960)
+++ scummvm/trunk/sound/softsynth/mt32/mt32_file.h	2010-10-30 21:27:42 UTC (rev 53961)
@@ -49,7 +49,7 @@
 
 class ANSIFile: public File {
 private:
-	FILE *fp;
+	void *fp;
 public:
 	bool open(const char *filename, OpenMode mode);
 	void close();


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list