]> git.ozlabs.org Git - ccan/blobdiff - talloc/talloc.h
First cut of hashing routines.
[ccan] / talloc / talloc.h
index f79f45b2fedd9015720be180b98f9b5ad3292669..5566a040440a9e71f5d6947ce8f1d60cdddc3443 100644 (file)
@@ -1,9 +1,6 @@
 #ifndef CCAN_TALLOC_H
 #define CCAN_TALLOC_H
 /* 
 #ifndef CCAN_TALLOC_H
 #define CCAN_TALLOC_H
 /* 
-   Unix SMB/CIFS implementation.
-   Samba temporary memory allocation functions
-
    Copyright (C) Andrew Tridgell 2004-2005
    Copyright (C) Stefan Metzmacher 2006
    
    Copyright (C) Andrew Tridgell 2004-2005
    Copyright (C) Stefan Metzmacher 2006
    
@@ -30,6 +27,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include "config.h"
 #include <stdio.h>
 #include <stdarg.h>
 #include "config.h"
+#include "typesafe_cb/typesafe_cb.h"
 
 /*
   this uses a little trick to allow __LINE__ to be stringified
 
 /*
   this uses a little trick to allow __LINE__ to be stringified
  * returned for success and -1 for failure. The only possible failure condition
  * is if the pointer had a destructor attached to it and the destructor
  * returned -1. See talloc_set_destructor() for details on destructors.
  * returned for success and -1 for failure. The only possible failure condition
  * is if the pointer had a destructor attached to it and the destructor
  * returned -1. See talloc_set_destructor() for details on destructors.
+ * errno will be preserved unless the talloc_free fails.
  *
  * If this pointer has an additional parent when talloc_free() is called then
  * the memory is not actually released, but instead the most recently
  *
  * If this pointer has an additional parent when talloc_free() is called then
  * the memory is not actually released, but instead the most recently
@@ -173,10 +172,7 @@ int talloc_free(void *ptr);
  *     talloc, talloc_free
  */
 #define talloc_set_destructor(ptr, function)                                 \
  *     talloc, talloc_free
  */
 #define talloc_set_destructor(ptr, function)                                 \
-       do {                                                                  \
-               int (*_talloc_destructor_fn)(_TALLOC_TYPEOF(ptr)) = (function);       \
-               _talloc_set_destructor((ptr), (int (*)(void *))_talloc_destructor_fn); \
-       } while(0)
+       _talloc_set_destructor((ptr), typesafe_cb(int, (function), (ptr)))
 
 /**
  * talloc_zero - allocate zeroed dynamic memory for a type
 
 /**
  * talloc_zero - allocate zeroed dynamic memory for a type