1
0
mirror of https://github.com/samba-team/samba.git synced 2025-11-28 12:23:49 +03:00

r2653: - data_blob() and data_blob_talloc() now get automatic names

- talloc_strdup() and related functions get automatic names
This commit is contained in:
Andrew Tridgell
2004-09-26 06:41:59 +00:00
committed by Gerald (Jerry) Carter
parent 4aba6e7101
commit 0cf427d14f
3 changed files with 20 additions and 11 deletions

View File

@@ -38,6 +38,7 @@ typedef void TALLOC_CTX;
#define talloc_p(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #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, __location__) #define talloc_array_p(ctx, type, count) (type *)talloc_array(ctx, sizeof(type), count, __location__)
#define talloc_realloc_p(p, type, count) (type *)talloc_realloc_array(p, sizeof(type), count, __location__) #define talloc_realloc_p(p, type, count) (type *)talloc_realloc_array(p, sizeof(type), count, __location__)
#define talloc_memdup(t, p, size) _talloc_memdup(t, p, size, __location__)
#define talloc_destroy(ctx) talloc_free(ctx) #define talloc_destroy(ctx) talloc_free(ctx)
@@ -45,5 +46,7 @@ typedef void TALLOC_CTX;
#define malloc_array_p(type, count) (type *)realloc_array(NULL, sizeof(type), count) #define malloc_array_p(type, count) (type *)realloc_array(NULL, sizeof(type), count)
#define realloc_p(p, type, count) (type *)realloc_array(p, sizeof(type), count) #define realloc_p(p, type, count) (type *)realloc_array(p, sizeof(type), count)
#define data_blob(ptr, size) data_blob_named(ptr, size, __location__)
#endif #endif

View File

@@ -25,7 +25,7 @@
construct a data blob, must be freed with data_blob_free() construct a data blob, must be freed with data_blob_free()
you can pass NULL for p and get a blank data blob you can pass NULL for p and get a blank data blob
*******************************************************************/ *******************************************************************/
DATA_BLOB data_blob(const void *p, size_t length) DATA_BLOB data_blob_named(const void *p, size_t length, const char *name)
{ {
DATA_BLOB ret; DATA_BLOB ret;
@@ -43,6 +43,7 @@ DATA_BLOB data_blob(const void *p, size_t length)
ret.length = 0; ret.length = 0;
return ret; return ret;
} }
talloc_set_name_const(ret.data, name);
ret.length = length; ret.length = length;
return ret; return ret;
} }

View File

@@ -26,9 +26,6 @@
#include "includes.h" #include "includes.h"
#undef talloc
#define talloc(ctx, size) _talloc(ctx, size)
#define MAX_TALLOC_SIZE 0x10000000 #define MAX_TALLOC_SIZE 0x10000000
#define TALLOC_MAGIC 0xe814ec4f #define TALLOC_MAGIC 0xe814ec4f
#define TALLOC_MAGIC_FREE 0x7faebef3 #define TALLOC_MAGIC_FREE 0x7faebef3
@@ -171,7 +168,7 @@ void *talloc_named(void *context, size_t size,
va_list ap; va_list ap;
void *ptr; void *ptr;
ptr = talloc(context, size); ptr = _talloc(context, size);
if (ptr == NULL) { if (ptr == NULL) {
return NULL; return NULL;
} }
@@ -192,7 +189,7 @@ void *talloc_named_const(void *context, size_t size, const char *name)
{ {
void *ptr; void *ptr;
ptr = talloc(context, size); ptr = _talloc(context, size);
if (ptr == NULL) { if (ptr == NULL) {
return NULL; return NULL;
} }
@@ -222,7 +219,7 @@ void *talloc_init(const char *fmt, ...) _PRINTF_ATTRIBUTE(1,2)
va_list ap; va_list ap;
void *ptr; void *ptr;
ptr = talloc(NULL, 0); ptr = _talloc(NULL, 0);
if (ptr == NULL) { if (ptr == NULL) {
return NULL; return NULL;
} }
@@ -438,7 +435,7 @@ static void talloc_report_all(void)
*/ */
void talloc_enable_leak_check(void) void talloc_enable_leak_check(void)
{ {
null_context = talloc_named(NULL, 0, "null_context"); null_context = talloc_named_const(NULL, 0, "null_context");
atexit(talloc_report_all); atexit(talloc_report_all);
} }
@@ -460,12 +457,13 @@ void *talloc_zero(void *t, size_t size)
/* /*
memdup with a talloc. memdup with a talloc.
*/ */
void *talloc_memdup(void *t, const void *p, size_t size) void *_talloc_memdup(void *t, const void *p, size_t size, const char *name)
{ {
void *newp = talloc(t,size); void *newp = _talloc(t,size);
if (newp) { if (newp) {
memcpy(newp, p, size); memcpy(newp, p, size);
talloc_set_name_const(newp, name);
} }
return newp; return newp;
@@ -476,10 +474,15 @@ void *talloc_memdup(void *t, const void *p, size_t size)
*/ */
char *talloc_strdup(void *t, const char *p) char *talloc_strdup(void *t, const char *p)
{ {
char *ret;
if (!p) { if (!p) {
return NULL; return NULL;
} }
return talloc_memdup(t, p, strlen(p) + 1); ret = talloc_memdup(t, p, strlen(p) + 1);
if (ret) {
talloc_set_name_const(ret, ret);
}
return ret;
} }
/* /*
@@ -511,6 +514,7 @@ char *talloc_vasprintf(void *t, const char *fmt, va_list ap) _PRINTF_ATTRIBUTE(2
if (ret) { if (ret) {
VA_COPY(ap2, ap); VA_COPY(ap2, ap);
vsnprintf(ret, len+1, fmt, ap2); vsnprintf(ret, len+1, fmt, ap2);
talloc_set_name_const(ret, ret);
} }
return ret; return ret;
@@ -563,6 +567,7 @@ static char *talloc_vasprintf_append(char *s,
VA_COPY(ap2, ap); VA_COPY(ap2, ap);
vsnprintf(s+s_len, len+1, fmt, ap2); vsnprintf(s+s_len, len+1, fmt, ap2);
talloc_set_name_const(s, s);
return s; return s;
} }