Skip to content

Commit 202a4ea

Browse files
committed
arr: Rename Free -> Deinit.
While this function frees the underlying array, and resets the entries, the a, n, and cap variables themselves are not freed (not that this necessarily makes sense). Using arr alone this distinction is not that important, but a user of arr might want to define a _free function that actually frees the entire container, including the meta data. The naming is also more consistent; deinit() is the complement to init().
1 parent 6642f4e commit 202a4ea

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

src/csnip/arr.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@
161161
*
162162
* This function deletes the memory associated with an array. The
163163
* result is an array of size 0 with no allocated memory
164-
* associated, i.e., it is like a freshly allocated array of
164+
* associated, i.e., it is like a freshly initialized array of
165165
* capacity 0.
166166
*/
167-
#define csnip_arr_Free(a, n, cap) \
167+
#define csnip_arr_Deinit(a, n, cap) \
168168
do { \
169169
csnip_mem_Free(a); \
170170
(n) = 0; \
@@ -202,7 +202,7 @@
202202
size_t i, val_type v); \
203203
scope void prefix ## delete_at(csnip_pp_prepend_##gen_args \
204204
size_t i); \
205-
scope void prefix ## free(csnip_pp_list_##gen_args);
205+
scope void prefix ## deinit(csnip_pp_list_##gen_args);
206206

207207
/** Define dynamic array managment functions.
208208
*
@@ -261,9 +261,9 @@
261261
{ \
262262
csnip_arr_DeleteAt(a, n, cap, i, err); \
263263
} \
264-
scope void prefix ## free(csnip_pp_list_##gen_args) \
264+
scope void prefix ## deinit(csnip_pp_list_##gen_args) \
265265
{ \
266-
csnip_arr_Free(a, n, cap); \
266+
csnip_arr_Deinit(a, n, cap); \
267267
}
268268
/** @} */
269269

@@ -276,6 +276,6 @@
276276
#define arr_Pop csnip_arr_Pop
277277
#define arr_InsertAt csnip_arr_InsertAt
278278
#define arr_DeleteAt csnip_arr_DeleteAt
279-
#define arr_Free csnip_arr_Free
279+
#define arr_Deinit csnip_arr_Deinit
280280
#define CSNIP_ARR_HAVE_SHORT_NAMES
281281
#endif /* CSNIP_SHORT_NAMES && !CSNIP_ARR_HAVE_SHORT_NAMES */

src/csnip/clopts.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ int csnip_clopts_process(csnip_clopts* opts,
228228

229229
void csnip_clopts_clear(csnip_clopts* opts)
230230
{
231-
arr_Free(opts->optinfo, opts->n_optinfo, opts->n_optinfo_cap);
231+
arr_Deinit(opts->optinfo, opts->n_optinfo, opts->n_optinfo_cap);
232232
}
233233

234234
int csnip_clopts_parser_uchar(const csnip_clopts* opts,

test/arr_test0.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ int main()
3131
for(int i = 0; i < N; ++i) {
3232
printf("[%d] %d\n", Ax.n - i - 1, Ax.el[Ax.n - i - 1]);
3333
}
34-
IntArray_free(&Ax);
34+
IntArray_deinit(&Ax);
3535
return 0;
3636
}

test/arr_test1.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static bool test_reserve()
6060
if (A.cap < 5)
6161
return false;
6262

63-
IntArr_free(&A, &err);
63+
IntArr_deinit(&A, &err);
6464
return true;
6565
}
6666

@@ -81,7 +81,7 @@ static bool test_push()
8181
return false;
8282
}
8383

84-
IntArr_free(&A, NULL);
84+
IntArr_deinit(&A, NULL);
8585
return true;
8686
}
8787

@@ -108,7 +108,7 @@ static bool test_pop()
108108
return false;
109109
}
110110

111-
IntArr_free(&A, NULL);
111+
IntArr_deinit(&A, NULL);
112112
return true;
113113
}
114114

@@ -145,7 +145,7 @@ static bool test_insert_at()
145145
}
146146
}
147147

148-
IntArr_free(&A, NULL);
148+
IntArr_deinit(&A, NULL);
149149
return true;
150150
}
151151

@@ -175,20 +175,20 @@ static bool test_delete_at()
175175
}
176176
}
177177

178-
IntArr_free(&A, NULL);
178+
IntArr_deinit(&A, NULL);
179179
return true;
180180
}
181181

182-
static bool test_free()
182+
static bool test_deinit()
183183
{
184184
IntArr A;
185185
IntArr_init(&A, NULL, 256);
186186

187-
IntArr_free(&A, NULL);
187+
IntArr_deinit(&A, NULL);
188188
if (A.cap != 0 || A.a != NULL)
189189
return false;
190190

191-
IntArr_free(&A, NULL); // free a 2nd time is a no-op.
191+
IntArr_deinit(&A, NULL); // deinit a 2nd time is a no-op.
192192
return true;
193193
}
194194

@@ -211,7 +211,7 @@ int main(int argc, char** argv)
211211
TEST(pop);
212212
TEST(insert_at);
213213
TEST(delete_at);
214-
TEST(free);
214+
TEST(deinit);
215215
#undef TEST
216216

217217
printf("Overall result: %s\n", (success ? "pass" : "FAIL"));

0 commit comments

Comments
 (0)