18 #ifndef LIBCWD_MACRO_ALLOCTAG_H
19 #define LIBCWD_MACRO_ALLOCTAG_H
21 #ifndef LIBCWD_LIBRARIES_DEBUG_H
22 #error "Don't include <libcwd/macro_AllocTag.h> directly, include the appropriate \"debug.h\" instead."
25 #ifndef LIBCWD_CONFIG_H
35 #ifndef LIBCWD_SMART_PTR_H
38 #ifndef LIBCWD_PRIVATE_SET_ALLOC_CHECKING_H
41 #ifndef LIBCWD_TYPE_INFO_H
44 #ifndef LIBCWD_PRIVATE_INTERNAL_STRINGSTREAM_H
54 extern void set_alloc_label(
void const* ptr, type_info_ct
const& ti,
char const* description LIBCWD_COMMA_TSD_PARAM);
56 extern void set_alloc_label(
void const* ptr, type_info_ct
const& ti, _private_::smart_ptr description LIBCWD_COMMA_TSD_PARAM);
59 extern char* allocate_AllocTag_WS_desc(
size_t size);
60 #ifndef LIBCWD_USE_EXTERNAL_C_LINKAGE_FOR_MALLOC
61 extern void register_external_allocation(
void const* ptr,
size_t size);
135 #define AllocTag1(p) \
137 LIBCWD_TSD_DECLARATION; \
138 ::libcwd::set_alloc_label(p, ::libcwd::type_info_of(p), (char const*)NULL LIBCWD_COMMA_TSD); \
143 #define AllocTag2(p, desc) \
145 LIBCWD_TSD_DECLARATION; \
146 ::libcwd::set_alloc_label(p, ::libcwd::type_info_of(p), const_cast<char const*>(desc) LIBCWD_COMMA_TSD); \
149 #if LIBCWD_THREAD_SAFE
150 #define LIBCWD_ALLOCTAG_LOCK \
153 static pthread_mutex_t WS_desc_mutex = PTHREAD_MUTEX_INITIALIZER; \
154 pthread_mutex_lock(&WS_desc_mutex);
155 #define LIBCWD_ALLOCTAG_UNLOCK \
156 pthread_mutex_unlock(&WS_desc_mutex); \
159 #define LIBCWD_ALLOCTAG_LOCK
160 #define LIBCWD_ALLOCTAG_UNLOCK
166 #define AllocTag(p, x) \
168 LIBCWD_TSD_DECLARATION; \
169 static char* WS_desc; \
170 LIBCWD_ALLOCTAG_LOCK; \
172 ++LIBCWD_DO_TSD_MEMBER_OFF(::libcwd::libcw_do); \
175 ::libcwd::_private_::auto_internal_stringstream buf; \
176 buf << x << ::std::ends; \
177 ::std::streampos pos = buf.rdbuf()->pubseekoff(0, ::std::ios_base::cur, ::std::ios_base::out); \
178 size_t size = pos - ::std::streampos(0); \
179 ::libcwd::_private_::set_alloc_checking_off(LIBCWD_TSD); \
180 WS_desc = ::libcwd::allocate_AllocTag_WS_desc(size); \
181 ::libcwd::_private_::set_alloc_checking_on(LIBCWD_TSD); \
182 buf.rdbuf()->sgetn(WS_desc, size); \
184 --LIBCWD_DO_TSD_MEMBER_OFF(::libcwd::libcw_do); \
186 LIBCWD_ALLOCTAG_UNLOCK; \
187 ::libcwd::set_alloc_label(p, ::libcwd::type_info_of(p), WS_desc LIBCWD_COMMA_TSD); \
193 #define AllocTag_dynamic_description(p, x) \
196 LIBCWD_TSD_DECLARATION; \
197 ++LIBCWD_DO_TSD_MEMBER_OFF(::libcwd::libcw_do); \
200 ::libcwd::_private_::auto_internal_stringstream buf; \
201 buf << x << ::std::ends; \
202 ::std::streampos pos = buf.rdbuf()->pubseekoff(0, ::std::ios_base::cur, ::std::ios_base::out); \
203 size_t size = pos - ::std::streampos(0); \
204 ::libcwd::_private_::set_alloc_checking_off(LIBCWD_TSD); \
205 desc = new char [size]; \
206 ::libcwd::_private_::set_alloc_checking_on(LIBCWD_TSD); \
207 buf.rdbuf()->sgetn(desc, size); \
209 --LIBCWD_DO_TSD_MEMBER_OFF(::libcwd::libcw_do); \
210 ::libcwd::set_alloc_label(p, ::libcwd::type_info_of(p), \
211 ::libcwd::_private_::smart_ptr(desc) LIBCWD_COMMA_TSD); \
214 template<
typename TYPE>
223 __libcwd_allocCatcher(TYPE* new_ptr)
232 #define NEW(x) __libcwd_allocCatcher(new x)
234 #ifndef LIBCWD_USE_EXTERNAL_C_LINKAGE_FOR_MALLOC
238 #define RegisterExternalAlloc(p, s) ::libcwd::register_external_allocation(p, s)
248 #define AllocTag(p, x)
249 #define AllocTag_dynamic_description(p, x)
251 #define AllocTag2(p, desc)
253 #ifndef LIBCWD_USE_EXTERNAL_C_LINKAGE_FOR_MALLOC
254 #define RegisterExternalAlloc(p, s)
namespace for libcwd.
Definition: debug.cc:87