Files
admin
base
basedrv
boot
busdrv
cluster
cmd
crts
asms
crtw32
bsku
convert
direct
dllstuff
dos
eh
exec
h
hack
heap
helper
iostream
linkopts
lowio
mbstring
misc
rtc
startup
stdcpp
stdcpp64
stdhpp
algorithm
bitset
cassert
cctype
cerrno
cfloat
ciso646
climits
clocale
cmath
complex
csetjmp
csignal
cstdarg
cstddef
cstdio
cstdlib
cstring
ctime
cwchar
cwctype
deque
exception
fstream
functional
hash_map
hash_set
iomanip
ios
iosfwd
iostream
iso646.h
istream
iterator
limits
list
locale
map
memory
new
numeric
ostream
queue
set
sstream
stack
stdexcept
stl.h
streambuf
string
strstream
typeinfo
use_ansi.h
utility
valarray
vector
wctype.h
xcomplex
xdebug
xhash
xiosbase
xlocale
xlocinfo
xlocinfo.h
xlocmes
xlocmon
xlocnum
xloctime
xmemory
xstddef
xstring
xtree
xutility
ymath.h
yvals.h
stdhpp64
stdio
string
time
tools
crt32.nt
dirs
oldv2log.txt
doc
fpw32
langapi
libw32
srcrel
cb.cmd
clean.bat
clean.cmd
cleanbld.cmd
clns_bld.bat
depsed.sed
dirs
log.txt
log_64.txt
log_v40.txt
log_v41.txt
log_v42.txt
log_v50.txt
log_v60.txt
make.cmd
makefile
makefile.inc
makefile.sub
mk.bat
mkbld.cmd
ntia64bld.cmd
prebld.sed
rmdepend.bat
ddk
dload
dloadhandler
efiutil
eventlog
firmware
fs
fsrec
hals
headless
inc
mspatch
mvdm
ntdll
ntdllsym
ntos
ntsetup
pnp
published
qfe
remoteboot
screg
seaudit
strsafe
stublibs
subsys
testlockout
tools
urtl
wdmdrv
wdmlib
win32
wmi
wow64
xip
zlib
dirs
prerelease.inc
project.mk
com
developer
drivers
ds
enduser
inetcore
inetsrv
loc
mergedcomponents
multimedia
net
printscan
public
published
sdktools
shell
termsrv
tools
windows
dirs
makefil0
WindowsXP/base/crts/crtw32/stdhpp/xdebug
2025-04-27 07:49:33 -04:00

143 lines
3.6 KiB
Plaintext

// debug heap support header for Microsoft
#pragma once
#ifndef _XDEBUG_
#define _XDEBUG_
#pragma pack(push,8)
#pragma warning(push,3)
// SUPPORT FOR DEBUG HEAP
#if !defined(_DEBUG)
#define _NEW_CRT new
#define _DELETE_CRT(_P) delete (_P)
#define _DELETE_CRT_VEC(_P) delete[] (_P)
#define _STRING_CRT string
#else
#include <xmemory>
#include <xstring>
_STD_BEGIN
struct _DebugHeapTag_t
{ // placement new tag type to select debug CRT heap
int _Type;
};
extern _CRTIMP2 const _DebugHeapTag_t _DebugHeapTag;
_STD_END
_CRTIMP2 void * __cdecl
operator new(size_t, const std::_DebugHeapTag_t&, char *, int)
_THROW1(std::bad_alloc); // allocate from the debug CRT heap
_CRTIMP2 void * __cdecl
operator new[](size_t, const std::_DebugHeapTag_t&, char *, int)
_THROW1(std::bad_alloc); // allocate array from the debug CRT heap
_CRTIMP2 void __cdecl
operator delete(void *, const std::_DebugHeapTag_t&, char *, int)
_THROW0(); // delete if new for debug CRT heap fails
_CRTIMP2 void __cdecl
operator delete[](void *, const std::_DebugHeapTag_t&, char *, int)
_THROW0(); // delete if array new for debug CRT heap fails
#define _NEW_CRT new(std::_DebugHeapTag, __FILE__, __LINE__)
#define _DELETE_CRT(_P) std::_DebugHeapDelete(_P)
#define _DELETE_CRT_VEC(_P) std::_DebugHeapDelete((void *)_P)
#define _STRING_CRT _DebugHeapString
_STD_BEGIN
// TEMPLATE FUNCTION _DebugHeapDelete
template<class _Ty>
void _DebugHeapDelete(_Ty *_Ptr)
{ // delete from the debug CRT heap even if operator delete differs
if (_Ptr != 0)
{
_Ptr->~_Ty();
// delete as _NORMAL_BLOCK, not _CRT_BLOCK, since we might have
// facets allocated by normal new.
free(_Ptr);
}
}
// TEMPLATE CLASS _DebugHeapAllocator
template<class _Ty>
class _DebugHeapAllocator
: public allocator<_Ty>
{ // an allocator which uses the debug CRT heap
public:
template<class _Other>
struct rebind
{ // convert _DebugHeapAllocator<_Ty> to _DebugHeapAllocator<_Other>
typedef _DebugHeapAllocator<_Other> other;
};
template<class _Other>
pointer allocate(size_type _Count, const _Other *)
{ // allocate array of _Count elements, ignore hint
return (_Ty *)_NEW_CRT char[_Count * sizeof(_Ty)];
}
pointer allocate(size_type _Count)
{ // allocate array of _Count elements
return (_Ty *)_NEW_CRT char[_Count * sizeof(_Ty)];
}
void deallocate(pointer _Ptr, size_type)
{ // deallocate object at _Ptr, ignore size
_DELETE_CRT_VEC(_Ptr);
}
};
// CLASS _DebugHeapString
class _DebugHeapString
: public basic_string<char, char_traits<char>, _DebugHeapAllocator<char> >
{ // a version of std::string allocated on the debug CRT heap
public:
typedef _DebugHeapString _Myt;
typedef basic_string<char, char_traits<char>, _DebugHeapAllocator<char> >
_Mybase;
typedef char _Elem;
_DebugHeapString()
: _Mybase()
{ // construct empty string
}
_DebugHeapString(const _Myt& _Right)
: _Mybase(_Right)
{ // construct by copying _Right
}
_DebugHeapString(const _Elem *_Ptr)
: _Mybase(_Ptr)
{ // construct from [_Ptr, <null>)
}
_DebugHeapString(const string &_Str)
: _Mybase(_Str.c_str())
{ // construct from std::string
}
operator string() const
{
return string(c_str());
}
};
_STD_END
#endif /* _DEBUG */
#pragma warning(pop)
#pragma pack(pop)
#endif /* _XDEBUG_ */
/*
* Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
* Consult your license regarding permissions and restrictions.
V3.10:0009 */