-/*
+/*
Samba Unix SMB/CIFS implementation.
Samba trivial allocation library - new interface
Copyright (C) Andrew Tridgell 2004
Copyright (C) Stefan Metzmacher 2006
-
+
** NOTE! The following LGPL license applies to the talloc
** library. This does NOT imply that all of Samba is released
** under the LGPL
-
+
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
#define TALLOC_MAGIC_REFERENCE ((const char *)1)
-/* by default we abort when given a bad pointer (such as when talloc_free() is called
+/* by default we abort when given a bad pointer (such as when talloc_free() is called
on a pointer that came from malloc() */
#ifndef TALLOC_ABORT
#define TALLOC_ABORT(reason) abort()
{
const char *pp = (const char *)ptr;
struct talloc_chunk *tc = discard_const_p(struct talloc_chunk, pp - TC_HDR_SIZE);
- if (unlikely((tc->flags & (TALLOC_FLAG_FREE | ~0xF)) != TALLOC_MAGIC)) {
+ if (unlikely((tc->flags & (TALLOC_FLAG_FREE | ~0xF)) != TALLOC_MAGIC)) {
if ((tc->flags & (~0xFFF)) == TALLOC_MAGIC_BASE) {
talloc_abort_magic(tc->flags & (~0xF));
return NULL;
return result;
}
-/*
+/*
Allocate a bit of memory as a child of an existing pointer
*/
static inline void *__talloc(const void *context, size_t size)
}
/*
- increase the reference count on a piece of memory.
+ increase the reference count on a piece of memory.
*/
_PUBLIC_ int talloc_increase_ref_count(const void *ptr)
{
}
/*
- more efficient way to add a name to a pointer - the name must point to a
+ more efficient way to add a name to a pointer - the name must point to a
true string constant
*/
static inline void _talloc_set_name_const(const void *ptr, const char *name)
make a secondary reference to a pointer, hanging off the given context.
the pointer remains valid until both the original caller and this given
context are freed.
-
- the major use for this is when two different structures need to reference the
+
+ the major use for this is when two different structures need to reference the
same underlying data, and you want to be able to free the two instances separately,
and in either order
*/
void *ptr,
const char *location);
-/*
+/*
internal talloc_free call
*/
static inline int _talloc_free_internal(void *ptr, const char *location)
/* we mark the freed memory with where we called the free
* from. This means on a double free error we can report where
- * the first free came from
- */
+ * the first free came from
+ */
tc->name = location;
if (tc->flags & TALLOC_FLAG_POOL) {
struct talloc_memlimit *old_limit,
struct talloc_memlimit *new_limit);
-/*
+/*
move a lump of memory from one talloc context to another return the
ptr on success, or NULL if it could not be transferred.
passing NULL as ptr will always return NULL with no side effects.
return discard_const_p(void, ptr);
}
-/*
+/*
move a lump of memory from one talloc context to another return the
ptr on success, or NULL if it could not be transferred.
passing NULL as ptr will always return NULL with no side effects.
if (unlikely(ptr == NULL)) {
return NULL;
}
-
+
tc = talloc_chunk_from_ptr(ptr);
-
+
if (unlikely(tc->refs != NULL) && talloc_parent(ptr) != new_ctx) {
struct talloc_reference_handle *h;
talloc_log("WARNING: stealing into talloc child at %s\n", location);
}
#endif
-
+
return _talloc_steal_internal(new_ctx, ptr);
}
-/*
+/*
this is like a talloc_steal(), but you must supply the old
parent. This resolves the ambiguity in a talloc_steal() which is
called on a context that has more than one parent (via references)
}
return discard_const_p(void, ptr);
}
- }
+ }
/* it wasn't a parent */
return NULL;
}
}
-/*
+/*
Allocate a bit of memory as a child of an existing pointer
*/
_PUBLIC_ void *_talloc(const void *context, size_t size)
return _talloc_named_const(context, size, name);
}
-/*
- free a talloc pointer. This also frees all child pointers of this
+/*
+ free a talloc pointer. This also frees all child pointers of this
pointer recursively
return 0 if the memory is actually freed, otherwise -1. The memory
if (unlikely(ptr == NULL)) {
return -1;
}
-
+
tc = talloc_chunk_from_ptr(ptr);
-
+
if (unlikely(tc->refs != NULL)) {
struct talloc_reference_handle *h;
}
return -1;
}
-
+
return _talloc_free_internal(ptr, location);
}
}
got_new_ptr:
#endif
- if (unlikely(!new_ptr)) {
- tc->flags &= ~TALLOC_FLAG_FREE;
- return NULL;
+ if (unlikely(!new_ptr)) {
+ tc->flags &= ~TALLOC_FLAG_FREE;
+ return NULL;
}
tc = (struct talloc_chunk *)new_ptr;
}
if (depth == 0) {
- fprintf(f,"%stalloc report on '%s' (total %6lu bytes in %3lu blocks)\n",
+ fprintf(f,"%stalloc report on '%s' (total %6lu bytes in %3lu blocks)\n",
(max_depth < 0 ? "full " :""), name,
(unsigned long)talloc_total_size(ptr),
(unsigned long)talloc_total_blocks(ptr));
return;
}
- fprintf(f, "%*s%-30s contains %6lu bytes in %3lu blocks (ref %d) %p\n",
+ fprintf(f, "%*s%-30s contains %6lu bytes in %3lu blocks (ref %d) %p\n",
depth*4, "",
name,
(unsigned long)talloc_total_size(ptr),
atexit(talloc_report_null_full);
}
-/*
- talloc and zero memory.
+/*
+ talloc and zero memory.
*/
_PUBLIC_ void *_talloc_zero(const void *ctx, size_t size, const char *name)
{
}
/*
- memdup with a talloc.
+ memdup with a talloc.
*/
_PUBLIC_ void *_talloc_memdup(const void *t, const void *p, size_t size, const char *name)
{