r22759: sync lib/talloc with samba4
authorStefan Metzmacher <metze@samba.org>
Tue, 8 May 2007 11:12:11 +0000 (11:12 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:21:54 +0000 (12:21 -0500)
metze

source/lib/talloc/Makefile.in
source/lib/talloc/configure.ac
source/lib/talloc/libtalloc.m4
source/lib/talloc/talloc.3.xml
source/lib/talloc/talloc.c
source/lib/talloc/talloc.pc.in
source/lib/talloc/talloc_guide.txt
source/lib/talloc/testsuite.c

index 14e81156921071d0d6fb9517244069bc8b664460..18b48c345984908b1f1521274b90249d58649ccb 100644 (file)
@@ -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
 
index 51e7256bf888266b022f0fc4f188adb47e903729..5f465fe93ab0a60a33f9b1d9733b6e67e563bfca 100644 (file)
@@ -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)
index 4a0ee3c8fc5bfa7e8be4ba9f12a5dba4c7318579..d2e8eba81a4ce33a05b10689300c55d0c83435d7 100644 (file)
@@ -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)
index 2400fef2dc55bc176ba460c194ceb179644da7ef..83ca67a495114308a719f84fef5010540230f15c 100644 (file)
@@ -583,11 +583,27 @@ if (ptr) memcpy(ptr, p, strlen(p)+1);</programlisting>
         </para>
         <programlisting>talloc_set_name_const(ptr, ptr)</programlisting>
     </refsect2>
+    <refsect2><title>char *talloc_append_string(const void *<emphasis role="italic">t</emphasis>, char *<emphasis role="italic">orig</emphasis>, const char *<emphasis role="italic">append</emphasis>);</title>
+        <para>
+         The talloc_append_string() function appends the given formatted
+         string to the given string.
+        </para>
+        <para>
+         This function sets the name of the new pointer to the new
+         string. This is equivalent to:
+        </para>
+        <programlisting>talloc_set_name_const(ptr, ptr)</programlisting>
+    </refsect2>
     <refsect2><title>char *talloc_vasprintf(const void *<emphasis role="italic">t</emphasis>, const char *<emphasis role="italic">fmt</emphasis>, va_list <emphasis role="italic">ap</emphasis>);</title>
         <para>
          The talloc_vasprintf() function is the talloc equivalent of the C
          library function vasprintf(3).
         </para>
+        <para>
+         This function sets the name of the new pointer to the new
+         string. This is equivalent to:
+        </para>
+        <programlisting>talloc_set_name_const(ptr, ptr)</programlisting>
     </refsect2>
     <refsect2><title>char *talloc_asprintf(const void *<emphasis role="italic">t</emphasis>, const char *<emphasis role="italic">fmt</emphasis>, ...);</title>
         <para>
@@ -605,6 +621,11 @@ if (ptr) memcpy(ptr, p, strlen(p)+1);</programlisting>
          The talloc_asprintf_append() function appends the given formatted
          string to the given string.
         </para>
+        <para>
+         This function sets the name of the new pointer to the new
+         string. This is equivalent to:
+        </para>
+        <programlisting>talloc_set_name_const(ptr, ptr)</programlisting>
     </refsect2>
     <refsect2><title>(type *)talloc_array(const void *ctx, type, uint_t count);</title>
         <para>
index b2b00d8c65ac4635749c02deaaee41b3ef193369..abc1e9438e60295a1b1f7fbc15c493bcde7bbc0f 100644 (file)
@@ -1137,6 +1137,8 @@ char *talloc_append_string(const void *t, char *orig, const char *append)
        /* append the string with the trailing \0 */
        memcpy(&ret[olen], append, alenz);
 
+       _talloc_set_name_const(ret, ret);
+
        return ret;
 }
 
index f93036a33dbba718af32e8fa8f418a563193571c..459cce70b1dcb5814e9a45c4cdb134ca6eb19071 100644 (file)
@@ -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/
index 8b252e4ab9b73c15bad29ac8950f245efe915a76..c4634ae19a9192533d85d54c342d00668f4b6a8f 100644 (file)
@@ -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
@@ -533,6 +533,15 @@ This functions sets the name of the new pointer to the passed
 string. This is equivalent to:
    talloc_set_name_const(ptr, ptr)
 
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
+char *talloc_append_string(const void *t, char *orig, const char *append);
+
+The talloc_append_string() function appends the given formatted
+string to the given string.
+
+This function sets the name of the new pointer to the new
+string. This is equivalent to:
+   talloc_set_name_const(ptr, ptr)
 
 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 char *talloc_vasprintf(const void *t, const char *fmt, va_list ap);
@@ -540,6 +549,10 @@ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap);
 The talloc_vasprintf() function is the talloc equivalent of the C
 library function vasprintf()
 
+This functions sets the name of the new pointer to the new
+string. This is equivalent to:
+   talloc_set_name_const(ptr, ptr)
+
 
 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 char *talloc_asprintf(const void *t, const char *fmt, ...);
@@ -547,7 +560,7 @@ char *talloc_asprintf(const void *t, const char *fmt, ...);
 The talloc_asprintf() function is the talloc equivalent of the C
 library function asprintf()
 
-This functions sets the name of the new pointer to the passed
+This functions sets the name of the new pointer to the new
 string. This is equivalent to:
    talloc_set_name_const(ptr, ptr)
 
@@ -558,6 +571,10 @@ char *talloc_asprintf_append(char *s, const char *fmt, ...);
 The talloc_asprintf_append() function appends the given formatted 
 string to the given string. 
 
+This functions sets the name of the new pointer to the new
+string. This is equivalent to:
+   talloc_set_name_const(ptr, ptr)
+
 
 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 (type *)talloc_array(const void *ctx, type, uint_t count);
index d122a5de0d4b6ad2c8fa5cf805d99c4c7e28b58f..587f270553de52bc9f8740578ba9991e01e30121 100644 (file)
@@ -993,7 +993,7 @@ static bool test_talloc_ptrtype(void)
        s4 = talloc_array_ptrtype(top, s4, 10);location4 = __location__;
 
        if (talloc_get_size(s4) != (sizeof(struct struct1 **) * 10)) {
-               printf("failure: TALLOC PTRTYPE [\n"
+               printf("failure: ptrtype [\n"
                      "talloc_array_ptrtype() allocated the wrong size "
                       "%lu (should be %lu)\n]\n",
                           (unsigned long)talloc_get_size(s4),
@@ -1010,6 +1010,45 @@ static bool test_talloc_ptrtype(void)
        return true;
 }
 
+static int _test_talloc_free_in_destructor(void **ptr)
+{
+       talloc_free(*ptr);
+       return 0;
+}
+
+static bool test_talloc_free_in_destructor(void)
+{
+       void *level0;
+       void *level1;
+       void *level2;
+       void *level3;
+       void *level4;
+       void **level5;
+
+       printf("test: free_in_destructor [\nTALLOC FREE IN DESTRUCTOR\n]\n");
+
+       level0 = talloc_new(NULL);
+       level1 = talloc_new(level0);
+       level2 = talloc_new(level1);
+       level3 = talloc_new(level2);
+       level4 = talloc_new(level3);
+       level5 = talloc(level4, void *);
+
+       *level5 = level3;
+       (void)talloc_reference(level0, level3);
+       (void)talloc_reference(level3, level3);
+       (void)talloc_reference(level5, level3);
+
+       talloc_set_destructor(level5, _test_talloc_free_in_destructor);
+
+       talloc_free(level1);
+
+       talloc_free(level0);
+
+       printf("success: free_in_destructor\n");
+       return true;
+}
+
 static bool test_autofree(void)
 {
 #if _SAMBA_BUILD_ < 4
@@ -1055,6 +1094,7 @@ bool torture_local_talloc(struct torture_context *tctx)
        ret &= test_loop();
        ret &= test_free_parent_deny_child(); 
        ret &= test_talloc_ptrtype();
+       ret &= test_talloc_free_in_destructor();
 
        if (ret) {
                ret &= test_speed();