Changeset 988 for vendor/current/lib/talloc/talloc.h
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/lib/talloc/talloc.h
r746 r988 1 1 #ifndef _TALLOC_H_ 2 2 #define _TALLOC_H_ 3 /* 3 /* 4 4 Unix SMB/CIFS implementation. 5 5 Samba temporary memory allocation functions … … 7 7 Copyright (C) Andrew Tridgell 2004-2005 8 8 Copyright (C) Stefan Metzmacher 2006 9 9 10 10 ** NOTE! The following LGPL license applies to the talloc 11 11 ** library. This does NOT imply that all of Samba is released 12 12 ** under the LGPL 13 13 14 14 This library is free software; you can redistribute it and/or 15 15 modify it under the terms of the GNU Lesser General Public … … 48 48 int talloc_version_major(void); 49 49 int talloc_version_minor(void); 50 /* This is mostly useful only for testing */ 51 int talloc_test_get_magic(void); 50 52 51 53 /** … … 194 196 * talloc_set_log_stderr() for more information on talloc logging 195 197 * 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. 196 203 * 197 204 * talloc_free() operates recursively on its children. … … 745 752 * 746 753 * This macro is used together with talloc(mem_ctx, struct foo). If you had to 747 * assi ngthe talloc chunk pointer to some void pointer variable,754 * assign the talloc chunk pointer to some void pointer variable, 748 755 * talloc_get_type_abort() is the recommended way to get the convert the void 749 756 * pointer back to a typed pointer. … … 757 764 void *talloc_get_type_abort(const void *ptr, #type); 758 765 #else 766 #ifdef TALLOC_GET_TYPE_ABORT_NOOP 767 #define talloc_get_type_abort(ptr, type) (type *)(ptr) 768 #else 759 769 #define talloc_get_type_abort(ptr, type) (type *)_talloc_get_type_abort(ptr, #type, __location__) 770 #endif 760 771 void *_talloc_get_type_abort(const void *ptr, const char *name, const char *location); 761 772 #endif … … 823 834 * grand-children, their memory is also taken from the talloc pool. 824 835 * 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 * 825 840 * If you talloc_free() children of a talloc pool, the memory is not given 826 841 * back to the system. Instead, free(3) is only called if the talloc_pool() … … 839 854 void *talloc_pool(const void *context, size_t size); 840 855 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 */ 876 void *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)) 886 void *_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 841 893 /** 842 894 * @brief Free a talloc chunk and NULL out the pointer. … … 848 900 * @param[in] ctx The chunk to be freed. 849 901 */ 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) 851 903 852 904 /* @} ******************************************************************/ … … 915 967 * @return The original pointer 'ptr', NULL if talloc ran out of 916 968 * 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. 917 973 * 918 974 * Example: … … 955 1011 * this function will fail and will return -1. Likewise, if ptr is NULL, 956 1012 * 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. 957 1017 * 958 1018 * Example: … … 1291 1351 1292 1352 /** 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. 1294 1366 * 1295 1367 * @param[in] s The destination to append to. … … 1297 1369 * @param[in] a The string you want to append. 1298 1370 * 1299 * @return The duplicated string, NULL on error.1371 * @return The concatenated strings, NULL on error. 1300 1372 * 1301 1373 * @see talloc_strdup() 1374 * @see talloc_strdup_append_buffer() 1302 1375 */ 1303 1376 char *talloc_strdup_append(char *s, const char *a); 1304 1377 1305 1378 /** 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. 1307 1401 * 1308 1402 * @param[in] s The destination buffer to append to. … … 1310 1404 * @param[in] a The string you want to append. 1311 1405 * 1312 * @return The duplicated string, NULL on error.1406 * @return The concatenated strings, NULL on error. 1313 1407 * 1314 1408 * @see talloc_strdup() 1409 * @see talloc_strdup_append() 1410 * @see talloc_array_length() 1315 1411 */ 1316 1412 char *talloc_strdup_append_buffer(char *s, const char *a); … … 1339 1435 1340 1436 /** 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. 1343 1450 * 1344 1451 * @param[in] s The destination string to append to. … … 1349 1456 * string. 1350 1457 * 1351 * @return The duplicated string, NULL on error.1458 * @return The concatenated strings, NULL on error. 1352 1459 * 1353 1460 * @see talloc_strndup() 1461 * @see talloc_strndup_append_buffer() 1354 1462 */ 1355 1463 char *talloc_strndup_append(char *s, const char *a, size_t n); 1356 1464 1357 1465 /** 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. 1360 1488 * 1361 1489 * @param[in] s The destination buffer to append to. … … 1366 1494 * string. 1367 1495 * 1368 * @return The duplicated string, NULL on error.1496 * @return The concatenated strings, NULL on error. 1369 1497 * 1370 1498 * @see talloc_strndup() 1499 * @see talloc_strndup_append() 1500 * @see talloc_array_length() 1371 1501 */ 1372 1502 char *talloc_strndup_append_buffer(char *s, const char *a, size_t n); … … 1463 1593 * @endcode 1464 1594 * 1595 * If <code>s == NULL</code> then new context is created. 1596 * 1465 1597 * @param[in] s The string to append to. 1466 1598 * … … 1476 1608 * @brief Append a formatted string to another string. 1477 1609 * 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 * 1478 1631 * @param[in] s The string to append to 1479 1632 * … … 1483 1636 * 1484 1637 * @return The formatted string, NULL on error. 1638 * 1639 * @see talloc_asprintf() 1640 * @see talloc_asprintf_append() 1485 1641 */ 1486 1642 char *talloc_asprintf_append_buffer(char *s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3); … … 1686 1842 void talloc_enable_leak_report_full(void); 1687 1843 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 */ 1875 void 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 */ 1885 void 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 */ 1893 void 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 */ 1912 int talloc_set_memlimit(const void *ctx, size_t max_size); 1913 1688 1914 /* @} ******************************************************************/ 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);1693 1915 1694 1916 #if TALLOC_DEPRECATED
Note:
See TracChangeset
for help on using the changeset viewer.