summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-02-10 23:13:00 +0300
committerAndrei Karas <akaras@inbox.ru>2017-02-10 23:25:52 +0300
commitaf1c910f5cc02f57e466ae066494fc73ed96e10a (patch)
treed77edc041625fe5c37d8eec6e1e9fceaf4a55620 /src
parent4d3c700bf736def3c55f7e03c175e2e43ed3db02 (diff)
downloadmv-af1c910f5cc02f57e466ae066494fc73ed96e10a.tar.gz
mv-af1c910f5cc02f57e466ae066494fc73ed96e10a.tar.bz2
mv-af1c910f5cc02f57e466ae066494fc73ed96e10a.tar.xz
mv-af1c910f5cc02f57e466ae066494fc73ed96e10a.zip
Fix virtfs checks.
Remove old check files related to physfs.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/debug.h2
-rw-r--r--src/maingui.cpp3
-rw-r--r--src/resources/atlas/atlasmanager.cpp1
-rw-r--r--src/test/testlauncher.cpp1
-rw-r--r--src/utils/physfscheckutils.cpp108
-rw-r--r--src/utils/physfscheckutils.h38
-rw-r--r--src/utils/physfsmemoryobject.h2
-rw-r--r--src/utils/virtfsrwops.cpp93
-rw-r--r--src/utils/virtfsrwops.h12
11 files changed, 105 insertions, 159 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1baa24081..099f2e4fb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -886,8 +886,6 @@ SET(SRCS
utils/paths.h
utils/perfomance.cpp
utils/perfomance.h
- utils/physfscheckutils.cpp
- utils/physfscheckutils.h
utils/physfsmemoryobject.h
utils/virtfsrwops.cpp
utils/virtfsrwops.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 2eea657a5..2bc72294e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -546,8 +546,6 @@ BASE_SRC += events/actionevent.h \
utils/paths.h \
utils/perfomance.cpp \
utils/perfomance.h \
- utils/physfscheckutils.cpp \
- utils/physfscheckutils.h \
utils/physfsmemoryobject.h \
utils/virtfsrwops.cpp \
utils/virtfsrwops.h \
diff --git a/src/debug.h b/src/debug.h
index 3faf63cde..edfe0408d 100644
--- a/src/debug.h
+++ b/src/debug.h
@@ -65,7 +65,7 @@
#ifdef DEBUG_PHYSFS
-// +++ need move this into VirtFs itself
+#define RWopsOpenRead(name) RWopsOpenRead(name, __FILE__, __LINE__)
#else // DEBUG_PHYSFS
#endif // DEBUG_PHYSFS
diff --git a/src/maingui.cpp b/src/maingui.cpp
index b2a25b48e..f34cfeb31 100644
--- a/src/maingui.cpp
+++ b/src/maingui.cpp
@@ -31,7 +31,6 @@
#include "utils/mkdir.h"
#include "utils/paths.h"
#endif // ANDROID
-#include "utils/physfscheckutils.h"
#include "utils/virtfsrwops.h"
#include "utils/process.h"
#include "utils/xml.h"
@@ -135,7 +134,7 @@ int mainGui(int argc, char *argv[])
VirtFs::reportRWops();
#endif // DUMP_LEAKED_RESOURCES
#ifdef DEBUG_PHYSFS
- reportPhysfsLeaks();
+ VirtFs::reportLeaks();
#endif // DEBUG_PHYSFS
return ret;
diff --git a/src/resources/atlas/atlasmanager.cpp b/src/resources/atlas/atlasmanager.cpp
index e3c6e685b..ecd00f3b7 100644
--- a/src/resources/atlas/atlasmanager.cpp
+++ b/src/resources/atlas/atlasmanager.cpp
@@ -29,7 +29,6 @@
#endif // DEBUG_IMAGES
#include "utils/mathutils.h"
-#include "utils/physfscheckutils.h"
#include "utils/virtfsrwops.h"
#include "utils/sdlcheckutils.h"
diff --git a/src/test/testlauncher.cpp b/src/test/testlauncher.cpp
index acd51413f..ac872fa54 100644
--- a/src/test/testlauncher.cpp
+++ b/src/test/testlauncher.cpp
@@ -31,7 +31,6 @@
#include "gui/fonts/font.h"
-#include "utils/physfscheckutils.h"
#include "utils/virtfsrwops.h"
#include "render/graphics.h"
diff --git a/src/utils/physfscheckutils.cpp b/src/utils/physfscheckutils.cpp
deleted file mode 100644
index 3c0382f0c..000000000
--- a/src/utils/physfscheckutils.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * 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
- * 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, see <http://www.gnu.org/licenses/>.
- */
-
-#include "utils/physfscheckutils.h"
-
-#ifdef DEBUG_PHYSFS
-
-#include "logger.h"
-
-#include "utils/stringutils.h"
-
-#include "utils/physfsmemoryobject.h"
-#include "utils/virtfsrwops.h"
-
-#include <map>
-
-#include "debug.h"
-
-namespace
-{
- std::map<void*, PHYSFSMemoryObject*> mRWops;
-} // namespace
-
-static SDL_RWops *addRWops(SDL_RWops *restrict const rwops,
- const char *restrict const name,
- const char *restrict const file,
- const unsigned line)
-{
- if (!rwops)
- return nullptr;
-
- mRWops[rwops] = new PHYSFSMemoryObject(name, file, line);
- return rwops;
-}
-
-static void deleteRWops(SDL_RWops *const rwops)
-{
- if (!rwops)
- return;
-
- std::map<void*, PHYSFSMemoryObject*>::iterator it = mRWops.find(rwops);
- if (it == mRWops.end())
- {
- logger->log("bad RWops delete: %p", static_cast<void*>(rwops));
- }
- else
- {
- PHYSFSMemoryObject *const obj = (*it).second;
- if (obj)
- {
- mRWops.erase(rwops);
- delete obj;
- }
- }
-}
-
-SDL_RWops *FakePHYSFSRWOPS_openRead(const char *restrict const name,
- const char *restrict const file,
- const unsigned line)
-{
- return addRWops(VirtFs::RWopsOpenRead(name), name, file, line);
-}
-
-void FakePhysFSClose(SDL_RWops *const rwops)
-{
- deleteRWops(rwops);
-}
-
-void reportPhysfsLeaks()
-{
- if (!mRWops.empty())
- {
- logger->log("RWops leaks detected");
- std::map<void*, PHYSFSMemoryObject*>::iterator it = mRWops.begin();
- const std::map<void*, PHYSFSMemoryObject*>::iterator
- it_end = mRWops.end();
- for (; it != it_end; ++it)
- {
- PHYSFSMemoryObject *obj = (*it).second;
- if (obj)
- {
- logger->log("file: %s at %s", obj->mName.c_str(),
- obj->mAddFile.c_str());
- delete obj;
- }
- }
- mRWops.clear();
- }
-}
-
-#endif // DEBUG_PHYSFS
diff --git a/src/utils/physfscheckutils.h b/src/utils/physfscheckutils.h
deleted file mode 100644
index 7b51504eb..000000000
--- a/src/utils/physfscheckutils.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * 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
- * 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, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef UTILS_PHYSFSCHECKUTILS_H
-#define UTILS_PHYSFSCHECKUTILS_H
-
-#include "localconsts.h"
-#ifdef DEBUG_PHYSFS
-
-#include <SDL.h>
-
-SDL_RWops *FakePHYSFSRWOPS_openRead(const char *restrict const name,
- const char *restrict const file,
- const unsigned line);
-
-void FakePhysFSClose(SDL_RWops *const rwops);
-
-void reportPhysfsLeaks();
-
-#endif // DEBUG_PHYSFS
-#endif // UTILS_PHYSFSCHECKUTILS_H
diff --git a/src/utils/physfsmemoryobject.h b/src/utils/physfsmemoryobject.h
index 62668b511..ec8ecad1f 100644
--- a/src/utils/physfsmemoryobject.h
+++ b/src/utils/physfsmemoryobject.h
@@ -23,7 +23,7 @@
#ifdef DEBUG_PHYSFS
-#include <string>
+#include "utils/stringutils.h"
#include "localconsts.h"
diff --git a/src/utils/virtfsrwops.cpp b/src/utils/virtfsrwops.cpp
index adcfa2784..347d26916 100644
--- a/src/utils/virtfsrwops.cpp
+++ b/src/utils/virtfsrwops.cpp
@@ -27,7 +27,9 @@
#include "logger.h"
#include "utils/fuzzer.h"
-#include "utils/physfscheckutils.h"
+#include "utils/physfsmemoryobject.h"
+
+#include <map>
#include "debug.h"
@@ -43,6 +45,68 @@
static int openedRWops = 0;
#endif // DUMP_LEAKED_RESOURCES
+#ifdef DEBUG_PHYSFS
+namespace
+{
+ std::map<void*, PHYSFSMemoryObject*> mRWops;
+} // namespace
+
+static SDL_RWops *addDebugRWops(SDL_RWops *restrict const rwops,
+ const char *restrict const name,
+ const char *restrict const file,
+ const unsigned line)
+{
+ if (!rwops)
+ return nullptr;
+
+ mRWops[rwops] = new PHYSFSMemoryObject(name, file, line);
+ return rwops;
+}
+
+static void deleteDebugRWops(SDL_RWops *const rwops)
+{
+ if (!rwops)
+ return;
+
+ std::map<void*, PHYSFSMemoryObject*>::iterator it = mRWops.find(rwops);
+ if (it == mRWops.end())
+ {
+ logger->log("bad RWops delete: %p", static_cast<void*>(rwops));
+ }
+ else
+ {
+ PHYSFSMemoryObject *const obj = (*it).second;
+ if (obj)
+ {
+ mRWops.erase(rwops);
+ delete obj;
+ }
+ }
+}
+
+void VirtFs::reportLeaks()
+{
+ if (!mRWops.empty())
+ {
+ logger->log("RWops leaks detected");
+ std::map<void*, PHYSFSMemoryObject*>::iterator it = mRWops.begin();
+ const std::map<void*, PHYSFSMemoryObject*>::iterator
+ it_end = mRWops.end();
+ for (; it != it_end; ++it)
+ {
+ PHYSFSMemoryObject *obj = (*it).second;
+ if (obj)
+ {
+ logger->log("file: %s at %s", obj->mName.c_str(),
+ obj->mAddFile.c_str());
+ delete obj;
+ }
+ }
+ mRWops.clear();
+ }
+}
+#endif // DEBUG_PHYSFS
+
static PHYSFSINT physfsrwops_seek(SDL_RWops *const rw,
const PHYSFSINT offset,
const int whence)
@@ -188,7 +252,7 @@ static int physfsrwops_close(SDL_RWops *const rw)
openedRWops --;
#endif // DUMP_LEAKED_RESOURCES
#ifdef DEBUG_PHYSFS
- FakePhysFSClose(rw);
+ deleteDebugRWops(rw);
#endif // DEBUG_PHYSFS
return 0;
@@ -262,7 +326,14 @@ static bool checkFilePath(const char *const fname)
}
#endif // __APPLE__
+#ifdef DEBUG_PHYSFS
+#undef RWopsOpenRead
+SDL_RWops *VirtFs::RWopsOpenRead(const char *const fname,
+ const char *restrict const file,
+ const unsigned line)
+#else // DEBUG_PHYSFS
SDL_RWops *VirtFs::RWopsOpenRead(const char *const fname)
+#endif // DEBUG_PHYSFS
{
BLOCK_START("RWopsopenRead")
#ifdef __APPLE__
@@ -274,12 +345,30 @@ SDL_RWops *VirtFs::RWopsOpenRead(const char *const fname)
return nullptr;
#endif // USE_FUZZER
#ifdef USE_PROFILER
+
+#ifdef DEBUG_PHYSFS
+ SDL_RWops *const ret = addDebugRWops(
+ create_rwops(VirtFs::openRead(fname)),
+ fname,
+ file,
+ line);
+#else // DEBUG_PHYSFS
SDL_RWops *const ret = create_rwops(VirtFs::openRead(fname));
+#endif // DEBUG_PHYSFS
+
BLOCK_END("RWopsopenRead")
return ret;
#else // USE_PROFILER
+#ifdef DEBUG_PHYSFS
+ return addDebugRWops(
+ create_rwops(VirtFs::openRead(fname)),
+ fname,
+ file,
+ line);
+#else // DEBUG_PHYSFS
return create_rwops(VirtFs::openRead(fname));
+#endif // DEBUG_PHYSFS
#endif // USE_PROFILER
} /* RWopsopenRead */
diff --git a/src/utils/virtfsrwops.h b/src/utils/virtfsrwops.h
index 83aa79996..e9d68f044 100644
--- a/src/utils/virtfsrwops.h
+++ b/src/utils/virtfsrwops.h
@@ -33,13 +33,23 @@
namespace VirtFs
{
- SDL_RWops *RWopsOpenRead(const char *const fname) A_WARN_UNUSED;
+#ifdef DEBUG_PHYSFS
+ SDL_RWops *RWopsOpenRead(const char *const fname,
+ const char *restrict const file,
+ const unsigned line);
+#else // DEBUG_PHYSFS
+ SDL_RWops *RWopsOpenRead(const char *const fname);
+#endif // DEBUG_PHYSFS
+
SDL_RWops *RWopsOpenWrite(const char *const fname) A_WARN_UNUSED;
SDL_RWops *RWopsOpenAppend(const char *const fname) A_WARN_UNUSED;
SDL_RWops *MakeRWops(PHYSFS_file *const handle) A_WARN_UNUSED;
#ifdef DUMP_LEAKED_RESOURCES
void reportRWops();
#endif // DUMP_LEAKED_RESOURCES
+#ifdef DEBUG_PHYSFS
+ void reportLeaks();
+#endif // DEBUG_PHYSFS
} // namespace VirtFs
#endif // UTILS_PHYSFSRWOPS_H