00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "dcast.h"
00020 #include "config_express.h"
00021
00022 #ifdef _WIN32
00023 #include <windows.h>
00024 #endif
00025
00026
00027 #ifndef NDEBUG
00028
00029
00030
00031
00032
00033
00034 bool
00035 _dcast_verify(TypeHandle want_handle, size_t want_size,
00036 const TypedObject *ptr) {
00037 if (get_verify_dcast()) {
00038 if ((ptr == (const TypedObject *)NULL)
00039 #if defined(_DEBUG) && defined(_WIN32)
00040 || IsBadWritePtr((TypedObject *)ptr, want_size)
00041 #endif
00042 ) {
00043 express_cat->warning()
00044 << "Attempt to cast NULL or invalid pointer to "
00045 << want_handle << "\n";
00046 return false;
00047 }
00048 if (!ptr->is_of_type(want_handle)) {
00049 express_cat->error()
00050 << "Attempt to cast pointer from " << ptr->get_type()
00051 << " to " << want_handle << "\n";
00052 if (ptr->get_type() == TypedObject::get_class_type()) {
00053 express_cat->error(false)
00054 << "Perhaps pointer was inadvertently deleted?\n";
00055 }
00056 return false;
00057 }
00058 }
00059
00060 return true;
00061 }
00062 #endif // NDEBUG
00063