Skip to content

Commit 1f8165b

Browse files
committed
remove unused functions
1 parent cd684ac commit 1f8165b

3 files changed

Lines changed: 1 addition & 226 deletions

File tree

src/lib/util/talloc.c

Lines changed: 0 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -779,30 +779,6 @@ char *talloc_buffer_append_variadic_buffer(TALLOC_CTX *ctx, char *to, int argc,
779779
return out;
780780
}
781781

782-
/** Compares two talloced uint8_t arrays with memcmp
783-
*
784-
* Talloc arrays carry their length as part of the structure, so can be passed to a generic
785-
* comparison function.
786-
*
787-
* @param a Pointer to first array.
788-
* @param b Pointer to second array.
789-
* @return
790-
* - 0 if the arrays match.
791-
* - a positive or negative integer otherwise.
792-
*/
793-
int talloc_memcmp_array(uint8_t const *a, uint8_t const *b)
794-
{
795-
size_t a_len, b_len;
796-
797-
a_len = talloc_array_length(a);
798-
b_len = talloc_array_length(b);
799-
800-
if (a_len > b_len) return +1;
801-
if (a_len < b_len) return -1;
802-
803-
return memcmp(a, b, a_len);
804-
}
805-
806782
/** Compares two talloced char arrays with memcmp
807783
*
808784
* Talloc arrays carry their length as part of the structure, so can be passed to a generic
@@ -892,38 +868,6 @@ void **talloc_array_null_terminate(void **array)
892868
return new;
893869
}
894870

895-
/** Remove a NULL termination pointer from an array of pointers
896-
*
897-
* If the end of the array is not NULL, NULL will be returned (error).
898-
*
899-
* @param[in] array to null strip. Will be invalidated (realloced).
900-
* @return
901-
* - NULL if array is NULL, if terminating element is not NULL, or reallocation fails.
902-
* - A realloced version of array without the terminating NULL element.
903-
*/
904-
void **talloc_array_null_strip(void **array)
905-
{
906-
size_t len;
907-
TALLOC_CTX *ctx;
908-
void **new;
909-
size_t size;
910-
911-
if (!array) return NULL;
912-
913-
len = talloc_array_length(array);
914-
ctx = talloc_parent(array);
915-
size = talloc_get_size(array) / talloc_array_length(array);
916-
917-
if ((len - 1) == 0) return NULL;
918-
919-
if (array[len - 1] != NULL) return NULL;
920-
921-
new = _talloc_realloc_array(ctx, array, size, len - 1, talloc_get_name(array));
922-
if (!new) return NULL;
923-
924-
return new;
925-
}
926-
927871
/** Callback to free the autofree ctx on global exit
928872
*
929873
*/
@@ -988,64 +932,3 @@ TALLOC_CTX *talloc_autofree_context_thread_local(void)
988932

989933
return af;
990934
}
991-
992-
993-
struct talloc_child_ctx_s {
994-
struct talloc_child_ctx_s *next;
995-
};
996-
997-
static int _child_ctx_free(TALLOC_CHILD_CTX *list)
998-
{
999-
while (list->next != NULL) {
1000-
TALLOC_CHILD_CTX *entry = list->next;
1001-
TALLOC_CHILD_CTX *next = entry->next;
1002-
1003-
if (talloc_free(entry) < 0) return -1;
1004-
1005-
list->next = next;
1006-
}
1007-
1008-
return 0;
1009-
}
1010-
1011-
/** Allocate and initialize a TALLOC_CHILD_CTX
1012-
*
1013-
* The TALLOC_CHILD_CTX ensures ordering for allocators and
1014-
* destructors. When a TALLOC_CHILD_CTX is created, it is added to
1015-
* parent, in LIFO order. In contrast, the basic talloc operations
1016-
* do not guarantee any kind of order.
1017-
*
1018-
* When the TALLOC_CHILD_CTX is freed, the children are freed in FILO
1019-
* order. That process ensures that the children are freed before
1020-
* the parent, and that the younger siblings are freed before the
1021-
* older siblings.
1022-
*
1023-
* The idea is that if we have an initializer for A, which in turn
1024-
* initializes B and C. When the memory is freed, we should do the
1025-
* operations in the reverse order.
1026-
*/
1027-
TALLOC_CHILD_CTX *talloc_child_ctx_init(TALLOC_CTX *ctx)
1028-
{
1029-
TALLOC_CHILD_CTX *child;
1030-
1031-
child = talloc_zero(ctx, TALLOC_CHILD_CTX);
1032-
if (!child) return NULL;
1033-
1034-
talloc_set_destructor(child, _child_ctx_free);
1035-
return child;
1036-
}
1037-
1038-
/** Allocate a TALLOC_CHILD_CTX from a parent.
1039-
*
1040-
*/
1041-
TALLOC_CHILD_CTX *talloc_child_ctx_alloc(TALLOC_CHILD_CTX *parent)
1042-
{
1043-
TALLOC_CHILD_CTX *child;
1044-
1045-
child = talloc(parent, TALLOC_CHILD_CTX);
1046-
if (!child) return NULL;
1047-
1048-
child->next = parent->next;
1049-
parent->next = child;
1050-
return child;
1051-
}

src/lib/util/talloc.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,12 @@ char *talloc_bstr_realloc(TALLOC_CTX *ctx, char *in, size_t inlen);
234234

235235
char *talloc_buffer_append_variadic_buffer(TALLOC_CTX *ctx, char *to, int argc, ...);
236236

237-
int talloc_memcmp_array(uint8_t const *a, uint8_t const *b);
238-
239237
int talloc_memcmp_bstr(char const *a, char const *b);
240238

241239
int talloc_decrease_ref_count(void const *ptr);
242240

243241
void **talloc_array_null_terminate(void **array);
244242

245-
void **talloc_array_null_strip(void **array);
246-
247243
/** Free const'd memory
248244
*
249245
* @param[in] ptr to free.
@@ -258,11 +254,6 @@ static inline int talloc_const_free(void const *ptr)
258254
TALLOC_CTX *talloc_autofree_context_global(void);
259255
TALLOC_CTX *talloc_autofree_context_thread_local(void);
260256

261-
typedef struct talloc_child_ctx_s TALLOC_CHILD_CTX;
262-
263-
TALLOC_CHILD_CTX *talloc_child_ctx_init(TALLOC_CTX *ctx);
264-
TALLOC_CHILD_CTX *talloc_child_ctx_alloc(TALLOC_CHILD_CTX *parent) CC_HINT(nonnull);
265-
266257
#ifdef __cplusplus
267258
}
268259
#endif

src/lib/util/test/talloc_tests.c

Lines changed: 1 addition & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -865,40 +865,6 @@ static void test_talloc_bstr_realloc(void)
865865
talloc_free(ctx);
866866
}
867867

868-
/*
869-
* talloc_memcmp_array - compare uint8_t arrays
870-
*/
871-
static void test_talloc_memcmp_array(void)
872-
{
873-
TALLOC_CTX *ctx;
874-
uint8_t *a, *b;
875-
uint8_t data3[] = {1, 2, 3};
876-
uint8_t data4a[] = {1, 2, 3, 4};
877-
uint8_t data4b[] = {1, 2, 4, 4};
878-
879-
ctx = talloc_init_const("test");
880-
881-
TEST_CASE("Equal arrays");
882-
a = talloc_typed_memdup(ctx, data3, sizeof(data3));
883-
b = talloc_typed_memdup(ctx, data3, sizeof(data3));
884-
TEST_CHECK(talloc_memcmp_array(a, b) == 0);
885-
886-
TEST_CASE("First array longer");
887-
talloc_free(a);
888-
a = talloc_typed_memdup(ctx, data4a, sizeof(data4a));
889-
TEST_CHECK(talloc_memcmp_array(a, b) > 0);
890-
891-
TEST_CASE("Second array longer");
892-
TEST_CHECK(talloc_memcmp_array(b, a) < 0);
893-
894-
TEST_CASE("Same length, different content");
895-
talloc_free(b);
896-
b = talloc_typed_memdup(ctx, data4b, sizeof(data4b));
897-
TEST_CHECK(talloc_memcmp_array(a, b) < 0); /* 3 < 4 */
898-
899-
talloc_free(ctx);
900-
}
901-
902868
/*
903869
* talloc_memcmp_bstr - compare char arrays
904870
*/
@@ -944,7 +910,7 @@ static void test_talloc_typed_memdup(void)
944910
}
945911

946912
/*
947-
* talloc_array_null_terminate / talloc_array_null_strip
913+
* talloc_array_null_terminate
948914
*/
949915
static void test_talloc_array_null_terminate(void)
950916
{
@@ -964,17 +930,9 @@ static void test_talloc_array_null_terminate(void)
964930
TEST_CHECK(result[3] == NULL);
965931
TEST_CHECK(result[0] == (void *)1);
966932

967-
TEST_CASE("Strip NULL termination");
968-
result = talloc_array_null_strip(result);
969-
TEST_ASSERT(result != NULL);
970-
TEST_CHECK(talloc_array_length(result) == 3);
971-
972933
TEST_CASE("NULL terminate NULL returns NULL");
973934
TEST_CHECK(talloc_array_null_terminate(NULL) == NULL);
974935

975-
TEST_CASE("NULL strip NULL returns NULL");
976-
TEST_CHECK(talloc_array_null_strip(NULL) == NULL);
977-
978936
talloc_free(ctx);
979937
}
980938

@@ -1056,61 +1014,6 @@ static void test_talloc_hdr_size(void)
10561014
TEST_CHECK(talloc_hdr_size() == hdr);
10571015
}
10581016

1059-
/*
1060-
* talloc_child_ctx - ordered allocation and deallocation
1061-
*/
1062-
static int child_free_order[4];
1063-
static int child_free_idx;
1064-
1065-
static int _track_free_order(int *ptr)
1066-
{
1067-
int val = *ptr;
1068-
if (child_free_idx < 4) child_free_order[child_free_idx++] = val;
1069-
return 0;
1070-
}
1071-
1072-
static void test_talloc_child_ctx(void)
1073-
{
1074-
TALLOC_CTX *ctx;
1075-
TALLOC_CHILD_CTX *list, *c1, *c2, *c3;
1076-
int *v1, *v2, *v3;
1077-
1078-
ctx = talloc_init_const("test");
1079-
1080-
TEST_CASE("Child ctx init");
1081-
list = talloc_child_ctx_init(ctx);
1082-
TEST_ASSERT(list != NULL);
1083-
1084-
TEST_CASE("Allocate children in order");
1085-
c1 = talloc_child_ctx_alloc(list);
1086-
TEST_ASSERT(c1 != NULL);
1087-
v1 = talloc(c1, int);
1088-
*v1 = 1;
1089-
talloc_set_destructor(v1, _track_free_order);
1090-
1091-
c2 = talloc_child_ctx_alloc(list);
1092-
TEST_ASSERT(c2 != NULL);
1093-
v2 = talloc(c2, int);
1094-
*v2 = 2;
1095-
talloc_set_destructor(v2, _track_free_order);
1096-
1097-
c3 = talloc_child_ctx_alloc(list);
1098-
TEST_ASSERT(c3 != NULL);
1099-
v3 = talloc(c3, int);
1100-
*v3 = 3;
1101-
talloc_set_destructor(v3, _track_free_order);
1102-
1103-
TEST_CASE("Children freed in FILO order");
1104-
child_free_idx = 0;
1105-
memset(child_free_order, 0, sizeof(child_free_order));
1106-
talloc_free(ctx);
1107-
1108-
/* FILO: c3 (newest) freed first, then c2, then c1 */
1109-
TEST_CHECK(child_free_order[0] == 3);
1110-
TEST_CHECK(child_free_order[1] == 2);
1111-
TEST_CHECK(child_free_order[2] == 1);
1112-
}
1113-
11141017
/*
11151018
* talloc_realloc_zero - realloc that zeros new memory
11161019
*/
@@ -1230,14 +1133,12 @@ TEST_LIST = {
12301133
{ "talloc_bstrndup", test_talloc_bstrndup },
12311134
{ "talloc_bstr_append", test_talloc_bstr_append },
12321135
{ "talloc_bstr_realloc", test_talloc_bstr_realloc },
1233-
{ "talloc_memcmp_array", test_talloc_memcmp_array },
12341136
{ "talloc_memcmp_bstr", test_talloc_memcmp_bstr },
12351137
{ "talloc_typed_memdup", test_talloc_typed_memdup },
12361138
{ "talloc_array_null_terminate", test_talloc_array_null_terminate },
12371139
{ "talloc_destructor_add", test_talloc_destructor_add },
12381140
{ "talloc_link_ctx", test_talloc_link_ctx },
12391141
{ "talloc_hdr_size", test_talloc_hdr_size },
1240-
{ "talloc_child_ctx", test_talloc_child_ctx },
12411142
{ "talloc_realloc_zero", test_talloc_realloc_zero },
12421143
{ "talloc_decrease_ref_count", test_talloc_decrease_ref_count },
12431144
{ "talloc_aligned_array", test_talloc_aligned_array },

0 commit comments

Comments
 (0)