[Scummvm-cvs-logs] SF.net SVN: scummvm: [27901] scummex/branches/gsoc2007-gameresbrowser
zbychs at users.sourceforge.net
zbychs at users.sourceforge.net
Wed Jul 4 21:20:58 CEST 2007
Revision: 27901
http://scummvm.svn.sourceforge.net/scummvm/?rev=27901&view=rev
Author: zbychs
Date: 2007-07-04 12:20:57 -0700 (Wed, 04 Jul 2007)
Log Message:
-----------
Added some asserts to be extra safe. Still hunting the segfaults.
Modified Paths:
--------------
scummex/branches/gsoc2007-gameresbrowser/src/core/FileTypeRecognizer.h
scummex/branches/gsoc2007-gameresbrowser/src/core/guid.cpp
scummex/branches/gsoc2007-gameresbrowser/src/core/guid.h
scummex/branches/gsoc2007-gameresbrowser/src/core/pinslot.cpp
scummex/branches/gsoc2007-gameresbrowser/src/core/pinslot.h
scummex/branches/gsoc2007-gameresbrowser/src/core/pinslot_detail.h
scummex/branches/gsoc2007-gameresbrowser/src/core/plugin_detail.h
scummex/branches/gsoc2007-gameresbrowser/src/core/safe_static.h
scummex/branches/gsoc2007-gameresbrowser/src/core/tostring.h
scummex/branches/gsoc2007-gameresbrowser/src/gui/MainForm.cpp
scummex/branches/gsoc2007-gameresbrowser/src/plugins/FileTypeRecognizer.cpp
scummex/branches/gsoc2007-gameresbrowser/src/plugins/ftregistry.cpp
scummex/branches/gsoc2007-gameresbrowser/vc8/core/core.vcproj
scummex/branches/gsoc2007-gameresbrowser/vc8/plugins/plugins.vcproj
Modified: scummex/branches/gsoc2007-gameresbrowser/src/core/FileTypeRecognizer.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/FileTypeRecognizer.h 2007-07-04 16:48:58 UTC (rev 27900)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/FileTypeRecognizer.h 2007-07-04 19:20:57 UTC (rev 27901)
@@ -48,7 +48,7 @@
/////////////////////////////////////////////////////////////////////////////
struct RecognizedFileType {
- static RecognizedFileType NotRecognized;
+ static const RecognizedFileType& NotRecognized();
FileTypeMatch _match;
BGUID _fileTypeGUID;
@@ -75,7 +75,7 @@
typedef std::list<BGUID> guid_list;
struct ResolvedFileTypeParsers {
- static ResolvedFileTypeParsers NoParsers;
+ static const ResolvedFileTypeParsers& NoParsers();
ResolvedParsersPriority _priority;
guid_list _parserGUIDs;
Modified: scummex/branches/gsoc2007-gameresbrowser/src/core/guid.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/guid.cpp 2007-07-04 16:48:58 UTC (rev 27900)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/guid.cpp 2007-07-04 19:20:57 UTC (rev 27901)
@@ -15,15 +15,14 @@
//
// Concrete interfaces should inherit GUIDs from their super-interfaces.
+#include "debugmem.h"
+
namespace Browser {
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
-/*static*/ const BGUID& BGUID::Unknown() {
- static BGUID unknown("Unknown Facility", "Unknown GUID", 1);
- return unknown;
-}
+SAFE_CLASS_STATIC(BGUID, Unknown, BGUID, ("Unknown Facility", "Unknown GUID", 1))
BGUID::BGUID(std::string _facility, std::string _identifier, int _version)
: facility(_facility), identifier(_identifier), version(_version) {}
Modified: scummex/branches/gsoc2007-gameresbrowser/src/core/guid.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/guid.h 2007-07-04 16:48:58 UTC (rev 27900)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/guid.h 2007-07-04 19:20:57 UTC (rev 27901)
@@ -11,6 +11,8 @@
#include <string>
#include <ostream>
+#include "safe_static.h"
+
// Plugins have GUIDs
// ObjectPlugins have GUIDs
// Objects have GUIDs
@@ -55,6 +57,7 @@
return /*clazz::*/static_GUID(); \
} \
static const BGUID& static_GUID() { \
+ ASSERT_STATICS_ALLOWED(); \
static BGUID guid(facility, name, version); \
return guid; \
}
Modified: scummex/branches/gsoc2007-gameresbrowser/src/core/pinslot.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/pinslot.cpp 2007-07-04 16:48:58 UTC (rev 27900)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/pinslot.cpp 2007-07-04 19:20:57 UTC (rev 27901)
@@ -9,6 +9,8 @@
#include "pinslot.h"
+#include <iostream>
+
#include "debugmem.h" //turn memory debugging ON
@@ -126,6 +128,60 @@
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
+// InitializedObjects
+
+bool InitializedObjects::_allow_creation = true;
+InitializedObjects* InitializedObjects::_instance = NULL;
+
+/*static*/ InitializedObjects* InitializedObjects::get() {
+ if (!_instance) {
+ ASSERT(_allow_creation);
+ _allow_creation = false;
+ _instance = new InitializedObjects();
+ }
+
+ return _instance;
+}
+
+/*static*/ void InitializedObjects::release() {
+ if (_instance)
+ delete _instance;
+ _instance = NULL;
+}
+
+ std::set<BObject*> _initializedObjects;
+
+void InitializedObjects::registerObject(BObject* obj) {
+ std::set<BObject*>::const_iterator i;
+ i = _initializedObjects.find(obj);
+ ASSERT(i == _initializedObjects.end());
+
+ _initializedObjects.insert(obj);
+}
+
+void InitializedObjects::unregisterObject(BObject* obj) {
+ std::set<BObject*>::const_iterator i;
+ i = _initializedObjects.find(obj);
+ ASSERT(i != _initializedObjects.end());
+
+ _initializedObjects.erase(obj);
+}
+
+void InitializedObjects::report() {
+ std::cout << "------------ DUMPING INITIALIZED OBJECTS -------------" << std::endl;
+ std::cout << "OBJECTS COUNT: " << _initializedObjects.size() << std::endl;
+
+ std::set<BObject*>::const_iterator i;
+ for (i = _initializedObjects.begin(); i != _initializedObjects.end(); ++i) {
+ BObject* obj = *i;
+ std::cout << obj->get_GUID().identifier << ": " << obj << std::endl;
+ }
+
+ std::cout << "---------- DONE DUMPING INITIALIZED OBJECTS ----------" << std::endl;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
// BObject is a reference counted object that is capable of holding pins and slots.
//do not call manually!
Modified: scummex/branches/gsoc2007-gameresbrowser/src/core/pinslot.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/pinslot.h 2007-07-04 16:48:58 UTC (rev 27900)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/pinslot.h 2007-07-04 19:20:57 UTC (rev 27901)
@@ -10,6 +10,8 @@
#define ZZ_PINSLOT_H
#include <map> // for PinSlotDescs
+#include <set> // for InitializedObjects
+
#include "guid.h"
#include "tostring.h"
@@ -217,6 +219,7 @@
return static_desc();
}
static const _PinSlotDesc& static_desc() {
+ ASSERT_STATICS_ALLOWED();
static _PinSlotDesc DESC(toString(I::static_GUID().identifier) + "-Pin",
I::static_GUID(), flags);
return DESC;
@@ -275,6 +278,7 @@
return static_desc();
}
static const _PinSlotDesc& static_desc() {
+ ASSERT_STATICS_ALLOWED();
static _PinSlotDesc DESC(toString(I::static_GUID().identifier) + "-Slot",
I::static_GUID(), flags);
return DESC;
@@ -340,8 +344,31 @@
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
+// For debug:
+
+class BObject;
+
+class InitializedObjects {
+ static bool _allow_creation;
+ static InitializedObjects* _instance;
+ InitializedObjects() {}
+
+ std::set<BObject*> _initializedObjects;
+public:
+ static InitializedObjects* get();
+ static void release();
+
+ void registerObject(BObject* obj);
+ void unregisterObject(BObject* obj);
+
+ void report();
+};
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
// BObject is a reference counted object that is capable of holding pins and slots.
+
class ObjectChain;
class BObject : public RCObject, public GUIDObject {
@@ -367,6 +394,7 @@
//when overriding allways run super
virtual void initialize() {
+ InitializedObjects::get()->registerObject(this);
RCObject::initialize();
init_pins_slots();
}
@@ -375,6 +403,7 @@
virtual void destroy() {
delete_pins_slots();
RCObject::destroy();
+ InitializedObjects::get()->unregisterObject(this);
}
//other lifecycle methods:
@@ -430,11 +459,13 @@
}
static const PinSlotDescs& static_pins() {
+ ASSERT_STATICS_ALLOWED();
static PinSlotDescs descs;
return descs;
}
static const PinSlotDescs& static_slots() {
+ ASSERT_STATICS_ALLOWED();
static PinSlotDescs descs;
return descs;
}
Modified: scummex/branches/gsoc2007-gameresbrowser/src/core/pinslot_detail.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/pinslot_detail.h 2007-07-04 16:48:58 UTC (rev 27900)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/pinslot_detail.h 2007-07-04 19:20:57 UTC (rev 27901)
@@ -48,6 +48,7 @@
return this_class::static_desc(); \
} \
static const BObjectDesc& static_desc() { \
+ ASSERT_STATICS_ALLOWED(); \
static BObjectDesc desc(THIS_CLASS_NAME, this_class::static_GUID(), flags, \
this_class::static_pins(), this_class::static_slots()); \
return desc; \
@@ -64,11 +65,13 @@
#define PIN_DESCS_EX(clazz) \
const PinSlotDescs& clazz::static_pins() { \
+ ASSERT_STATICS_ALLOWED(); \
static PinSlotDescs descs( \
PinSlotDescs(true).insert_copy(clazz::super_class::static_pins())
#define SLOT_DESCS_EX(clazz) \
const PinSlotDescs& clazz::static_slots() { \
+ ASSERT_STATICS_ALLOWED(); \
static PinSlotDescs descs( \
PinSlotDescs(true).insert_copy(clazz::super_class::static_pins())
@@ -76,11 +79,13 @@
#define PIN_DESCS \
static const PinSlotDescs& static_pins() { \
+ ASSERT_STATICS_ALLOWED(); \
static PinSlotDescs descs( \
PinSlotDescs(true).insert_copy(super_class::static_pins())
#define SLOT_DESCS \
static const PinSlotDescs& static_slots() { \
+ ASSERT_STATICS_ALLOWED(); \
static PinSlotDescs descs( \
PinSlotDescs(true).insert_copy(super_class::static_pins())
Modified: scummex/branches/gsoc2007-gameresbrowser/src/core/plugin_detail.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/plugin_detail.h 2007-07-04 16:48:58 UTC (rev 27900)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/plugin_detail.h 2007-07-04 19:20:57 UTC (rev 27901)
@@ -34,6 +34,7 @@
virtual const ObjectPlugins& getObjectPlugins() const { \
typedef std::pair<const BGUID, ObjectPlugin*> the_pair; \
typedef std::pair<ObjectPlugins::iterator, bool> ret_pair; \
+ ASSERT_STATICS_ALLOWED(); \
static ObjectPlugins plugins;
#define PLUGGED_OBJECT(ObjectClazz) \
@@ -48,6 +49,7 @@
}; \
\
const Plugin& AccName() { \
+ ASSERT_STATICS_ALLOWED(); \
static PluginClazz plugin; \
return plugin; \
}
Modified: scummex/branches/gsoc2007-gameresbrowser/src/core/safe_static.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/safe_static.h 2007-07-04 16:48:58 UTC (rev 27900)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/safe_static.h 2007-07-04 19:20:57 UTC (rev 27901)
@@ -7,6 +7,15 @@
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
+namespace Browser {
+extern bool statics_allowed;
+
+void set_statics_not_allowed();
+}
+
+#define ASSERT_STATICS_ALLOWED() \
+ ASSERT( Browser::statics_allowed )
+
#define EMPTY_INITIALIZER
#define SAFE_STATIC_DECL(name, type) \
@@ -14,10 +23,21 @@
#define SAFE_STATIC(name, type, initialisation) \
const type& name() { \
+ ASSERT_STATICS_ALLOWED(); \
static type safe initialisation; \
return safe; \
}
+#define SAFE_CLASS_STATIC_DECL(clazz, name, type) \
+ const type& name();
+
+#define SAFE_CLASS_STATIC(clazz, name, type, initialisation) \
+ const type& clazz::name() { \
+ ASSERT_STATICS_ALLOWED(); \
+ static type safe initialisation; \
+ return safe; \
+ }
+
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
Modified: scummex/branches/gsoc2007-gameresbrowser/src/core/tostring.h
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/core/tostring.h 2007-07-04 16:48:58 UTC (rev 27900)
+++ scummex/branches/gsoc2007-gameresbrowser/src/core/tostring.h 2007-07-04 19:20:57 UTC (rev 27901)
@@ -11,7 +11,6 @@
#include <string>
#include <sstream> // only for implementation
-//struct wxString;
#include <wx/string.h>
namespace Browser {
Modified: scummex/branches/gsoc2007-gameresbrowser/src/gui/MainForm.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/gui/MainForm.cpp 2007-07-04 16:48:58 UTC (rev 27900)
+++ scummex/branches/gsoc2007-gameresbrowser/src/gui/MainForm.cpp 2007-07-04 19:20:57 UTC (rev 27901)
@@ -20,6 +20,8 @@
#include "oregistry.h"
#include "VirtualNode.h"
+#include "safe_static.h"
+
#include "debugmem.h"
using namespace Browser;
@@ -69,6 +71,11 @@
ExplorationTree::release();
FileTypeRegistry::release();
ObjectRegistry::release();
+
+ InitializedObjects::get()->report();
+ InitializedObjects::release();
+
+ set_statics_not_allowed();
}
void MainForm::CreateGUIControls() {
Modified: scummex/branches/gsoc2007-gameresbrowser/src/plugins/FileTypeRecognizer.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/FileTypeRecognizer.cpp 2007-07-04 16:48:58 UTC (rev 27900)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/FileTypeRecognizer.cpp 2007-07-04 19:20:57 UTC (rev 27901)
@@ -18,10 +18,12 @@
/////////////////////////////////////////////////////////////////////////////
// Static fields
-RecognizedFileType RecognizedFileType::NotRecognized(NO_MATCH, BGUID::Unknown());
+SAFE_CLASS_STATIC(RecognizedFileType, NotRecognized, RecognizedFileType,
+ (NO_MATCH, BGUID::Unknown()) )
SAFE_STATIC(_empty_guid_list, guid_list, EMPTY_INITIALIZER)
-ResolvedFileTypeParsers ResolvedFileTypeParsers::NoParsers(NO_PARSERS, _empty_guid_list());
+SAFE_CLASS_STATIC(ResolvedFileTypeParsers, NoParsers, ResolvedFileTypeParsers,
+ (NO_PARSERS, _empty_guid_list()) )
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
@@ -36,9 +38,10 @@
ResolvedFileTypeParsers BinaryFileTypeParserResolver::resolve(const BGUID& fileType) {
guid_list parsers;
if (fileType != binaryFileType())
- return ResolvedFileTypeParsers::NoParsers;
+ return ResolvedFileTypeParsers::NoParsers();
//FIXME: this is temporary
+ ASSERT_STATICS_ALLOWED();
static BGUID filePresenterGUID("CoreObjects", "FilePresenter", 1);
parsers.push_back(filePresenterGUID);
@@ -57,11 +60,11 @@
chain.addObject( _this );
chain.connect(_file, _this, IFile::static_GUID());
if (!chain.realize())
- return RecognizedFileType::NotRecognized;
+ return RecognizedFileType::NotRecognized();
IFile* ifile = _fileSlot->getInterface();
if (!ifile)
- return RecognizedFileType::NotRecognized;
+ return RecognizedFileType::NotRecognized();
RecognizedFileType recognized = doRecognize(file, ifile);
@@ -76,14 +79,14 @@
RecognizedFileType BMPFileTypeRecognizer::doRecognize(VirtualFile* file, IFile* ifile) {
Common::SeekableReadStream* stream = ifile->getStream();
if (!stream)
- return RecognizedFileType::NotRecognized;
+ return RecognizedFileType::NotRecognized();
stream->seek(0, SEEK_SET);
byte b = stream->readByte();
byte m = stream->readByte();
if ( b != 'B' || m != 'M' )
- return RecognizedFileType::NotRecognized;
+ return RecognizedFileType::NotRecognized();
return RecognizedFileType(IDEAL_MATCH, bmpFileType());
}
@@ -92,11 +95,13 @@
/////////////////////////////////////////////////////////////////////////////
ResolvedFileTypeParsers BMPFileTypeParserResolver::resolve(const BGUID& fileType) {
- guid_list parsers;
if (fileType != bmpFileType())
- return ResolvedFileTypeParsers(NO_PARSERS, parsers);
+ return ResolvedFileTypeParsers::NoParsers();
+ guid_list parsers;
+
//FIXME: this is temporary
+ ASSERT_STATICS_ALLOWED();
static BGUID bmpParserGUID("CoreObjects", "BMPParser", 1);
parsers.push_back(bmpParserGUID);
static BGUID filePresenterGUID("CoreObjects", "FilePresenter", 1);
Modified: scummex/branches/gsoc2007-gameresbrowser/src/plugins/ftregistry.cpp
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/src/plugins/ftregistry.cpp 2007-07-04 16:48:58 UTC (rev 27900)
+++ scummex/branches/gsoc2007-gameresbrowser/src/plugins/ftregistry.cpp 2007-07-04 19:20:57 UTC (rev 27901)
@@ -95,7 +95,7 @@
}
ResolvedFileTypeParsers FileTypeRegistry::resolveParsers(const BGUID& fileType) {
- ResolvedFileTypeParsers bestParsers(ResolvedFileTypeParsers::NoParsers);
+ ResolvedFileTypeParsers bestParsers(ResolvedFileTypeParsers::NoParsers());
object_list::iterator i;
for (i = _resolvers.begin(); i != _resolvers.end(); ++i) {
Modified: scummex/branches/gsoc2007-gameresbrowser/vc8/core/core.vcproj
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/vc8/core/core.vcproj 2007-07-04 16:48:58 UTC (rev 27900)
+++ scummex/branches/gsoc2007-gameresbrowser/vc8/core/core.vcproj 2007-07-04 19:20:57 UTC (rev 27901)
@@ -178,6 +178,10 @@
>
</File>
<File
+ RelativePath="..\..\src\core\safe_static.cpp"
+ >
+ </File>
+ <File
RelativePath="..\..\src\core\stdafx.cpp"
>
<FileConfiguration
@@ -305,6 +309,14 @@
RelativePath="..\..\src\core\common\stream.h"
>
</File>
+ <File
+ RelativePath="..\..\src\core\common\xorstream.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\core\common\xorstream.h"
+ >
+ </File>
</Filter>
<File
RelativePath="..\..\src\core\ReadMe.txt"
Modified: scummex/branches/gsoc2007-gameresbrowser/vc8/plugins/plugins.vcproj
===================================================================
--- scummex/branches/gsoc2007-gameresbrowser/vc8/plugins/plugins.vcproj 2007-07-04 16:48:58 UTC (rev 27900)
+++ scummex/branches/gsoc2007-gameresbrowser/vc8/plugins/plugins.vcproj 2007-07-04 19:20:57 UTC (rev 27901)
@@ -237,6 +237,30 @@
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
+ <Filter
+ Name="scumm"
+ >
+ <File
+ RelativePath="..\..\src\plugins\scumm\resource.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\plugins\scumm\resource.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\plugins\scumm\ScummRecognizer.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\plugins\scumm\ScummRecognizer.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\plugins\scumm\scummutil.h"
+ >
+ </File>
+ </Filter>
<File
RelativePath="..\..\src\plugins\ReadMe.txt"
>
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