Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/lib/talloc/talloc.h

    r746 r988  
    11#ifndef _TALLOC_H_
    22#define _TALLOC_H_
    3 /* 
     3/*
    44   Unix SMB/CIFS implementation.
    55   Samba temporary memory allocation functions
     
    77   Copyright (C) Andrew Tridgell 2004-2005
    88   Copyright (C) Stefan Metzmacher 2006
    9    
     9
    1010     ** NOTE! The following LGPL license applies to the talloc
    1111     ** library. This does NOT imply that all of Samba is released
    1212     ** under the LGPL
    13    
     13
    1414   This library is free software; you can redistribute it and/or
    1515   modify it under the terms of the GNU Lesser General Public
     
    4848int talloc_version_major(void);
    4949int talloc_version_minor(void);
     50/* This is mostly useful only for testing */
     51int talloc_test_get_magic(void);
    5052
    5153/**
     
    194196 * talloc_set_log_stderr() for more information on talloc logging
    195197 * functions.
     198 *
     199 * If <code>TALLOC_FREE_FILL</code> environment variable is set,
     200 * the memory occupied by the context is filled with the value of this variable.
     201 * The value should be a numeric representation of the character you want to
     202 * use.
    196203 *
    197204 * talloc_free() operates recursively on its children.
     
    745752 *
    746753 * This macro is used together with talloc(mem_ctx, struct foo). If you had to
    747  * assing the talloc chunk pointer to some void pointer variable,
     754 * assign the talloc chunk pointer to some void pointer variable,
    748755 * talloc_get_type_abort() is the recommended way to get the convert the void
    749756 * pointer back to a typed pointer.
     
    757764void *talloc_get_type_abort(const void *ptr, #type);
    758765#else
     766#ifdef TALLOC_GET_TYPE_ABORT_NOOP
     767#define talloc_get_type_abort(ptr, type) (type *)(ptr)
     768#else
    759769#define talloc_get_type_abort(ptr, type) (type *)_talloc_get_type_abort(ptr, #type, __location__)
     770#endif
    760771void *_talloc_get_type_abort(const void *ptr, const char *name, const char *location);
    761772#endif
     
    823834 * grand-children, their memory is also taken from the talloc pool.
    824835 *
     836 * If there is not enough memory in the pool to allocate the new child,
     837 * it will create a new talloc chunk as if the parent was a normal talloc
     838 * context.
     839 *
    825840 * If you talloc_free() children of a talloc pool, the memory is not given
    826841 * back to the system. Instead, free(3) is only called if the talloc_pool()
     
    839854void *talloc_pool(const void *context, size_t size);
    840855
     856#ifdef DOXYGEN
     857/**
     858 * @brief Allocate a talloc object as/with an additional pool.
     859 *
     860 * This is like talloc_pool(), but's it's more flexible
     861 * and allows an object to be a pool for its children.
     862 *
     863 * @param[in] ctx                   The talloc context to hang the result off.
     864 *
     865 * @param[in] type                  The type that we want to allocate.
     866 *
     867 * @param[in] num_subobjects        The expected number of subobjects, which will
     868 *                                  be allocated within the pool. This allocates
     869 *                                  space for talloc_chunk headers.
     870 *
     871 * @param[in] total_subobjects_size The size that all subobjects can use in total.
     872 *
     873 *
     874 * @return              The allocated talloc object, NULL on error.
     875 */
     876void *talloc_pooled_object(const void *ctx, #type,
     877                           unsigned num_subobjects,
     878                           size_t total_subobjects_size);
     879#else
     880#define talloc_pooled_object(_ctx, _type, \
     881                             _num_subobjects, \
     882                             _total_subobjects_size) \
     883        (_type *)_talloc_pooled_object((_ctx), sizeof(_type), #_type, \
     884                                        (_num_subobjects), \
     885                                        (_total_subobjects_size))
     886void *_talloc_pooled_object(const void *ctx,
     887                            size_t type_size,
     888                            const char *type_name,
     889                            unsigned num_subobjects,
     890                            size_t total_subobjects_size);
     891#endif
     892
    841893/**
    842894 * @brief Free a talloc chunk and NULL out the pointer.
     
    848900 * @param[in]  ctx      The chunk to be freed.
    849901 */
    850 #define TALLOC_FREE(ctx) do { talloc_free(ctx); ctx=NULL; } while(0)
     902#define TALLOC_FREE(ctx) do { if (ctx != NULL) { talloc_free(ctx); ctx=NULL; } } while(0)
    851903
    852904/* @} ******************************************************************/
     
    915967 * @return              The original pointer 'ptr', NULL if talloc ran out of
    916968 *                      memory in creating the reference.
     969 *
     970 * @warning You should try to avoid using this interface. It turns a beautiful
     971 *          talloc-tree into a graph. It is often really hard to debug if you
     972 *          screw something up by accident.
    917973 *
    918974 * Example:
     
    9551011 * this function will fail and will return -1.  Likewise, if ptr is NULL,
    9561012 * then the function will make no modifications and return -1.
     1013 *
     1014 * @warning You should try to avoid using this interface. It turns a beautiful
     1015 *          talloc-tree into a graph. It is often really hard to debug if you
     1016 *          screw something up by accident.
    9571017 *
    9581018 * Example:
     
    12911351
    12921352/**
    1293  * @brief Append a string to given string and duplicate the result.
     1353 * @brief Append a string to given string.
     1354 *
     1355 * The destination string is reallocated to take
     1356 * <code>strlen(s) + strlen(a) + 1</code> characters.
     1357 *
     1358 * This functions sets the name of the new pointer to the new
     1359 * string. This is equivalent to:
     1360 *
     1361 * @code
     1362 *      talloc_set_name_const(ptr, ptr)
     1363 * @endcode
     1364 *
     1365 * If <code>s == NULL</code> then new context is created.
    12941366 *
    12951367 * @param[in]  s        The destination to append to.
     
    12971369 * @param[in]  a        The string you want to append.
    12981370 *
    1299  * @return              The duplicated string, NULL on error.
     1371 * @return              The concatenated strings, NULL on error.
    13001372 *
    13011373 * @see talloc_strdup()
     1374 * @see talloc_strdup_append_buffer()
    13021375 */
    13031376char *talloc_strdup_append(char *s, const char *a);
    13041377
    13051378/**
    1306  * @brief Append a string to a given buffer and duplicate the result.
     1379 * @brief Append a string to a given buffer.
     1380 *
     1381 * This is a more efficient version of talloc_strdup_append(). It determines the
     1382 * length of the destination string by the size of the talloc context.
     1383 *
     1384 * Use this very carefully as it produces a different result than
     1385 * talloc_strdup_append() when a zero character is in the middle of the
     1386 * destination string.
     1387 *
     1388 * @code
     1389 *      char *str_a = talloc_strdup(NULL, "hello world");
     1390 *      char *str_b = talloc_strdup(NULL, "hello world");
     1391 *      str_a[5] = str_b[5] = '\0'
     1392 *
     1393 *      char *app = talloc_strdup_append(str_a, ", hello");
     1394 *      char *buf = talloc_strdup_append_buffer(str_b, ", hello");
     1395 *
     1396 *      printf("%s\n", app); // hello, hello (app = "hello, hello")
     1397 *      printf("%s\n", buf); // hello (buf = "hello\0world, hello")
     1398 * @endcode
     1399 *
     1400 * If <code>s == NULL</code> then new context is created.
    13071401 *
    13081402 * @param[in]  s        The destination buffer to append to.
     
    13101404 * @param[in]  a        The string you want to append.
    13111405 *
    1312  * @return              The duplicated string, NULL on error.
     1406 * @return              The concatenated strings, NULL on error.
    13131407 *
    13141408 * @see talloc_strdup()
     1409 * @see talloc_strdup_append()
     1410 * @see talloc_array_length()
    13151411 */
    13161412char *talloc_strdup_append_buffer(char *s, const char *a);
     
    13391435
    13401436/**
    1341  * @brief Append at most n characters of a string to given string and duplicate
    1342  *        the result.
     1437 * @brief Append at most n characters of a string to given string.
     1438 *
     1439 * The destination string is reallocated to take
     1440 * <code>strlen(s) + strnlen(a, n) + 1</code> characters.
     1441 *
     1442 * This functions sets the name of the new pointer to the new
     1443 * string. This is equivalent to:
     1444 *
     1445 * @code
     1446 *      talloc_set_name_const(ptr, ptr)
     1447 * @endcode
     1448 *
     1449 * If <code>s == NULL</code> then new context is created.
    13431450 *
    13441451 * @param[in]  s        The destination string to append to.
     
    13491456 *                      string.
    13501457 *
    1351  * @return              The duplicated string, NULL on error.
     1458 * @return              The concatenated strings, NULL on error.
    13521459 *
    13531460 * @see talloc_strndup()
     1461 * @see talloc_strndup_append_buffer()
    13541462 */
    13551463char *talloc_strndup_append(char *s, const char *a, size_t n);
    13561464
    13571465/**
    1358  * @brief Append at most n characters of a string to given buffer and duplicate
    1359  *        the result.
     1466 * @brief Append at most n characters of a string to given buffer
     1467 *
     1468 * This is a more efficient version of talloc_strndup_append(). It determines
     1469 * the length of the destination string by the size of the talloc context.
     1470 *
     1471 * Use this very carefully as it produces a different result than
     1472 * talloc_strndup_append() when a zero character is in the middle of the
     1473 * destination string.
     1474 *
     1475 * @code
     1476 *      char *str_a = talloc_strdup(NULL, "hello world");
     1477 *      char *str_b = talloc_strdup(NULL, "hello world");
     1478 *      str_a[5] = str_b[5] = '\0'
     1479 *
     1480 *      char *app = talloc_strndup_append(str_a, ", hello", 7);
     1481 *      char *buf = talloc_strndup_append_buffer(str_b, ", hello", 7);
     1482 *
     1483 *      printf("%s\n", app); // hello, hello (app = "hello, hello")
     1484 *      printf("%s\n", buf); // hello (buf = "hello\0world, hello")
     1485 * @endcode
     1486 *
     1487 * If <code>s == NULL</code> then new context is created.
    13601488 *
    13611489 * @param[in]  s        The destination buffer to append to.
     
    13661494 *                      string.
    13671495 *
    1368  * @return              The duplicated string, NULL on error.
     1496 * @return              The concatenated strings, NULL on error.
    13691497 *
    13701498 * @see talloc_strndup()
     1499 * @see talloc_strndup_append()
     1500 * @see talloc_array_length()
    13711501 */
    13721502char *talloc_strndup_append_buffer(char *s, const char *a, size_t n);
     
    14631593 * @endcode
    14641594 *
     1595 * If <code>s == NULL</code> then new context is created.
     1596 *
    14651597 * @param[in]  s        The string to append to.
    14661598 *
     
    14761608 * @brief Append a formatted string to another string.
    14771609 *
     1610 * This is a more efficient version of talloc_asprintf_append(). It determines
     1611 * the length of the destination string by the size of the talloc context.
     1612 *
     1613 * Use this very carefully as it produces a different result than
     1614 * talloc_asprintf_append() when a zero character is in the middle of the
     1615 * destination string.
     1616 *
     1617 * @code
     1618 *      char *str_a = talloc_strdup(NULL, "hello world");
     1619 *      char *str_b = talloc_strdup(NULL, "hello world");
     1620 *      str_a[5] = str_b[5] = '\0'
     1621 *
     1622 *      char *app = talloc_asprintf_append(str_a, "%s", ", hello");
     1623 *      char *buf = talloc_strdup_append_buffer(str_b, "%s", ", hello");
     1624 *
     1625 *      printf("%s\n", app); // hello, hello (app = "hello, hello")
     1626 *      printf("%s\n", buf); // hello (buf = "hello\0world, hello")
     1627 * @endcode
     1628 *
     1629 * If <code>s == NULL</code> then new context is created.
     1630 *
    14781631 * @param[in]  s        The string to append to
    14791632 *
     
    14831636 *
    14841637 * @return              The formatted string, NULL on error.
     1638 *
     1639 * @see talloc_asprintf()
     1640 * @see talloc_asprintf_append()
    14851641 */
    14861642char *talloc_asprintf_append_buffer(char *s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
     
    16861842void talloc_enable_leak_report_full(void);
    16871843
     1844/**
     1845 * @brief Set a custom "abort" function that is called on serious error.
     1846 *
     1847 * The default "abort" function is <code>abort()</code>.
     1848 *
     1849 * The "abort" function is called when:
     1850 *
     1851 * <ul>
     1852 *  <li>talloc_get_type_abort() fails</li>
     1853 *  <li>the provided pointer is not a valid talloc context</li>
     1854 *  <li>when the context meta data are invalid</li>
     1855 *  <li>when access after free is detected</li>
     1856 * </ul>
     1857 *
     1858 * Example:
     1859 *
     1860 * @code
     1861 * void my_abort(const char *reason)
     1862 * {
     1863 *      fprintf(stderr, "talloc abort: %s\n", reason);
     1864 *      abort();
     1865 * }
     1866 *
     1867 *      talloc_set_abort_fn(my_abort);
     1868 * @endcode
     1869 *
     1870 * @param[in]  abort_fn      The new "abort" function.
     1871 *
     1872 * @see talloc_set_log_fn()
     1873 * @see talloc_get_type()
     1874 */
     1875void talloc_set_abort_fn(void (*abort_fn)(const char *reason));
     1876
     1877/**
     1878 * @brief Set a logging function.
     1879 *
     1880 * @param[in]  log_fn      The logging function.
     1881 *
     1882 * @see talloc_set_log_stderr()
     1883 * @see talloc_set_abort_fn()
     1884 */
     1885void talloc_set_log_fn(void (*log_fn)(const char *message));
     1886
     1887/**
     1888 * @brief Set stderr as the output for logs.
     1889 *
     1890 * @see talloc_set_log_fn()
     1891 * @see talloc_set_abort_fn()
     1892 */
     1893void talloc_set_log_stderr(void);
     1894
     1895/**
     1896 * @brief Set a max memory limit for the current context hierarchy
     1897 *        This affects all children of this context and constrain any
     1898 *        allocation in the hierarchy to never exceed the limit set.
     1899 *        The limit can be removed by setting 0 (unlimited) as the
     1900 *        max_size by calling the funciton again on the sam context.
     1901 *        Memory limits can also be nested, meaning a hild can have
     1902 *        a stricter memory limit than a parent.
     1903 *        Memory limits are enforced only at memory allocation time.
     1904 *        Stealing a context into a 'limited' hierarchy properly
     1905 *        updates memory usage but does *not* cause failure if the
     1906 *        move causes the new parent to exceed its limits. However
     1907 *        any further allocation on that hierarchy will then fail.
     1908 *
     1909 * @param[in]   ctx             The talloc context to set the limit on
     1910 * @param[in]   max_size        The (new) max_size
     1911 */
     1912int talloc_set_memlimit(const void *ctx, size_t max_size);
     1913
    16881914/* @} ******************************************************************/
    1689 
    1690 void talloc_set_abort_fn(void (*abort_fn)(const char *reason));
    1691 void talloc_set_log_fn(void (*log_fn)(const char *message));
    1692 void talloc_set_log_stderr(void);
    16931915
    16941916#if TALLOC_DEPRECATED
Note: See TracChangeset for help on using the changeset viewer.