1
0
forked from 0ad/0ad

win_internal: removed contents of crtdbg and malloc.h (no longer needed, since precompiled.h now correctly includes the mem trackers and all memory-related system headers)

precompiled: restructured, documented everything, memory system headers
are now included before mmgr.h to prevent conflicts (before, had
#defined include guard of crtdbg.h and malloc.h and manually declared
their contents - a hack)

This was SVN commit r1885.
This commit is contained in:
janwas 2005-01-30 23:09:51 +00:00
parent bc4351b1c8
commit 7cb28a242c
2 changed files with 89 additions and 78 deletions

View File

@ -1,8 +1,12 @@
// if precompiled headers are supported, include all headers we'd ever need
// that don't often change. if not supported, include nothing (would actually
// slow down the build, since unnecessary headers would be included).
// hence, all files include precompiled.h and then all the headers they'd
// normally lead => best build performance with or without PCH.
// precompiled header. must be the first non-comment part of every source
// file (VC6/7 requirement).
//
// if the compiler supports PCH (i.e. HAVE_PCH is defined), this
// tries to include all headers that may be needed. otherwise, all source
// files will still need to include this (for various global fixes and the
// memory trackers), but additionally include all required headers.
//
// this policy yields the best compile performance with or without PCH.
#include "config.h"
#include "types.h"
@ -16,53 +20,97 @@
// iterator debugging - a better solution would be to fix that.)
#define _HAS_ITERATOR_DEBUGGING 0
//
// memory headers
//
// these are all system headers that contain "new", "malloc" etc.; they must
// come before the memory tracker headers to avoid conflicts with their
// macros. therefore, they are always included, even if !HAVE_PCH.
#ifdef _WIN32
#include <crtdbg.h>
#endif
#include <malloc.h>
#include <new>
#include <memory>
#include <cstring> // uses placement new
//
// headers to be precompiled
//
// candidates are all system headers we may possibly need or large/rarely
// changed project headers; everything placed in here will not need to be
// compiled every time. however, if they change, the project will have to be
// completely rebuilt. (slow!)
//
// if the compiler doesn't support precompiled headers (i.e. !HAVE_PCH),
// including anything here would actually slow things down, because we might
// not otherwise need some of these headers. therefore, do nothing and rely
// on all source files (additionally) including everything they need.
#ifdef HAVE_PCH
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <stdarg.h>
#include <limits.h>
#include <time.h>
#include <wchar.h>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cfloat>
#include <csetjmp>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cwchar>
#include <algorithm>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <list>
#include <map>
#include <vector>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <set>
#include <deque>
#include <fstream>
#include <vector>
#include <functional>
#include <algorithm>
#include <numeric>
// Nicer memory leak reporting in MSVC:
// (You've got to include all STL headers first to avoid lots of errors,
// so make sure they're in the list above and you compile with PCH)
/*
#ifdef HAVE_DEBUGALLOC
# include <crtdbg.h>
# include <malloc.h>
// Can't define _CRTDBG_MAP_ALLOC because it has a broken 'new',
// so manually redefine the appropriate functions
# define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
# define malloc(s) _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
# define calloc(c, s) _calloc_dbg(c, s, _NORMAL_BLOCK, __FILE__, __LINE__)
# define realloc(p, s) _realloc_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
# define free(p) _free_dbg(p, _NORMAL_BLOCK)
#endif // HAVE_DEBUGALLOC
*/
// (further headers to be precompiled go here)
#endif // #ifdef HAVE_PCH
#define _INC_CRTDBG
#define _INC_MALLOC
//
// memory trackers
//
// these must be included from every file to make sure all allocations
// are hooked. placing in the precompiled header is more convenient than
// manually #including from every file, but requires that all system
// headers containing "new", "malloc" etc. come before this (see above).
// use VC debug heap (superceded by mmgr; it remains for completeness)
#ifdef HAVE_DEBUGALLOC
// can't define _CRTDBG_MAP_ALLOC because it has a broken 'new',
// so manually redefine the appropriate functions.
# define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
# define malloc(s) _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
# define calloc(c, s) _calloc_dbg(c, s, _NORMAL_BLOCK, __FILE__, __LINE__)
# define realloc(p, s) _realloc_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
# define free(p) _free_dbg(p, _NORMAL_BLOCK)
#endif // #ifdef HAVE_DEBUGALLOC
// use custom memory tracker (lib/mmgr.cpp)
#ifdef USE_MMGR
# include "mmgr.h"
#endif

View File

@ -325,43 +325,6 @@ extern _CRTIMP int _close(int);
extern _CRTIMP char* _getcwd(char*, size_t);
// can't include malloc.h or crtdbg due to conflicts with mmgr.h
extern _CRTIMP int _heapchk(void);
#ifndef NDEBUG
extern _CRTIMP int _CrtSetDbgFlag(int);
#else
#define _CrtSetDbgFlag(f)
#endif
extern _CRTIMP void _aligned_free(void *);
extern _CRTIMP void* _aligned_malloc(size_t, size_t);
extern _CRTIMP void* _aligned_realloc(void *, size_t, size_t);
/*
* Bit values for _crtDbgFlag flag:
*
* These bitflags control debug heap behavior.
*/
#define _CRTDBG_ALLOC_MEM_DF 0x01 /* Turn on debug allocation */
#define _CRTDBG_DELAY_FREE_MEM_DF 0x02 /* Don't actually free memory */
#define _CRTDBG_CHECK_ALWAYS_DF 0x04 /* Check heap every alloc/dealloc */
#define _CRTDBG_RESERVED_DF 0x08 /* Reserved - do not use */
#define _CRTDBG_CHECK_CRT_DF 0x10 /* Leak check/diff CRT blocks */
#define _CRTDBG_LEAK_CHECK_DF 0x20 /* Leak check at program exit */
/*
We do not check the heap by default at this point because the cost was too high
for some applications. You can still turn this feature on manually.
*/
#define _CRTDBG_CHECK_DEFAULT_DF 0
#define _CRTDBG_REPORT_FLAG -1 /* Query bitflag status */
#ifndef NO_WINSOCK
extern __declspec(dllimport) int __stdcall WSAStartup(unsigned short, void*);
extern __declspec(dllimport) int __stdcall WSACleanup(void);