summaryrefslogtreecommitdiffhomepage
path: root/FoundationEx
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-03-27 17:42:26 +0200
committerAki <please@ignore.pl>2022-03-27 17:42:26 +0200
commita12e588079700d55a0b788fea2df7727c2e41f52 (patch)
tree690072569624c73af5043b3619acaab4d298b1fa /FoundationEx
parent72bb517271dad40a440533ad0796a88247011199 (diff)
downloadstarshatter-a12e588079700d55a0b788fea2df7727c2e41f52.zip
starshatter-a12e588079700d55a0b788fea2df7727c2e41f52.tar.gz
starshatter-a12e588079700d55a0b788fea2df7727c2e41f52.tar.bz2
Removed MemDebug from FoundationEx
Diffstat (limited to 'FoundationEx')
-rw-r--r--FoundationEx/CMakeLists.txt1
-rw-r--r--FoundationEx/Dictionary.inl13
-rw-r--r--FoundationEx/List.inl10
-rw-r--r--FoundationEx/MemDebug.cpp296
-rw-r--r--FoundationEx/MemDebug.h97
-rw-r--r--FoundationEx/Text.cpp89
6 files changed, 0 insertions, 506 deletions
diff --git a/FoundationEx/CMakeLists.txt b/FoundationEx/CMakeLists.txt
index c2b546b..497c732 100644
--- a/FoundationEx/CMakeLists.txt
+++ b/FoundationEx/CMakeLists.txt
@@ -2,7 +2,6 @@ project(FoundationEx)
add_library(
FoundationEx
STATIC
- MemDebug.cpp
Text.cpp
Utils.cpp
)
diff --git a/FoundationEx/Dictionary.inl b/FoundationEx/Dictionary.inl
index 53ee998..cd58679 100644
--- a/FoundationEx/Dictionary.inl
+++ b/FoundationEx/Dictionary.inl
@@ -63,15 +63,8 @@ T& Dictionary<T>::operator[](const Text& key)
if (cell == 0) { // empty chain
items++;
-
-#ifdef MEM_DEBUG
- cell = new(__FILE__,__LINE__) DictionaryCell<T>(key);
-#else
cell = new DictionaryCell<T>(key);
-#endif
-
table[idx] = cell;
-
return cell->value;
}
else { // search for key
@@ -80,13 +73,7 @@ T& Dictionary<T>::operator[](const Text& key)
if (cell->key != key) { // not found in chain
items++;
-
-#ifdef MEM_DEBUG
- cell->next = new(__FILE__,__LINE__) DictionaryCell<T>(key);
-#else
cell->next = new DictionaryCell<T>(key);
-#endif
-
return cell->next->value;
}
else { // found: return it!
diff --git a/FoundationEx/List.inl b/FoundationEx/List.inl
index e39cc27..5fff962 100644
--- a/FoundationEx/List.inl
+++ b/FoundationEx/List.inl
@@ -21,12 +21,7 @@ template <class T>
List<T>::List(const List<T>& l)
: items(l.items), extent(l.extent)
{
-#ifdef MEM_DEBUG
- array = new(__FILE__,__LINE__) PTR[extent];
-#else
array = new PTR[extent];
-#endif
-
for (int i = 0; i < extent; i++)
array[i] = l.array[i];
}
@@ -123,12 +118,7 @@ void List<T>::resize(int newsize)
{
if (newsize > extent) {
extent = 16 * (newsize/16 + 1);
-
-#ifdef MEM_DEBUG
- T** v = new(__FILE__,__LINE__) PTR[extent];
-#else
T** v = new PTR[extent];
-#endif
int i;
for (i = 0; i < items; i++)
v[i] = array[i];
diff --git a/FoundationEx/MemDebug.cpp b/FoundationEx/MemDebug.cpp
deleted file mode 100644
index 077f06d..0000000
--- a/FoundationEx/MemDebug.cpp
+++ /dev/null
@@ -1,296 +0,0 @@
-/* Starshatter: The Open Source Project
- Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors
- Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
- Copyright (c) 1997-2006, Destroyer Studios LLC.
-
- AUTHOR: John DiCamillo
-
-
- OVERVIEW
- ========
- Memory Debugging class
-*/
-
-#include "MemDebug.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <crtdbg.h>
-#include <malloc.h>
-
-// +--------------------------------------------------------------------+
-
-#ifndef FOUNDATION_USE_MFC
-static Memory::LEVEL mem_chk_level = Memory::PERIODIC;
-#endif
-
-#ifdef _DEBUG
-static _CrtMemState mem_chk_p1,
- mem_chk_p2;
-#endif
-
-static HANDLE mem_log_file = 0;
-
-// +--------------------------------------------------------------------+
-
-#ifdef _DEBUG
-#define CrtSetDebugField(a) _CrtSetDbgFlag((a) | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
-#define CrtClrDebugField(a) _CrtSetDbgFlag(~(a) & _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
-#endif
-
-#ifdef FOUNDATION_USE_MFC
-
-#ifndef _DEBUG
-
-void* __cdecl operator new(unsigned int s, const char*, int)
-{
- return ::operator new(s);
-}
-
-void __cdecl operator delete(void* p, const char*, int)
-{
- ::operator delete(p);
-}
-
-#else
-
-// No definitions for the following:
-//void* __cdecl operator new(unsigned int s, const char*, int) {}
-//void __cdecl operator delete(void* p, const char*, int) {}
-
-#endif
-
-#else // if not defined FOUNDATION_USE_MFC
-
-#ifndef _DEBUG
-
-void* __cdecl operator new[](unsigned int s, const char*, int)
-{
- return ::operator new[](s);
-}
-
-void* __cdecl operator new(unsigned int s, const char*, int)
-{
- return ::operator new(s);
-}
-
-void __cdecl operator delete[](void* p, const char*, int)
-{
- ::operator delete[](p);
-}
-
-void __cdecl operator delete(void* p, const char*, int)
-{
- ::operator delete(p);
-}
-
-#else
-
-// No definitions for the following:
-//void* __cdecl operator new(unsigned int, int, const char*, int) {}
-
-void* __cdecl operator new[](unsigned int s, const char*, int)
-{
- return ::operator new[](s);
-}
-
-void* __cdecl operator new(unsigned int s, const char* f, int l)
-{
- return ::operator new(s, 1, f, l);
-}
-
-void* __cdecl operator new(unsigned int s)
-{
- return ::operator new(s, 1, __FILE__, __LINE__);
-}
-
-void __cdecl operator delete[](void* p, const char*, int)
-{
- ::operator delete[](p);
-}
-
-void __cdecl operator delete(void* p, const char*, int)
-{
- ::operator delete(p);
-}
-
-#endif // _DEBUG
-
-#endif // FOUNDATION_USE_MFC
-
-static void heapdump()
-{
- _HEAPINFO hinfo;
- int heapstatus;
- DWORD used = 0;
- DWORD avail = 0;
- char report[256];
-
- hinfo._pentry = NULL;
- while ((heapstatus = _heapwalk( &hinfo )) == _HEAPOK) {
- sprintf_s(report, "%6s block at %Fp of size %4.4X\n",
- ( hinfo._useflag == _USEDENTRY ? "USED" : "FREE" ),
- hinfo._pentry, hinfo._size);
-
- _RPT0(_CRT_WARN, report);
-
- if (hinfo._useflag == _USEDENTRY)
- used += hinfo._size;
- else
- avail += hinfo._size;
- }
-
- sprintf_s(report, "------\nUsed Blocks: %d\nAvail Blocks: %d\nTotal Blocks: %d\n", used, avail, used+avail); //-V576
- _RPT0(_CRT_WARN, report);
-
- switch (heapstatus) {
- case _HEAPEMPTY:
- _RPT0(_CRT_WARN, "OK - empty heap\n" );
- break;
- case _HEAPEND:
- _RPT0(_CRT_WARN, "OK - end of heap\n" );
- break;
- case _HEAPBADPTR:
- _RPT0(_CRT_WARN, "ERROR - bad pointer to heap\n" );
- break;
- case _HEAPBADBEGIN:
- _RPT0(_CRT_WARN, "ERROR - bad start of heap\n" );
- break;
- case _HEAPBADNODE:
- _RPT0(_CRT_WARN, "ERROR - bad node in heap\n" );
- break;
- }
-}
-
-// +--------------------------------------------------------------------+
-
-#ifndef FOUNDATION_USE_MFC
-void
-Memory::OpenLog(const char* filename)
-{
-#ifdef _DEBUG
- if (!filename || !strlen(filename))
- filename = "memdbg.txt";
-
- mem_log_file = CreateFile(filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
-
- if (mem_log_file) {
- _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
- _CrtSetReportFile(_CRT_WARN, mem_log_file);
- _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
- _CrtSetReportFile(_CRT_ERROR, mem_log_file);
- _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
- _CrtSetReportFile(_CRT_ASSERT, mem_log_file);
- }
-
- _CrtMemCheckpoint(&mem_chk_p1);
-#endif
-}
-
-// +--------------------------------------------------------------------+
-
-void
-Memory::CloseLog()
-{
-#ifdef _DEBUG
- if (mem_log_file) {
- CloseHandle(mem_log_file);
- mem_log_file = 0;
-
- _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
- _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT);
- _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
- _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDOUT);
- _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
- _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT);
- }
-#endif
-}
-
-// +--------------------------------------------------------------------+
-
-void
-Memory::Check()
-{
-#ifdef _DEBUG
- if (! _CrtCheckMemory()) {
- _RPT0(_CRT_ERROR, "\n\nMemory Check Failed.\n");
- heapdump();
- Checkpoint();
- _asm { int 3 }
- exit(1111);
- }
-#endif
-}
-
-// +--------------------------------------------------------------------+
-
-void
-Memory::Checkpoint()
-{
-#ifdef _DEBUG
- if (mem_chk_level < PERIODIC) return;
-
- _RPT0(_CRT_WARN, "\n\nMemory Checkpoint:\n"
- "--------------------------------------------------\n");
-
- _CrtMemState s;
- _CrtMemCheckpoint(&mem_chk_p2);
- _CrtMemDifference(&s, &mem_chk_p1, &mem_chk_p2);
- _CrtMemDumpStatistics(&s);
-
- memcpy(&mem_chk_p1, &mem_chk_p2, sizeof(mem_chk_p1));
-#endif
-}
-
-// +--------------------------------------------------------------------+
-
-void
-Memory::Stats()
-{
-#ifdef _DEBUG
- if (mem_chk_level < PERIODIC) return;
-
- _RPT0(_CRT_WARN, "\n\nMemory Stats:\n"
- "--------------------------------------------------\n");
-
- _CrtMemState s;
- _CrtMemCheckpoint(&s);
- _CrtMemDumpStatistics(&s);
-#endif
-}
-
-// +--------------------------------------------------------------------+
-
-void
-Memory::DumpLeaks()
-{
-#ifdef _DEBUG
- _RPT0(_CRT_WARN, "\n\nMemory Dump Leaks:\n"
- "--------------------------------------------------\n");
- _CrtDumpMemoryLeaks();
-#endif
-}
-
-// +--------------------------------------------------------------------+
-
-void
-Memory::SetLevel(LEVEL l)
-{
-#ifdef _DEBUG
- mem_chk_level = l;
-
- _CrtSetDbgFlag(0);
-
- switch (mem_chk_level) {
- case MAXIMAL: CrtSetDebugField(_CRTDBG_CHECK_ALWAYS_DF);
- case PERIODIC: CrtSetDebugField(_CRTDBG_DELAY_FREE_MEM_DF);
- case LEAKS: CrtSetDebugField(_CRTDBG_LEAK_CHECK_DF);
- case OFF:
- default: break;
- }
-#endif
-}
-
-#endif
-
diff --git a/FoundationEx/MemDebug.h b/FoundationEx/MemDebug.h
deleted file mode 100644
index c54b776..0000000
--- a/FoundationEx/MemDebug.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/* Starshatter: The Open Source Project
- Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors
- Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
- Copyright (c) 1997-2006, Destroyer Studios LLC.
-
- AUTHOR: John DiCamillo
-
-
- OVERVIEW
- ========
- Memory Debugging class
-*/
-
-
-#ifndef MemDebug_h
-#define MemDebug_h
-
-// +--------------------------------------------------------------------+
-
-#ifdef WIN32
-#include <windows.h>
-#include <windowsx.h>
-#endif
-
-#ifdef FOUNDATION_USE_MFC
-
-#ifndef _DEBUG
-
-void* __cdecl operator new[](unsigned int, const char*, int);
-void* __cdecl operator new(unsigned int s, const char*, int);
-void __cdecl operator delete[](void* p, const char*, int);
-void __cdecl operator delete(void* p, const char*, int);
-
-#else
-
-void* __cdecl operator new[](unsigned int, const char*, int);
-void* __cdecl operator new(unsigned int s, const char*, int);
-void __cdecl operator delete[](void* p, const char*, int);
-void __cdecl operator delete(void* p, const char*, int);
-
-#endif
-
-#else
-
-//
-// MEMORY DEBUGGING NOT SUPPORTED UNDER MFC
-//
-
-// +--------------------------------------------------------------------+
-
-class Memory
-{
-public:
- enum LEVEL { OFF, LEAKS, PERIODIC, MAXIMAL };
-
- static void OpenLog(const char* filename=0);
- static void CloseLog();
-
- static void Check();
- static void Checkpoint();
- static void Stats();
- static void DumpLeaks();
-
- static void SetLevel(LEVEL l);
-};
-
-// +--------------------------------------------------------------------+
-
-#ifndef _DEBUG
-
-void* __cdecl operator new[](unsigned int, const char*, int);
-void* __cdecl operator new(unsigned int s, const char*, int);
-void __cdecl operator delete[](void* p, const char*, int);
-void __cdecl operator delete(void* p, const char*, int);
-
-#else
-/*_CRTIMP*/
-void* __cdecl operator new[](unsigned int, const char*, int);
-
-void* __cdecl operator new(unsigned int, int, const char*, int);
-
-void* __cdecl operator new(unsigned int s, const char* f, int l);
-
-void* __cdecl operator new(unsigned int s);
-
-void __cdecl operator delete[](void* p, const char*, int);
-
-void __cdecl operator delete(void* p, const char*, int);
-
-#endif // _DEBUG
-
-// +--------------------------------------------------------------------+
-
-#endif // FOUNDATION_USE_MFC
-
-#endif // MemDebug_h
-
diff --git a/FoundationEx/Text.cpp b/FoundationEx/Text.cpp
index 235bbaa..e73149a 100644
--- a/FoundationEx/Text.cpp
+++ b/FoundationEx/Text.cpp
@@ -11,7 +11,6 @@
Implementation of the Text class
*/
-#include "MemDebug.h"
#include "Text.h"
#include "stdio.h"
#include <ctype.h>
@@ -26,11 +25,7 @@ TextRep TextRep::nullrep;
TextRep::TextRep()
: ref(1234567), data(0), length(0), hash(0), sensitive(true)
{
-#ifdef MEM_DEBUG
- data = new(__FILE__,__LINE__) char[4];
-#else
data = new char[4];
-#endif
if (data)
ZeroMemory(data, 4);
@@ -46,11 +41,7 @@ TextRep::TextRep(const char* s)
{
if (s) length = ::strlen(s);
-#ifdef MEM_DEBUG
- data = new(__FILE__,__LINE__) char[length+1];
-#else
data = new char[length+1];
-#endif
if (data) {
if (s) ::strcpy(data, s);
@@ -65,11 +56,7 @@ TextRep::TextRep(const char* s, int len)
{
if (length < 0) length = 0;
-#ifdef MEM_DEBUG
- data = new(__FILE__,__LINE__) char[length+1];
-#else
data = new char[length+1];
-#endif
if (data) {
::CopyMemory(data, s, length);
@@ -83,11 +70,7 @@ TextRep::TextRep(char c, int len)
{
if (length < 0) length = 0;
-#ifdef MEM_DEBUG
- data = new(__FILE__,__LINE__) char[length+1];
-#else
data = new char[length+1];
-#endif
if (data) {
::FillMemory(data, length, c);
@@ -101,11 +84,7 @@ TextRep::TextRep(const TextRep* rep)
{
length = rep->length;
-#ifdef MEM_DEBUG
- data = new(__FILE__,__LINE__) char[length+1];
-#else
data = new char[length+1];
-#endif
hash = rep->hash;
sensitive = rep->sensitive;
@@ -177,11 +156,7 @@ Text::Text(char c)
{
char buf[2]; buf[0] = c; buf[1] = '\0';
-#ifdef MEM_DEBUG
- rep = new(__FILE__,__LINE__) TextRep(buf);
-#else
rep = new TextRep(buf);
-#endif
if (!rep) {
rep = &TextRep::nullrep;
@@ -193,11 +168,7 @@ Text::Text(char c)
Text::Text(const char* s)
{
-#ifdef MEM_DEBUG
- rep = new(__FILE__,__LINE__) TextRep(s);
-#else
rep = new TextRep(s);
-#endif
if (!rep) {
rep = &TextRep::nullrep;
@@ -209,11 +180,7 @@ Text::Text(const char* s)
Text::Text(const char* s, int len)
{
-#ifdef MEM_DEBUG
- rep = new(__FILE__,__LINE__) TextRep(s, len);
-#else
rep = new TextRep(s, len);
-#endif
if (!rep) {
rep = &TextRep::nullrep;
@@ -225,11 +192,7 @@ Text::Text(const char* s, int len)
Text::Text(char c, int len)
{
-#ifdef MEM_DEBUG
- rep = new(__FILE__,__LINE__) TextRep(c, len);
-#else
rep = new TextRep(c, len);
-#endif
if (!rep) {
rep = &TextRep::nullrep;
@@ -258,11 +221,7 @@ Text&
Text::operator=(const char* s)
{
if (rep->deref() == 0) delete rep;
-#ifdef MEM_DEBUG
- rep = new(__FILE__,__LINE__) TextRep(s);
-#else
rep = new TextRep(s);
-#endif
if (!rep)
rep = &TextRep::nullrep;
@@ -283,11 +242,7 @@ Text::operator=(const Text& s)
Text
Text::operator+(char c)
{
-#ifdef MEM_DEBUG
- char* buf = new(__FILE__,__LINE__) char[rep->length + 2];
-#else
char* buf = new char[rep->length + 2];
-#endif
if (buf) {
::strcpy(buf, sym);
@@ -306,11 +261,7 @@ Text::operator+(char c)
Text
Text::operator+(const char* s)
{
-#ifdef MEM_DEBUG
- char* buf = new(__FILE__,__LINE__) char[::strlen(s) + rep->length + 1];
-#else
char* buf = new char[::strlen(s) + rep->length + 1];
-#endif
if (buf) {
::strcpy(buf, sym);
@@ -328,11 +279,7 @@ Text::operator+(const char* s)
Text
Text::operator+(const Text& s)
{
-#ifdef MEM_DEBUG
- char* buf = new(__FILE__,__LINE__) char[s.rep->length + rep->length + 1];
-#else
char* buf = new char[s.rep->length + rep->length + 1];
-#endif
if (buf) {
::strcpy(buf, sym);
@@ -362,11 +309,7 @@ Text::setSensitive(bool s)
Text&
Text::append(char c)
{
-#ifdef MEM_DEBUG
- char* buf = new(__FILE__,__LINE__) char[rep->length + 2];
-#else
char* buf = new char[rep->length + 2];
-#endif
if (buf) {
::strcpy(buf, sym);
@@ -374,11 +317,7 @@ Text::append(char c)
buf[rep->length+1] = '\0';
if (rep->deref() == 0) delete rep;
-#ifdef MEM_DEBUG
- rep = new(__FILE__,__LINE__) TextRep(buf);
-#else
rep = new TextRep(buf);
-#endif
if (!rep)
rep = &TextRep::nullrep;
@@ -393,22 +332,14 @@ Text::append(char c)
Text&
Text::append(const char* s)
{
-#ifdef MEM_DEBUG
- char* buf = new(__FILE__,__LINE__) char[::strlen(s) + rep->length + 1];
-#else
char* buf = new char[::strlen(s) + rep->length + 1];
-#endif
if (buf) {
::strcpy(buf, sym);
::strcat(buf, s);
if (rep->deref() == 0) delete rep;
-#ifdef MEM_DEBUG
- rep = new(__FILE__,__LINE__) TextRep(buf);
-#else
rep = new TextRep(buf);
-#endif
if (!rep)
rep = &TextRep::nullrep;
@@ -423,11 +354,7 @@ Text::append(const char* s)
Text&
Text::append(const Text& s)
{
-#ifdef MEM_DEBUG
- char* buf = new(__FILE__,__LINE__) char[s.rep->length + rep->length + 1];
-#else
char* buf = new char[s.rep->length + rep->length + 1];
-#endif
if (buf) {
int lenA = rep->length;
@@ -439,11 +366,7 @@ Text::append(const Text& s)
if (rep->deref() == 0) delete rep;
-#ifdef MEM_DEBUG
- rep = new(__FILE__,__LINE__) TextRep(buf, lenA + lenB);
-#else
rep = new TextRep(buf);
-#endif
if (!rep)
rep = &TextRep::nullrep;
@@ -461,11 +384,7 @@ Text::clone()
if (rep->ref > 1) {
rep->deref();
-#ifdef MEM_DEBUG
- TextRep* t = new(__FILE__,__LINE__) TextRep(rep);
-#else
TextRep* t = new TextRep(rep);
-#endif
rep = t;
@@ -522,11 +441,7 @@ Text::operator()(int start, int len) const
if (start + len > rep->length)
len = rep->length - start;
-#ifdef MEM_DEBUG
- char* buf = new(__FILE__,__LINE__) char[len+1];
-#else
char* buf = new char[len+1];
-#endif
if (buf) {
::strncpy(buf, sym+start, len);
@@ -689,11 +604,7 @@ Text::substring(int start, int length)
const char* s = sym + start;
-#ifdef MEM_DEBUG
- result.rep = new(__FILE__,__LINE__) TextRep(s, length);
-#else
result.rep = new TextRep(s, length);
-#endif
if (!result.rep)
result.rep = &TextRep::nullrep;