object: add object_array initializer helper function

The object_array API has an OBJECT_ARRAY_INIT macro, but lacks a function to initialize an object_array at a given location in memory. Introduce `object_array_init()` to implement such a function. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed May 8, 2023 at 13:38 UTC fe90355361430dc52f858845a821370db0c54c80
2 files changed +8
object.c
+6
@@ -356,6 +356,12 @@ void object_list_free(struct object_list **list)
356 */
357 static char object_array_slopbuf[1];
358
359 +void object_array_init(struct object_array *array)
360 +{
361 + struct object_array blank = OBJECT_ARRAY_INIT;
362 + memcpy(array, &blank, sizeof(*array));
363 +}
364 +
365 void add_object_array_with_path(struct object *obj, const char *name,
366 struct object_array *array,
367 unsigned mode, const char *path)
object.h
+2
@@ -57,6 +57,8 @@ struct object_array {
57
58 #define OBJECT_ARRAY_INIT { 0 }
59
60 +void object_array_init(struct object_array *array);
61 +
62 /*
63 * object flag allocation:
64 * revision.h: 0---------10 15 23------27