[asterisk-commits] rizzo: branch rizzo/astobj2 r47345 - /team/rizzo/astobj2/main/astobj2.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Nov 8 16:03:00 MST 2006


Author: rizzo
Date: Wed Nov  8 17:03:00 2006
New Revision: 47345

URL: http://svn.digium.com/view/asterisk?rev=47345&view=rev
Log:
a bit more debugging support, including backtrace if
available (support to be committed later).


Modified:
    team/rizzo/astobj2/main/astobj2.c

Modified: team/rizzo/astobj2/main/astobj2.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/main/astobj2.c?rev=47345&r1=47344&r2=47345&view=diff
==============================================================================
--- team/rizzo/astobj2/main/astobj2.c (original)
+++ team/rizzo/astobj2/main/astobj2.c Wed Nov  8 17:03:00 2006
@@ -57,22 +57,45 @@
 
 volatile int ao2_total_objects;
 
+#ifndef HAVE_BKTR	/* backtrace support */
+static void bt(void) {}
+#else
+#include <execinfo.h>    /* for backtrace */
+
+static void bt(void) {
+    int c, i;
+#define N1	20
+    void *addresses[N1];
+    char **strings;
+
+    c = backtrace(addresses, N1);
+    strings = backtrace_symbols(addresses,c);
+    ast_verbose("backtrace returned: %d\n", c);
+    for(i = 0; i < c; i++) {
+        ast_verbose("%d: %p %s\n", i, addresses[i], strings[i]);
+    }
+}
+#endif
 /*
  * From a pointer _p to a user-defined object,
  * return the pointer to the astobj2 structure
  */
-static struct astobj2 *INTERNAL_OBJ(void *user_data)
-{
-	struct astobj2 *p;
-
-	assert (user_data != NULL);
-	p = (struct astobj2 *)((char *)(user_data) - sizeof(struct astobj2));
-	if (AO2_MAGIC != (p->priv_data.magic ^ (uint32_t)p) ) {
-		ast_verbose("----!!!!!--------- bad magic number 0x%x for %p\n", p->priv_data.magic, p);
-		p = NULL;
-	}
-	return p;
-}
+//static inline struct astobj2 *INTERNAL_OBJ(void *user_data)
+#define INTERNAL_OBJ(user_data)	\
+({\
+	struct astobj2 *p;\
+\
+	if (user_data == NULL) {\
+		bt();\
+		assert(user_data != NULL);\
+	}\
+	p = (struct astobj2 *)((char *)(user_data) - sizeof(struct astobj2));\
+	if (AO2_MAGIC != (p->priv_data.magic ^ (uint32_t)p) ) {\
+		ast_verbose("----!!!!!--------- bad magic number 0x%x for %p\n", p->priv_data.magic, p);\
+		p = NULL;\
+	}\
+	(p);\
+})
 
 /*
  * From a pointer _p to an astobj2 object,
@@ -268,8 +291,9 @@
 	/* create a new list entry */
 	struct bucket_list *p;
 	struct astobj2 *obj = INTERNAL_OBJ(user_data);
-
 	if (obj == NULL)
+		return NULL;
+	if (INTERNAL_OBJ(c) == NULL)
 		return NULL;
 	p = ast_calloc(1, sizeof(struct bucket_list));
 	if (p == NULL)		/* alloc failure, die */
@@ -334,6 +358,8 @@
 	int i, last;	/* search boundaries */
 	void *ret = NULL;
 
+	if (INTERNAL_OBJ(c) == NULL)	/* safety check on the argument */
+		return NULL;
 	if ( (flags & (OBJ_SINGLE | OBJ_DATA)) == OBJ_DATA) {
 		ast_log(LOG_WARNING, "multiple data return not implemented yet");
 		return NULL;
@@ -464,6 +490,8 @@
 	int lim;
 	struct bucket_list *p = NULL;
 
+	if (INTERNAL_OBJ(a->c) == NULL)
+		return NULL;
 	if (!(a->flags & F_AO2I_DONTLOCK))
 		ao2_lock(a->c);
 	/* optimization. If the container is unchanged and



More information about the asterisk-commits mailing list