@@ -1,7 +1,6 @@
#include "git-compat-util.h"
#include "add-interactive.h"
#include "advice.h"
-#include "alloc.h"
#include "editor.h"
#include "environment.h"
#include "gettext.h"
@@ -1,6 +1,5 @@
#include "git-compat-util.h"
#include "alias.h"
-#include "alloc.h"
#include "config.h"
#include "gettext.h"
#include "strbuf.h"
@@ -17,79 +17,4 @@ void *alloc_object_node(struct repository *r);
struct alloc_state *allocate_alloc_state(void);
void clear_alloc_state(struct alloc_state *s);
-#define alloc_nr(x) (((x)+16)*3/2)
-
-/**
- * Dynamically growing an array using realloc() is error prone and boring.
- *
- * Define your array with:
- *
- * - a pointer (`item`) that points at the array, initialized to `NULL`
- * (although please name the variable based on its contents, not on its
- * type);
- *
- * - an integer variable (`alloc`) that keeps track of how big the current
- * allocation is, initialized to `0`;
- *
- * - another integer variable (`nr`) to keep track of how many elements the
- * array currently has, initialized to `0`.
- *
- * Then before adding `n`th element to the item, call `ALLOC_GROW(item, n,
- * alloc)`. This ensures that the array can hold at least `n` elements by
- * calling `realloc(3)` and adjusting `alloc` variable.
- *
- * ------------
- * sometype *item;
- * size_t nr;
- * size_t alloc
- *
- * for (i = 0; i < nr; i++)
- * if (we like item[i] already)
- * return;
- *
- * // we did not like any existing one, so add one
- * ALLOC_GROW(item, nr + 1, alloc);
- * item[nr++] = value you like;
- * ------------
- *
- * You are responsible for updating the `nr` variable.
- *
- * If you need to specify the number of elements to allocate explicitly
- * then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`.
- *
- * Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some
- * added niceties.
- *
- * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.
- */
-#define ALLOC_GROW(x, nr, alloc) \
- do { \
- if ((nr) > alloc) { \
- if (alloc_nr(alloc) < (nr)) \
- alloc = (nr); \
- else \
- alloc = alloc_nr(alloc); \
- REALLOC_ARRAY(x, alloc); \
- } \
- } while (0)
-
-/*
- * Similar to ALLOC_GROW but handles updating of the nr value and
- * zeroing the bytes of the newly-grown array elements.
- *
- * DO NOT USE any expression with side-effect for any of the
- * arguments.
- */
-#define ALLOC_GROW_BY(x, nr, increase, alloc) \
- do { \
- if (increase) { \
- size_t new_nr = nr + (increase); \
- if (new_nr < nr) \
- BUG("negative growth in ALLOC_GROW_BY"); \
- ALLOC_GROW(x, new_nr, alloc); \
- memset((x) + nr, 0, sizeof(*(x)) * (increase)); \
- nr = new_nr; \
- } \
- } while (0)
-
#endif
@@ -9,7 +9,6 @@
#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "base85.h"
#include "config.h"
#include "object-store-ll.h"
@@ -2,7 +2,6 @@
* Copyright (c) 2005, 2006 Rene Scharfe
*/
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "gettext.h"
#include "git-zlib.h"
@@ -1,6 +1,5 @@
#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "convert.h"
#include "environment.h"
@@ -7,7 +7,6 @@
*/
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "exec-cmd.h"
@@ -6,7 +6,6 @@
*/
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "color.h"
#include "builtin.h"
@@ -5,7 +5,6 @@
*/
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
-#include "alloc.h"
#include "config.h"
#include "convert.h"
#include "diff.h"
@@ -1,5 +1,4 @@
#include "builtin.h"
-#include "alloc.h"
#include "config.h"
#include "entry.h"
#include "gettext.h"
@@ -1,6 +1,5 @@
#include "builtin.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "color.h"
#include "editor.h"
@@ -1,6 +1,5 @@
#include "builtin.h"
#include "abspath.h"
-#include "alloc.h"
#include "gettext.h"
#include "object-file.h"
#include "parse-options.h"
@@ -1,5 +1,4 @@
#include "builtin.h"
-#include "alloc.h"
#include "gettext.h"
#include "hex.h"
#include "object-file.h"
@@ -1,6 +1,5 @@
#include "builtin.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
@@ -4,7 +4,6 @@
* Copyright (c) 2006 Junio C Hamano
*/
#include "builtin.h"
-#include "alloc.h"
#include "gettext.h"
#include "hex.h"
#include "repository.h"
@@ -1,5 +1,4 @@
#include "builtin.h"
-#include "alloc.h"
#include "config.h"
#include "delta.h"
#include "environment.h"
@@ -6,7 +6,6 @@
*/
#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
@@ -10,7 +10,6 @@
#include "builtin.h"
#include "abspath.h"
#include "advice.h"
-#include "alloc.h"
#include "config.h"
#include "editor.h"
#include "environment.h"
@@ -4,7 +4,6 @@
* Copyright (c) Junio C Hamano, 2006, 2009
*/
#include "builtin.h"
-#include "alloc.h"
#include "gettext.h"
#include "hex.h"
#include "quote.h"
@@ -7,7 +7,6 @@
#include "builtin.h"
#include "abspath.h"
#include "advice.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
@@ -1,5 +1,4 @@
#include "builtin.h"
-#include "alloc.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
@@ -1,5 +1,4 @@
#include "builtin.h"
-#include "alloc.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
@@ -1,5 +1,4 @@
#include "builtin.h"
-#include "alloc.h"
#include "config.h"
#include "dir.h"
#include "environment.h"
@@ -6,7 +6,6 @@
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "commit.h"
#include "environment.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "builtin.h"
#include "parse-options.h"
@@ -5,7 +5,6 @@
*/
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
-#include "alloc.h"
#include "advice.h"
#include "config.h"
#include "lockfile.h"
@@ -1,7 +1,6 @@
#define USE_THE_INDEX_VARIABLE
#include "builtin.h"
#include "abspath.h"
-#include "alloc.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
@@ -2,7 +2,6 @@
* Copyright (c) 2011, Google Inc.
*/
#include "git-compat-util.h"
-#include "alloc.h"
#include "bulk-checkin.h"
#include "environment.h"
#include "gettext.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "environment.h"
#include "hex.h"
#include "lockfile.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "chunk-format.h"
#include "csum-file.h"
#include "gettext.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "commit.h"
#include "commit-graph.h"
#include "decorate.h"
@@ -199,6 +199,81 @@ static inline int cast_size_t_to_int(size_t a)
*/
#define FREE_AND_NULL(p) do { free(p); (p) = NULL; } while (0)
+#define alloc_nr(x) (((x)+16)*3/2)
+
+/**
+ * Dynamically growing an array using realloc() is error prone and boring.
+ *
+ * Define your array with:
+ *
+ * - a pointer (`item`) that points at the array, initialized to `NULL`
+ * (although please name the variable based on its contents, not on its
+ * type);
+ *
+ * - an integer variable (`alloc`) that keeps track of how big the current
+ * allocation is, initialized to `0`;
+ *
+ * - another integer variable (`nr`) to keep track of how many elements the
+ * array currently has, initialized to `0`.
+ *
+ * Then before adding `n`th element to the item, call `ALLOC_GROW(item, n,
+ * alloc)`. This ensures that the array can hold at least `n` elements by
+ * calling `realloc(3)` and adjusting `alloc` variable.
+ *
+ * ------------
+ * sometype *item;
+ * size_t nr;
+ * size_t alloc
+ *
+ * for (i = 0; i < nr; i++)
+ * if (we like item[i] already)
+ * return;
+ *
+ * // we did not like any existing one, so add one
+ * ALLOC_GROW(item, nr + 1, alloc);
+ * item[nr++] = value you like;
+ * ------------
+ *
+ * You are responsible for updating the `nr` variable.
+ *
+ * If you need to specify the number of elements to allocate explicitly
+ * then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`.
+ *
+ * Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some
+ * added niceties.
+ *
+ * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.
+ */
+#define ALLOC_GROW(x, nr, alloc) \
+ do { \
+ if ((nr) > alloc) { \
+ if (alloc_nr(alloc) < (nr)) \
+ alloc = (nr); \
+ else \
+ alloc = alloc_nr(alloc); \
+ REALLOC_ARRAY(x, alloc); \
+ } \
+ } while (0)
+
+/*
+ * Similar to ALLOC_GROW but handles updating of the nr value and
+ * zeroing the bytes of the newly-grown array elements.
+ *
+ * DO NOT USE any expression with side-effect for any of the
+ * arguments.
+ */
+#define ALLOC_GROW_BY(x, nr, increase, alloc) \
+ do { \
+ if (increase) { \
+ size_t new_nr = nr + (increase); \
+ if (new_nr < nr) \
+ BUG("negative growth in ALLOC_GROW_BY"); \
+ ALLOC_GROW(x, new_nr, alloc); \
+ memset((x) + nr, 0, sizeof(*(x)) * (increase)); \
+ nr = new_nr; \
+ } \
+ } while (0)
+
#define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc)))
#define CALLOC_ARRAY(x, alloc) (x) = xcalloc((alloc), sizeof(*(x)))
#define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc)))
@@ -8,7 +8,6 @@
#include "git-compat-util.h"
#include "abspath.h"
#include "advice.h"
-#include "alloc.h"
#include "date.h"
#include "branch.h"
#include "config.h"
@@ -1,6 +1,5 @@
#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "path.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "attr.h"
#include "object.h"
#include "blob.h"
@@ -3,7 +3,6 @@
*/
#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "base85.h"
#include "config.h"
#include "convert.h"
@@ -3,7 +3,6 @@
* Copyright (C) 2005 Junio C Hamano
*/
#include "git-compat-util.h"
-#include "alloc.h"
#include "diff.h"
#include "diffcore.h"
#include "object-store-ll.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "dir.h"
#include "iterator.h"
#include "dir-iterator.h"
@@ -7,7 +7,6 @@
*/
#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "convert.h"
#include "dir.h"
@@ -17,7 +17,6 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "git-compat-util.h"
-#include "alloc.h"
#include "ewok.h"
#define EWAH_MASK(x) ((eword_t)1 << (x % BITS_IN_EWORD))
@@ -17,7 +17,6 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "git-compat-util.h"
-#include "alloc.h"
#include "ewok.h"
#include "ewok_rlw.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "repository.h"
#include "config.h"
#include "date.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "refs.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "date.h"
#include "dir.h"
#include "hex.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "builtin.h"
#include "exec-cmd.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "git-zlib.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "line-range.h"
#include "hex.h"
#include "tag.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "commit.h"
#include "config.h"
#include "gettext.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "dir.h"
#include "gettext.h"
#include "hex.h"
@@ -1,6 +1,5 @@
#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "csum-file.h"
#include "dir.h"
@@ -8,7 +8,6 @@
*/
#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "convert.h"
#include "environment.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "oid-array.h"
#include "hash-lookup.h"
@@ -4,7 +4,6 @@
*/
#include "git-compat-util.h"
#include "oidtree.h"
-#include "alloc.h"
#include "hash.h"
struct oidtree_iter_data {
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "commit.h"
#include "gettext.h"
#include "hex.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "object.h"
#include "pack.h"
#include "pack-objects.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "entry.h"
#include "gettext.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "commit.h"
#include "environment.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "prio-queue.h"
static inline int compare(struct prio_queue *queue, int i, int j)
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "path.h"
#include "quote.h"
#include "strbuf.h"
@@ -4,7 +4,6 @@
* Copyright (C) Linus Torvalds, 2005
*/
#include "git-compat-util.h"
-#include "alloc.h"
#include "bulk-checkin.h"
#include "config.h"
#include "date.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "environment.h"
#include "gettext.h"
#include "gpg-interface.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "commit.h"
#include "refs.h"
#include "diff.h"
@@ -4,7 +4,6 @@
#include "git-compat-util.h"
#include "advice.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "hashmap.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "gettext.h"
#include "hash.h"
#include "hex.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
@@ -1,6 +1,5 @@
#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
@@ -1,6 +1,5 @@
#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "copy.h"
#include "gettext.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
@@ -1,7 +1,6 @@
#include "git-compat-util.h"
#include "abspath.h"
#include "advice.h"
-#include "alloc.h"
#include "config.h"
#include "copy.h"
#include "environment.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "dir.h"
#include "environment.h"
#include "hex.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "hex.h"
#include "repository.h"
#include "tempfile.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "sigchain.h"
#define SIGCHAIN_MAX_SIGNALS 32
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "environment.h"
#include "gettext.h"
#include "name-hash.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "gettext.h"
#include "hash.h"
#include "mem-pool.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "gettext.h"
#include "hex.h"
#include "path.h"
@@ -1,6 +1,5 @@
#include "git-compat-util.h"
#include "string-list.h"
-#include "alloc.h"
void string_list_init_nodup(struct string_list *list)
{
@@ -1,6 +1,5 @@
#include "git-compat-util.h"
#include "strvec.h"
-#include "alloc.h"
#include "hex.h"
#include "strbuf.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "dir.h"
#include "environment.h"
#include "gettext.h"
@@ -1,6 +1,5 @@
#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "repository.h"
#include "config.h"
#include "submodule-config.h"
@@ -1,5 +1,4 @@
#include "test-tool.h"
-#include "alloc.h"
#include "commit.h"
#include "commit-reach.h"
#include "config.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "thread-utils.h"
#include "trace.h"
#include "trace2/tr2_tls.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
@@ -1,6 +1,5 @@
#include "git-compat-util.h"
#include "advice.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
#include "hex.h"
@@ -1,6 +1,5 @@
#include "git-compat-util.h"
#include "tree-walk.h"
-#include "alloc.h"
#include "dir.h"
#include "gettext.h"
#include "hex.h"
@@ -1,5 +1,4 @@
#include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "userdiff.h"
#include "attr.h"
@@ -1,6 +1,5 @@
#include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "environment.h"
#include "gettext.h"
#include "path.h"
alloc_nr, ALLOC_GROW, and ALLOC_GROW_BY are commonly used macros for dynamic array allocation. Moving these macros to common.h focuses alloc.[ch] to allocation for Git objects and additionally allows us to remove inclusions to alloc.h from files that solely used the above macros. Signed-off-by: Calvin Wan <calvinwan@google.com> --- add-patch.c | 1 - alias.c | 1 - alloc.h | 75 ------------------------------ apply.c | 1 - archive-tar.c | 1 - archive.c | 1 - attr.c | 1 - builtin/blame.c | 1 - builtin/cat-file.c | 1 - builtin/checkout--worker.c | 1 - builtin/config.c | 1 - builtin/credential-cache--daemon.c | 1 - builtin/fetch-pack.c | 1 - builtin/fsmonitor--daemon.c | 1 - builtin/grep.c | 1 - builtin/index-pack.c | 1 - builtin/log.c | 1 - builtin/merge.c | 1 - builtin/mktree.c | 1 - builtin/mv.c | 1 - builtin/name-rev.c | 1 - builtin/pack-objects.c | 1 - builtin/repack.c | 1 - builtin/rev-parse.c | 1 - builtin/revert.c | 1 - builtin/rm.c | 1 - builtin/submodule--helper.c | 1 - bulk-checkin.c | 1 - cache-tree.c | 1 - chunk-format.c | 1 - commit-reach.c | 1 - common.h | 75 ++++++++++++++++++++++++++++++ config.c | 1 - daemon.c | 1 - delta-islands.c | 1 - diff.c | 1 - diffcore-rename.c | 1 - dir-iterator.c | 1 - dir.c | 1 - ewah/bitmap.c | 1 - ewah/ewah_bitmap.c | 1 - fetch-pack.c | 1 - fmt-merge-msg.c | 1 - fsck.c | 1 - help.c | 1 - http-backend.c | 1 - line-log.c | 1 - list-objects-filter-options.c | 1 - list-objects-filter.c | 1 - midx.c | 1 - object-file.c | 1 - oid-array.c | 1 - oidtree.c | 1 - pack-bitmap-write.c | 1 - pack-bitmap.c | 1 - pack-objects.c | 1 - packfile.c | 1 - parallel-checkout.c | 1 - pretty.c | 1 - prio-queue.c | 1 - quote.c | 1 - read-cache.c | 1 - ref-filter.c | 1 - reflog-walk.c | 1 - refs.c | 1 - refspec.c | 1 - remote-curl.c | 1 - remote.c | 1 - rerere.c | 1 - revision.c | 1 - sequencer.c | 1 - server-info.c | 1 - shallow.c | 1 - sigchain.c | 1 - sparse-index.c | 1 - split-index.c | 1 - strbuf.c | 1 - string-list.c | 1 - strvec.c | 1 - submodule-config.c | 1 - submodule.c | 1 - t/helper/test-reach.c | 1 - trace2/tr2_tls.c | 1 - trailer.c | 1 - transport.c | 1 - tree-walk.c | 1 - userdiff.c | 1 - worktree.c | 1 - 88 files changed, 75 insertions(+), 161 deletions(-)