so talloc now doesn't contain any ldb specific functions.
allow NULL to be passed to a couple more talloc() functions
attrs[i] = NULL;
}
- ldb_set_alloc(ldb, talloc_ldb_alloc, samdb);
+ ldb_set_alloc(ldb, talloc_realloc_fn, samdb);
count = ldb_search(ldb, basedn, scope, r->filter, attrs, &res);
for (i=0; i < count; i++) {
add_result->dn = talloc_steal(add_reply, dn);
if (result == LDAP_SUCCESS) {
- ldb_set_alloc(ldb, talloc_ldb_alloc, samdb);
+ ldb_set_alloc(ldb, talloc_realloc_fn, samdb);
ldb_ret = ldb_add(ldb, msg);
if (ldb_ret == 0) {
result = LDAP_SUCCESS;
DEBUG(10, ("sldb_Del: dn: [%s]\n", dn));
- ldb_set_alloc(ldb, talloc_ldb_alloc, samdb);
+ ldb_set_alloc(ldb, talloc_realloc_fn, samdb);
ldb_ret = ldb_delete(ldb, dn);
del_reply = ldapsrv_init_reply(call, LDAP_TAG_DelResponse);
modify_result->dn = talloc_steal(modify_reply, dn);
if (result == LDAP_SUCCESS) {
- ldb_set_alloc(ldb, talloc_ldb_alloc, samdb);
+ ldb_set_alloc(ldb, talloc_realloc_fn, samdb);
ldb_ret = ldb_modify(ldb, msg);
if (ldb_ret == 0) {
result = LDAP_SUCCESS;
attrs[0] = NULL;
- ldb_set_alloc(ldb, talloc_ldb_alloc, samdb);
+ ldb_set_alloc(ldb, talloc_realloc_fn, samdb);
count = ldb_search(ldb, dn, LDB_SCOPE_BASE, filter, attrs, &res);
compare_r = ldapsrv_init_reply(call, LDAP_TAG_CompareResponse);
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;
/*
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
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;
};
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);
/*
struct talloc_chunk *tc_p, *new_p;
void *new_parent;
+ if (context == NULL) {
+ context = null_context;
+ }
+
if (talloc_unreference(context, ptr) == 0) {
return 0;
}
return NULL;
}
+ if (new_ctx == NULL) {
+ new_ctx = null_context;
+ }
+
tc = talloc_chunk_from_ptr(ptr);
if (new_ctx == NULL) {
}
/*
- 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);
}
return -1;
}
- ldb_set_alloc(ldb, talloc_ldb_alloc, mem_ctx);
+ ldb_set_alloc(ldb, talloc_realloc_fn, mem_ctx);
count = ldb_search(ldb, basedn, LDB_SCOPE_SUBTREE, expr, attrs, res);
return NULL;
}
- ldb_set_alloc(ldb, talloc_ldb_alloc, mem_ctx);
+ ldb_set_alloc(ldb, talloc_realloc_fn, mem_ctx);
return ldb;
}
TALLOC_CTX *mem_ctx, struct ldb_message **res)
{
struct samdb_context *sam_ctx = ctx;
- ldb_set_alloc(sam_ctx->ldb, talloc_ldb_alloc, mem_ctx);
+ ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_search_free(sam_ctx->ldb, res);
}
if (s == NULL || a == NULL) {
return -1;
}
- ldb_set_alloc(sam_ctx->ldb, talloc_ldb_alloc, mem_ctx);
+ ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_msg_add_string(sam_ctx->ldb, msg, a, s);
}
if (a == NULL) {
return -1;
}
- ldb_set_alloc(sam_ctx->ldb, talloc_ldb_alloc, mem_ctx);
+ ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
/* we use an empty replace rather than a delete, as it allows for
samdb_replace() to be used everywhere */
return ldb_msg_add_empty(sam_ctx->ldb, msg, a, LDB_FLAG_MOD_REPLACE);
return -1;
}
memcpy(val.data, hash.hash, 16);
- ldb_set_alloc(sam_ctx->ldb, talloc_ldb_alloc, mem_ctx);
+ ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_msg_add_value(sam_ctx->ldb, msg, attr_name, &val);
}
for (i=0;i<count;i++) {
memcpy(i*16 + (char *)val.data, hashes[i].hash, 16);
}
- ldb_set_alloc(sam_ctx->ldb, talloc_ldb_alloc, mem_ctx);
+ ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_msg_add_value(sam_ctx->ldb, msg, attr_name, &val);
}
struct ldb_val val;
val.length = hours.units_per_week / 8;
val.data = hours.bitmap;
- ldb_set_alloc(sam_ctx->ldb, talloc_ldb_alloc, mem_ctx);
+ ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_msg_add_value(sam_ctx->ldb, msg, attr_name, &val);
}
struct samdb_context *sam_ctx = ctx;
struct ldb_message_element *el;
- ldb_set_alloc(sam_ctx->ldb, talloc_ldb_alloc, mem_ctx);
+ ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
el = ldb_msg_find_element(msg, attr_name);
if (el) {
{
struct samdb_context *sam_ctx = ctx;
- ldb_set_alloc(sam_ctx->ldb, talloc_ldb_alloc, mem_ctx);
+ ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_add(sam_ctx->ldb, msg);
}
{
struct samdb_context *sam_ctx = ctx;
- ldb_set_alloc(sam_ctx->ldb, talloc_ldb_alloc, mem_ctx);
+ ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_delete(sam_ctx->ldb, dn);
}
{
struct samdb_context *sam_ctx = ctx;
- ldb_set_alloc(sam_ctx->ldb, talloc_ldb_alloc, mem_ctx);
+ ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_modify(sam_ctx->ldb, msg);
}
except that it provides integer overflow protection for the multiply,
returning NULL if the multiply overflows.
+
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+void *talloc_realloc_fn(const void *ctx, void *ptr, size_t size);
+
+This is a non-macro version of talloc_realloc(), which is useful
+as libraries sometimes want a ralloc function pointer. A realloc()
+implementation encapsulates the functionality of malloc(), free() and
+realloc() in one call, which is why it is useful to be able to pass
+around a single function pointer.
+