svn commit: samba r2641 - in branches/SAMBA_4_0/source: include lib
tridge at samba.org
tridge at samba.org
Sun Sep 26 01:41:04 GMT 2004
Author: tridge
Date: 2004-09-26 01:41:04 +0000 (Sun, 26 Sep 2004)
New Revision: 2641
WebSVN: http://websvn.samba.org/websvn/changeset.php?rep=samba&path=/branches/SAMBA_4_0/source&rev=2641&nolog=1
Log:
talloc_p() now produces a named talloc pointer, with the name
auto-derived from the type you are allocating. This is done with
basically zero overhead by relying on the stringify operator in cpp
producing string constants.
the result is that --leak-check nicely names all pointers that come
from talloc_p()
Modified:
branches/SAMBA_4_0/source/include/talloc.h
branches/SAMBA_4_0/source/lib/talloc.c
Changeset:
Modified: branches/SAMBA_4_0/source/include/talloc.h
===================================================================
--- branches/SAMBA_4_0/source/include/talloc.h 2004-09-26 01:14:26 UTC (rev 2640)
+++ branches/SAMBA_4_0/source/include/talloc.h 2004-09-26 01:41:04 UTC (rev 2641)
@@ -25,7 +25,7 @@
typedef void TALLOC_CTX;
/* useful macros for creating type checked pointers */
-#define talloc_p(ctx, type) (type *)talloc(ctx, sizeof(type))
+#define talloc_p(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #type)
#define talloc_array_p(ctx, type, count) (type *)talloc_array(ctx, sizeof(type), count)
#define talloc_realloc_p(p, type, count) (type *)talloc_realloc_array(p, sizeof(type), count)
Modified: branches/SAMBA_4_0/source/lib/talloc.c
===================================================================
--- branches/SAMBA_4_0/source/lib/talloc.c 2004-09-26 01:14:26 UTC (rev 2640)
+++ branches/SAMBA_4_0/source/lib/talloc.c 2004-09-26 01:41:04 UTC (rev 2641)
@@ -39,7 +39,7 @@
uint_t magic;
uint_t ref_count;
int (*destructor)(void *);
- char *name;
+ const char *name;
};
/* panic if we get a bad magic value */
@@ -133,7 +133,7 @@
static void talloc_set_name_v(void *ptr, const char *fmt, va_list ap)
{
struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr);
- vasprintf(&tc->name, fmt, ap);
+ tc->name = talloc_vasprintf(ptr, fmt, ap);
}
/*
@@ -148,6 +148,16 @@
}
/*
+ more efficient way to add a name to a pointer - the name must point to a
+ true string constant
+*/
+void talloc_set_name_const(void *ptr, const char *name)
+{
+ struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr);
+ tc->name = name;
+}
+
+/*
create a named talloc pointer. Any talloc pointer can be named, and
talloc_named() operates just like talloc() except that it allows you
to name the pointer.
@@ -171,6 +181,25 @@
}
/*
+ create a named talloc pointer. Any talloc pointer can be named, and
+ talloc_named() operates just like talloc() except that it allows you
+ to name the pointer.
+*/
+void *talloc_named_const(void *context, size_t size, const char *name)
+{
+ void *ptr;
+
+ ptr = talloc(context, size);
+ if (ptr == NULL) {
+ return NULL;
+ }
+
+ talloc_set_name_const(ptr, name);
+
+ return ptr;
+}
+
+/*
return the name of a talloc ptr, or "UNNAMED"
*/
const char *talloc_get_name(void *ptr)
@@ -250,7 +279,6 @@
}
tc->magic = TALLOC_MAGIC_FREE;
- if (tc->name) free(tc->name);
free(tc);
return 0;
More information about the samba-cvs
mailing list