diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2012-06-19 12:42:08 +0930 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2012-06-19 05:38:07 +0200 |
commit | d938c0b591d9c4aff9c92ae5eedd26ed97455f42 (patch) | |
tree | e3744f9c660fbf23d759493e0391d577e528ffcd /lib/ntdb/ntdb.h | |
parent | 6d5a3e1602a1db8ca8e778f5e4f40bb623dff1e7 (diff) | |
download | samba-d938c0b591d9c4aff9c92ae5eedd26ed97455f42.tar.gz samba-d938c0b591d9c4aff9c92ae5eedd26ed97455f42.tar.bz2 samba-d938c0b591d9c4aff9c92ae5eedd26ed97455f42.zip |
ntdb: allocator attribute.
This is designed to allow us to make ntdb_context (and NTDB_DATA returned
from ntdb_fetch) a talloc pointer. But it can also be used for any other
alternate allocator.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/ntdb/ntdb.h')
-rw-r--r-- | lib/ntdb/ntdb.h | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/lib/ntdb/ntdb.h b/lib/ntdb/ntdb.h index 1a011fddf5..87f3f5bbfa 100644 --- a/lib/ntdb/ntdb.h +++ b/lib/ntdb/ntdb.h @@ -633,6 +633,7 @@ enum ntdb_attribute_type { NTDB_ATTRIBUTE_STATS = 3, NTDB_ATTRIBUTE_OPENHOOK = 4, NTDB_ATTRIBUTE_FLOCK = 5, + NTDB_ATTRIBUTE_ALLOCATOR = 6 }; /** @@ -865,6 +866,30 @@ struct ntdb_attribute_flock { }; /** + * struct ntdb_attribute_allocator - allocator for ntdb to use. + * + * You can replace malloc/free with your own allocation functions. + * The allocator takes an "owner" pointer, which is either NULL (for + * the initial struct ntdb_context and struct ntdb_file), or a + * previously allocated pointer. This is useful for relationship + * tracking, such as the talloc library. + * + * The expand function is realloc, but only ever used to expand an + * existing allocation. + * + * Be careful mixing allocators: two ntdb_contexts which have the same file + * open will share the same struct ntdb_file. This may be allocated by one + * ntdb's allocator, and freed by the other. + */ +struct ntdb_attribute_allocator { + struct ntdb_attribute_base base; /* .attr = NTDB_ATTRIBUTE_ALLOCATOR */ + void *(*alloc)(const void *owner, size_t len, void *priv_data); + void *(*expand)(void *old, size_t newlen, void *priv_data); + void (*free)(void *old, void *priv_data); + void *priv_data; +}; + +/** * union ntdb_attribute - ntdb attributes. * * This represents all the known attributes. @@ -872,7 +897,8 @@ struct ntdb_attribute_flock { * See also: * struct ntdb_attribute_log, struct ntdb_attribute_hash, * struct ntdb_attribute_seed, struct ntdb_attribute_stats, - * struct ntdb_attribute_openhook, struct ntdb_attribute_flock. + * struct ntdb_attribute_openhook, struct ntdb_attribute_flock, + * struct ntdb_attribute_allocator alloc. */ union ntdb_attribute { struct ntdb_attribute_base base; @@ -882,6 +908,7 @@ union ntdb_attribute { struct ntdb_attribute_stats stats; struct ntdb_attribute_openhook openhook; struct ntdb_attribute_flock flock; + struct ntdb_attribute_allocator alloc; }; #ifdef __cplusplus |