27 #undef NULL_FOR_BAD_CAST
28 #ifdef NULL_FOR_BAD_CAST
29 # define BADCASTMSG g_critical
31 # define BADCASTMSG g_error
66 static GHashTable* ObjectClassAssociation= NULL;
67 static GHashTable* SuperClassAssociation = NULL;
68 static GHashTable* DebugClassAssociation = NULL;
69 static GHashTable* FreedClassAssociation = NULL;
70 static guint32 proj_class_obj_count = 0;
71 static guint32 proj_class_max_obj_count = 0;
81 ObjectClassAssociation = g_hash_table_new(NULL, NULL);
82 FreedClassAssociation = g_hash_table_new(NULL, NULL);
83 SuperClassAssociation = g_hash_table_new(NULL, NULL);
84 DebugClassAssociation = g_hash_table_new(g_str_hash, g_str_equal);
90 g_hash_table_destroy(ObjectClassAssociation); ObjectClassAssociation = NULL;
91 g_hash_table_destroy(FreedClassAssociation); FreedClassAssociation = NULL;
92 g_hash_table_destroy(SuperClassAssociation); SuperClassAssociation = NULL;
93 g_hash_table_destroy(DebugClassAssociation); DebugClassAssociation = NULL;
101 const char * static_classname)
104 GQuark classquark = g_quark_from_static_string(static_classname);
106 if (NULL == ObjectClassAssociation) {
109 if (NULL != g_hash_table_lookup(ObjectClassAssociation,
object)) {
110 g_error(
"Attempt to re-allocate memory already allocated at address %p",
object);
112 g_hash_table_insert(ObjectClassAssociation,
object, GUINT_TO_POINTER(classquark));
113 ++ proj_class_obj_count;
114 if (proj_class_obj_count > proj_class_max_obj_count) {
115 proj_class_max_obj_count = proj_class_obj_count;
119 static guint global_debug_counter = 0;
124 if (NULL == ObjectClassAssociation) {
127 if (*debugcount == 0) {
128 *debugcount = global_debug_counter;
133 g_hash_table_replace(DebugClassAssociation, (gpointer)((guintptr)classname), debugcount);
161 GQuark CclassQuark = g_quark_from_static_string(Cclass);
163 if (DebugClassAssociation) {
164 g_hash_table_iter_init(&iter, DebugClassAssociation);
168 while (g_hash_table_iter_next(&iter, &classname, &gdebugptr)) {
169 guint* debug = gdebugptr;
170 GQuark classQ = g_quark_from_static_string(classname);
172 if (incr < 0 && (guint)-incr >= *debug) {
180 if (Cclass == NULL) {
181 if (incr < 0 && (guint)-incr >= global_debug_counter) {
182 global_debug_counter = 0;
184 global_debug_counter += incr;
193 const char * static_subclassname)
196 GQuark subclassquark = g_quark_from_static_string(static_subclassname);
197 GQuark superclassquark;
199 if (NULL == ObjectClassAssociation) {
202 superclassquark = GPOINTER_TO_INT(g_hash_table_lookup(ObjectClassAssociation,
object));
203 if (0 == superclassquark) {
204 g_error(
"Attempt to subclass an object that's not a class object %p",
object);
208 g_hash_table_replace(ObjectClassAssociation,
object, GUINT_TO_POINTER(subclassquark));
215 const char * static_classname)
217 gpointer ret =
MALLOC0(objsize);
230 GQuark objquark = GPOINTER_TO_INT(g_hash_table_lookup(ObjectClassAssociation,
object));
231 -- proj_class_obj_count;
233 GQuark freedquark = GPOINTER_TO_INT(g_hash_table_lookup(FreedClassAssociation,
object));
234 const char * oldclass = (freedquark == 0 ?
"(unknown class)" : g_quark_to_string(freedquark));
235 BADCASTMSG(
"Attempt to free memory not currently shown as allocated to a class object - former class: %s"
240 g_hash_table_insert(FreedClassAssociation,
object, GUINT_TO_POINTER(objquark));
241 g_hash_table_remove(ObjectClassAssociation,
object);
263 if (NULL ==
object) {
267 objquark = GPOINTER_TO_INT(g_hash_table_lookup(ObjectClassAssociation,
object));
268 classquark = g_quark_from_static_string(Cclass);
270 if (objquark != classquark || classquark == 0) {
286 const char * castclass)
290 GQuark freedquark = GPOINTER_TO_INT(g_hash_table_lookup(FreedClassAssociation,
object));
291 const char * oldclass = (freedquark == 0 ?
"(unknown class)" : g_quark_to_string(freedquark));
292 BADCASTMSG(
"Attempt to cast %s pointer at address %p to %s (formerly a %s)", objclass,
object, castclass
306 const char * castclass)
310 GQuark freedquark = GPOINTER_TO_INT(g_hash_table_lookup(FreedClassAssociation,
object));
311 const char * oldclass = (freedquark == 0 ?
"(unknown class)" : g_quark_to_string(freedquark));
312 BADCASTMSG(
"Attempt to cast %s pointer at address %p to a const %s (formerly a %s)", objclass,
object, castclass
326 GQuark objquark = GPOINTER_TO_INT(g_hash_table_lookup(ObjectClassAssociation,
object));
327 return (objquark == 0 ?
"(unknown class)" : g_quark_to_string(objquark));
336 g_hash_table_insert(SuperClassAssociation, GUINT_TO_POINTER(subclass), GUINT_TO_POINTER(superclass));
345 while (objectclass != 0) {
346 if (objectclass == testclass) {
349 objectclass = GPOINTER_TO_INT(g_hash_table_lookup(SuperClassAssociation, GUINT_TO_POINTER(objectclass)));
362 g_debug(
"START of live C Class object dump:");
363 if (ObjectClassAssociation) {
364 g_hash_table_iter_init(&iter, ObjectClassAssociation);
365 while (g_hash_table_iter_next(&iter, &
object, &quarkp)) {
369 g_debug(
" %s object %s at %p ref count %d"
377 g_debug(
"END of live C Class object dump.");
384 char * objstr = NULL;
385 const char * pad =
"";
387 if (prefix != NULL) {
394 , (prefix == NULL ?
"" : prefix)
396 , (obj == NULL ?
"<NULL OBJECT>" : objstr)
397 , (suffix == NULL ?
"" : suffix));
399 g_free(objstr); objstr = NULL;
414 if (ObjectClassAssociation) {
415 g_hash_table_iter_init(&iter, ObjectClassAssociation);
416 while (g_hash_table_iter_next(&iter, &
object, &quarkp)) {
420 g_assert(count == proj_class_obj_count);
428 return proj_class_max_obj_count;