diff options
Diffstat (limited to 'ctdb/lib/talloc')
-rw-r--r-- | ctdb/lib/talloc/Makefile.in | 19 | ||||
-rw-r--r-- | ctdb/lib/talloc/config.h.in | 9 | ||||
-rw-r--r-- | ctdb/lib/talloc/configure.ac | 2 | ||||
-rw-r--r-- | ctdb/lib/talloc/libtalloc.m4 | 10 | ||||
-rw-r--r-- | ctdb/lib/talloc/talloc.3 | 4 | ||||
-rw-r--r-- | ctdb/lib/talloc/talloc.3.html | 78 | ||||
-rw-r--r-- | ctdb/lib/talloc/talloc.c | 21 | ||||
-rw-r--r-- | ctdb/lib/talloc/talloc.h | 16 | ||||
-rw-r--r-- | ctdb/lib/talloc/talloc.pc | 1 | ||||
-rw-r--r-- | ctdb/lib/talloc/talloc.pc.in | 2 | ||||
-rw-r--r-- | ctdb/lib/talloc/talloc_guide.txt | 2 | ||||
-rw-r--r-- | ctdb/lib/talloc/testsuite.c | 4 |
12 files changed, 90 insertions, 78 deletions
diff --git a/ctdb/lib/talloc/Makefile.in b/ctdb/lib/talloc/Makefile.in index 14e8115692..18b48c3459 100644 --- a/ctdb/lib/talloc/Makefile.in +++ b/ctdb/lib/talloc/Makefile.in @@ -12,12 +12,12 @@ builddir = @builddir@ XSLTPROC = @XSLTPROC@ INSTALLCMD = @INSTALL@ CC = @CC@ -CFLAGS = @CFLAGS@ -DHAVE_CONFIG_H= -I. -I@srcdir@ -I@libreplacedir@ +CFLAGS = @CFLAGS@ -DHAVE_CONFIG_H= -I. -I@srcdir@ EXTRA_TARGETS = @DOC_TARGET@ .SUFFIXES: .c .o .3 .3.xml .xml .html -LIBOBJ = @TALLOCOBJ@ @LIBREPLACEOBJ@ +LIBOBJ = @TALLOC_OBJ@ @LIBREPLACEOBJ@ all: showflags libtalloc.a testsuite $(EXTRA_TARGETS) @@ -34,13 +34,14 @@ libtalloc.a: $(LIBOBJ) @-ranlib $@ install: all - ${INSTALLCMD} -d ${libdir} - ${INSTALLCMD} -m 755 libtalloc.a $(libdir) - ${INSTALLCMD} -d ${includedir} - ${INSTALLCMD} -m 644 $(srcdir)/talloc.h $(includedir) - ${INSTALLCMD} -m 644 talloc.pc $(libdir)/pkgconfig - if [ -f talloc.3 ];then ${INSTALLCMD} -d ${mandir}/man3; fi - if [ -f talloc.3 ];then ${INSTALLCMD} -m 644 talloc.3 $(mandir)/man3; fi + ${INSTALLCMD} -d $(DESTDIR)$(libdir) + ${INSTALLCMD} -d $(DESTDIR)$(libdir)/pkgconfig + ${INSTALLCMD} -m 755 libtalloc.a $(DESTDIR)$(libdir) + ${INSTALLCMD} -d $(DESTDIR)${includedir} + ${INSTALLCMD} -m 644 $(srcdir)/talloc.h $(DESTDIR)$(includedir) + ${INSTALLCMD} -m 644 talloc.pc $(DESTDIR)$(libdir)/pkgconfig + if [ -f talloc.3 ];then ${INSTALLCMD} -d $(DESTDIR)$(mandir)/man3; fi + if [ -f talloc.3 ];then ${INSTALLCMD} -m 644 talloc.3 $(DESTDIR)$(mandir)/man3; fi doc: talloc.3 talloc.3.html diff --git a/ctdb/lib/talloc/config.h.in b/ctdb/lib/talloc/config.h.in index 2c52e63551..407af7c8d4 100644 --- a/ctdb/lib/talloc/config.h.in +++ b/ctdb/lib/talloc/config.h.in @@ -77,9 +77,6 @@ /* Define to 1 if you have the `endnetgrent' function. */ #undef HAVE_ENDNETGRENT -/* Define to 1 if you have the `epoll_create' function. */ -#undef HAVE_EPOLL_CREATE - /* Whether errno() is available */ #undef HAVE_ERRNO_DECL @@ -224,6 +221,9 @@ /* Define to 1 if you have the `seteuid' function. */ #undef HAVE_SETEUID +/* Define to 1 if you have the <setjmp.h> header file. */ +#undef HAVE_SETJMP_H + /* Define to 1 if you have the `setlinebuf' function. */ #undef HAVE_SETLINEBUF @@ -346,9 +346,6 @@ */ #undef HAVE_SYS_DIR_H -/* Define to 1 if you have the <sys/epoll.h> header file. */ -#undef HAVE_SYS_EPOLL_H - /* Define to 1 if you have the <sys/fcntl.h> header file. */ #undef HAVE_SYS_FCNTL_H diff --git a/ctdb/lib/talloc/configure.ac b/ctdb/lib/talloc/configure.ac index 51e7256bf8..5f465fe93a 100644 --- a/ctdb/lib/talloc/configure.ac +++ b/ctdb/lib/talloc/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ(2.50) -AC_INIT(talloc.h) +AC_INIT(talloc, 1.0) AC_CONFIG_SRCDIR([talloc.c]) AC_SUBST(datarootdir) AC_CONFIG_HEADER(config.h) diff --git a/ctdb/lib/talloc/libtalloc.m4 b/ctdb/lib/talloc/libtalloc.m4 index 4a0ee3c8fc..d2e8eba81a 100644 --- a/ctdb/lib/talloc/libtalloc.m4 +++ b/ctdb/lib/talloc/libtalloc.m4 @@ -12,8 +12,14 @@ done if test x"$tallocdir" = "x"; then AC_MSG_ERROR([cannot find talloc source in $tallocpaths]) fi -TALLOCOBJ="talloc.o" -AC_SUBST(TALLOCOBJ) +TALLOC_OBJ="talloc.o" +AC_SUBST(TALLOC_OBJ) + +TALLOC_CFLAGS="-I$tallocdir" +AC_SUBST(TALLOC_CFLAGS) + +TALLOC_LIBS="" +AC_SUBST(TALLOC_LIBS) AC_CHECK_SIZEOF(size_t,cross) AC_CHECK_SIZEOF(void *,cross) diff --git a/ctdb/lib/talloc/talloc.3 b/ctdb/lib/talloc/talloc.3 index 5f9f10e488..1ad6c8d634 100644 --- a/ctdb/lib/talloc/talloc.3 +++ b/ctdb/lib/talloc/talloc.3 @@ -1,11 +1,11 @@ .\" Title: talloc .\" Author: .\" Generator: DocBook XSL Stylesheets v1.71.0 <http://docbook.sf.net/> -.\" Date: 12/09/2006 +.\" Date: 02/26/2007 .\" Manual: .\" Source: .\" -.TH "TALLOC" "3" "12/09/2006" "" "" +.TH "TALLOC" "3" "02/26/2007" "" "" .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) diff --git a/ctdb/lib/talloc/talloc.3.html b/ctdb/lib/talloc/talloc.3.html index 160afa03e4..7d0129d30c 100644 --- a/ctdb/lib/talloc/talloc.3.html +++ b/ctdb/lib/talloc/talloc.3.html @@ -1,4 +1,4 @@ -<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>talloc</title><meta name="generator" content="DocBook XSL Stylesheets V1.71.0"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en"><a name="id2478266"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>talloc — hierarchical reference counted memory pool system with destructors</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">#include <talloc/talloc.h></pre></div><div class="refsect1" lang="en"><a name="id2517036"></a><h2>DESCRIPTION</h2><p> +<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>talloc</title><meta name="generator" content="DocBook XSL Stylesheets V1.71.0"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en"><a name="id2478730"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>talloc — hierarchical reference counted memory pool system with destructors</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">#include <talloc/talloc.h></pre></div><div class="refsect1" lang="en"><a name="id2517362"></a><h2>DESCRIPTION</h2><p> If you are used to talloc from Samba3 then please read this carefully, as talloc has changed a lot. </p><p> @@ -30,10 +30,10 @@ If you find this confusing, then I suggest you run the <code class="literal">testsuite</code> program to watch talloc in action. You may also like to add your own tests to <code class="literal">testsuite.c</code> to clarify how some particular situation is handled. - </p></div><div class="refsect1" lang="en"><a name="id2478366"></a><h2>TALLOC API</h2><p> + </p></div><div class="refsect1" lang="en"><a name="id2478829"></a><h2>TALLOC API</h2><p> The following is a complete guide to the talloc API. Read it all at least twice. - </p><div class="refsect2" lang="en"><a name="id2478375"></a><h3>(type *)talloc(const void *ctx, type);</h3><p> + </p><div class="refsect2" lang="en"><a name="id2478838"></a><h3>(type *)talloc(const void *ctx, type);</h3><p> The talloc() macro is the core of the talloc library. It takes a memory <span class="italic">ctx</span> and a <span class="italic">type</span>, and returns a pointer to a new area of memory of the given <span class="italic">type</span>. @@ -48,18 +48,18 @@ </p><p> The <span class="italic">ctx</span> argument to talloc() can be NULL, in which case a new top level context is created. - </p></div><div class="refsect2" lang="en"><a name="id2478439"></a><h3>void *talloc_size(const void *ctx, size_t size);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2478902"></a><h3>void *talloc_size(const void *ctx, size_t size);</h3><p> The function talloc_size() should be used when you don't have a convenient type to pass to talloc(). Unlike talloc(), it is not type safe (as it returns a void *), so you are on your own for type checking. - </p></div><div class="refsect2" lang="en"><a name="id2478452"></a><h3>(typeof(ptr)) talloc_ptrtype(const void *ctx, ptr);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2478915"></a><h3>(typeof(ptr)) talloc_ptrtype(const void *ctx, ptr);</h3><p> The talloc_ptrtype() macro should be used when you have a pointer and want to allocate memory to point at with this pointer. When compiling with gcc >= 3 it is typesafe. Note this is a wrapper of talloc_size() and talloc_get_name() will return the current location in the source file. and not the type. - </p></div><div class="refsect2" lang="en"><a name="id2478467"></a><h3>int talloc_free(void *ptr);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2478930"></a><h3>int talloc_free(void *ptr);</h3><p> The talloc_free() function frees a piece of talloc memory, and all its children. You can call talloc_free() on any pointer returned by talloc(). @@ -143,14 +143,14 @@ free will be ignored. This would be a pointless operation anyway, as the destructor is only called when the memory is just about to go away. - </p></div><div class="refsect2" lang="en"><a name="id2479422"></a><h3>int talloc_increase_ref_count(const void *<span class="italic">ptr</span>);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2479748"></a><h3>int talloc_increase_ref_count(const void *<span class="italic">ptr</span>);</h3><p> The talloc_increase_ref_count(<span class="italic">ptr</span>) function is exactly equivalent to: </p><pre class="programlisting">talloc_reference(NULL, ptr);</pre><p> You can use either syntax, depending on which you think is clearer in your code. </p><p> It returns 0 on success and -1 on failure. - </p></div><div class="refsect2" lang="en"><a name="id2479459"></a><h3>size_t talloc_reference_count(const void *<span class="italic">ptr</span>);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2479785"></a><h3>size_t talloc_reference_count(const void *<span class="italic">ptr</span>);</h3><p> Return the number of references to the pointer. </p></div><div class="refsect2" lang="en"><a name="talloc_set_name"></a><h3>void talloc_set_name(const void *ptr, const char *fmt, ...);</h3><p> Each talloc pointer has a "name". The name is used principally @@ -173,7 +173,7 @@ Note that multiple calls to talloc_set_name() will allocate more memory without releasing the name. All of the memory is released when the ptr is freed using talloc_free(). - </p></div><div class="refsect2" lang="en"><a name="id2479578"></a><h3>void talloc_set_name_const(const void *<span class="italic">ptr</span>, const char *<span class="italic">name</span>);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2479904"></a><h3>void talloc_set_name_const(const void *<span class="italic">ptr</span>, const char *<span class="italic">name</span>);</h3><p> The function talloc_set_name_const() is just like talloc_set_name(), but it takes a string constant, and is much faster. It is extensively used by the "auto naming" macros, such @@ -184,27 +184,27 @@ ptr. This means you must not pass a <span class="italic">name</span> pointer to memory that will disappear before <span class="italic">ptr</span> is freed with talloc_free(). - </p></div><div class="refsect2" lang="en"><a name="id2479622"></a><h3>void *talloc_named(const void *<span class="italic">ctx</span>, size_t <span class="italic">size</span>, const char *<span class="italic">fmt</span>, ...);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2479948"></a><h3>void *talloc_named(const void *<span class="italic">ctx</span>, size_t <span class="italic">size</span>, const char *<span class="italic">fmt</span>, ...);</h3><p> The talloc_named() function creates a named talloc pointer. It is equivalent to: </p><pre class="programlisting">ptr = talloc_size(ctx, size); -talloc_set_name(ptr, fmt, ....);</pre></div><div class="refsect2" lang="en"><a name="id2479657"></a><h3>void *talloc_named_const(const void *<span class="italic">ctx</span>, size_t <span class="italic">size</span>, const char *<span class="italic">name</span>);</h3><p> +talloc_set_name(ptr, fmt, ....);</pre></div><div class="refsect2" lang="en"><a name="id2479983"></a><h3>void *talloc_named_const(const void *<span class="italic">ctx</span>, size_t <span class="italic">size</span>, const char *<span class="italic">name</span>);</h3><p> This is equivalent to: </p><pre class="programlisting">ptr = talloc_size(ctx, size); -talloc_set_name_const(ptr, name);</pre></div><div class="refsect2" lang="en"><a name="id2479692"></a><h3>const char *talloc_get_name(const void *<span class="italic">ptr</span>);</h3><p> +talloc_set_name_const(ptr, name);</pre></div><div class="refsect2" lang="en"><a name="id2480018"></a><h3>const char *talloc_get_name(const void *<span class="italic">ptr</span>);</h3><p> This returns the current name for the given talloc pointer, <span class="italic">ptr</span>. See <a href="#talloc_set_name" title="void talloc_set_name(const void *ptr, const char *fmt, ...);">“<span class="quote">talloc_set_name()</span>”</a> for details. - </p></div><div class="refsect2" lang="en"><a name="id2479723"></a><h3>void *talloc_init(const char *<span class="italic">fmt</span>, ...);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2480049"></a><h3>void *talloc_init(const char *<span class="italic">fmt</span>, ...);</h3><p> This function creates a zero length named talloc context as a top level context. It is equivalent to: - </p><pre class="programlisting">talloc_named(NULL, 0, fmt, ...);</pre></div><div class="refsect2" lang="en"><a name="id2479746"></a><h3>void *talloc_new(void *<span class="italic">ctx</span>);</h3><p> + </p><pre class="programlisting">talloc_named(NULL, 0, fmt, ...);</pre></div><div class="refsect2" lang="en"><a name="id2480072"></a><h3>void *talloc_new(void *<span class="italic">ctx</span>);</h3><p> This is a utility macro that creates a new memory context hanging off an exiting context, automatically naming it "talloc_new: __location__" where __location__ is the source line it is called from. It is particularly useful for creating a new temporary working context. - </p></div><div class="refsect2" lang="en"><a name="id2526437"></a><h3>(<span class="italic">type</span> *)talloc_realloc(const void *<span class="italic">ctx</span>, void *<span class="italic">ptr</span>, <span class="italic">type</span>, <span class="italic">count</span>);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2526763"></a><h3>(<span class="italic">type</span> *)talloc_realloc(const void *<span class="italic">ctx</span>, void *<span class="italic">ptr</span>, <span class="italic">type</span>, <span class="italic">count</span>);</h3><p> The talloc_realloc() macro changes the size of a talloc pointer. It has the following equivalences: </p><pre class="programlisting">talloc_realloc(ctx, NULL, type, 1) ==> talloc(ctx, type); @@ -216,10 +216,10 @@ talloc_realloc(ctx, ptr, type, 0) ==> talloc_free(ptr);</pre><p> talloc_realloc() returns the new pointer, or NULL on failure. The call will fail either due to a lack of memory, or because the pointer has more than one parent (see <a href="#talloc_reference" title="void *talloc_reference(const void *ctx, const void *ptr);">“<span class="quote">talloc_reference()</span>”</a>). - </p></div><div class="refsect2" lang="en"><a name="id2526515"></a><h3>void *talloc_realloc_size(const void *ctx, void *ptr, size_t size);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2526841"></a><h3>void *talloc_realloc_size(const void *ctx, void *ptr, size_t size);</h3><p> the talloc_realloc_size() function is useful when the type is not known so the type-safe talloc_realloc() cannot be used. - </p></div><div class="refsect2" lang="en"><a name="id2526527"></a><h3>TYPE *talloc_steal(const void *<span class="italic">new_ctx</span>, const TYPE *<span class="italic">ptr</span>);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2526853"></a><h3>TYPE *talloc_steal(const void *<span class="italic">new_ctx</span>, const TYPE *<span class="italic">ptr</span>);</h3><p> The talloc_steal() function changes the parent context of a talloc pointer. It is typically used when the context that the pointer is currently a child of is going to be freed and you wish @@ -232,14 +232,14 @@ talloc_realloc(ctx, ptr, type, 0) ==> talloc_free(ptr);</pre><p> relationship if you are not careful with talloc_steal(). No guarantees are provided as to your sanity or the safety of your data if you do this. - </p></div><div class="refsect2" lang="en"><a name="id2526564"></a><h3>TYPE *talloc_move(const void *<span class="italic">new_ctx</span>, TYPE **<span class="italic">ptr</span>);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2526890"></a><h3>TYPE *talloc_move(const void *<span class="italic">new_ctx</span>, TYPE **<span class="italic">ptr</span>);</h3><p> The talloc_move() function is a wrapper around talloc_steal() which zeros the source pointer after the move. This avoids a potential source of bugs where a programmer leaves a pointer in two structures, and uses the pointer from the old structure after it has been moved to a new one. - </p></div><div class="refsect2" lang="en"><a name="id2526590"></a><h3>size_t talloc_total_size(const void *<span class="italic">ptr</span>);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2526916"></a><h3>size_t talloc_total_size(const void *<span class="italic">ptr</span>);</h3><p> The talloc_total_size() function returns the total size in bytes used by this pointer and all child pointers. Mostly useful for debugging. @@ -247,7 +247,7 @@ talloc_realloc(ctx, ptr, type, 0) ==> talloc_free(ptr);</pre><p> Passing NULL is allowed, but it will only give a meaningful result if talloc_enable_leak_report() or talloc_enable_leak_report_full() has been called. - </p></div><div class="refsect2" lang="en"><a name="id2526614"></a><h3>size_t talloc_total_blocks(const void *<span class="italic">ptr</span>);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2526940"></a><h3>size_t talloc_total_blocks(const void *<span class="italic">ptr</span>);</h3><p> The talloc_total_blocks() function returns the total memory block count used by this pointer and all child pointers. Mostly useful for debugging. @@ -331,79 +331,79 @@ p1 contains 18 bytes in 7 blocks (ref 0) x3 contains 1 bytes in 1 blocks (ref 0) x2 contains 1 bytes in 1 blocks (ref 0) x1 contains 1 bytes in 1 blocks (ref 0) - </pre></div><div class="refsect2" lang="en"><a name="id2526922"></a><h3>(<span class="italic">type</span> *)talloc_zero(const void *<span class="italic">ctx</span>, <span class="italic">type</span>);</h3><p> + </pre></div><div class="refsect2" lang="en"><a name="id2527248"></a><h3>(<span class="italic">type</span> *)talloc_zero(const void *<span class="italic">ctx</span>, <span class="italic">type</span>);</h3><p> The talloc_zero() macro is equivalent to: </p><pre class="programlisting">ptr = talloc(ctx, type); -if (ptr) memset(ptr, 0, sizeof(type));</pre></div><div class="refsect2" lang="en"><a name="id2526956"></a><h3>void *talloc_zero_size(const void *<span class="italic">ctx</span>, size_t <span class="italic">size</span>)</h3><p> +if (ptr) memset(ptr, 0, sizeof(type));</pre></div><div class="refsect2" lang="en"><a name="id2527281"></a><h3>void *talloc_zero_size(const void *<span class="italic">ctx</span>, size_t <span class="italic">size</span>)</h3><p> The talloc_zero_size() function is useful when you don't have a known type. - </p></div><div class="refsect2" lang="en"><a name="id2526977"></a><h3>void *talloc_memdup(const void *<span class="italic">ctx</span>, const void *<span class="italic">p</span>, size_t size);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2527304"></a><h3>void *talloc_memdup(const void *<span class="italic">ctx</span>, const void *<span class="italic">p</span>, size_t size);</h3><p> The talloc_memdup() function is equivalent to: </p><pre class="programlisting">ptr = talloc_size(ctx, size); -if (ptr) memcpy(ptr, p, size);</pre></div><div class="refsect2" lang="en"><a name="id2527006"></a><h3>char *talloc_strdup(const void *<span class="italic">ctx</span>, const char *<span class="italic">p</span>);</h3><p> +if (ptr) memcpy(ptr, p, size);</pre></div><div class="refsect2" lang="en"><a name="id2527332"></a><h3>char *talloc_strdup(const void *<span class="italic">ctx</span>, const char *<span class="italic">p</span>);</h3><p> The talloc_strdup() function is equivalent to: </p><pre class="programlisting">ptr = talloc_size(ctx, strlen(p)+1); if (ptr) memcpy(ptr, p, strlen(p)+1);</pre><p> This function sets the name of the new pointer to the passed string. This is equivalent to: - </p><pre class="programlisting">talloc_set_name_const(ptr, ptr)</pre></div><div class="refsect2" lang="en"><a name="id2527046"></a><h3>char *talloc_strndup(const void *<span class="italic">t</span>, const char *<span class="italic">p</span>, size_t <span class="italic">n</span>);</h3><p> + </p><pre class="programlisting">talloc_set_name_const(ptr, ptr)</pre></div><div class="refsect2" lang="en"><a name="id2527372"></a><h3>char *talloc_strndup(const void *<span class="italic">t</span>, const char *<span class="italic">p</span>, size_t <span class="italic">n</span>);</h3><p> The talloc_strndup() function is the talloc equivalent of the C library function strndup(3). </p><p> This function sets the name of the new pointer to the passed string. This is equivalent to: - </p><pre class="programlisting">talloc_set_name_const(ptr, ptr)</pre></div><div class="refsect2" lang="en"><a name="id2527086"></a><h3>char *talloc_vasprintf(const void *<span class="italic">t</span>, const char *<span class="italic">fmt</span>, va_list <span class="italic">ap</span>);</h3><p> + </p><pre class="programlisting">talloc_set_name_const(ptr, ptr)</pre></div><div class="refsect2" lang="en"><a name="id2527412"></a><h3>char *talloc_vasprintf(const void *<span class="italic">t</span>, const char *<span class="italic">fmt</span>, va_list <span class="italic">ap</span>);</h3><p> The talloc_vasprintf() function is the talloc equivalent of the C library function vasprintf(3). - </p></div><div class="refsect2" lang="en"><a name="id2527114"></a><h3>char *talloc_asprintf(const void *<span class="italic">t</span>, const char *<span class="italic">fmt</span>, ...);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2527441"></a><h3>char *talloc_asprintf(const void *<span class="italic">t</span>, const char *<span class="italic">fmt</span>, ...);</h3><p> The talloc_asprintf() function is the talloc equivalent of the C library function asprintf(3). </p><p> This function sets the name of the new pointer to the passed string. This is equivalent to: - </p><pre class="programlisting">talloc_set_name_const(ptr, ptr)</pre></div><div class="refsect2" lang="en"><a name="id2527148"></a><h3>char *talloc_asprintf_append(char *s, const char *fmt, ...);</h3><p> + </p><pre class="programlisting">talloc_set_name_const(ptr, ptr)</pre></div><div class="refsect2" lang="en"><a name="id2527475"></a><h3>char *talloc_asprintf_append(char *s, const char *fmt, ...);</h3><p> The talloc_asprintf_append() function appends the given formatted string to the given string. - </p></div><div class="refsect2" lang="en"><a name="id2527160"></a><h3>(type *)talloc_array(const void *ctx, type, uint_t count);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2527486"></a><h3>(type *)talloc_array(const void *ctx, type, uint_t count);</h3><p> The talloc_array() macro is equivalent to: </p><pre class="programlisting">(type *)talloc_size(ctx, sizeof(type) * count);</pre><p> except that it provides integer overflow protection for the multiply, returning NULL if the multiply overflows. - </p></div><div class="refsect2" lang="en"><a name="id2527183"></a><h3>void *talloc_array_size(const void *ctx, size_t size, uint_t count);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2527509"></a><h3>void *talloc_array_size(const void *ctx, size_t size, uint_t count);</h3><p> The talloc_array_size() function is useful when the type is not known. It operates in the same way as talloc_array(), but takes a size instead of a type. - </p></div><div class="refsect2" lang="en"><a name="id2527196"></a><h3>(typeof(ptr)) talloc_array_ptrtype(const void *ctx, ptr, uint_t count);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2527522"></a><h3>(typeof(ptr)) talloc_array_ptrtype(const void *ctx, ptr, uint_t count);</h3><p> The talloc_ptrtype() macro should be used when you have a pointer to an array and want to allocate memory of an array to point at with this pointer. When compiling with gcc >= 3 it is typesafe. Note this is a wrapper of talloc_array_size() and talloc_get_name() will return the current location in the source file. and not the type. - </p></div><div class="refsect2" lang="en"><a name="id2527212"></a><h3>void *talloc_realloc_fn(const void *ctx, void *ptr, size_t size)</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2527538"></a><h3>void *talloc_realloc_fn(const void *ctx, void *ptr, size_t size)</h3><p> This is a non-macro version of talloc_realloc(), which is useful as libraries sometimes want a realloc function pointer. A realloc(3) implementation encapsulates the functionality of malloc(3), free(3) and realloc(3) in one call, which is why it is useful to be able to pass around a single function pointer. - </p></div><div class="refsect2" lang="en"><a name="id2527227"></a><h3>void *talloc_autofree_context(void);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2527554"></a><h3>void *talloc_autofree_context(void);</h3><p> This is a handy utility function that returns a talloc context which will be automatically freed on program exit. This can be used to reduce the noise in memory leak reports. - </p></div><div class="refsect2" lang="en"><a name="id2527240"></a><h3>void *talloc_check_name(const void *ptr, const char *name);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2527566"></a><h3>void *talloc_check_name(const void *ptr, const char *name);</h3><p> This function checks if a pointer has the specified <span class="italic">name</span>. If it does then the pointer is returned. It it doesn't then NULL is returned. - </p></div><div class="refsect2" lang="en"><a name="id2527258"></a><h3>(type *)talloc_get_type(const void *ptr, type);</h3><p> + </p></div><div class="refsect2" lang="en"><a name="id2527584"></a><h3>(type *)talloc_get_type(const void *ptr, type);</h3><p> This macro allows you to do type checking on talloc pointers. It is particularly useful for void* private pointers. It is equivalent to this: - </p><pre class="programlisting">(type *)talloc_check_name(ptr, #type)</pre></div><div class="refsect2" lang="en"><a name="id2527277"></a><h3>talloc_set_type(const void *ptr, type);</h3><p> + </p><pre class="programlisting">(type *)talloc_check_name(ptr, #type)</pre></div><div class="refsect2" lang="en"><a name="id2527603"></a><h3>talloc_set_type(const void *ptr, type);</h3><p> This macro allows you to force the name of a pointer to be a particular <span class="emphasis"><em>type</em></span>. This can be used in conjunction with talloc_get_type() to do type checking on void* pointers. </p><p> It is equivalent to this: - </p><pre class="programlisting">talloc_set_name_const(ptr, #type)</pre></div></div><div class="refsect1" lang="en"><a name="id2527304"></a><h2>PERFORMANCE</h2><p> + </p><pre class="programlisting">talloc_set_name_const(ptr, #type)</pre></div></div><div class="refsect1" lang="en"><a name="id2527631"></a><h2>PERFORMANCE</h2><p> All the additional features of talloc(3) over malloc(3) do come at a price. We have a simple performance test in Samba4 that measures talloc() versus malloc() performance, and it seems that talloc() is @@ -411,10 +411,10 @@ if (ptr) memcpy(ptr, p, strlen(p)+1);</pre><p> Samba, the great reduction in code complexity that we get by using talloc makes this worthwhile, especially as the total overhead of talloc/malloc in Samba is already quite small. - </p></div><div class="refsect1" lang="en"><a name="id2527322"></a><h2>SEE ALSO</h2><p> + </p></div><div class="refsect1" lang="en"><a name="id2527648"></a><h2>SEE ALSO</h2><p> malloc(3), strndup(3), vasprintf(3), asprintf(3), <a href="http://talloc.samba.org/" target="_top">http://talloc.samba.org/</a> - </p></div><div class="refsect1" lang="en"><a name="id2527336"></a><h2>COPYRIGHT/LICENSE</h2><p> + </p></div><div class="refsect1" lang="en"><a name="id2527662"></a><h2>COPYRIGHT/LICENSE</h2><p> Copyright (C) Andrew Tridgell 2004 </p><p> This program is free software; you can redistribute it and/or modify diff --git a/ctdb/lib/talloc/talloc.c b/ctdb/lib/talloc/talloc.c index c8161fd63d..b2b00d8c65 100644 --- a/ctdb/lib/talloc/talloc.c +++ b/ctdb/lib/talloc/talloc.c @@ -1028,7 +1028,7 @@ static void talloc_report_null(void) /* report on any memory hanging off the null context */ -void talloc_report_null_full(void) +static void talloc_report_null_full(void) { if (talloc_total_size(null_context) != 0) { talloc_report_full(null_context, stderr); @@ -1086,7 +1086,6 @@ void *_talloc_zero(const void *ctx, size_t size, const char *name) return p; } - /* memdup with a talloc. */ @@ -1174,10 +1173,11 @@ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) va_list ap2; char c; - va_copy(ap2, ap); - /* this call looks strange, but it makes it work on older solaris boxes */ - if ((len = vsnprintf(&c, 1, fmt, ap2)) < 0) { + va_copy(ap2, ap); + len = vsnprintf(&c, 1, fmt, ap2); + va_end(ap2); + if (len < 0) { return NULL; } @@ -1185,6 +1185,7 @@ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) if (ret) { va_copy(ap2, ap); vsnprintf(ret, len+1, fmt, ap2); + va_end(ap2); _talloc_set_name_const(ret, ret); } @@ -1226,10 +1227,13 @@ char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap) tc = talloc_chunk_from_ptr(s); + s_len = tc->size - 1; + va_copy(ap2, ap); + len = vsnprintf(&c, 1, fmt, ap2); + va_end(ap2); - s_len = tc->size - 1; - if ((len = vsnprintf(&c, 1, fmt, ap2)) <= 0) { + if (len <= 0) { /* Either the vsnprintf failed or the format resulted in * no characters being formatted. In the former case, we * ought to return NULL, in the latter we ought to return @@ -1243,8 +1247,8 @@ char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap) if (!s) return NULL; va_copy(ap2, ap); - vsnprintf(s+s_len, len+1, fmt, ap2); + va_end(ap2); _talloc_set_name_const(s, s); return s; @@ -1287,7 +1291,6 @@ void *_talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const return _talloc_zero(ctx, el_size * count, name); } - /* realloc an array, checking for integer overflow in the array size */ diff --git a/ctdb/lib/talloc/talloc.h b/ctdb/lib/talloc/talloc.h index bb068019cc..d9e7d94338 100644 --- a/ctdb/lib/talloc/talloc.h +++ b/ctdb/lib/talloc/talloc.h @@ -26,16 +26,22 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <stdlib.h> +#include <stdio.h> +#include <stdarg.h> + /* this is only needed for compatibility with the old talloc */ typedef void TALLOC_CTX; /* this uses a little trick to allow __LINE__ to be stringified */ -#define _STRING_LINE_(s) #s -#define _STRING_LINE2_(s) _STRING_LINE_(s) -#define __LINESTR__ _STRING_LINE2_(__LINE__) -#define __location__ __FILE__ ":" __LINESTR__ +#ifndef __location__ +#define __TALLOC_STRING_LINE1__(s) #s +#define __TALLOC_STRING_LINE2__(s) __TALLOC_STRING_LINE1__(s) +#define __TALLOC_STRING_LINE3__ __TALLOC_STRING_LINE2__(__LINE__) +#define __location__ __FILE__ ":" __TALLOC_STRING_LINE3__ +#endif #ifndef TALLOC_DEPRECATED #define TALLOC_DEPRECATED 0 @@ -142,7 +148,6 @@ void talloc_report_depth_file(const void *ptr, int depth, int max_depth, FILE *f void talloc_report_full(const void *ptr, FILE *f); void talloc_report(const void *ptr, FILE *f); void talloc_enable_null_tracking(void); -void talloc_report_null_full(void); void talloc_disable_null_tracking(void); void talloc_enable_leak_report(void); void talloc_enable_leak_report_full(void); @@ -166,4 +171,3 @@ void talloc_show_parents(const void *context, FILE *file); int talloc_is_parent(const void *context, const void *ptr); #endif - diff --git a/ctdb/lib/talloc/talloc.pc b/ctdb/lib/talloc/talloc.pc index 397ae4937f..5c50026dd8 100644 --- a/ctdb/lib/talloc/talloc.pc +++ b/ctdb/lib/talloc/talloc.pc @@ -5,6 +5,7 @@ includedir=${prefix}/include Name: talloc Description: A hierarchical pool based memory system with destructors +Requires.private: Version: 0.0.1 Libs: -L${libdir} -ltalloc Libs.private: -lreplace diff --git a/ctdb/lib/talloc/talloc.pc.in b/ctdb/lib/talloc/talloc.pc.in index f93036a33d..459cce70b1 100644 --- a/ctdb/lib/talloc/talloc.pc.in +++ b/ctdb/lib/talloc/talloc.pc.in @@ -5,7 +5,7 @@ includedir=@includedir@ Name: talloc Description: A hierarchical pool based memory system with destructors -Version: 4.0 +Version: @PACKAGE_VERSION@ Libs: -L${libdir} -ltalloc Cflags: -I${includedir} URL: http://talloc.samba.org/ diff --git a/ctdb/lib/talloc/talloc_guide.txt b/ctdb/lib/talloc/talloc_guide.txt index 8b252e4ab9..6481b58611 100644 --- a/ctdb/lib/talloc/talloc_guide.txt +++ b/ctdb/lib/talloc/talloc_guide.txt @@ -12,7 +12,7 @@ this carefully, as talloc has changed a lot. With 3.0.20 (or 3.0.14?) the Samba4 talloc has been ported back to Samba3, so this guide applies to both. The new talloc is a hierarchical, reference counted memory pool system -with destructors. Quite a mounthful really, but not too bad once you +with destructors. Quite a mouthful really, but not too bad once you get used to it. Perhaps the biggest change from Samba3 is that there is no distinction diff --git a/ctdb/lib/talloc/testsuite.c b/ctdb/lib/talloc/testsuite.c index 88ed638252..d122a5de0d 100644 --- a/ctdb/lib/talloc/testsuite.c +++ b/ctdb/lib/talloc/testsuite.c @@ -1012,7 +1012,7 @@ static bool test_talloc_ptrtype(void) static bool test_autofree(void) { -#ifndef _SAMBA_BUILD_ +#if _SAMBA_BUILD_ < 4 /* autofree test would kill smbtorture */ void *p; printf("test: autofree [\nTALLOC AUTOFREE CONTEXT\n]\n"); @@ -1064,7 +1064,7 @@ bool torture_local_talloc(struct torture_context *tctx) return ret; } -#ifndef _SAMBA_BUILD_ +#if _SAMBA_BUILD_ < 4 int main(void) { bool ret = torture_local_talloc(NULL); |