Changeset 746 for vendor/current/lib/talloc
- Timestamp:
- Nov 27, 2012, 4:56:06 PM (13 years ago)
- Location:
- vendor/current/lib/talloc
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/lib/talloc/talloc.3.xml
r740 r746 784 784 <para> 785 785 This program is free software; you can redistribute it and/or modify 786 it under the terms of the GNU General Public License as published by787 the Free Software Foundation; either version 3 of the License, or (at788 your option) any later version.786 it under the terms of the GNU Lesser General Public License as 787 published by the Free Software Foundation; either version 3 of the 788 License, or (at your option) any later version. 789 789 </para> 790 790 <para> -
vendor/current/lib/talloc/talloc.c
r740 r746 839 839 if (tc->prev) tc->prev->next = tc->next; 840 840 if (tc->next) tc->next->prev = tc->prev; 841 tc->prev = tc->next = NULL; 841 842 } 842 843 … … 926 927 if (tc->prev) tc->prev->next = tc->next; 927 928 if (tc->next) tc->next->prev = tc->prev; 929 tc->prev = tc->next = NULL; 928 930 } 929 931 … … 1252 1254 if (p) new_parent = TC_PTR_FROM_CHUNK(p); 1253 1255 } 1254 /* finding the parent here is potentially quite1255 expensive, but the alternative, which is to change1256 talloc to always have a valid tc->parent pointer,1257 makes realloc more expensive where there are a1258 large number of children.1259 1260 The reason we need the parent pointer here is that1261 if _talloc_free_internal() fails due to references1262 or a failing destructor we need to re-parent, but1263 the free call can invalidate the prev pointer.1264 */1265 if (new_parent == null_context && (tc->child->refs || tc->child->destructor)) {1266 old_parent = talloc_parent_chunk(ptr);1267 }1268 1256 if (unlikely(_talloc_free_internal(child, location) == -1)) { 1269 1257 if (new_parent == null_context) { 1270 struct talloc_chunk *p = old_parent;1258 struct talloc_chunk *p = talloc_parent_chunk(ptr); 1271 1259 if (p) new_parent = TC_PTR_FROM_CHUNK(p); 1272 1260 } … … 1283 1271 _PUBLIC_ void talloc_free_children(void *ptr) 1284 1272 { 1273 struct talloc_chunk *tc_name = NULL; 1285 1274 struct talloc_chunk *tc; 1286 1275 … … 1291 1280 tc = talloc_chunk_from_ptr(ptr); 1292 1281 1282 /* we do not want to free the context name if it is a child .. */ 1283 if (likely(tc->child)) { 1284 for (tc_name = tc->child; tc_name; tc_name = tc_name->next) { 1285 if (tc->name == TC_PTR_FROM_CHUNK(tc_name)) break; 1286 } 1287 if (tc_name) { 1288 _TLIST_REMOVE(tc->child, tc_name); 1289 if (tc->child) { 1290 tc->child->parent = tc; 1291 } 1292 } 1293 } 1294 1293 1295 _talloc_free_children_internal(tc, ptr, __location__); 1296 1297 /* .. so we put it back after all other children have been freed */ 1298 if (tc_name) { 1299 if (tc->child) { 1300 tc->child->parent = NULL; 1301 } 1302 tc_name->parent = tc; 1303 _TLIST_ADD(tc->child, tc_name); 1304 } 1294 1305 } 1295 1306 -
vendor/current/lib/talloc/talloc.h
r740 r746 174 174 * no modifications and return -1. 175 175 * 176 * If this pointer has an additional parent when talloc_free() is called 177 * then the memory is not actually released, but instead the most 178 * recently established parent is destroyed. See talloc_reference() for 179 * details on establishing additional parents. 180 * 181 * For more control on which parent is removed, see talloc_unlink() 182 * 183 * talloc_free() operates recursively on its children. 184 * 185 * From the 2.0 version of talloc, as a special case, talloc_free() is 186 * refused on pointers that have more than one parent, as talloc would 187 * have no way of knowing which parent should be removed. To free a 176 * From version 2.0 and onwards, as a special case, talloc_free() is 177 * refused on pointers that have more than one parent associated, as talloc 178 * would have no way of knowing which parent should be removed. This is 179 * different from older versions in the sense that always the reference to 180 * the most recently established parent has been destroyed. Hence to free a 188 181 * pointer that has more than one parent please use talloc_unlink(). 189 182 * … … 201 194 * talloc_set_log_stderr() for more information on talloc logging 202 195 * functions. 196 * 197 * talloc_free() operates recursively on its children. 203 198 * 204 199 * @param[in] ptr The chunk to be freed. … … 234 229 * talloc_free()s only the children, not the context itself. 235 230 * 236 * @param[in] ptr The chunk that you want to free the children of. 231 * A NULL argument is handled as no-op. 232 * 233 * @param[in] ptr The chunk that you want to free the children of 234 * (NULL is allowed too) 237 235 */ 238 236 void talloc_free_children(void *ptr); … … 403 401 * @param[in] new_ctx The new parent context. 404 402 * 405 * @param[in] p trPointer to the talloc chunk to move.403 * @param[in] pptr Pointer to the talloc chunk to move. 406 404 * 407 405 * @return The pointer of the talloc chunk it has been moved to, 408 406 * NULL on error. 409 407 */ 410 void *talloc_move(const void *new_ctx, const void *ptr);411 #else 412 #define talloc_move(ctx, p tr) (_TALLOC_TYPEOF(*(ptr)))_talloc_move((ctx),(void *)(ptr))408 void *talloc_move(const void *new_ctx, void **pptr); 409 #else 410 #define talloc_move(ctx, pptr) (_TALLOC_TYPEOF(*(pptr)))_talloc_move((ctx),(void *)(pptr)) 413 411 void *_talloc_move(const void *new_ctx, const void *pptr); 414 412 #endif … … 703 701 * @brief Assign a type to a talloc chunk. 704 702 * 705 * This macro allows you to force the name of a pointer to be a particular type.706 * This can be used in conjunction with talloc_get_type() to do type checking on707 * void* pointers.703 * This macro allows you to force the name of a pointer to be of a particular 704 * type. This can be used in conjunction with talloc_get_type() to do type 705 * checking on void* pointers. 708 706 * 709 707 * It is equivalent to this: … … 906 904 * cause this pointer to be freed if it runs out of parents. 907 905 * 908 * - you can talloc_free() the pointer itself . That will destroy the909 * most recently established parent to the pointer and leave the910 * pointer as a child of its current parent.906 * - you can talloc_free() the pointer itself if it has at maximum one 907 * parent. This behaviour has been changed since the release of version 908 * 2.0. Further informations in the description of "talloc_free". 911 909 * 912 910 * For more control on which parent to remove, see talloc_unlink() … … 943 941 * a direct parent of ptr. 944 942 * 945 * Usually you can just use talloc_free() instead of talloc_unlink(), but 946 * sometimes it is useful to have the additional control on which parent is 947 * removed. 943 * You can just use talloc_free() instead of talloc_unlink() if there 944 * is at maximum one parent. This behaviour has been changed since the 945 * release of version 2.0. Further informations in the description of 946 * "talloc_free". 948 947 * 949 948 * @param[in] context The talloc parent to remove. … … 993 992 * @brief Get the size of a talloc chunk. 994 993 * 995 * This function lets you know the amount of memory alloc ed so far by994 * This function lets you know the amount of memory allocated so far by 996 995 * this context. It does NOT account for subcontext memory. 997 996 * This can be used to calculate the size of an array. … … 1454 1453 * 1455 1454 * This function appends the given formatted string to the given string. Use 1456 * this vari ent when the string in the current talloc buffer may have been1455 * this variant when the string in the current talloc buffer may have been 1457 1456 * truncated in length. 1458 1457 * … … 1552 1551 * 1553 1552 * This provides a more detailed report than talloc_report(). It will 1554 * recursively print the en sire tree of memory referenced by the1553 * recursively print the entire tree of memory referenced by the 1555 1554 * pointer. References in the tree are shown by giving the name of the 1556 1555 * pointer that is referenced. -
vendor/current/lib/talloc/talloc_guide.txt
r740 r746 27 27 28 28 and the pointer X->name would be a "child" of the talloc context "X" 29 which is itself a child of mem_ctx. So if you do talloc_free(mem_ctx)29 which is itself a child of "mem_ctx". So if you do talloc_free(mem_ctx) 30 30 then it is all destroyed, whereas if you do talloc_free(X) then just X 31 31 and X->name are destroyed, and if you do talloc_free(X->name) then … … 65 65 the underlying "malloc" is), as long as each thread uses different 66 66 memory contexts. 67 If two threads use s the same context then they need to synchronize in67 If two threads use the same context then they need to synchronize in 68 68 order to be safe. In particular: 69 69 - when using talloc_enable_leak_report(), giving directly NULL as a … … 137 137 no modifications and returns -1. 138 138 139 If this pointer has an additional parent when talloc_free() is called 140 then the memory is not actually released, but instead the most 141 recently established parent is destroyed. See talloc_reference() for 142 details on establishing additional parents. 143 144 For more control on which parent is removed, see talloc_unlink() 145 146 talloc_free() operates recursively on its children. 147 148 From the 2.0 version of talloc, as a special case, talloc_free() is 149 refused on pointers that have more than one parent, as talloc would 150 have no way of knowing which parent should be removed. To free a 139 From version 2.0 and onwards, as a special case, talloc_free() is 140 refused on pointers that have more than one parent associated, as talloc 141 would have no way of knowing which parent should be removed. This is 142 different from older versions in the sense that always the reference to 143 the most recently established parent has been destroyed. Hence to free a 151 144 pointer that has more than one parent please use talloc_unlink(). 152 145 … … 163 156 functions. 164 157 165 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 166 int talloc_free_children(void *ptr); 158 talloc_free() operates recursively on its children. 159 160 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 161 void talloc_free_children(void *ptr); 167 162 168 163 The talloc_free_children() walks along the list of all children of a … … 170 165 itself. 171 166 167 A NULL argument is handled as no-op. 172 168 173 169 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- … … 191 187 cause this pointer to be freed if it runs out of parents. 192 188 193 - you can talloc_free() the pointer itself . That will destroy the194 most recently established parent to the pointer and leave the195 pointer as a child of its current parent.189 - you can talloc_free() the pointer itself if it has at maximum one 190 parent. This behaviour has been changed since the release of version 191 2.0. Further informations in the description of "talloc_free". 196 192 197 193 For more control on which parent to remove, see talloc_unlink() … … 209 205 is NULL, then the function will make no modifications and return -1. 210 206 211 Usually you can just use talloc_free() instead of talloc_unlink(), but 212 sometimes it is useful to have the additional control on which parent 213 is removed. 214 207 You can just use talloc_free() instead of talloc_unlink() if there 208 is at maximum one parent. This behaviour has been changed since the 209 release of version 2.0. Further informations in the description of 210 "talloc_free". 215 211 216 212 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- … … 484 480 485 481 This provides a more detailed report than talloc_report(). It will 486 recursively print the en sire tree of memory referenced by the482 recursively print the entire tree of memory referenced by the 487 483 pointer. References in the tree are shown by giving the name of the 488 484 pointer that is referenced. … … 643 639 The talloc_asprintf_append() function appends the given formatted 644 640 string to the given string. 645 Use this vari ent when the string in the current talloc buffer may641 Use this variant when the string in the current talloc buffer may 646 642 have been truncated in length. 647 643 … … 657 653 The talloc_asprintf_append() function appends the given formatted 658 654 string to the end of the currently allocated talloc buffer. 659 Use this vari ent when the string in the current talloc buffer has655 Use this variant when the string in the current talloc buffer has 660 656 not been changed. 661 657 … … 731 727 talloc_set_type(const void *ptr, type); 732 728 733 This macro allows you to force the name of a pointer to be a729 This macro allows you to force the name of a pointer to be of a 734 730 particular type. This can be used in conjunction with 735 731 talloc_get_type() to do type checking on void* pointers. … … 742 738 talloc_get_size(const void *ctx); 743 739 744 This function lets you know the amount of memory alloc ed so far by740 This function lets you know the amount of memory allocated so far by 745 741 this context. It does NOT account for subcontext memory. 746 742 This can be used to calculate the size of an array. … … 769 765 void talloc_set_log_stderr(void) 770 766 771 This sets the talloc log function to write log messages to stderr 767 This sets the talloc log function to write log messages to stderr. -
vendor/current/lib/talloc/testsuite.c
r740 r746 1318 1318 talloc_report_full(root, stdout); 1319 1319 talloc_free(root); 1320 CHECK_BLOCKS("null_context", NULL, 2); 1321 return true; 1322 } 1323 1324 static bool test_free_children(void) 1325 { 1326 void *root; 1327 const char *p1, *p2, *name, *name2; 1328 1329 talloc_enable_null_tracking(); 1330 root = talloc_new(NULL); 1331 p1 = talloc_strdup(root, "foo1"); 1332 p2 = talloc_strdup(p1, "foo2"); 1333 1334 talloc_set_name(p1, "%s", "testname"); 1335 talloc_free_children(p1); 1336 /* check its still a valid talloc ptr */ 1337 talloc_get_size(talloc_get_name(p1)); 1338 if (strcmp(talloc_get_name(p1), "testname") != 0) { 1339 return false; 1340 } 1341 1342 talloc_set_name(p1, "%s", "testname"); 1343 name = talloc_get_name(p1); 1344 talloc_free_children(p1); 1345 /* check its still a valid talloc ptr */ 1346 talloc_get_size(talloc_get_name(p1)); 1347 torture_assert("name", name == talloc_get_name(p1), "name ptr changed"); 1348 torture_assert("namecheck", strcmp(talloc_get_name(p1), "testname") == 0, 1349 "wrong name"); 1350 CHECK_BLOCKS("name1", p1, 2); 1351 1352 /* note that this does not free the old child name */ 1353 talloc_set_name_const(p1, "testname2"); 1354 name2 = talloc_get_name(p1); 1355 /* but this does */ 1356 talloc_free_children(p1); 1357 torture_assert("namecheck", strcmp(talloc_get_name(p1), "testname2") == 0, 1358 "wrong name"); 1359 CHECK_BLOCKS("name1", p1, 1); 1360 1361 talloc_report_full(root, stdout); 1362 talloc_free(root); 1320 1363 return true; 1321 1364 } … … 1380 1423 test_reset(); 1381 1424 ret &= test_rusty(); 1425 test_reset(); 1426 ret &= test_free_children(); 1382 1427 1383 1428 if (ret) {
Note:
See TracChangeset
for help on using the changeset viewer.