00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "dcast.h"
00016 #include "config_express.h"
00017
00018 #ifdef _WIN32
00019 #define WIN32_LEAN_AND_MEAN
00020 #include <windows.h>
00021 #endif
00022
00023
00024 #ifdef DO_DCAST
00025
00026
00027
00028
00029
00030
00031 bool
00032 _dcast_verify(TypeHandle want_handle, size_t want_size,
00033 const TypedObject *ptr) {
00034 if (get_verify_dcast()) {
00035 if (ptr == (const TypedObject *)NULL) {
00036
00037
00038 return true;
00039 }
00040 #if defined(_DEBUG) && defined(_WIN32)
00041 if (IsBadWritePtr((TypedObject *)ptr, want_size)) {
00042 express_cat->warning()
00043 << "Attempt to cast invalid pointer to "
00044 << want_handle << "\n";
00045 return false;
00046 }
00047 #endif
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 // DO_DCAST
00063
00064