[SCM] Samba Shared Repository - branch master updated - release-4-0-0alpha8-1148-gf60f007

Andrew Tridgell tridge at samba.org
Mon Aug 24 00:30:34 MDT 2009


The branch, master has been updated
       via  f60f0077e4f9e5d2dfe89786ca840a8330507a6d (commit)
       via  2c846058ff104f83e50bc93aa90c0dc7a8c7fe0f (commit)
       via  798b3fbb53fb229c93b841e380a4439d6575d75a (commit)
       via  e6da38c8b7791292243b539cfbaf763f5b61f509 (commit)
       via  a0e20418360cbbb0ddaff5f71675300b3b3db72a (commit)
       via  39cd5bbb3306300a24e2f057a570e74aafce0b6b (commit)
       via  a5358402b26e08b9f69c5c766e5cb7438c695dbf (commit)
       via  e8782de8fe51310e89eb480f0a67f1d392698896 (commit)
       via  851b01f64ed8c5dbb7f4b9cf058d94e5a685d86e (commit)
       via  251b03eee626c10b294eee4a45a1dcc82a4fd1d9 (commit)
       via  5cefde407559497c2ff53d0caa9d22d4af063a68 (commit)
       via  55dbe80d0537ae2addf7bcd682372fe1829152a6 (commit)
       via  64e05779d2bf697b3c5f9f53234839f4f352a408 (commit)
       via  6c9ace27c591e48fdffdf5add6b4e11b2f669922 (commit)
       via  9baacbbbdf766b87512f6d0f518f91decbbf2e2b (commit)
       via  5760edeeb6b6d5a8aaebae2422ba3e7c3df700cc (commit)
       via  8a90c8bc98a2501da41af132512d1c3875463102 (commit)
       via  ed384e8aac36fa768741ff7589e76b233064c586 (commit)
       via  e40f3144f2a3f8e7aebf009a4cddb9f463292c1c (commit)
       via  ac8aeec824b49c69a97e107f170337fcaa75120f (commit)
       via  84810d7182f2d9b3f4cb65db89489cb0a75dcc2e (commit)
       via  f8559b8238409b28ba198c89e6a31e62cf28df88 (commit)
       via  13227f83b9efb549ae05a0b508095de288347386 (commit)
       via  1fbc86c57a60fdb828a50d24c65750ba01b92f10 (commit)
       via  2c664db7494da12e1738dbcbdece41374f561661 (commit)
       via  d1895d2fee9eec6f0b16dd38728b34d2f8233b0c (commit)
      from  fced9dfc1ea45f902e9281679f479ae18d229c17 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit f60f0077e4f9e5d2dfe89786ca840a8330507a6d
Author: Andrew Tridgell <tridge at samba.org>
Date:   Mon Aug 24 16:27:05 2009 +1000

    fixed typo in talloc doc XML

commit 2c846058ff104f83e50bc93aa90c0dc7a8c7fe0f
Author: Andrew Tridgell <tridge at samba.org>
Date:   Mon Aug 24 16:21:58 2009 +1000

    LIBREPLACEOBJ now contains the full path

commit 798b3fbb53fb229c93b841e380a4439d6575d75a
Author: Andrew Tridgell <tridge at samba.org>
Date:   Mon Aug 24 16:01:18 2009 +1000

    updated XML source for talloc man page

commit e6da38c8b7791292243b539cfbaf763f5b61f509
Author: Andrew Tridgell <tridge at samba.org>
Date:   Mon Aug 24 16:01:05 2009 +1000

    added talloc_set_log_* documentation

commit a0e20418360cbbb0ddaff5f71675300b3b3db72a
Author: Andrew Tridgell <tridge at samba.org>
Date:   Mon Aug 24 12:34:53 2009 +1000

    updated talloc guide for recent API changes

commit 39cd5bbb3306300a24e2f057a570e74aafce0b6b
Author: Andrew Tridgell <tridge at samba.org>
Date:   Mon Jul 27 17:12:27 2009 +1000

    make lib/replace more usable in standalone builds
    
    This makes the lib/replace m4 work in lib/talloc as a standalone build

commit a5358402b26e08b9f69c5c766e5cb7438c695dbf
Author: Andrew Tridgell <tridge at samba.org>
Date:   Mon Jul 27 17:12:56 2009 +1000

    fixed getpass m4
    
    This allows the getpass.m4 code to work in standalone talloc builds

commit e8782de8fe51310e89eb480f0a67f1d392698896
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Aug 3 11:30:44 2009 +0200

    s3:lib: setup talloc log and abort functions
    
    metze

commit 851b01f64ed8c5dbb7f4b9cf058d94e5a685d86e
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 21 10:01:15 2009 +0200

    s3:configure: require talloc >= 2.0.0
    
    metze

commit 251b03eee626c10b294eee4a45a1dcc82a4fd1d9
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Jul 30 08:37:01 2009 +0200

    s4:cmdline: setup talloc log and abort functions
    
    metze

commit 5cefde407559497c2ff53d0caa9d22d4af063a68
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 21 10:00:51 2009 +0200

    s4:build: require talloc >= 2.0.0
    
    metze

commit 55dbe80d0537ae2addf7bcd682372fe1829152a6
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 21 09:25:57 2009 +0200

    talloc: add --enable-talloc-compat1 to build a compat library for talloc 1.x.x
    
    metze

commit 64e05779d2bf697b3c5f9f53234839f4f352a408
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 21 09:53:51 2009 +0200

    talloc: update talloc.exports and talloc.signatures
    
    metze

commit 6c9ace27c591e48fdffdf5add6b4e11b2f669922
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Aug 20 13:43:42 2009 +0200

    talloc: add defines and functions for TALLOC_MAJOR/MINOR_VERSION
    
    We also use the major and minor versions in the TALLOC_MAGIC,
    so that we can detect if two conflicting versions of talloc
    are loaded in one process. In this case we use talloc_log() to
    output a very useful debug message before we call
    talloc_abort().
    
    metze

commit 9baacbbbdf766b87512f6d0f518f91decbbf2e2b
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Aug 20 13:43:18 2009 +0200

    talloc: change version to 2.0.0
    
    metze

commit 5760edeeb6b6d5a8aaebae2422ba3e7c3df700cc
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Aug 20 13:36:33 2009 +0200

    talloc: remove ABI compat functions
    
    metze

commit 8a90c8bc98a2501da41af132512d1c3875463102
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Aug 3 11:33:06 2009 +0200

    talloc: remove unused build dependecies to samba
    
    metze

commit ed384e8aac36fa768741ff7589e76b233064c586
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Jul 29 22:00:05 2009 +0200

    talloc/testsuite: use talloc_set_log_fn() and log to stdout
    
    metze

commit e40f3144f2a3f8e7aebf009a4cddb9f463292c1c
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Jul 29 21:54:28 2009 +0200

    talloc: add talloc_set_log_fn() and talloc_set_log_stderr()
    
    So that the application can setup a log function to get ERROR
    and WARNING messages.
    
    metze

commit ac8aeec824b49c69a97e107f170337fcaa75120f
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Jul 29 21:41:34 2009 +0200

    talloc: let talloc_steal() only generate a warning if it's used with references
    
    We have to many callers, which rely on that talloc_steal() never fails.
    
    metze

commit 84810d7182f2d9b3f4cb65db89489cb0a75dcc2e
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Jul 13 20:34:10 2009 +0200

    talloc/testsuite: report __location__ of testsuite failures
    
    metze

commit f8559b8238409b28ba198c89e6a31e62cf28df88
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Jul 14 11:58:16 2009 +0200

    talloc/testsuite: add infrastructure to test aborts
    
    metze

commit 13227f83b9efb549ae05a0b508095de288347386
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Jul 13 18:52:44 2009 +0200

    talloc/testsuite: reset the globals after each subtest
    
    metze

commit 1fbc86c57a60fdb828a50d24c65750ba01b92f10
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Jul 14 11:56:33 2009 +0200

    talloc: call return after abort, because an overloaded abort function might not exit
    
    This will be useful in the testsuite,
    where we could check if an abort would happen.
    
    metze

commit 2c664db7494da12e1738dbcbdece41374f561661
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Jul 13 20:32:50 2009 +0200

    talloc: report the size of reference handles as 0
    
    metze

commit d1895d2fee9eec6f0b16dd38728b34d2f8233b0c
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Jul 13 18:51:24 2009 +0200

    talloc: let talloc_total_blocks() and talloc_get_size() operate on the null_context
    
    metze

-----------------------------------------------------------------------

Summary of changes:
 lib/replace/getpass.m4              |    4 +-
 lib/replace/libreplace.m4           |    4 +-
 lib/replace/samba.m4                |    5 +-
 lib/talloc/Makefile.in              |    7 +-
 lib/talloc/compat/talloc_compat1.c  |   51 ++++++++++
 lib/talloc/compat/talloc_compat1.m4 |   14 +++
 lib/talloc/compat/talloc_compat1.mk |   21 ++++
 lib/talloc/configure.ac             |   23 +++++-
 lib/talloc/talloc.3.xml             |   75 +++++++++++++++-
 lib/talloc/talloc.c                 |  177 +++++++++++++++++++++-------------
 lib/talloc/talloc.exports           |    6 +-
 lib/talloc/talloc.h                 |   11 ++-
 lib/talloc/talloc.mk                |    4 +-
 lib/talloc/talloc.pc.in             |    2 +-
 lib/talloc/talloc.signatures        |    6 +-
 lib/talloc/talloc_guide.txt         |   67 +++++++++++++-
 lib/talloc/testsuite.c              |   70 ++++++++++++--
 source3/configure.in                |    7 +-
 source3/lib/popt_common.c           |    7 ++
 source4/include/includes.h          |    5 -
 source4/lib/cmdline/popt_common.c   |    7 ++
 source4/min_versions.m4             |    2 +-
 22 files changed, 464 insertions(+), 111 deletions(-)
 create mode 100644 lib/talloc/compat/talloc_compat1.c
 create mode 100644 lib/talloc/compat/talloc_compat1.m4
 create mode 100644 lib/talloc/compat/talloc_compat1.mk


Changeset truncated at 500 lines:

diff --git a/lib/replace/getpass.m4 b/lib/replace/getpass.m4
index b93817f..78a0afe 100644
--- a/lib/replace/getpass.m4
+++ b/lib/replace/getpass.m4
@@ -3,7 +3,7 @@ AC_CHECK_FUNC(getpassphrase, libreplace_cv_HAVE_GETPASSPHRASE=yes)
 if test x"$libreplace_cv_HAVE_GETPASS" = x"yes" -a x"$libreplace_cv_HAVE_GETPASSPHRASE" = x"yes"; then
         AC_DEFINE(REPLACE_GETPASS_BY_GETPASSPHRASE, 1, [getpass returns <9 chars where getpassphrase returns <265 chars])
 	AC_DEFINE(REPLACE_GETPASS,1,[Whether getpass should be replaced])
-	LIBREPLACEOBJ="${LIBREPLACEOBJ} getpass.o"
+	LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/getpass.o"
 else
 
 AC_CACHE_CHECK([whether getpass should be replaced],libreplace_cv_REPLACE_GETPASS,[
@@ -18,7 +18,7 @@ CPPFLAGS="$SAVE_CPPFLAGS"
 ])
 if test x"$libreplace_cv_REPLACE_GETPASS" = x"yes"; then
 	AC_DEFINE(REPLACE_GETPASS,1,[Whether getpass should be replaced])
-	LIBREPLACEOBJ="${LIBREPLACEOBJ} getpass.o"
+	LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/getpass.o"
 fi
 
 fi
diff --git a/lib/replace/libreplace.m4 b/lib/replace/libreplace.m4
index a3a26ef..7815901 100644
--- a/lib/replace/libreplace.m4
+++ b/lib/replace/libreplace.m4
@@ -46,10 +46,10 @@ if test x"$libreplacedir" = "x"; then
 	AC_MSG_ERROR([cannot find libreplace in $libreplacepaths])
 fi
 
-LIBREPLACEOBJ="replace.o"
+LIBREPLACEOBJ="$libreplacedir/replace.o"
 AC_SUBST(LIBREPLACEOBJ)
 
-LIBREPLACEOBJ="${LIBREPLACEOBJ} snprintf.o"
+LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/snprintf.o"
 
 AC_TYPE_SIGNAL
 AC_TYPE_UID_T
diff --git a/lib/replace/samba.m4 b/lib/replace/samba.m4
index 4514728..b758220 100644
--- a/lib/replace/samba.m4
+++ b/lib/replace/samba.m4
@@ -17,10 +17,7 @@ LIBREPLACE_DIR=`echo ${libreplacedir} |sed -e 's/^\.\///g'`
 # build directory.
 LIBREPLACE_DIR=`echo ${LIBREPLACE_DIR} | sed -e "s|^$srcdir/||g"`
 
-LIBREPLACE_OBJS=""
-for obj in ${LIBREPLACEOBJ}; do
-	LIBREPLACE_OBJS="${LIBREPLACE_OBJS} ${LIBREPLACE_DIR}/${obj}"
-done
+LIBREPLACE_OBJS="${LIBREPLACEOBJ}"
 
 SMB_SUBSYSTEM(LIBREPLACE,
 	[${LIBREPLACE_OBJS}],
diff --git a/lib/talloc/Makefile.in b/lib/talloc/Makefile.in
index a45f72b..94f031a 100644
--- a/lib/talloc/Makefile.in
+++ b/lib/talloc/Makefile.in
@@ -16,7 +16,10 @@ CC = @CC@
 CFLAGS = @CFLAGS@ -DHAVE_CONFIG_H= -I. -I at srcdir@
 EXTRA_TARGETS = @DOC_TARGET@
 PICFLAG = @PICFLAG@
-PACKAGE_VERSION = @PACKAGE_VERSION@
+TALLOC_VERSION = @TALLOC_VERSION@
+TALLOC_VERSION_MAJOR = @TALLOC_VERSION_MAJOR@
+TALLOC_VERSION_MINOR = @TALLOC_VERSION_MINOR@
+TALLOC_VERSION_RELEASE = @TALLOC_VERSION_RELEASE@
 SHLIBEXT = @SHLIBEXT@
 SHLD = @SHLD@
 SHLD_FLAGS = @SHLD_FLAGS@
@@ -33,6 +36,8 @@ all:: showflags $(EXTRA_TARGETS)
 include $(tallocdir)/rules.mk
 include $(tallocdir)/talloc.mk
 
+ at TALLOC_COMPAT1_MK@
+
 $(TALLOC_SOLIB): $(LIBOBJ)
 	$(SHLD) $(SHLD_FLAGS) -o $@ $(LIBOBJ) $(VERSIONSCRIPT) $(EXPORTSFILE) $(SONAMEFLAG)$(TALLOC_SONAME)
 
diff --git a/lib/talloc/compat/talloc_compat1.c b/lib/talloc/compat/talloc_compat1.c
new file mode 100644
index 0000000..519e8c3
--- /dev/null
+++ b/lib/talloc/compat/talloc_compat1.c
@@ -0,0 +1,51 @@
+/*
+   Samba trivial allocation library - compat functions
+
+   Copyright (C) Stefan Metzmacher 2009
+
+     ** NOTE! The following LGPL license applies to the talloc
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+/*
+ * This file contains only function to build a
+ * compat talloc.so.1 library on top of talloc.so.2
+ */
+
+#include "replace.h"
+#include "talloc.h"
+
+void *_talloc_reference(const void *context, const void *ptr);
+void *_talloc_reference(const void *context, const void *ptr) {
+	return _talloc_reference_loc(context, ptr,
+				     "Called from talloc compat1 "
+				     "_talloc_reference");
+}
+
+void *_talloc_steal(const void *new_ctx, const void *ptr);
+void *_talloc_steal(const void *new_ctx, const void *ptr)
+{
+	return talloc_reparent(talloc_parent(ptr), new_ctx, ptr);
+}
+
+#undef talloc_free
+int talloc_free(void *ptr);
+int talloc_free(void *ptr)
+{
+	return talloc_unlink(talloc_parent(ptr), ptr);
+}
+
diff --git a/lib/talloc/compat/talloc_compat1.m4 b/lib/talloc/compat/talloc_compat1.m4
new file mode 100644
index 0000000..2ec530e
--- /dev/null
+++ b/lib/talloc/compat/talloc_compat1.m4
@@ -0,0 +1,14 @@
+TALLOC_COMPAT1_MK=""
+AC_SUBST(TALLOC_COMPAT1_MK)
+
+AC_ARG_ENABLE(talloc-compat1,
+	[AS_HELP_STRING([--enable-talloc-compat1],
+		[Build talloc 1.x.x compat library [default=no]])],
+	[ enable_talloc_compat1=$enableval ],
+	[ enable_talloc_compat1=no ]
+)
+
+if test "x$enable_talloc_compat1" = x"yes"; then
+	TALLOC_COMPAT1_MK='include $(tallocdir)/compat/talloc_compat1.mk'
+fi
+
diff --git a/lib/talloc/compat/talloc_compat1.mk b/lib/talloc/compat/talloc_compat1.mk
new file mode 100644
index 0000000..d1817f0
--- /dev/null
+++ b/lib/talloc/compat/talloc_compat1.mk
@@ -0,0 +1,21 @@
+talloccompatdir := $(tallocdir)/compat
+
+TALLOC_COMPAT1_VERSION_MAJOR = 1
+TALLOC_COMPAT1_OBJ = $(talloccompatdir)/talloc_compat1.o
+
+TALLOC_COMPAT1_SOLIB = libtalloc-compat1-$(TALLOC_VERSION).$(SHLIBEXT)
+TALLOC_COMPAT1_SONAME = libtalloc.$(SHLIBEXT).$(TALLOC_COMPAT1_VERSION_MAJOR)
+
+$(TALLOC_COMPAT1_SOLIB): $(TALLOC_COMPAT1_OBJ) $(TALLOC_SOLIB)
+	$(SHLD) $(SHLD_FLAGS) -o $@ $(TALLOC_COMPAT1_OBJ) \
+		$(TALLOC_SOLIB) $(SONAMEFLAG)$(TALLOC_COMPAT1_SONAME)
+
+all:: $(TALLOC_COMPAT1_SOLIB)
+
+install::
+	${INSTALLCMD} -d $(DESTDIR)$(libdir)
+	${INSTALLCMD} -m 755 $(TALLOC_COMPAT1_SOLIB) $(DESTDIR)$(libdir)
+
+clean::
+	rm -f $(TALLOC_COMPAT1_OBJ) $(TALLOC_COMPAT1_SOLIB)
+
diff --git a/lib/talloc/configure.ac b/lib/talloc/configure.ac
index 161f6f7..a169f79 100644
--- a/lib/talloc/configure.ac
+++ b/lib/talloc/configure.ac
@@ -1,9 +1,29 @@
 AC_PREREQ(2.50)
-AC_INIT(talloc, 1.4.0)
+AC_INIT(talloc, 2.0.0)
 AC_CONFIG_SRCDIR([talloc.c])
 AC_SUBST(datarootdir)
 AC_CONFIG_HEADER(config.h)
 
+TALLOC_VERSION=${PACKAGE_VERSION}
+TALLOC_VERSION_MAJOR=`echo ${PACKAGE_VERSION} | cut -d '.' -f1`
+TALLOC_VERSION_MINOR=`echo ${PACKAGE_VERSION} | cut -d '.' -f2`
+TALLOC_VERSION_RELEASE=`echo ${PACKAGE_VERSION} | cut -d '.' -f3`
+
+AC_SUBST(TALLOC_VERSION)
+AC_SUBST(TALLOC_VERSION_MAJOR)
+AC_SUBST(TALLOC_VERSION_MINOR)
+AC_SUBST(TALLOC_VERSION_RELEASE)
+
+AC_DEFINE_UNQUOTED(TALLOC_BUILD_VERSION_MAJOR,
+	[${TALLOC_VERSION_MAJOR}],
+	[talloc major version])
+AC_DEFINE_UNQUOTED(TALLOC_BUILD_VERSION_MINOR,
+	[${TALLOC_VERSION_MINOR}],
+	[talloc minor version])
+AC_DEFINE_UNQUOTED(TALLOC_BUILD_VERSION_RELEASE,
+	[${TALLOC_VERSION_RELEASE}],
+	[talloc release version])
+
 AC_LIBREPLACE_ALL_CHECKS
 
 AC_LD_PICFLAG
@@ -14,6 +34,7 @@ AC_LIBREPLACE_SHLD
 AC_LIBREPLACE_SHLD_FLAGS
 
 m4_include(libtalloc.m4)
+m4_include(compat/talloc_compat1.m4)
 
 AC_PATH_PROG(XSLTPROC,xsltproc)
 DOC_TARGET=""
diff --git a/lib/talloc/talloc.3.xml b/lib/talloc/talloc.3.xml
index 67de15b..18c3788 100644
--- a/lib/talloc/talloc.3.xml
+++ b/lib/talloc/talloc.3.xml
@@ -135,6 +135,29 @@
         <para>
 	  talloc_free() operates recursively on its children.
         </para>
+	<para>
+	  As a special case, talloc_free() is refused on pointers that
+	  have more than one parent, as talloc would have no way of knowing
+	  which parent should be removed. To free a pointer that has more than
+	  one parent please use talloc_unlink().
+	</para>
+	<para>
+	  To help you find problems in your code caused by this behaviour, if
+	  you do try and free a pointer with more than one parent then the
+	  talloc logging function will be called to give output like this:
+	</para>
+	<para>
+	  <screen format="linespecific">
+	    ERROR: talloc_free with references at some_dir/source/foo.c:123
+  	  	reference at some_dir/source/other.c:325
+  	  	reference at some_dir/source/third.c:121
+	  </screen>
+	</para>
+	<para>
+	  Please see the documentation for talloc_set_log_fn() and
+	  talloc_set_log_stderr() for more information on talloc logging
+	  functions.
+	</para>
     </refsect2>
     <refsect2 id="talloc_reference"><title>void *talloc_reference(const void *ctx, const void *ptr);</title>
         <para>
@@ -381,11 +404,49 @@ talloc_realloc(ctx, ptr, type, 0)  ==> talloc_free(ptr);</programlisting>
 	   It does not have any failure modes.
         </para>
         <para>
-	  NOTE: It is possible to produce loops in the parent/child
+	  It is possible to produce loops in the parent/child
 	  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.
         </para>
+        <para>
+	  Note that if you try and call talloc_steal() on a pointer that has
+	  more than one parent then the result is ambiguous. Talloc will choose
+	  to remove the parent that is currently indicated by talloc_parent()
+	  and replace it with the chosen parent. You will also get a message
+	  like this via the talloc logging functions:
+        </para>
+        <para>
+	  <screen format="linespecific">
+	  WARNING: talloc_steal with references at some_dir/source/foo.c:123
+  	  	reference at some_dir/source/other.c:325
+  	  	reference at some_dir/source/third.c:121
+	  </screen>
+        </para>
+        <para>
+	  To unambiguously change the parent of a pointer please see
+	  the
+	  function <link linkend="talloc_reference"><quote>talloc_reparent()</quote></link>. See
+	  the talloc_set_log_fn() documentation for more information
+	  on talloc logging.  
+	</para>
+    </refsect2>
+    <refsect2><title>TYPE *talloc_reparent(const void *<emphasis role="italic">old_parent</emphasis>, const void *<emphasis role="italic">new_parent</emphasis>, const TYPE *<emphasis role="italic">ptr</emphasis>);</title>
+        <para>
+	  The talloc_reparent() 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 to keep the
+	  memory for a longer time.
+        </para>
+        <para>
+	  The talloc_reparent() function returns the pointer that you pass it. It
+	  does not have any failure modes.
+        </para>
+        <para>
+	  The difference between talloc_reparent() and talloc_steal() is that
+	  talloc_reparent() can specify which parent you wish to change. This is
+	  useful when a pointer has multiple parents via references.
+        </para>
     </refsect2>
     <refsect2><title>TYPE *talloc_move(const void *<emphasis role="italic">new_ctx</emphasis>, TYPE **<emphasis role="italic">ptr</emphasis>);</title>
         <para>
@@ -696,6 +757,18 @@ if (ptr) memcpy(ptr, p, strlen(p)+1);</programlisting>
         </para>
         <programlisting>talloc_set_name_const(ptr, #type)</programlisting>
     </refsect2>
+    <refsect2><title>talloc_set_log_fn(void (*log_fn)(const char *message));</title>
+        <para>
+	  This function sets a logging function that talloc will use for
+	  warnings and errors. By default talloc will not print any warnings or
+	  errors.
+	</para>
+    </refsect2>
+    <refsect2><title>talloc_set_log_stderr(void);</title>
+        <para>
+	  This sets the talloc log function to write log messages to stderr
+	</para>
+    </refsect2>
   </refsect1>
   <refsect1><title>PERFORMANCE</title>
     <para>
diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c
index 0126567..0133b44 100644
--- a/lib/talloc/talloc.c
+++ b/lib/talloc/talloc.c
@@ -30,26 +30,20 @@
   inspired by http://swapped.cc/halloc/
 */
 
-#ifdef _SAMBA_BUILD_
-#include "version.h"
-#if (SAMBA_VERSION_MAJOR<4)
-#include "includes.h"
-/* This is to circumvent SAMBA3's paranoid malloc checker. Here in this file
- * we trust ourselves... */
-#ifdef malloc
-#undef malloc
+#include "replace.h"
+#include "talloc.h"
+
+#ifdef TALLOC_BUILD_VERSION_MAJOR
+#if (TALLOC_VERSION_MAJOR != TALLOC_BUILD_VERSION_MAJOR)
+#error "TALLOC_VERSION_MAJOR != TALLOC_BUILD_VERSION_MAJOR"
 #endif
-#ifdef realloc
-#undef realloc
 #endif
-#define _TALLOC_SAMBA3
-#endif /* (SAMBA_VERSION_MAJOR<4) */
-#endif /* _SAMBA_BUILD_ */
 
-#ifndef _TALLOC_SAMBA3
-#include "replace.h"
-#include "talloc.h"
-#endif /* not _TALLOC_SAMBA3 */
+#ifdef TALLOC_BUILD_VERSION_MINOR
+#if (TALLOC_VERSION_MINOR != TALLOC_BUILD_VERSION_MINOR)
+#error "TALLOC_VERSION_MINOR != TALLOC_BUILD_VERSION_MINOR"
+#endif
+#endif
 
 /* use this to force every realloc to change the pointer, to stress test
    code that might not cope */
@@ -57,9 +51,13 @@
 
 
 #define MAX_TALLOC_SIZE 0x10000000
-#define TALLOC_MAGIC_V1 0xe814ec70
-#define TALLOC_MAGIC_V2 0xe814ec80
-#define TALLOC_MAGIC    TALLOC_MAGIC_V2
+#define TALLOC_MAGIC_BASE 0xe814ec70
+#define TALLOC_MAGIC ( \
+	TALLOC_MAGIC_BASE + \
+	(TALLOC_VERSION_MAJOR << 12) + \
+	(TALLOC_VERSION_MINOR << 4) \
+)
+
 #define TALLOC_FLAG_FREE 0x01
 #define TALLOC_FLAG_LOOP 0x02
 #define TALLOC_FLAG_POOL 0x04		/* This is a talloc pool */
@@ -141,6 +139,51 @@ struct talloc_chunk {
 #define TC_HDR_SIZE ((sizeof(struct talloc_chunk)+15)&~15)
 #define TC_PTR_FROM_CHUNK(tc) ((void *)(TC_HDR_SIZE + (char*)tc))
 
+int talloc_version_major(void)
+{
+	return TALLOC_VERSION_MAJOR;
+}
+
+int talloc_version_minor(void)
+{
+	return TALLOC_VERSION_MINOR;
+}
+
+static void (*talloc_log_fn)(const char *message);
+
+void talloc_set_log_fn(void (*log_fn)(const char *message))
+{
+	talloc_log_fn = log_fn;
+}
+
+static void talloc_log(const char *fmt, ...) PRINTF_ATTRIBUTE(1,2);
+static void talloc_log(const char *fmt, ...)
+{
+	va_list ap;
+	char *message;
+
+	if (!talloc_log_fn) {
+		return;
+	}
+
+	va_start(ap, fmt);
+	message = talloc_vasprintf(NULL, fmt, ap);
+	va_end(ap);
+
+	talloc_log_fn(message);
+	talloc_free(message);
+}
+
+static void talloc_log_stderr(const char *message)
+{
+	fprintf(stderr, "%s", message);
+}
+
+void talloc_set_log_stderr(void)
+{
+	talloc_set_log_fn(talloc_log_stderr);
+}
+
 static void (*talloc_abort_fn)(const char *reason);
 
 void talloc_set_abort_fn(void (*abort_fn)(const char *reason))
@@ -150,6 +193,8 @@ void talloc_set_abort_fn(void (*abort_fn)(const char *reason))
 
 static void talloc_abort(const char *reason)
 {
+	talloc_log("%s\n", reason);
+
 	if (!talloc_abort_fn) {
 		TALLOC_ABORT(reason);
 	}
@@ -157,9 +202,15 @@ static void talloc_abort(const char *reason)
 	talloc_abort_fn(reason);
 }
 
-static void talloc_abort_magic_v1(void)
+static void talloc_abort_magic(unsigned magic)
 {
-	talloc_abort("Bad talloc magic value - old magic v1 used");
+	unsigned striped = magic - TALLOC_MAGIC_BASE;
+	unsigned major = (striped & 0xFFFFF000) >> 12;
+	unsigned minor = (striped & 0x00000FF0) >> 4;
+	talloc_log("Bad talloc magic[0x%08X/%u/%u] expected[0x%08X/%u/%u]\n",
+		   magic, major, minor,
+		   TALLOC_MAGIC, TALLOC_VERSION_MAJOR, TALLOC_VERSION_MINOR);
+	talloc_abort("Bad talloc magic value - wrong talloc version used/mixed");
 }
 
 static void talloc_abort_double_free(void)
@@ -178,14 +229,17 @@ static inline struct talloc_chunk *talloc_chunk_from_ptr(const void *ptr)
 	const char *pp = (const char *)ptr;
 	struct talloc_chunk *tc = discard_const_p(struct talloc_chunk, pp - TC_HDR_SIZE);
 	if (unlikely((tc->flags & (TALLOC_FLAG_FREE | ~0xF)) != TALLOC_MAGIC)) { 
-		if ((tc->flags & (~0xF)) == TALLOC_MAGIC_V1) {
-			talloc_abort_magic_v1();
+		if ((tc->flags & (~0xFFF)) == TALLOC_MAGIC_BASE) {
+			talloc_abort_magic(tc->flags & (~0xF));
+			return NULL;
 		}
 
 		if (tc->flags & TALLOC_FLAG_FREE) {
 			talloc_abort_double_free();
+			return NULL;
 		} else {
 			talloc_abort_unknown_value();
+			return NULL;
 		}
 	}
 	return tc;
@@ -595,6 +649,7 @@ static inline int _talloc_free_internal(void *ptr)
 
 		if (*pool_object_count == 0) {
 			talloc_abort("Pool object count zero!");
+			return 0;
 		}
 
 		*pool_object_count -= 1;
@@ -683,15 +738,14 @@ void *_talloc_steal_loc(const void *new_ctx, const void *ptr, const char *locati
 	
 	if (unlikely(tc->refs != NULL) && talloc_parent(ptr) != new_ctx) {


-- 
Samba Shared Repository


More information about the samba-cvs mailing list