Blame talloc.h

rpm-build 95f51c
#ifndef _TALLOC_H_
rpm-build 95f51c
#define _TALLOC_H_
rpm-build 95f51c
/*
rpm-build 95f51c
   Unix SMB/CIFS implementation.
rpm-build 95f51c
   Samba temporary memory allocation functions
rpm-build 95f51c
rpm-build 95f51c
   Copyright (C) Andrew Tridgell 2004-2005
rpm-build 95f51c
   Copyright (C) Stefan Metzmacher 2006
rpm-build 95f51c
rpm-build 95f51c
     ** NOTE! The following LGPL license applies to the talloc
rpm-build 95f51c
     ** library. This does NOT imply that all of Samba is released
rpm-build 95f51c
     ** under the LGPL
rpm-build 95f51c
rpm-build 95f51c
   This library is free software; you can redistribute it and/or
rpm-build 95f51c
   modify it under the terms of the GNU Lesser General Public
rpm-build 95f51c
   License as published by the Free Software Foundation; either
rpm-build 95f51c
   version 3 of the License, or (at your option) any later version.
rpm-build 95f51c
rpm-build 95f51c
   This library is distributed in the hope that it will be useful,
rpm-build 95f51c
   but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build 95f51c
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
rpm-build 95f51c
   Lesser General Public License for more details.
rpm-build 95f51c
rpm-build 95f51c
   You should have received a copy of the GNU Lesser General Public
rpm-build 95f51c
   License along with this library; if not, see <http://www.gnu.org/licenses/>.
rpm-build 95f51c
*/
rpm-build 95f51c
rpm-build 95f51c
#include <stdlib.h>
rpm-build 95f51c
#include <stdio.h>
rpm-build 95f51c
#include <stdarg.h>
rpm-build 95f51c
rpm-build 95f51c
#ifdef __cplusplus
rpm-build 95f51c
extern "C" {
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @defgroup talloc The talloc API
rpm-build 95f51c
 *
rpm-build 95f51c
 * talloc is a hierarchical, reference counted memory pool system with
rpm-build 95f51c
 * destructors. It is the core memory allocator used in Samba.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @{
rpm-build 95f51c
 */
rpm-build 95f51c
rpm-build 95f51c
#define TALLOC_VERSION_MAJOR 2
rpm-build 95f51c
#define TALLOC_VERSION_MINOR 3
rpm-build 95f51c
rpm-build 95f51c
int talloc_version_major(void);
rpm-build 95f51c
int talloc_version_minor(void);
rpm-build 95f51c
/* This is mostly useful only for testing */
rpm-build 95f51c
int talloc_test_get_magic(void);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Define a talloc parent type
rpm-build 95f51c
 *
rpm-build 95f51c
 * As talloc is a hierarchial memory allocator, every talloc chunk is a
rpm-build 95f51c
 * potential parent to other talloc chunks. So defining a separate type for a
rpm-build 95f51c
 * talloc chunk is not strictly necessary. TALLOC_CTX is defined nevertheless,
rpm-build 95f51c
 * as it provides an indicator for function arguments. You will frequently
rpm-build 95f51c
 * write code like
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      struct foo *foo_create(TALLOC_CTX *mem_ctx)
rpm-build 95f51c
 *      {
rpm-build 95f51c
 *              struct foo *result;
rpm-build 95f51c
 *              result = talloc(mem_ctx, struct foo);
rpm-build 95f51c
 *              if (result == NULL) return NULL;
rpm-build 95f51c
 *                      ... initialize foo ...
rpm-build 95f51c
 *              return result;
rpm-build 95f51c
 *      }
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * In this type of allocating functions it is handy to have a general
rpm-build 95f51c
 * TALLOC_CTX type to indicate which parent to put allocated structures on.
rpm-build 95f51c
 */
rpm-build 95f51c
typedef void TALLOC_CTX;
rpm-build 95f51c
rpm-build 95f51c
/*
rpm-build 95f51c
  this uses a little trick to allow __LINE__ to be stringified
rpm-build 95f51c
*/
rpm-build 95f51c
#ifndef __location__
rpm-build 95f51c
#define __TALLOC_STRING_LINE1__(s)    #s
rpm-build 95f51c
#define __TALLOC_STRING_LINE2__(s)   __TALLOC_STRING_LINE1__(s)
rpm-build 95f51c
#define __TALLOC_STRING_LINE3__  __TALLOC_STRING_LINE2__(__LINE__)
rpm-build 95f51c
#define __location__ __FILE__ ":" __TALLOC_STRING_LINE3__
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
#ifndef TALLOC_DEPRECATED
rpm-build 95f51c
#define TALLOC_DEPRECATED 0
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
#ifndef PRINTF_ATTRIBUTE
rpm-build 95f51c
#if (__GNUC__ >= 3)
rpm-build 95f51c
/** Use gcc attribute to check printf fns.  a1 is the 1-based index of
rpm-build 95f51c
 * the parameter containing the format, and a2 the index of the first
rpm-build 95f51c
 * argument. Note that some gcc 2.x versions don't handle this
rpm-build 95f51c
 * properly **/
rpm-build 95f51c
#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
rpm-build 95f51c
#else
rpm-build 95f51c
#define PRINTF_ATTRIBUTE(a1, a2)
rpm-build 95f51c
#endif
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
#ifndef _DEPRECATED_
rpm-build 95f51c
#ifdef HAVE___ATTRIBUTE__
rpm-build 95f51c
#define _DEPRECATED_ __attribute__ ((deprecated))
rpm-build 95f51c
#else
rpm-build 95f51c
#define _DEPRECATED_
rpm-build 95f51c
#endif
rpm-build 95f51c
#endif
rpm-build 95f51c
#ifdef DOXYGEN
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Create a new talloc context.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The talloc() macro is the core of the talloc library. It takes a memory
rpm-build 95f51c
 * context and a type, and returns a pointer to a new area of memory of the
rpm-build 95f51c
 * given type.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The returned pointer is itself a talloc context, so you can use it as the
rpm-build 95f51c
 * context argument to more calls to talloc if you wish.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The returned pointer is a "child" of the supplied context. This means that if
rpm-build 95f51c
 * you talloc_free() the context then the new child disappears as well.
rpm-build 95f51c
 * Alternatively you can free just the child.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ctx      A talloc context to create a new reference on or NULL to
rpm-build 95f51c
 *                      create a new top level context.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  type     The type of memory to allocate.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              A type casted talloc context or NULL on error.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      unsigned int *a, *b;
rpm-build 95f51c
 *
rpm-build 95f51c
 *      a = talloc(NULL, unsigned int);
rpm-build 95f51c
 *      b = talloc(a, unsigned int);
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * @see talloc_zero
rpm-build 95f51c
 * @see talloc_array
rpm-build 95f51c
 * @see talloc_steal
rpm-build 95f51c
 * @see talloc_free
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc(const void *ctx, #type);
rpm-build 95f51c
#else
rpm-build 95f51c
#define talloc(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #type)
rpm-build 95f51c
void *_talloc(const void *context, size_t size);
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Create a new top level talloc context.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This function creates a zero length named talloc context as a top level
rpm-build 95f51c
 * context. It is equivalent to:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      talloc_named(NULL, 0, fmt, ...);
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 * @param[in]  fmt      Format string for the name.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ...      Additional printf-style arguments.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The allocated memory chunk, NULL on error.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @see talloc_named()
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_init(const char *fmt, ...) PRINTF_ATTRIBUTE(1,2);
rpm-build 95f51c
rpm-build 95f51c
#ifdef DOXYGEN
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Free a chunk of talloc memory.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The talloc_free() function frees a piece of talloc memory, and all its
rpm-build 95f51c
 * children. You can call talloc_free() on any pointer returned by
rpm-build 95f51c
 * talloc().
rpm-build 95f51c
 *
rpm-build 95f51c
 * The return value of talloc_free() indicates success or failure, with 0
rpm-build 95f51c
 * returned for success and -1 for failure. A possible failure condition
rpm-build 95f51c
 * is if the pointer had a destructor attached to it and the destructor
rpm-build 95f51c
 * returned -1. See talloc_set_destructor() for details on
rpm-build 95f51c
 * destructors. Likewise, if "ptr" is NULL, then the function will make
rpm-build 95f51c
 * no modifications and return -1.
rpm-build 95f51c
 *
rpm-build 95f51c
 * From version 2.0 and onwards, as a special case, talloc_free() is
rpm-build 95f51c
 * refused on pointers that have more than one parent associated, as talloc
rpm-build 95f51c
 * would have no way of knowing which parent should be removed. This is
rpm-build 95f51c
 * different from older versions in the sense that always the reference to
rpm-build 95f51c
 * the most recently established parent has been destroyed. Hence to free a
rpm-build 95f51c
 * pointer that has more than one parent please use talloc_unlink().
rpm-build 95f51c
 *
rpm-build 95f51c
 * To help you find problems in your code caused by this behaviour, if
rpm-build 95f51c
 * you do try and free a pointer with more than one parent then the
rpm-build 95f51c
 * talloc logging function will be called to give output like this:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *   ERROR: talloc_free with references at some_dir/source/foo.c:123
rpm-build 95f51c
 *     reference at some_dir/source/other.c:325
rpm-build 95f51c
 *     reference at some_dir/source/third.c:121
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * Please see the documentation for talloc_set_log_fn() and
rpm-build 95f51c
 * talloc_set_log_stderr() for more information on talloc logging
rpm-build 95f51c
 * functions.
rpm-build 95f51c
 *
rpm-build 95f51c
 * If TALLOC_FREE_FILL environment variable is set,
rpm-build 95f51c
 * the memory occupied by the context is filled with the value of this variable.
rpm-build 95f51c
 * The value should be a numeric representation of the character you want to
rpm-build 95f51c
 * use.
rpm-build 95f51c
 *
rpm-build 95f51c
 * talloc_free() operates recursively on its children.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The chunk to be freed.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              Returns 0 on success and -1 on error. A possible
rpm-build 95f51c
 *                      failure condition is if the pointer had a destructor
rpm-build 95f51c
 *                      attached to it and the destructor returned -1. Likewise,
rpm-build 95f51c
 *                      if "ptr" is NULL, then the function will make no
rpm-build 95f51c
 *                      modifications and returns -1.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Example:
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      unsigned int *a, *b;
rpm-build 95f51c
 *      a = talloc(NULL, unsigned int);
rpm-build 95f51c
 *      b = talloc(a, unsigned int);
rpm-build 95f51c
 *
rpm-build 95f51c
 *      talloc_free(a); // Frees a and b
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * @see talloc_set_destructor()
rpm-build 95f51c
 * @see talloc_unlink()
rpm-build 95f51c
 */
rpm-build 95f51c
int talloc_free(void *ptr);
rpm-build 95f51c
#else
rpm-build 95f51c
#define talloc_free(ctx) _talloc_free(ctx, __location__)
rpm-build 95f51c
int _talloc_free(void *ptr, const char *location);
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Free a talloc chunk's children.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The function walks along the list of all children of a talloc context and
rpm-build 95f51c
 * talloc_free()s only the children, not the context itself.
rpm-build 95f51c
 *
rpm-build 95f51c
 * A NULL argument is handled as no-op.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The chunk that you want to free the children of
rpm-build 95f51c
 *                      (NULL is allowed too)
rpm-build 95f51c
 */
rpm-build 95f51c
void talloc_free_children(void *ptr);
rpm-build 95f51c
rpm-build 95f51c
#ifdef DOXYGEN
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Assign a destructor function to be called when a chunk is freed.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The function talloc_set_destructor() sets the "destructor" for the pointer
rpm-build 95f51c
 * "ptr". A destructor is a function that is called when the memory used by a
rpm-build 95f51c
 * pointer is about to be released. The destructor receives the pointer as an
rpm-build 95f51c
 * argument, and should return 0 for success and -1 for failure.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The destructor can do anything it wants to, including freeing other pieces
rpm-build 95f51c
 * of memory. A common use for destructors is to clean up operating system
rpm-build 95f51c
 * resources (such as open file descriptors) contained in the structure the
rpm-build 95f51c
 * destructor is placed on.
rpm-build 95f51c
 *
rpm-build 95f51c
 * You can only place one destructor on a pointer. If you need more than one
rpm-build 95f51c
 * destructor then you can create a zero-length child of the pointer and place
rpm-build 95f51c
 * an additional destructor on that.
rpm-build 95f51c
 *
rpm-build 95f51c
 * To remove a destructor call talloc_set_destructor() with NULL for the
rpm-build 95f51c
 * destructor.
rpm-build 95f51c
 *
rpm-build 95f51c
 * If your destructor attempts to talloc_free() the pointer that it is the
rpm-build 95f51c
 * destructor for then talloc_free() will return -1 and the free will be
rpm-build 95f51c
 * ignored. This would be a pointless operation anyway, as the destructor is
rpm-build 95f51c
 * only called when the memory is just about to go away.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The talloc chunk to add a destructor to.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  destructor  The destructor function to be called. NULL to remove
rpm-build 95f51c
 *                         it.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Example:
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      static int destroy_fd(int *fd) {
rpm-build 95f51c
 *              close(*fd);
rpm-build 95f51c
 *              return 0;
rpm-build 95f51c
 *      }
rpm-build 95f51c
 *
rpm-build 95f51c
 *      int *open_file(const char *filename) {
rpm-build 95f51c
 *              int *fd = talloc(NULL, int);
rpm-build 95f51c
 *              *fd = open(filename, O_RDONLY);
rpm-build 95f51c
 *              if (*fd < 0) {
rpm-build 95f51c
 *                      talloc_free(fd);
rpm-build 95f51c
 *                      return NULL;
rpm-build 95f51c
 *              }
rpm-build 95f51c
 *              // Whenever they free this, we close the file.
rpm-build 95f51c
 *              talloc_set_destructor(fd, destroy_fd);
rpm-build 95f51c
 *              return fd;
rpm-build 95f51c
 *      }
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * @see talloc()
rpm-build 95f51c
 * @see talloc_free()
rpm-build 95f51c
 */
rpm-build 95f51c
void talloc_set_destructor(const void *ptr, int (*destructor)(void *));
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Change a talloc chunk's parent.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The talloc_steal() function changes the parent context of a talloc
rpm-build 95f51c
 * pointer. It is typically used when the context that the pointer is
rpm-build 95f51c
 * currently a child of is going to be freed and you wish to keep the
rpm-build 95f51c
 * memory for a longer time.
rpm-build 95f51c
 *
rpm-build 95f51c
 * To make the changed hierarchy less error-prone, you might consider to use
rpm-build 95f51c
 * talloc_move().
rpm-build 95f51c
 *
rpm-build 95f51c
 * If you try and call talloc_steal() on a pointer that has more than one
rpm-build 95f51c
 * parent then the result is ambiguous. Talloc will choose to remove the
rpm-build 95f51c
 * parent that is currently indicated by talloc_parent() and replace it with
rpm-build 95f51c
 * the chosen parent. You will also get a message like this via the talloc
rpm-build 95f51c
 * logging functions:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *   WARNING: talloc_steal with references at some_dir/source/foo.c:123
rpm-build 95f51c
 *     reference at some_dir/source/other.c:325
rpm-build 95f51c
 *     reference at some_dir/source/third.c:121
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * To unambiguously change the parent of a pointer please see the function
rpm-build 95f51c
 * talloc_reparent(). See the talloc_set_log_fn() documentation for more
rpm-build 95f51c
 * information on talloc logging.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  new_ctx  The new parent context.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The talloc chunk to move.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              Returns the pointer that you pass it. It does not have
rpm-build 95f51c
 *                      any failure modes.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @note It is possible to produce loops in the parent/child relationship
rpm-build 95f51c
 * if you are not careful with talloc_steal(). No guarantees are provided
rpm-build 95f51c
 * as to your sanity or the safety of your data if you do this.
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_steal(const void *new_ctx, const void *ptr);
rpm-build 95f51c
#else /* DOXYGEN */
rpm-build 95f51c
/* try to make talloc_set_destructor() and talloc_steal() type safe,
rpm-build 95f51c
   if we have a recent gcc */
rpm-build 95f51c
#if (__GNUC__ >= 3)
rpm-build 95f51c
#define _TALLOC_TYPEOF(ptr) __typeof__(ptr)
rpm-build 95f51c
#define talloc_set_destructor(ptr, function)				      \
rpm-build 95f51c
	do {								      \
rpm-build 95f51c
		int (*_talloc_destructor_fn)(_TALLOC_TYPEOF(ptr)) = (function);	      \
rpm-build 95f51c
		_talloc_set_destructor((ptr), (int (*)(void *))_talloc_destructor_fn); \
rpm-build 95f51c
	} while(0)
rpm-build 95f51c
/* this extremely strange macro is to avoid some braindamaged warning
rpm-build 95f51c
   stupidity in gcc 4.1.x */
rpm-build 95f51c
#define talloc_steal(ctx, ptr) ({ _TALLOC_TYPEOF(ptr) __talloc_steal_ret = (_TALLOC_TYPEOF(ptr))_talloc_steal_loc((ctx),(ptr), __location__); __talloc_steal_ret; })
rpm-build 95f51c
#else /* __GNUC__ >= 3 */
rpm-build 95f51c
#define talloc_set_destructor(ptr, function) \
rpm-build 95f51c
	_talloc_set_destructor((ptr), (int (*)(void *))(function))
rpm-build 95f51c
#define _TALLOC_TYPEOF(ptr) void *
rpm-build 95f51c
#define talloc_steal(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_steal_loc((ctx),(ptr), __location__)
rpm-build 95f51c
#endif /* __GNUC__ >= 3 */
rpm-build 95f51c
void _talloc_set_destructor(const void *ptr, int (*_destructor)(void *));
rpm-build 95f51c
void *_talloc_steal_loc(const void *new_ctx, const void *ptr, const char *location);
rpm-build 95f51c
#endif /* DOXYGEN */
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Assign a name to a talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Each talloc pointer has a "name". The name is used principally for
rpm-build 95f51c
 * debugging purposes, although it is also possible to set and get the name on
rpm-build 95f51c
 * a pointer in as a way of "marking" pointers in your code.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The main use for names on pointer is for "talloc reports". See
rpm-build 95f51c
 * talloc_report() and talloc_report_full() for details. Also see
rpm-build 95f51c
 * talloc_enable_leak_report() and talloc_enable_leak_report_full().
rpm-build 95f51c
 *
rpm-build 95f51c
 * The talloc_set_name() function allocates memory as a child of the
rpm-build 95f51c
 * pointer. It is logically equivalent to:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      talloc_set_name_const(ptr, talloc_asprintf(ptr, fmt, ...));
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The talloc chunk to assign a name to.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  fmt      Format string for the name.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ...      Add printf-style additional arguments.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The assigned name, NULL on error.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @note Multiple calls to talloc_set_name() will allocate more memory without
rpm-build 95f51c
 * releasing the name. All of the memory is released when the ptr is freed
rpm-build 95f51c
 * using talloc_free().
rpm-build 95f51c
 */
rpm-build 95f51c
const char *talloc_set_name(const void *ptr, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
rpm-build 95f51c
rpm-build 95f51c
#ifdef DOXYGEN
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Change a talloc chunk's parent.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This function has the same effect as talloc_steal(), and additionally sets
rpm-build 95f51c
 * the source pointer to NULL. You would use it like this:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      struct foo *X = talloc(tmp_ctx, struct foo);
rpm-build 95f51c
 *      struct foo *Y;
rpm-build 95f51c
 *      Y = talloc_move(new_ctx, &X);
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  new_ctx  The new parent context.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  pptr     Pointer to a pointer to the talloc chunk to move.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The pointer to the talloc chunk that moved.
rpm-build 95f51c
 *                      It does not have any failure modes.
rpm-build 95f51c
 *
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_move(const void *new_ctx, void **pptr);
rpm-build 95f51c
#else
rpm-build 95f51c
#define talloc_move(ctx, pptr) (_TALLOC_TYPEOF(*(pptr)))_talloc_move((ctx),(void *)(pptr))
rpm-build 95f51c
void *_talloc_move(const void *new_ctx, const void *pptr);
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Assign a name to a talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The function is just like talloc_set_name(), but it takes a string constant,
rpm-build 95f51c
 * and is much faster. It is extensively used by the "auto naming" macros, such
rpm-build 95f51c
 * as talloc_p().
rpm-build 95f51c
 *
rpm-build 95f51c
 * This function does not allocate any memory. It just copies the supplied
rpm-build 95f51c
 * pointer into the internal representation of the talloc ptr. This means you
rpm-build 95f51c
 * must not pass a name pointer to memory that will disappear before the ptr
rpm-build 95f51c
 * is freed with talloc_free().
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The talloc chunk to assign a name to.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  name     Format string for the name.
rpm-build 95f51c
 */
rpm-build 95f51c
void talloc_set_name_const(const void *ptr, const char *name);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Create a named talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The talloc_named() function creates a named talloc pointer. It is
rpm-build 95f51c
 * equivalent to:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      ptr = talloc_size(context, size);
rpm-build 95f51c
 *      talloc_set_name(ptr, fmt, ....);
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  context  The talloc context to hang the result off.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  size     Number of char's that you want to allocate.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  fmt      Format string for the name.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ...      Additional printf-style arguments.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The allocated memory chunk, NULL on error.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @see talloc_set_name()
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_named(const void *context, size_t size,
rpm-build 95f51c
		   const char *fmt, ...) PRINTF_ATTRIBUTE(3,4);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Basic routine to allocate a chunk of memory.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This is equivalent to:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      ptr = talloc_size(context, size);
rpm-build 95f51c
 *      talloc_set_name_const(ptr, name);
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  context  The parent context.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  size     The number of char's that we want to allocate.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  name     The name the talloc block has.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return             The allocated memory chunk, NULL on error.
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_named_const(const void *context, size_t size, const char *name);
rpm-build 95f51c
rpm-build 95f51c
#ifdef DOXYGEN
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Untyped allocation.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The function should be used when you don't have a convenient type to pass to
rpm-build 95f51c
 * talloc(). Unlike talloc(), it is not type safe (as it returns a void *), so
rpm-build 95f51c
 * you are on your own for type checking.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Best to use talloc() or talloc_array() instead.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ctx     The talloc context to hang the result off.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  size    Number of char's that you want to allocate.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return             The allocated memory chunk, NULL on error.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Example:
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      void *mem = talloc_size(NULL, 100);
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_size(const void *ctx, size_t size);
rpm-build 95f51c
#else
rpm-build 95f51c
#define talloc_size(ctx, size) talloc_named_const(ctx, size, __location__)
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
#ifdef DOXYGEN
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Allocate into a typed pointer.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The talloc_ptrtype() macro should be used when you have a pointer and want
rpm-build 95f51c
 * to allocate memory to point at with this pointer. When compiling with
rpm-build 95f51c
 * gcc >= 3 it is typesafe. Note this is a wrapper of talloc_size() and
rpm-build 95f51c
 * talloc_get_name() will return the current location in the source file and
rpm-build 95f51c
 * not the type.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ctx      The talloc context to hang the result off.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  type     The pointer you want to assign the result to.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The properly casted allocated memory chunk, NULL on
rpm-build 95f51c
 *                      error.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Example:
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *       unsigned int *a = talloc_ptrtype(NULL, a);
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_ptrtype(const void *ctx, #type);
rpm-build 95f51c
#else
rpm-build 95f51c
#define talloc_ptrtype(ctx, ptr) (_TALLOC_TYPEOF(ptr))talloc_size(ctx, sizeof(*(ptr)))
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
#ifdef DOXYGEN
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Allocate a new 0-sized talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This is a utility macro that creates a new memory context hanging off an
rpm-build 95f51c
 * existing context, automatically naming it "talloc_new: __location__" where
rpm-build 95f51c
 * __location__ is the source line it is called from. It is particularly
rpm-build 95f51c
 * useful for creating a new temporary working context.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ctx      The talloc parent context.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              A new talloc chunk, NULL on error.
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_new(const void *ctx);
rpm-build 95f51c
#else
rpm-build 95f51c
#define talloc_new(ctx) talloc_named_const(ctx, 0, "talloc_new: " __location__)
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
#ifdef DOXYGEN
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Allocate a 0-initizialized structure.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The macro is equivalent to:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      ptr = talloc(ctx, type);
rpm-build 95f51c
 *      if (ptr) memset(ptr, 0, sizeof(type));
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ctx      The talloc context to hang the result off.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  type     The type that we want to allocate.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              Pointer to a piece of memory, properly cast to 'type *',
rpm-build 95f51c
 *                      NULL on error.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Example:
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      unsigned int *a, *b;
rpm-build 95f51c
 *      a = talloc_zero(NULL, unsigned int);
rpm-build 95f51c
 *      b = talloc_zero(a, unsigned int);
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * @see talloc()
rpm-build 95f51c
 * @see talloc_zero_size()
rpm-build 95f51c
 * @see talloc_zero_array()
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_zero(const void *ctx, #type);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Allocate untyped, 0-initialized memory.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ctx      The talloc context to hang the result off.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  size     Number of char's that you want to allocate.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The allocated memory chunk.
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_zero_size(const void *ctx, size_t size);
rpm-build 95f51c
#else
rpm-build 95f51c
#define talloc_zero(ctx, type) (type *)_talloc_zero(ctx, sizeof(type), #type)
rpm-build 95f51c
#define talloc_zero_size(ctx, size) _talloc_zero(ctx, size, __location__)
rpm-build 95f51c
void *_talloc_zero(const void *ctx, size_t size, const char *name);
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Return the name of a talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The current name for the given talloc pointer.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @see talloc_set_name()
rpm-build 95f51c
 */
rpm-build 95f51c
const char *talloc_get_name(const void *ptr);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Verify that a talloc chunk carries a specified name.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This function checks if a pointer has the specified name. If it does
rpm-build 95f51c
 * then the pointer is returned.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr       The talloc chunk to check.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  name      The name to check against.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return               The pointer if the name matches, NULL if it doesn't.
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_check_name(const void *ptr, const char *name);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Get the parent chunk of a pointer.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The talloc pointer to inspect.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The talloc parent of ptr, NULL on error.
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_parent(const void *ptr);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Get a talloc chunk's parent name.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The talloc pointer to inspect.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The name of ptr's parent chunk.
rpm-build 95f51c
 */
rpm-build 95f51c
const char *talloc_parent_name(const void *ptr);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Get the total size of a talloc chunk including its children.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The function returns the total size in bytes used by this pointer and all
rpm-build 95f51c
 * child pointers. Mostly useful for debugging.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Passing NULL is allowed, but it will only give a meaningful result if
rpm-build 95f51c
 * talloc_enable_leak_report() or talloc_enable_leak_report_full() has
rpm-build 95f51c
 * been called.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The total size.
rpm-build 95f51c
 */
rpm-build 95f51c
size_t talloc_total_size(const void *ptr);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Get the number of talloc chunks hanging off a chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The talloc_total_blocks() function returns the total memory block
rpm-build 95f51c
 * count used by this pointer and all child pointers. Mostly useful for
rpm-build 95f51c
 * debugging.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Passing NULL is allowed, but it will only give a meaningful result if
rpm-build 95f51c
 * talloc_enable_leak_report() or talloc_enable_leak_report_full() has
rpm-build 95f51c
 * been called.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The total size.
rpm-build 95f51c
 */
rpm-build 95f51c
size_t talloc_total_blocks(const void *ptr);
rpm-build 95f51c
rpm-build 95f51c
#ifdef DOXYGEN
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Duplicate a memory area into a talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The function is equivalent to:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      ptr = talloc_size(ctx, size);
rpm-build 95f51c
 *      if (ptr) memcpy(ptr, p, size);
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  t        The talloc context to hang the result off.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  p        The memory chunk you want to duplicate.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  size     Number of char's that you want copy.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The allocated memory chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @see talloc_size()
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_memdup(const void *t, const void *p, size_t size);
rpm-build 95f51c
#else
rpm-build 95f51c
#define talloc_memdup(t, p, size) _talloc_memdup(t, p, size, __location__)
rpm-build 95f51c
void *_talloc_memdup(const void *t, const void *p, size_t size, const char *name);
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
#ifdef DOXYGEN
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Assign a type to a talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This macro allows you to force the name of a pointer to be of a particular
rpm-build 95f51c
 * type. This can be used in conjunction with talloc_get_type() to do type
rpm-build 95f51c
 * checking on void* pointers.
rpm-build 95f51c
 *
rpm-build 95f51c
 * It is equivalent to this:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      talloc_set_name_const(ptr, #type)
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The talloc chunk to assign the type to.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  type     The type to assign.
rpm-build 95f51c
 */
rpm-build 95f51c
void talloc_set_type(const char *ptr, #type);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Get a typed pointer out of a talloc pointer.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This macro allows you to do type checking on talloc pointers. It is
rpm-build 95f51c
 * particularly useful for void* private pointers. It is equivalent to
rpm-build 95f51c
 * this:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      (type *)talloc_check_name(ptr, #type)
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The talloc pointer to check.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  type     The type to check against.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The properly casted pointer given by ptr, NULL on error.
rpm-build 95f51c
 */
rpm-build 95f51c
type *talloc_get_type(const void *ptr, #type);
rpm-build 95f51c
#else
rpm-build 95f51c
#define talloc_set_type(ptr, type) talloc_set_name_const(ptr, #type)
rpm-build 95f51c
#define talloc_get_type(ptr, type) (type *)talloc_check_name(ptr, #type)
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
#ifdef DOXYGEN
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Safely turn a void pointer into a typed pointer.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This macro is used together with talloc(mem_ctx, struct foo). If you had to
rpm-build 95f51c
 * assign the talloc chunk pointer to some void pointer variable,
rpm-build 95f51c
 * talloc_get_type_abort() is the recommended way to get the convert the void
rpm-build 95f51c
 * pointer back to a typed pointer.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The void pointer to convert.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  type     The type that this chunk contains
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The same value as ptr, type-checked and properly cast.
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_get_type_abort(const void *ptr, #type);
rpm-build 95f51c
#else
rpm-build 95f51c
#ifdef TALLOC_GET_TYPE_ABORT_NOOP
rpm-build 95f51c
#define talloc_get_type_abort(ptr, type) (type *)(ptr)
rpm-build 95f51c
#else
rpm-build 95f51c
#define talloc_get_type_abort(ptr, type) (type *)_talloc_get_type_abort(ptr, #type, __location__)
rpm-build 95f51c
#endif
rpm-build 95f51c
void *_talloc_get_type_abort(const void *ptr, const char *name, const char *location);
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Find a parent context by name.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Find a parent memory context of the current context that has the given
rpm-build 95f51c
 * name. This can be very useful in complex programs where it may be
rpm-build 95f51c
 * difficult to pass all information down to the level you need, but you
rpm-build 95f51c
 * know the structure you want is a parent of another context.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ctx      The talloc chunk to start from.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  name     The name of the parent we look for.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The memory context we are looking for, NULL if not
rpm-build 95f51c
 *                      found.
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_find_parent_byname(const void *ctx, const char *name);
rpm-build 95f51c
rpm-build 95f51c
#ifdef DOXYGEN
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Find a parent context by type.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Find a parent memory context of the current context that has the given
rpm-build 95f51c
 * name. This can be very useful in complex programs where it may be
rpm-build 95f51c
 * difficult to pass all information down to the level you need, but you
rpm-build 95f51c
 * know the structure you want is a parent of another context.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Like talloc_find_parent_byname() but takes a type, making it typesafe.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The talloc chunk to start from.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  type     The type of the parent to look for.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The memory context we are looking for, NULL if not
rpm-build 95f51c
 *                      found.
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_find_parent_bytype(const void *ptr, #type);
rpm-build 95f51c
#else
rpm-build 95f51c
#define talloc_find_parent_bytype(ptr, type) (type *)talloc_find_parent_byname(ptr, #type)
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Allocate a talloc pool.
rpm-build 95f51c
 *
rpm-build 95f51c
 * A talloc pool is a pure optimization for specific situations. In the
rpm-build 95f51c
 * release process for Samba 3.2 we found out that we had become considerably
rpm-build 95f51c
 * slower than Samba 3.0 was. Profiling showed that malloc(3) was a large CPU
rpm-build 95f51c
 * consumer in benchmarks. For Samba 3.2 we have internally converted many
rpm-build 95f51c
 * static buffers to dynamically allocated ones, so malloc(3) being beaten
rpm-build 95f51c
 * more was no surprise. But it made us slower.
rpm-build 95f51c
 *
rpm-build 95f51c
 * talloc_pool() is an optimization to call malloc(3) a lot less for the use
rpm-build 95f51c
 * pattern Samba has: The SMB protocol is mainly a request/response protocol
rpm-build 95f51c
 * where we have to allocate a certain amount of memory per request and free
rpm-build 95f51c
 * that after the SMB reply is sent to the client.
rpm-build 95f51c
 *
rpm-build 95f51c
 * talloc_pool() creates a talloc chunk that you can use as a talloc parent
rpm-build 95f51c
 * exactly as you would use any other ::TALLOC_CTX. The difference is that
rpm-build 95f51c
 * when you talloc a child of this pool, no malloc(3) is done. Instead, talloc
rpm-build 95f51c
 * just increments a pointer inside the talloc_pool. This also works
rpm-build 95f51c
 * recursively. If you use the child of the talloc pool as a parent for
rpm-build 95f51c
 * grand-children, their memory is also taken from the talloc pool.
rpm-build 95f51c
 *
rpm-build 95f51c
 * If there is not enough memory in the pool to allocate the new child,
rpm-build 95f51c
 * it will create a new talloc chunk as if the parent was a normal talloc
rpm-build 95f51c
 * context.
rpm-build 95f51c
 *
rpm-build 95f51c
 * If you talloc_free() children of a talloc pool, the memory is not given
rpm-build 95f51c
 * back to the system. Instead, free(3) is only called if the talloc_pool()
rpm-build 95f51c
 * itself is released with talloc_free().
rpm-build 95f51c
 *
rpm-build 95f51c
 * The downside of a talloc pool is that if you talloc_move() a child of a
rpm-build 95f51c
 * talloc pool to a talloc parent outside the pool, the whole pool memory is
rpm-build 95f51c
 * not free(3)'ed until that moved chunk is also talloc_free()ed.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  context  The talloc context to hang the result off.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  size     Size of the talloc pool.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The allocated talloc pool, NULL on error.
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_pool(const void *context, size_t size);
rpm-build 95f51c
rpm-build 95f51c
#ifdef DOXYGEN
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Allocate a talloc object as/with an additional pool.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This is like talloc_pool(), but's it's more flexible
rpm-build 95f51c
 * and allows an object to be a pool for its children.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in] ctx                   The talloc context to hang the result off.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in] type                  The type that we want to allocate.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in] num_subobjects        The expected number of subobjects, which will
rpm-build 95f51c
 *                                  be allocated within the pool. This allocates
rpm-build 95f51c
 *                                  space for talloc_chunk headers.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in] total_subobjects_size The size that all subobjects can use in total.
rpm-build 95f51c
 *
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The allocated talloc object, NULL on error.
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_pooled_object(const void *ctx, #type,
rpm-build 95f51c
			   unsigned num_subobjects,
rpm-build 95f51c
			   size_t total_subobjects_size);
rpm-build 95f51c
#else
rpm-build 95f51c
#define talloc_pooled_object(_ctx, _type, \
rpm-build 95f51c
			     _num_subobjects, \
rpm-build 95f51c
			     _total_subobjects_size) \
rpm-build 95f51c
	(_type *)_talloc_pooled_object((_ctx), sizeof(_type), #_type, \
rpm-build 95f51c
					(_num_subobjects), \
rpm-build 95f51c
					(_total_subobjects_size))
rpm-build 95f51c
void *_talloc_pooled_object(const void *ctx,
rpm-build 95f51c
			    size_t type_size,
rpm-build 95f51c
			    const char *type_name,
rpm-build 95f51c
			    unsigned num_subobjects,
rpm-build 95f51c
			    size_t total_subobjects_size);
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Free a talloc chunk and NULL out the pointer.
rpm-build 95f51c
 *
rpm-build 95f51c
 * TALLOC_FREE() frees a pointer and sets it to NULL. Use this if you want
rpm-build 95f51c
 * immediate feedback (i.e. crash) if you use a pointer after having free'ed
rpm-build 95f51c
 * it.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ctx      The chunk to be freed.
rpm-build 95f51c
 */
rpm-build 95f51c
#define TALLOC_FREE(ctx) do { if (ctx != NULL) { talloc_free(ctx); ctx=NULL; } } while(0)
rpm-build 95f51c
rpm-build 95f51c
/* @} ******************************************************************/
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * \defgroup talloc_ref The talloc reference function.
rpm-build 95f51c
 * @ingroup talloc
rpm-build 95f51c
 *
rpm-build 95f51c
 * This module contains the definitions around talloc references
rpm-build 95f51c
 *
rpm-build 95f51c
 * @{
rpm-build 95f51c
 */
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Increase the reference count of a talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The talloc_increase_ref_count(ptr) function is exactly equivalent to:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      talloc_reference(NULL, ptr);
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * You can use either syntax, depending on which you think is clearer in
rpm-build 95f51c
 * your code.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The pointer to increase the reference count.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              0 on success, -1 on error.
rpm-build 95f51c
 */
rpm-build 95f51c
int talloc_increase_ref_count(const void *ptr);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Get the number of references to a talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The pointer to retrieve the reference count from.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The number of references.
rpm-build 95f51c
 */
rpm-build 95f51c
size_t talloc_reference_count(const void *ptr);
rpm-build 95f51c
rpm-build 95f51c
#ifdef DOXYGEN
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Create an additional talloc parent to a pointer.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The talloc_reference() function makes "context" an additional parent of
rpm-build 95f51c
 * ptr. Each additional reference consumes around 48 bytes of memory on intel
rpm-build 95f51c
 * x86 platforms.
rpm-build 95f51c
 *
rpm-build 95f51c
 * If ptr is NULL, then the function is a no-op, and simply returns NULL.
rpm-build 95f51c
 *
rpm-build 95f51c
 * After creating a reference you can free it in one of the following ways:
rpm-build 95f51c
 *
rpm-build 95f51c
 * - you can talloc_free() any parent of the original pointer. That
rpm-build 95f51c
 *   will reduce the number of parents of this pointer by 1, and will
rpm-build 95f51c
 *   cause this pointer to be freed if it runs out of parents.
rpm-build 95f51c
 *
rpm-build 95f51c
 * - you can talloc_free() the pointer itself if it has at maximum one
rpm-build 95f51c
 *   parent. This behaviour has been changed since the release of version
rpm-build 95f51c
 *   2.0. Further information in the description of "talloc_free".
rpm-build 95f51c
 *
rpm-build 95f51c
 * For more control on which parent to remove, see talloc_unlink()
rpm-build 95f51c
 * @param[in]  ctx      The additional parent.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The pointer you want to create an additional parent for.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The original pointer 'ptr', NULL if talloc ran out of
rpm-build 95f51c
 *                      memory in creating the reference.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @warning You should try to avoid using this interface. It turns a beautiful
rpm-build 95f51c
 *          talloc-tree into a graph. It is often really hard to debug if you
rpm-build 95f51c
 *          screw something up by accident.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Example:
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      unsigned int *a, *b, *c;
rpm-build 95f51c
 *      a = talloc(NULL, unsigned int);
rpm-build 95f51c
 *      b = talloc(NULL, unsigned int);
rpm-build 95f51c
 *      c = talloc(a, unsigned int);
rpm-build 95f51c
 *      // b also serves as a parent of c.
rpm-build 95f51c
 *      talloc_reference(b, c);
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * @see talloc_unlink()
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_reference(const void *ctx, const void *ptr);
rpm-build 95f51c
#else
rpm-build 95f51c
#define talloc_reference(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_reference_loc((ctx),(ptr), __location__)
rpm-build 95f51c
void *_talloc_reference_loc(const void *context, const void *ptr, const char *location);
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Remove a specific parent from a talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The function removes a specific parent from ptr. The context passed must
rpm-build 95f51c
 * either be a context used in talloc_reference() with this pointer, or must be
rpm-build 95f51c
 * a direct parent of ptr.
rpm-build 95f51c
 *
rpm-build 95f51c
 * You can just use talloc_free() instead of talloc_unlink() if there
rpm-build 95f51c
 * is at maximum one parent. This behaviour has been changed since the
rpm-build 95f51c
 * release of version 2.0. Further information in the description of
rpm-build 95f51c
 * "talloc_free".
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  context  The talloc parent to remove.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The talloc ptr you want to remove the parent from.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              0 on success, -1 on error.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @note If the parent has already been removed using talloc_free() then
rpm-build 95f51c
 * this function will fail and will return -1.  Likewise, if ptr is NULL,
rpm-build 95f51c
 * then the function will make no modifications and return -1.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @warning You should try to avoid using this interface. It turns a beautiful
rpm-build 95f51c
 *          talloc-tree into a graph. It is often really hard to debug if you
rpm-build 95f51c
 *          screw something up by accident.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Example:
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      unsigned int *a, *b, *c;
rpm-build 95f51c
 *      a = talloc(NULL, unsigned int);
rpm-build 95f51c
 *      b = talloc(NULL, unsigned int);
rpm-build 95f51c
 *      c = talloc(a, unsigned int);
rpm-build 95f51c
 *      // b also serves as a parent of c.
rpm-build 95f51c
 *      talloc_reference(b, c);
rpm-build 95f51c
 *      talloc_unlink(b, c);
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 */
rpm-build 95f51c
int talloc_unlink(const void *context, void *ptr);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Provide a talloc context that is freed at program exit.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This is a handy utility function that returns a talloc context
rpm-build 95f51c
 * which will be automatically freed on program exit. This can be used
rpm-build 95f51c
 * to reduce the noise in memory leak reports.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Never use this in code that might be used in objects loaded with
rpm-build 95f51c
 * dlopen and unloaded with dlclose. talloc_autofree_context()
rpm-build 95f51c
 * internally uses atexit(3). Some platforms like modern Linux handles
rpm-build 95f51c
 * this fine, but for example FreeBSD does not deal well with dlopen()
rpm-build 95f51c
 * and atexit() used simultaneously: dlclose() does not clean up the
rpm-build 95f51c
 * list of atexit-handlers, so when the program exits the code that
rpm-build 95f51c
 * was registered from within talloc_autofree_context() is gone, the
rpm-build 95f51c
 * program crashes at exit.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              A talloc context, NULL on error.
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_autofree_context(void) _DEPRECATED_;
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Get the size of a talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This function lets you know the amount of memory allocated so far by
rpm-build 95f51c
 * this context. It does NOT account for subcontext memory.
rpm-build 95f51c
 * This can be used to calculate the size of an array.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ctx      The talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The size of the talloc chunk.
rpm-build 95f51c
 */
rpm-build 95f51c
size_t talloc_get_size(const void *ctx);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Show the parentage of a context.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  context            The talloc context to look at.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  file               The output to use, a file, stdout or stderr.
rpm-build 95f51c
 */
rpm-build 95f51c
void talloc_show_parents(const void *context, FILE *file);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Check if a context is parent of a talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This checks if context is referenced in the talloc hierarchy above ptr.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  context  The assumed talloc context.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The talloc chunk to check.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              Return 1 if this is the case, 0 if not.
rpm-build 95f51c
 */
rpm-build 95f51c
int talloc_is_parent(const void *context, const void *ptr);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Change the parent context of a talloc pointer.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The function changes the parent context of a talloc pointer. It is typically
rpm-build 95f51c
 * used when the context that the pointer is currently a child of is going to be
rpm-build 95f51c
 * freed and you wish to keep the memory for a longer time.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The difference between talloc_reparent() and talloc_steal() is that
rpm-build 95f51c
 * talloc_reparent() can specify which parent you wish to change. This is
rpm-build 95f51c
 * useful when a pointer has multiple parents via references.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  old_parent
rpm-build 95f51c
 * @param[in]  new_parent
rpm-build 95f51c
 * @param[in]  ptr
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              Return the pointer you passed. It does not have any
rpm-build 95f51c
 *                      failure modes.
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_reparent(const void *old_parent, const void *new_parent, const void *ptr);
rpm-build 95f51c
rpm-build 95f51c
/* @} ******************************************************************/
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @defgroup talloc_array The talloc array functions
rpm-build 95f51c
 * @ingroup talloc
rpm-build 95f51c
 *
rpm-build 95f51c
 * Talloc contains some handy helpers for handling Arrays conveniently
rpm-build 95f51c
 *
rpm-build 95f51c
 * @{
rpm-build 95f51c
 */
rpm-build 95f51c
rpm-build 95f51c
#ifdef DOXYGEN
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Allocate an array.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The macro is equivalent to:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      (type *)talloc_size(ctx, sizeof(type) * count);
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * except that it provides integer overflow protection for the multiply,
rpm-build 95f51c
 * returning NULL if the multiply overflows.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ctx      The talloc context to hang the result off.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  type     The type that we want to allocate.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  count    The number of 'type' elements you want to allocate.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The allocated result, properly cast to 'type *', NULL on
rpm-build 95f51c
 *                      error.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Example:
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      unsigned int *a, *b;
rpm-build 95f51c
 *      a = talloc_zero(NULL, unsigned int);
rpm-build 95f51c
 *      b = talloc_array(a, unsigned int, 100);
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * @see talloc()
rpm-build 95f51c
 * @see talloc_zero_array()
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_array(const void *ctx, #type, unsigned count);
rpm-build 95f51c
#else
rpm-build 95f51c
#define talloc_array(ctx, type, count) (type *)_talloc_array(ctx, sizeof(type), count, #type)
rpm-build 95f51c
void *_talloc_array(const void *ctx, size_t el_size, unsigned count, const char *name);
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
#ifdef DOXYGEN
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Allocate an array.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ctx      The talloc context to hang the result off.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  size     The size of an array element.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  count    The number of elements you want to allocate.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The allocated result, NULL on error.
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_array_size(const void *ctx, size_t size, unsigned count);
rpm-build 95f51c
#else
rpm-build 95f51c
#define talloc_array_size(ctx, size, count) _talloc_array(ctx, size, count, __location__)
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
#ifdef DOXYGEN
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Allocate an array into a typed pointer.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The macro should be used when you have a pointer to an array and want to
rpm-build 95f51c
 * allocate memory of an array to point at with this pointer. When compiling
rpm-build 95f51c
 * with gcc >= 3 it is typesafe. Note this is a wrapper of talloc_array_size()
rpm-build 95f51c
 * and talloc_get_name() will return the current location in the source file
rpm-build 95f51c
 * and not the type.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ctx      The talloc context to hang the result off.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The pointer you want to assign the result to.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  count    The number of elements you want to allocate.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The allocated memory chunk, properly casted. NULL on
rpm-build 95f51c
 *                      error.
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_array_ptrtype(const void *ctx, const void *ptr, unsigned count);
rpm-build 95f51c
#else
rpm-build 95f51c
#define talloc_array_ptrtype(ctx, ptr, count) (_TALLOC_TYPEOF(ptr))talloc_array_size(ctx, sizeof(*(ptr)), count)
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
#ifdef DOXYGEN
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Get the number of elements in a talloc'ed array.
rpm-build 95f51c
 *
rpm-build 95f51c
 * A talloc chunk carries its own size, so for talloc'ed arrays it is not
rpm-build 95f51c
 * necessary to store the number of elements explicitly.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ctx      The allocated array.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The number of elements in ctx.
rpm-build 95f51c
 */
rpm-build 95f51c
size_t talloc_array_length(const void *ctx);
rpm-build 95f51c
#else
rpm-build 95f51c
#define talloc_array_length(ctx) (talloc_get_size(ctx)/sizeof(*ctx))
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
#ifdef DOXYGEN
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Allocate a zero-initialized array
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ctx      The talloc context to hang the result off.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  type     The type that we want to allocate.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  count    The number of "type" elements you want to allocate.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The allocated result casted to "type *", NULL on error.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The talloc_zero_array() macro is equivalent to:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *     ptr = talloc_array(ctx, type, count);
rpm-build 95f51c
 *     if (ptr) memset(ptr, 0, sizeof(type) * count);
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_zero_array(const void *ctx, #type, unsigned count);
rpm-build 95f51c
#else
rpm-build 95f51c
#define talloc_zero_array(ctx, type, count) (type *)_talloc_zero_array(ctx, sizeof(type), count, #type)
rpm-build 95f51c
void *_talloc_zero_array(const void *ctx,
rpm-build 95f51c
			 size_t el_size,
rpm-build 95f51c
			 unsigned count,
rpm-build 95f51c
			 const char *name);
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
#ifdef DOXYGEN
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Change the size of a talloc array.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The macro changes the size of a talloc pointer. The 'count' argument is the
rpm-build 95f51c
 * number of elements of type 'type' that you want the resulting pointer to
rpm-build 95f51c
 * hold.
rpm-build 95f51c
 *
rpm-build 95f51c
 * talloc_realloc() has the following equivalences:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      talloc_realloc(ctx, NULL, type, 1) ==> talloc(ctx, type);
rpm-build 95f51c
 *      talloc_realloc(ctx, NULL, type, N) ==> talloc_array(ctx, type, N);
rpm-build 95f51c
 *      talloc_realloc(ctx, ptr, type, 0)  ==> talloc_free(ptr);
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * The "context" argument is only used if "ptr" is NULL, otherwise it is
rpm-build 95f51c
 * ignored.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ctx      The parent context used if ptr is NULL.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The chunk to be resized.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  type     The type of the array element inside ptr.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  count    The intended number of array elements.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The new array, NULL on error. The call will fail either
rpm-build 95f51c
 *                      due to a lack of memory, or because the pointer has more
rpm-build 95f51c
 *                      than one parent (see talloc_reference()).
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_realloc(const void *ctx, void *ptr, #type, size_t count);
rpm-build 95f51c
#else
rpm-build 95f51c
#define talloc_realloc(ctx, p, type, count) (type *)_talloc_realloc_array(ctx, p, sizeof(type), count, #type)
rpm-build 95f51c
void *_talloc_realloc_array(const void *ctx, void *ptr, size_t el_size, unsigned count, const char *name);
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
#ifdef DOXYGEN
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Untyped realloc to change the size of a talloc array.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The macro is useful when the type is not known so the typesafe
rpm-build 95f51c
 * talloc_realloc() cannot be used.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ctx      The parent context used if 'ptr' is NULL.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The chunk to be resized.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  size     The new chunk size.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The new array, NULL on error.
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_realloc_size(const void *ctx, void *ptr, size_t size);
rpm-build 95f51c
#else
rpm-build 95f51c
#define talloc_realloc_size(ctx, ptr, size) _talloc_realloc(ctx, ptr, size, __location__)
rpm-build 95f51c
void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *name);
rpm-build 95f51c
#endif
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Provide a function version of talloc_realloc_size.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This is a non-macro version of talloc_realloc(), which is useful as
rpm-build 95f51c
 * libraries sometimes want a ralloc function pointer. A realloc()
rpm-build 95f51c
 * implementation encapsulates the functionality of malloc(), free() and
rpm-build 95f51c
 * realloc() in one call, which is why it is useful to be able to pass around
rpm-build 95f51c
 * a single function pointer.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  context  The parent context used if ptr is NULL.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The chunk to be resized.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  size     The new chunk size.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The new chunk, NULL on error.
rpm-build 95f51c
 */
rpm-build 95f51c
void *talloc_realloc_fn(const void *context, void *ptr, size_t size);
rpm-build 95f51c
rpm-build 95f51c
/* @} ******************************************************************/
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @defgroup talloc_string The talloc string functions.
rpm-build 95f51c
 * @ingroup talloc
rpm-build 95f51c
 *
rpm-build 95f51c
 * talloc string allocation and manipulation functions.
rpm-build 95f51c
 * @{
rpm-build 95f51c
 */
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Duplicate a string into a talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This function is equivalent to:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      ptr = talloc_size(ctx, strlen(p)+1);
rpm-build 95f51c
 *      if (ptr) memcpy(ptr, p, strlen(p)+1);
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * This functions sets the name of the new pointer to the passed
rpm-build 95f51c
 * string. This is equivalent to:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      talloc_set_name_const(ptr, ptr)
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  t        The talloc context to hang the result off.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  p        The string you want to duplicate.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The duplicated string, NULL on error.
rpm-build 95f51c
 */
rpm-build 95f51c
char *talloc_strdup(const void *t, const char *p);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Append a string to given string.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The destination string is reallocated to take
rpm-build 95f51c
 * strlen(s) + strlen(a) + 1 characters.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This functions sets the name of the new pointer to the new
rpm-build 95f51c
 * string. This is equivalent to:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      talloc_set_name_const(ptr, ptr)
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * If s == NULL then new context is created.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  s        The destination to append to.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  a        The string you want to append.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The concatenated strings, NULL on error.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @see talloc_strdup()
rpm-build 95f51c
 * @see talloc_strdup_append_buffer()
rpm-build 95f51c
 */
rpm-build 95f51c
char *talloc_strdup_append(char *s, const char *a);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Append a string to a given buffer.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This is a more efficient version of talloc_strdup_append(). It determines the
rpm-build 95f51c
 * length of the destination string by the size of the talloc context.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Use this very carefully as it produces a different result than
rpm-build 95f51c
 * talloc_strdup_append() when a zero character is in the middle of the
rpm-build 95f51c
 * destination string.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      char *str_a = talloc_strdup(NULL, "hello world");
rpm-build 95f51c
 *      char *str_b = talloc_strdup(NULL, "hello world");
rpm-build 95f51c
 *      str_a[5] = str_b[5] = '\0'
rpm-build 95f51c
 *
rpm-build 95f51c
 *      char *app = talloc_strdup_append(str_a, ", hello");
rpm-build 95f51c
 *      char *buf = talloc_strdup_append_buffer(str_b, ", hello");
rpm-build 95f51c
 *
rpm-build 95f51c
 *      printf("%s\n", app); // hello, hello (app = "hello, hello")
rpm-build 95f51c
 *      printf("%s\n", buf); // hello (buf = "hello\0world, hello")
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * If s == NULL then new context is created.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  s        The destination buffer to append to.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  a        The string you want to append.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The concatenated strings, NULL on error.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @see talloc_strdup()
rpm-build 95f51c
 * @see talloc_strdup_append()
rpm-build 95f51c
 * @see talloc_array_length()
rpm-build 95f51c
 */
rpm-build 95f51c
char *talloc_strdup_append_buffer(char *s, const char *a);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Duplicate a length-limited string into a talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This function is the talloc equivalent of the C library function strndup(3).
rpm-build 95f51c
 *
rpm-build 95f51c
 * This functions sets the name of the new pointer to the passed string. This is
rpm-build 95f51c
 * equivalent to:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      talloc_set_name_const(ptr, ptr)
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  t        The talloc context to hang the result off.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  p        The string you want to duplicate.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  n        The maximum string length to duplicate.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The duplicated string, NULL on error.
rpm-build 95f51c
 */
rpm-build 95f51c
char *talloc_strndup(const void *t, const char *p, size_t n);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Append at most n characters of a string to given string.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The destination string is reallocated to take
rpm-build 95f51c
 * strlen(s) + strnlen(a, n) + 1 characters.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This functions sets the name of the new pointer to the new
rpm-build 95f51c
 * string. This is equivalent to:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      talloc_set_name_const(ptr, ptr)
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * If s == NULL then new context is created.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  s        The destination string to append to.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  a        The source string you want to append.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  n        The number of characters you want to append from the
rpm-build 95f51c
 *                      string.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The concatenated strings, NULL on error.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @see talloc_strndup()
rpm-build 95f51c
 * @see talloc_strndup_append_buffer()
rpm-build 95f51c
 */
rpm-build 95f51c
char *talloc_strndup_append(char *s, const char *a, size_t n);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Append at most n characters of a string to given buffer
rpm-build 95f51c
 *
rpm-build 95f51c
 * This is a more efficient version of talloc_strndup_append(). It determines
rpm-build 95f51c
 * the length of the destination string by the size of the talloc context.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Use this very carefully as it produces a different result than
rpm-build 95f51c
 * talloc_strndup_append() when a zero character is in the middle of the
rpm-build 95f51c
 * destination string.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      char *str_a = talloc_strdup(NULL, "hello world");
rpm-build 95f51c
 *      char *str_b = talloc_strdup(NULL, "hello world");
rpm-build 95f51c
 *      str_a[5] = str_b[5] = '\0'
rpm-build 95f51c
 *
rpm-build 95f51c
 *      char *app = talloc_strndup_append(str_a, ", hello", 7);
rpm-build 95f51c
 *      char *buf = talloc_strndup_append_buffer(str_b, ", hello", 7);
rpm-build 95f51c
 *
rpm-build 95f51c
 *      printf("%s\n", app); // hello, hello (app = "hello, hello")
rpm-build 95f51c
 *      printf("%s\n", buf); // hello (buf = "hello\0world, hello")
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * If s == NULL then new context is created.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  s        The destination buffer to append to.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  a        The source string you want to append.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  n        The number of characters you want to append from the
rpm-build 95f51c
 *                      string.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The concatenated strings, NULL on error.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @see talloc_strndup()
rpm-build 95f51c
 * @see talloc_strndup_append()
rpm-build 95f51c
 * @see talloc_array_length()
rpm-build 95f51c
 */
rpm-build 95f51c
char *talloc_strndup_append_buffer(char *s, const char *a, size_t n);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Format a string given a va_list.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This function is the talloc equivalent of the C library function
rpm-build 95f51c
 * vasprintf(3).
rpm-build 95f51c
 *
rpm-build 95f51c
 * This functions sets the name of the new pointer to the new string. This is
rpm-build 95f51c
 * equivalent to:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      talloc_set_name_const(ptr, ptr)
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  t        The talloc context to hang the result off.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  fmt      The format string.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ap       The parameters used to fill fmt.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The formatted string, NULL on error.
rpm-build 95f51c
 */
rpm-build 95f51c
char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2,0);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Format a string given a va_list and append it to the given destination
rpm-build 95f51c
 *        string.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  s        The destination string to append to.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  fmt      The format string.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ap       The parameters used to fill fmt.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The formatted string, NULL on error.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @see talloc_vasprintf()
rpm-build 95f51c
 */
rpm-build 95f51c
char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2,0);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Format a string given a va_list and append it to the given destination
rpm-build 95f51c
 *        buffer.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  s        The destination buffer to append to.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  fmt      The format string.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ap       The parameters used to fill fmt.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The formatted string, NULL on error.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @see talloc_vasprintf()
rpm-build 95f51c
 */
rpm-build 95f51c
char *talloc_vasprintf_append_buffer(char *s, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2,0);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Format a string.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This function is the talloc equivalent of the C library function asprintf(3).
rpm-build 95f51c
 *
rpm-build 95f51c
 * This functions sets the name of the new pointer to the new string. This is
rpm-build 95f51c
 * equivalent to:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      talloc_set_name_const(ptr, ptr)
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  t        The talloc context to hang the result off.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  fmt      The format string.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ...      The parameters used to fill fmt.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The formatted string, NULL on error.
rpm-build 95f51c
 */
rpm-build 95f51c
char *talloc_asprintf(const void *t, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Append a formatted string to another string.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This function appends the given formatted string to the given string. Use
rpm-build 95f51c
 * this variant when the string in the current talloc buffer may have been
rpm-build 95f51c
 * truncated in length.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This functions sets the name of the new pointer to the new
rpm-build 95f51c
 * string. This is equivalent to:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      talloc_set_name_const(ptr, ptr)
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * If s == NULL then new context is created.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  s        The string to append to.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  fmt      The format string.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ...      The parameters used to fill fmt.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The formatted string, NULL on error.
rpm-build 95f51c
 */
rpm-build 95f51c
char *talloc_asprintf_append(char *s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Append a formatted string to another string.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This is a more efficient version of talloc_asprintf_append(). It determines
rpm-build 95f51c
 * the length of the destination string by the size of the talloc context.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Use this very carefully as it produces a different result than
rpm-build 95f51c
 * talloc_asprintf_append() when a zero character is in the middle of the
rpm-build 95f51c
 * destination string.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      char *str_a = talloc_strdup(NULL, "hello world");
rpm-build 95f51c
 *      char *str_b = talloc_strdup(NULL, "hello world");
rpm-build 95f51c
 *      str_a[5] = str_b[5] = '\0'
rpm-build 95f51c
 *
rpm-build 95f51c
 *      char *app = talloc_asprintf_append(str_a, "%s", ", hello");
rpm-build 95f51c
 *      char *buf = talloc_strdup_append_buffer(str_b, "%s", ", hello");
rpm-build 95f51c
 *
rpm-build 95f51c
 *      printf("%s\n", app); // hello, hello (app = "hello, hello")
rpm-build 95f51c
 *      printf("%s\n", buf); // hello (buf = "hello\0world, hello")
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * If s == NULL then new context is created.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  s        The string to append to
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  fmt      The format string.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ...      The parameters used to fill fmt.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @return              The formatted string, NULL on error.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @see talloc_asprintf()
rpm-build 95f51c
 * @see talloc_asprintf_append()
rpm-build 95f51c
 */
rpm-build 95f51c
char *talloc_asprintf_append_buffer(char *s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
rpm-build 95f51c
rpm-build 95f51c
/* @} ******************************************************************/
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @defgroup talloc_debug The talloc debugging support functions
rpm-build 95f51c
 * @ingroup talloc
rpm-build 95f51c
 *
rpm-build 95f51c
 * To aid memory debugging, talloc contains routines to inspect the currently
rpm-build 95f51c
 * allocated memory hierarchy.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @{
rpm-build 95f51c
 */
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Walk a complete talloc hierarchy.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This provides a more flexible reports than talloc_report(). It
rpm-build 95f51c
 * will recursively call the callback for the entire tree of memory
rpm-build 95f51c
 * referenced by the pointer. References in the tree are passed with
rpm-build 95f51c
 * is_ref = 1 and the pointer that is referenced.
rpm-build 95f51c
 *
rpm-build 95f51c
 * You can pass NULL for the pointer, in which case a report is
rpm-build 95f51c
 * printed for the top level memory context, but only if
rpm-build 95f51c
 * talloc_enable_leak_report() or talloc_enable_leak_report_full()
rpm-build 95f51c
 * has been called.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The recursion is stopped when depth >= max_depth.
rpm-build 95f51c
 * max_depth = -1 means only stop at leaf nodes.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  depth    Internal parameter to control recursion. Call with 0.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  max_depth  Maximum recursion level.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  callback  Function to be called on every chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  private_data  Private pointer passed to callback.
rpm-build 95f51c
 */
rpm-build 95f51c
void talloc_report_depth_cb(const void *ptr, int depth, int max_depth,
rpm-build 95f51c
			    void (*callback)(const void *ptr,
rpm-build 95f51c
					     int depth, int max_depth,
rpm-build 95f51c
					     int is_ref,
rpm-build 95f51c
					     void *private_data),
rpm-build 95f51c
			    void *private_data);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Print a talloc hierarchy.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This provides a more flexible reports than talloc_report(). It
rpm-build 95f51c
 * will let you specify the depth and max_depth.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  depth    Internal parameter to control recursion. Call with 0.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  max_depth  Maximum recursion level.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  f        The file handle to print to.
rpm-build 95f51c
 */
rpm-build 95f51c
void talloc_report_depth_file(const void *ptr, int depth, int max_depth, FILE *f);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Print a summary report of all memory used by ptr.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This provides a more detailed report than talloc_report(). It will
rpm-build 95f51c
 * recursively print the entire tree of memory referenced by the
rpm-build 95f51c
 * pointer. References in the tree are shown by giving the name of the
rpm-build 95f51c
 * pointer that is referenced.
rpm-build 95f51c
 *
rpm-build 95f51c
 * You can pass NULL for the pointer, in which case a report is printed
rpm-build 95f51c
 * for the top level memory context, but only if
rpm-build 95f51c
 * talloc_enable_leak_report() or talloc_enable_leak_report_full() has
rpm-build 95f51c
 * been called.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  f        The file handle to print to.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Example:
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      unsigned int *a, *b;
rpm-build 95f51c
 *      a = talloc(NULL, unsigned int);
rpm-build 95f51c
 *      b = talloc(a, unsigned int);
rpm-build 95f51c
 *      fprintf(stderr, "Dumping memory tree for a:\n");
rpm-build 95f51c
 *      talloc_report_full(a, stderr);
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * @see talloc_report()
rpm-build 95f51c
 */
rpm-build 95f51c
void talloc_report_full(const void *ptr, FILE *f);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Print a summary report of all memory used by ptr.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This function prints a summary report of all memory used by ptr. One line of
rpm-build 95f51c
 * report is printed for each immediate child of ptr, showing the total memory
rpm-build 95f51c
 * and number of blocks used by that child.
rpm-build 95f51c
 *
rpm-build 95f51c
 * You can pass NULL for the pointer, in which case a report is printed
rpm-build 95f51c
 * for the top level memory context, but only if talloc_enable_leak_report()
rpm-build 95f51c
 * or talloc_enable_leak_report_full() has been called.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  ptr      The talloc chunk.
rpm-build 95f51c
 *
rpm-build 95f51c
 * @param[in]  f        The file handle to print to.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Example:
rpm-build 95f51c
 * @code
rpm-build 95f51c
 *      unsigned int *a, *b;
rpm-build 95f51c
 *      a = talloc(NULL, unsigned int);
rpm-build 95f51c
 *      b = talloc(a, unsigned int);
rpm-build 95f51c
 *      fprintf(stderr, "Summary of memory tree for a:\n");
rpm-build 95f51c
 *      talloc_report(a, stderr);
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 *
rpm-build 95f51c
 * @see talloc_report_full()
rpm-build 95f51c
 */
rpm-build 95f51c
void talloc_report(const void *ptr, FILE *f);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Enable tracking the use of NULL memory contexts.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This enables tracking of the NULL memory context without enabling leak
rpm-build 95f51c
 * reporting on exit. Useful for when you want to do your own leak
rpm-build 95f51c
 * reporting call via talloc_report_null_full();
rpm-build 95f51c
 */
rpm-build 95f51c
void talloc_enable_null_tracking(void);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Enable tracking the use of NULL memory contexts.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This enables tracking of the NULL memory context without enabling leak
rpm-build 95f51c
 * reporting on exit. Useful for when you want to do your own leak
rpm-build 95f51c
 * reporting call via talloc_report_null_full();
rpm-build 95f51c
 */
rpm-build 95f51c
void talloc_enable_null_tracking_no_autofree(void);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Disable tracking of the NULL memory context.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This disables tracking of the NULL memory context.
rpm-build 95f51c
 */
rpm-build 95f51c
void talloc_disable_null_tracking(void);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Enable leak report when a program exits.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This enables calling of talloc_report(NULL, stderr) when the program
rpm-build 95f51c
 * exits. In Samba4 this is enabled by using the --leak-report command
rpm-build 95f51c
 * line option.
rpm-build 95f51c
 *
rpm-build 95f51c
 * For it to be useful, this function must be called before any other
rpm-build 95f51c
 * talloc function as it establishes a "null context" that acts as the
rpm-build 95f51c
 * top of the tree. If you don't call this function first then passing
rpm-build 95f51c
 * NULL to talloc_report() or talloc_report_full() won't give you the
rpm-build 95f51c
 * full tree printout.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Here is a typical talloc report:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 * talloc report on 'null_context' (total 267 bytes in 15 blocks)
rpm-build 95f51c
 *      libcli/auth/spnego_parse.c:55  contains     31 bytes in   2 blocks
rpm-build 95f51c
 *      libcli/auth/spnego_parse.c:55  contains     31 bytes in   2 blocks
rpm-build 95f51c
 *      iconv(UTF8,CP850)              contains     42 bytes in   2 blocks
rpm-build 95f51c
 *      libcli/auth/spnego_parse.c:55  contains     31 bytes in   2 blocks
rpm-build 95f51c
 *      iconv(CP850,UTF8)              contains     42 bytes in   2 blocks
rpm-build 95f51c
 *      iconv(UTF8,UTF-16LE)           contains     45 bytes in   2 blocks
rpm-build 95f51c
 *      iconv(UTF-16LE,UTF8)           contains     45 bytes in   2 blocks
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 */
rpm-build 95f51c
void talloc_enable_leak_report(void);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Enable full leak report when a program exits.
rpm-build 95f51c
 *
rpm-build 95f51c
 * This enables calling of talloc_report_full(NULL, stderr) when the
rpm-build 95f51c
 * program exits. In Samba4 this is enabled by using the
rpm-build 95f51c
 * --leak-report-full command line option.
rpm-build 95f51c
 *
rpm-build 95f51c
 * For it to be useful, this function must be called before any other
rpm-build 95f51c
 * talloc function as it establishes a "null context" that acts as the
rpm-build 95f51c
 * top of the tree. If you don't call this function first then passing
rpm-build 95f51c
 * NULL to talloc_report() or talloc_report_full() won't give you the
rpm-build 95f51c
 * full tree printout.
rpm-build 95f51c
 *
rpm-build 95f51c
 * Here is a typical full report:
rpm-build 95f51c
 *
rpm-build 95f51c
 * @code
rpm-build 95f51c
 * full talloc report on 'root' (total 18 bytes in 8 blocks)
rpm-build 95f51c
 *      p1                             contains     18 bytes in   7 blocks (ref 0)
rpm-build 95f51c
 *      r1                             contains     13 bytes in   2 blocks (ref 0)
rpm-build 95f51c
 *      reference to: p2
rpm-build 95f51c
 *      p2                             contains      1 bytes in   1 blocks (ref 1)
rpm-build 95f51c
 *      x3                             contains      1 bytes in   1 blocks (ref 0)
rpm-build 95f51c
 *      x2                             contains      1 bytes in   1 blocks (ref 0)
rpm-build 95f51c
 *      x1                             contains      1 bytes in   1 blocks (ref 0)
rpm-build 95f51c
 * @endcode
rpm-build 95f51c
 */
rpm-build 95f51c
void talloc_enable_leak_report_full(void);
rpm-build 95f51c
rpm-build 95f51c
/**
rpm-build 95f51c
 * @brief Set a custom "abort" function that is called on serious error.
rpm-build 95f51c
 *
rpm-build 95f51c
 * The default "abort" function is abort().
rpm-build 95f51c
 *
rpm-build 95f51c
 * The "abort" function is called when:
rpm-build 95f51c
 *
rpm-build 95f51c
 * 
    rpm-build 95f51c
     *  
  • talloc_get_type_abort() fails
  • rpm-build 95f51c
     *  
  • the provided pointer is not a valid talloc context
  • rpm-build 95f51c
     *  
  • when the context meta data are invalid
  • rpm-build 95f51c
     *  
  • when access after free is detected
  • rpm-build 95f51c
     * 
    rpm-build 95f51c
     *
    rpm-build 95f51c
     * Example:
    rpm-build 95f51c
     *
    rpm-build 95f51c
     * @code
    rpm-build 95f51c
     * void my_abort(const char *reason)
    rpm-build 95f51c
     * {
    rpm-build 95f51c
     *      fprintf(stderr, "talloc abort: %s\n", reason);
    rpm-build 95f51c
     *      abort();
    rpm-build 95f51c
     * }
    rpm-build 95f51c
     *
    rpm-build 95f51c
     *      talloc_set_abort_fn(my_abort);
    rpm-build 95f51c
     * @endcode
    rpm-build 95f51c
     *
    rpm-build 95f51c
     * @param[in]  abort_fn      The new "abort" function.
    rpm-build 95f51c
     *
    rpm-build 95f51c
     * @see talloc_set_log_fn()
    rpm-build 95f51c
     * @see talloc_get_type()
    rpm-build 95f51c
     */
    rpm-build 95f51c
    void talloc_set_abort_fn(void (*abort_fn)(const char *reason));
    rpm-build 95f51c
    rpm-build 95f51c
    /**
    rpm-build 95f51c
     * @brief Set a logging function.
    rpm-build 95f51c
     *
    rpm-build 95f51c
     * @param[in]  log_fn      The logging function.
    rpm-build 95f51c
     *
    rpm-build 95f51c
     * @see talloc_set_log_stderr()
    rpm-build 95f51c
     * @see talloc_set_abort_fn()
    rpm-build 95f51c
     */
    rpm-build 95f51c
    void talloc_set_log_fn(void (*log_fn)(const char *message));
    rpm-build 95f51c
    rpm-build 95f51c
    /**
    rpm-build 95f51c
     * @brief Set stderr as the output for logs.
    rpm-build 95f51c
     *
    rpm-build 95f51c
     * @see talloc_set_log_fn()
    rpm-build 95f51c
     * @see talloc_set_abort_fn()
    rpm-build 95f51c
     */
    rpm-build 95f51c
    void talloc_set_log_stderr(void);
    rpm-build 95f51c
    rpm-build 95f51c
    /**
    rpm-build 95f51c
     * @brief Set a max memory limit for the current context hierarchy
    rpm-build 95f51c
     *	  This affects all children of this context and constrain any
    rpm-build 95f51c
     *	  allocation in the hierarchy to never exceed the limit set.
    rpm-build 95f51c
     *	  The limit can be removed by setting 0 (unlimited) as the
    rpm-build 95f51c
     *	  max_size by calling the function again on the same context.
    rpm-build 95f51c
     *	  Memory limits can also be nested, meaning a child can have
    rpm-build 95f51c
     *	  a stricter memory limit than a parent.
    rpm-build 95f51c
     *	  Memory limits are enforced only at memory allocation time.
    rpm-build 95f51c
     *	  Stealing a context into a 'limited' hierarchy properly
    rpm-build 95f51c
     *	  updates memory usage but does *not* cause failure if the
    rpm-build 95f51c
     *	  move causes the new parent to exceed its limits. However
    rpm-build 95f51c
     *	  any further allocation on that hierarchy will then fail.
    rpm-build 95f51c
     *
    rpm-build 95f51c
     * @warning talloc memlimit functionality is deprecated. Please
    rpm-build 95f51c
     *	    consider using cgroup memory limits instead.
    rpm-build 95f51c
     *
    rpm-build 95f51c
     * @param[in]	ctx		The talloc context to set the limit on
    rpm-build 95f51c
     * @param[in]	max_size	The (new) max_size
    rpm-build 95f51c
     */
    rpm-build 95f51c
    int talloc_set_memlimit(const void *ctx, size_t max_size) _DEPRECATED_;
    rpm-build 95f51c
    rpm-build 95f51c
    /* @} ******************************************************************/
    rpm-build 95f51c
    rpm-build 95f51c
    #if TALLOC_DEPRECATED
    rpm-build 95f51c
    #define talloc_zero_p(ctx, type) talloc_zero(ctx, type)
    rpm-build 95f51c
    #define talloc_p(ctx, type) talloc(ctx, type)
    rpm-build 95f51c
    #define talloc_array_p(ctx, type, count) talloc_array(ctx, type, count)
    rpm-build 95f51c
    #define talloc_realloc_p(ctx, p, type, count) talloc_realloc(ctx, p, type, count)
    rpm-build 95f51c
    #define talloc_destroy(ctx) talloc_free(ctx)
    rpm-build 95f51c
    #define talloc_append_string(c, s, a) (s?talloc_strdup_append(s,a):talloc_strdup(c, a))
    rpm-build 95f51c
    #endif
    rpm-build 95f51c
    rpm-build 95f51c
    #ifndef TALLOC_MAX_DEPTH
    rpm-build 95f51c
    #define TALLOC_MAX_DEPTH 10000
    rpm-build 95f51c
    #endif
    rpm-build 95f51c
    rpm-build 95f51c
    #ifdef __cplusplus
    rpm-build 95f51c
    } /* end of extern "C" */
    rpm-build 95f51c
    #endif
    rpm-build 95f51c
    rpm-build 95f51c
    #endif