template<typename T> void safe_dispose(T* &ptr); //Intentionally left w/o a body
#define DIPOSEABLE(type) \
template<> void safe_dispose<type>(type* &ptr) \
{ \
std::free(ptr); \
ptr = 0; \
}
#define DISPOSE(ptr) safe_dispose(ptr)
DISPOSEABLE(const char)
#define DISPOSE(point) \
do \
{ \
if( (point) ) \
{ \
if( typeid((point)) == typeid(char*) || typeid((point)) == typeid(const char*) ) \
{ \
if( in_hash_table( (char*)(point) ) ) \
{ \
log_printf( "&RDISPOSE called on STRALLOC pointer: %s, line %d\n", __FILE__, __LINE__ ); \
log_string( "Attempting to correct." ); \
if( str_free( (char*)(point) ) == -1 ) \
log_printf( "&RSTRFREEing bad pointer: %s, line %d\n", __FILE__, __LINE__ ); \
} \
else \
delete[] (point); \
} \
else \
free( (point) ); \
(point) = NULL; \
} \
else \
(point) = NULL; \
} while(0)
template<typename T> void safe_dispose(T* &ptr); // Intentionally left w/o a body
#define DISPOSEABLE(type) \
template<> void safe_dispose<type>(type* &ptr) \
{ \
free(ptr); \
ptr = NULL; \
}
#define DISPOSE(ptr) safe_dispose((ptr))
DISPOSEABLE(const char*)
DISPOSEABLE(const char*)
DISPOSEABLE(const char*)
DISPOSEABLE(const char)
DISPOSEABLE(const char*)
DISPOSEABLE(const char)
template<typename T> void safe_dispose(T* &ptr); // Intentionally left w/o a body
#define DISPOSEABLE(type) \
template<> void safe_dispose<type>(type* &ptr) \
{ \
free(ptr); \
ptr = NULL; \
}
#define DISPOSE(ptr) safe_dispose((ptr))
DISPOSEABLE(const char*)
template<typename T> void safe_dispose(T *&ptr); //Intentionally left undefined
//Yes, BOTH functions are needed
#define DISPOSABLE(type) \
template<> inline void safe_dispose<type>(type *& ptr) \
{ \
std::free(ptr); \
ptr = 0; \
}\
template<> inline void safe_dispose<type>(const type*& ptr)\
{\
std::free(ptr);\
ptr = 0;\
}
DISPOSABLE(CHAR_DATA)
DISPOSABLE(some_other_diku_type)
//THERE IS NO DISPOSABLE(char)!
//Yes, the two functions are BOTH needed
inline void str_free(char *&ptr )
{
//string freeing code
ptr = 0;
}
inline void str_free(const char *&ptr )
{
//string freeing code
ptr = 0;
}
easy way to find DISPOSE and CREATE calls that haven't been changed when they should be. (For constructors and destructors)
Say you recently changed.. EXTRA_DESCR_DATA to a class..
In your DISPOSE macro you would change:
To:
This would print a bug message when DISPOSE was used on an EXTRA_DESCR_DATA pointer, delete it properly and exit the macro. (You also need to #include <typeinfo> at the top of mud.h)