From 05cdd9ccafeeb384792b9ce7ca044bcec1bfc839 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Sep 2006 02:33:51 +0000 Subject: [PATCH] r18439: 2nd try at a talloc_move() api. This type with the ** ptr interface exposed. Unfortunately this generates a large number of type punning warnings. We'll have to find some magic to hide those. (This used to be commit 254cbf09dee5a1e20c47e47a298f1a8d172b41b9) --- source4/lib/ldb/common/ldb.c | 4 ++-- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 7 ++++--- source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c | 2 +- source4/lib/ldb/ldb_tdb/ldb_index.c | 8 ++++---- source4/lib/ldb/ldb_tdb/ldb_search.c | 2 +- source4/lib/ldb/modules/asq.c | 4 ++-- source4/lib/ldb/modules/objectclass.c | 2 +- source4/lib/ldb/modules/paged_results.c | 4 ++-- source4/lib/ldb/modules/sort.c | 12 ++++++------ source4/lib/ldb/tools/ad2oLschema.c | 9 +++++---- source4/lib/ldb/tools/ldbsearch.c | 4 ++-- source4/lib/talloc/talloc.3.xml | 2 +- source4/lib/talloc/talloc.h | 2 +- source4/lib/talloc/testsuite.c | 4 ++-- 14 files changed, 34 insertions(+), 32 deletions(-) diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c index 1089fb3d92e..473c6324edb 100644 --- a/source4/lib/ldb/common/ldb.c +++ b/source4/lib/ldb/common/ldb.c @@ -528,7 +528,7 @@ static int ldb_search_callback(struct ldb_context *ldb, void *context, struct ld res->msgs[res->count + 1] = NULL; - res->msgs[res->count] = talloc_move(res->msgs, ares->message); + res->msgs[res->count] = talloc_move(res->msgs, &ares->message); res->count++; } @@ -544,7 +544,7 @@ static int ldb_search_callback(struct ldb_context *ldb, void *context, struct ld goto error; } - res->refs[n] = talloc_move(res->refs, ares->referral); + res->refs[n] = talloc_move(res->refs, &ares->referral); res->refs[n + 1] = NULL; } diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 49a8e8627a4..5b69ac06c9a 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -249,7 +249,7 @@ static void ildb_callback(struct ldap_request *req) return; } - ares->controls = talloc_move(ares, msg->controls); + ares->controls = talloc_move(ares, &msg->controls); if (msg->r.SearchResultDone.resultcode) { if (msg->r.SearchResultDone.errormessage) { ldb_set_errstring(ac->module->ldb, msg->r.SearchResultDone.errormessage); @@ -278,7 +278,8 @@ static void ildb_callback(struct ldap_request *req) return; } ares->message->num_elements = search->num_attributes; - ares->message->elements = talloc_move(ares->message, search->attributes); + ares->message->elements = talloc_move(ares->message, + &search->attributes); handle->status = LDB_SUCCESS; handle->state = LDB_ASYNC_PENDING; @@ -391,7 +392,7 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg req->async.fn = ildb_callback; req->async.private_data = (void *)h; - ildb_ac->req = talloc_move(ildb_ac, req); + ildb_ac->req = talloc_move(ildb_ac, &req); *handle = h; return LDB_SUCCESS; diff --git a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c index 9d71b9e8e85..91256222b12 100644 --- a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c +++ b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c @@ -865,7 +865,7 @@ static int lsql_search_sync_callback(struct ldb_context *ldb, void *context, str res->msgs[res->count + 1] = NULL; - res->msgs[res->count] = talloc_move(res->msgs, ares->message); + res->msgs[res->count] = talloc_move(res->msgs, &ares->message); res->count++; } else { ldb_debug(ldb, LDB_DEBUG_ERROR, "unrecognized async reply in ltdb_search_sync_callback!\n"); diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c index f2816ec1daf..59c1645ba8c 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_index.c +++ b/source4/lib/ldb/ldb_tdb/ldb_index.c @@ -378,7 +378,7 @@ static int list_intersect(struct ldb_context *ldb, for (i=0;icount;i++) { if (ldb_list_find(list->dn[i], list2->dn, list2->count, sizeof(char *), (comparison_fn_t)strcmp) != -1) { - list3->dn[list3->count] = talloc_move(list3->dn, list->dn[i]); + list3->dn[list3->count] = talloc_move(list3->dn, &list->dn[i]); list3->count++; } else { talloc_free(list->dn[i]); @@ -386,7 +386,7 @@ static int list_intersect(struct ldb_context *ldb, } talloc_free(list->dn); - list->dn = talloc_move(list, list3->dn); + list->dn = talloc_move(list, &list3->dn); list->count = list3->count; talloc_free(list3); @@ -486,7 +486,7 @@ static int ltdb_index_dn_or(struct ldb_module *module, if (ret == -1) { ret = 1; - list->dn = talloc_move(list, list2->dn); + list->dn = talloc_move(list, &list2->dn); list->count = list2->count; } else { if (list_union(ldb, list, list2) == -1) { @@ -567,7 +567,7 @@ static int ltdb_index_dn_and(struct ldb_module *module, if (ret == -1) { ret = 1; talloc_free(list->dn); - list->dn = talloc_move(list, list2->dn); + list->dn = talloc_move(list, &list2->dn); list->count = list2->count; } else { if (list_intersect(ldb, list, list2) == -1) { diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 612ca5c0fe4..7cdb2b672f0 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -312,7 +312,7 @@ int ltdb_add_attr_results(struct ldb_module *module, (*res) = res2; - (*res)[*count] = talloc_move(*res, msg2); + (*res)[*count] = talloc_move(*res, &msg2); (*res)[(*count)+1] = NULL; (*count)++; diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index 75afae2c7e7..229a6eacd94 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -117,7 +117,7 @@ static int asq_terminate(struct ldb_handle *handle) if (ac->controls) { for (i = 0; ac->controls[i]; i++); - ares->controls = talloc_move(ares, ac->controls); + ares->controls = talloc_move(ares, &ac->controls); } else { i = 0; } @@ -162,7 +162,7 @@ static int asq_base_callback(struct ldb_context *ldb, void *context, struct ldb_ /* we are interested only in the single reply (base search) we receive here */ if (ares->type == LDB_REPLY_ENTRY) { - ac->base_res = talloc_move(ac, ares); + ac->base_res = talloc_move(ac, &ares); } else { talloc_free(ares); } diff --git a/source4/lib/ldb/modules/objectclass.c b/source4/lib/ldb/modules/objectclass.c index fb7cd5db5e0..493ecdaad40 100644 --- a/source4/lib/ldb/modules/objectclass.c +++ b/source4/lib/ldb/modules/objectclass.c @@ -439,7 +439,7 @@ static int get_self_callback(struct ldb_context *ldb, void *context, struct ldb_ return LDB_ERR_OPERATIONS_ERROR; } - ac->search_res = talloc_move(ac, ares); + ac->search_res = talloc_move(ac, &ares); } else { talloc_free(ares); } diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index 6636efcccbe..133ee1fb782 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -210,7 +210,7 @@ static int paged_search_callback(struct ldb_context *ldb, void *context, struct } if (ares->type == LDB_REPLY_DONE) { - ac->store->controls = talloc_move(ac->store, ares->controls); + ac->store->controls = talloc_move(ac->store, &ares->controls); talloc_free(ares); } @@ -383,7 +383,7 @@ static int paged_results(struct ldb_handle *handle) ares->controls = ac->store->controls; while (ares->controls[i]) i++; /* counting */ - ares->controls = talloc_move(ares, ac->store->controls); + ares->controls = talloc_move(ares, &ac->store->controls); num_ctrls += i; } diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index acee40833be..3a0598c5289 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -185,7 +185,7 @@ static int server_sort_search_callback(struct ldb_context *ldb, void *context, s ac->msgs[ac->num_msgs + 1] = NULL; - ac->msgs[ac->num_msgs] = talloc_move(ac->msgs, ares->message); + ac->msgs[ac->num_msgs] = talloc_move(ac->msgs, &ares->message); ac->num_msgs++; } @@ -196,13 +196,13 @@ static int server_sort_search_callback(struct ldb_context *ldb, void *context, s } ac->referrals[ac->num_refs + 1] = NULL; - ac->referrals[ac->num_refs] = talloc_move(ac->referrals, ares->referral); + ac->referrals[ac->num_refs] = talloc_move(ac->referrals, &ares->referral); ac->num_refs++; } if (ares->type == LDB_REPLY_DONE) { - ac->controls = talloc_move(ac, ares->controls); + ac->controls = talloc_move(ac, &ares->controls); } talloc_free(ares); @@ -330,7 +330,7 @@ static int server_sort_results(struct ldb_handle *handle) } ares->type = LDB_REPLY_ENTRY; - ares->message = talloc_move(ares, ac->msgs[i]); + ares->message = talloc_move(ares, &ac->msgs[i]); handle->status = ac->up_callback(ac->module->ldb, ac->up_context, ares); if (handle->status != LDB_SUCCESS) { @@ -346,7 +346,7 @@ static int server_sort_results(struct ldb_handle *handle) } ares->type = LDB_REPLY_REFERRAL; - ares->referral = talloc_move(ares, ac->referrals[i]); + ares->referral = talloc_move(ares, &ac->referrals[i]); handle->status = ac->up_callback(ac->module->ldb, ac->up_context, ares); if (handle->status != LDB_SUCCESS) { @@ -361,7 +361,7 @@ static int server_sort_results(struct ldb_handle *handle) } ares->type = LDB_REPLY_DONE; - ares->controls = talloc_move(ares, ac->controls); + ares->controls = talloc_move(ares, &ac->controls); handle->status = ac->up_callback(ac->module->ldb, ac->up_context, ares); if (handle->status != LDB_SUCCESS) { diff --git a/source4/lib/ldb/tools/ad2oLschema.c b/source4/lib/ldb/tools/ad2oLschema.c index dae3778d82f..23cf892930c 100644 --- a/source4/lib/ldb/tools/ad2oLschema.c +++ b/source4/lib/ldb/tools/ad2oLschema.c @@ -139,7 +139,8 @@ static int fetch_oc_recursive(struct ldb_context *ldb, struct ldb_dn *schemadn, if (!res_list->msgs) { return LDB_ERR_OPERATIONS_ERROR; } - res_list->msgs[res_list->count] = talloc_move(res_list, search_from->msgs[i]); + res_list->msgs[res_list->count] = talloc_move(res_list, + &search_from->msgs[i]); res_list->count++; res_list->msgs[res_list->count] = NULL; @@ -191,7 +192,7 @@ static int fetch_objectclass_schema(struct ldb_context *ldb, struct ldb_dn *sche return LDB_ERR_OPERATIONS_ERROR; } - *objectclasses_res = talloc_move(mem_ctx, ret_res); + *objectclasses_res = talloc_move(mem_ctx, &ret_res); return ret; } @@ -280,7 +281,7 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ p++; oid_map = talloc_realloc(mem_ctx, oid_map, struct oid_map, num_maps + 2); trim_string(line, " ", " "); - oid_map[num_maps].old_oid = talloc_move(oid_map, line); + oid_map[num_maps].old_oid = talloc_move(oid_map, &line); trim_string(p, " ", " "); oid_map[num_maps].new_oid = p; num_maps++; @@ -288,7 +289,7 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ } else { attrs_skip = talloc_realloc(mem_ctx, attrs_skip, const char *, num_skip + 2); trim_string(line, " ", " "); - attrs_skip[num_skip] = talloc_move(attrs_skip, line); + attrs_skip[num_skip] = talloc_move(attrs_skip, &line); num_skip++; attrs_skip[num_skip] = NULL; } diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 181d857efc6..23d8115c201 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -81,7 +81,7 @@ static int store_message(struct ldb_message *msg, struct search_context *sctx) { return -1; } - sctx->store[sctx->num_stored] = talloc_move(sctx->store, msg); + sctx->store[sctx->num_stored] = talloc_move(sctx->store, &msg); sctx->num_stored++; sctx->store[sctx->num_stored] = NULL; @@ -96,7 +96,7 @@ static int store_referral(char *referral, struct search_context *sctx) { return -1; } - sctx->refs_store[sctx->refs] = talloc_move(sctx->refs_store, referral); + sctx->refs_store[sctx->refs] = talloc_move(sctx->refs_store, &referral); sctx->refs++; sctx->refs_store[sctx->refs] = NULL; diff --git a/source4/lib/talloc/talloc.3.xml b/source4/lib/talloc/talloc.3.xml index 76b54ddb801..2400fef2dc5 100644 --- a/source4/lib/talloc/talloc.3.xml +++ b/source4/lib/talloc/talloc.3.xml @@ -387,7 +387,7 @@ talloc_realloc(ctx, ptr, type, 0) ==> talloc_free(ptr); data if you do this. - TYPE *talloc_move(const void *<emphasis role="italic">new_ctx</emphasis>, TYPE *<emphasis role="italic">ptr</emphasis>); + TYPE *talloc_move(const void *<emphasis role="italic">new_ctx</emphasis>, TYPE **<emphasis role="italic">ptr</emphasis>); The talloc_move() function is a wrapper around talloc_steal() which zeros the source pointer after the diff --git a/source4/lib/talloc/talloc.h b/source4/lib/talloc/talloc.h index b9ecd8f0b81..56f9dbb21ab 100644 --- a/source4/lib/talloc/talloc.h +++ b/source4/lib/talloc/talloc.h @@ -73,7 +73,7 @@ typedef void TALLOC_CTX; #endif #define talloc_reference(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_reference((ctx),(ptr)) -#define talloc_move(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_move((ctx),&(ptr)) +#define talloc_move(ctx, ptr) (_TALLOC_TYPEOF(*(ptr)))_talloc_move((ctx),(const void **)(ptr)) /* useful macros for creating type checked pointers */ #define talloc(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #type) diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index 38039c11bf4..00ea212e58f 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -750,8 +750,8 @@ static bool test_move(void) t1->x = talloc(t1, int); *t1->x = 42; - t2->p = talloc_move(t2, t1->p); - t2->x = talloc_move(t2, t1->x); + t2->p = talloc_move(t2, &t1->p); + t2->x = talloc_move(t2, &t1->x); if (t1->p != NULL || t1->x != NULL || strcmp(t2->p, "foo") || *t2->x != 42) { -- 2.34.1