summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-10-03 06:39:19 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:59:34 -0500
commit1429ed54f14055a1a9399452cb6cfc94f9451cf5 (patch)
tree31fe5adaed9e5afe6f886a919078053fa34e7b4f /source4/lib
parent15b9736ed30d8e947dbe2513dd9cf27d5b3761af (diff)
downloadsamba-1429ed54f14055a1a9399452cb6cfc94f9451cf5.tar.gz
samba-1429ed54f14055a1a9399452cb6cfc94f9451cf5.tar.bz2
samba-1429ed54f14055a1a9399452cb6cfc94f9451cf5.zip
r2792: got rid of talloc_ldb_alloc() and instead created talloc_realloc_fn(),
so talloc now doesn't contain any ldb specific functions. allow NULL to be passed to a couple more talloc() functions (This used to be commit 1246f80d806fb5f63cfbf3879de6d546384552a8)
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/ldb/common/ldb_alloc.c4
-rw-r--r--source4/lib/ldb/include/ldb.h4
-rw-r--r--source4/lib/talloc.c23
3 files changed, 17 insertions, 14 deletions
diff --git a/source4/lib/ldb/common/ldb_alloc.c b/source4/lib/ldb/common/ldb_alloc.c
index 6abd6fa8c3..0053c5e73f 100644
--- a/source4/lib/ldb/common/ldb_alloc.c
+++ b/source4/lib/ldb/common/ldb_alloc.c
@@ -39,7 +39,7 @@
this allows the user to choose their own allocation function
*/
int ldb_set_alloc(struct ldb_context *ldb,
- void *(*alloc)(void *context, void *ptr, size_t size),
+ void *(*alloc)(const void *context, void *ptr, size_t size),
void *context)
{
ldb->alloc_ops.alloc = alloc;
@@ -50,7 +50,7 @@ int ldb_set_alloc(struct ldb_context *ldb,
/*
this is the default memory allocation function
*/
-static void *ldb_default_alloc(void *context, void *ptr, size_t size)
+static void *ldb_default_alloc(const void *context, void *ptr, size_t size)
{
/* by setting LDB_ALLOC_OFS to non-zero the test suite can
catch any places where we incorrectly use the libc alloc
diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h
index 241f186991..4b1401f673 100644
--- a/source4/lib/ldb/include/ldb.h
+++ b/source4/lib/ldb/include/ldb.h
@@ -145,7 +145,7 @@ struct ldb_backend_ops {
for pool allocators
*/
struct ldb_alloc_ops {
- void *(*alloc)(void *context, void *ptr, size_t size);
+ void *(*alloc)(const void *context, void *ptr, size_t size);
void *context;
};
@@ -320,7 +320,7 @@ const char *ldb_msg_find_string(const struct ldb_message *msg,
which often take a context argument
*/
int ldb_set_alloc(struct ldb_context *ldb,
- void *(*alloc)(void *context, void *ptr, size_t size),
+ void *(*alloc)(const void *context, void *ptr, size_t size),
void *context);
/*
diff --git a/source4/lib/talloc.c b/source4/lib/talloc.c
index fc65546063..5c1f3e7dcd 100644
--- a/source4/lib/talloc.c
+++ b/source4/lib/talloc.c
@@ -273,6 +273,10 @@ int talloc_unlink(const void *context, void *ptr)
struct talloc_chunk *tc_p, *new_p;
void *new_parent;
+ if (context == NULL) {
+ context = null_context;
+ }
+
if (talloc_unreference(context, ptr) == 0) {
return 0;
}
@@ -561,6 +565,10 @@ void *talloc_steal(const void *new_ctx, const void *ptr)
return NULL;
}
+ if (new_ctx == NULL) {
+ new_ctx = null_context;
+ }
+
tc = talloc_chunk_from_ptr(ptr);
if (new_ctx == NULL) {
@@ -948,16 +956,11 @@ void *talloc_realloc_array(const void *ctx, void *ptr, size_t el_size, unsigned
}
/*
- a alloc function for ldb that uses talloc
+ a function version of talloc_realloc(), so it can be passed as a function pointer
+ to libraries that want a realloc function (a realloc function encapsulates
+ all the basic capabilities of an allocation library, which is why this is useful)
*/
-void *talloc_ldb_alloc(void *context, void *ptr, size_t size)
+void *talloc_realloc_fn(const void *context, void *ptr, size_t size)
{
- if (ptr == NULL) {
- return talloc(context, size);
- }
- if (size == 0) {
- talloc_free(ptr);
- return NULL;
- }
- return talloc_realloc(context, ptr, size);
+ return _talloc_realloc(context, ptr, size, NULL);
}