Samba4 poor mans debug_ctx()
authorAmin Azez <azez@ufomechanic.net>
Fri, 1 Feb 2008 16:19:36 +0000 (16:19 +0000)
committerStefan Metzmacher <metze@samba.org>
Fri, 1 Feb 2008 17:09:49 +0000 (18:09 +0100)
DEBUG(), DEBUGADD() and friends can now use debug_ctx() in the
formatting expressions again,
e.g.

DEBUG(5,("Guid failed to match: %s\n", GUID_string(debug_ctx(), r->guid)));

Sadly it's done with macros (again) but when we need to save the 8 or 16
bytes of object code per DEBUG() expression we can do it the Samba 3 way
with added thread-safety for Samba 4. That could save up to 200K,
allowing 12 bytes for each occurrance of DEBUG...

Signed-off-by: Amin Azez <azez@ufomechanic.net>
source/lib/util/debug.h

index 1895ed53adf228ff0c2ee4ff389666d9c793a674..605628174a949589b433303cff2356ad722f410d 100644 (file)
@@ -41,13 +41,17 @@ struct debug_ops {
 
 extern int DEBUGLEVEL;
 
+#define debug_ctx() (_debug_ctx?_debug_ctx:(_debug_ctx=talloc_new(NULL)))
+
 #define DEBUGLVL(level) ((level) <= DEBUGLEVEL)
 #define _DEBUG(level, body, header) do { \
        if (DEBUGLVL(level)) { \
+               void* _debug_ctx=NULL; \
                if (header) { \
                        do_debug_header(level, __location__, __FUNCTION__); \
                } \
                do_debug body; \
+               talloc_free(_debug_ctx); \
        } \
 } while (0)
 /**