Thread (1 message) 1 message, 1 author, 2016-06-15

Re: [PATCH 01/14] Fix non-constant array creation

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:47:17
Subsystem: the rest · Maintainer: Linus Torvalds

Possibly related (same subject, not in this thread)

Marius Storm-Olsen [off-list ref] writes:
MSVC doesn't munge the non-constant expression, so use xmalloc instead.
Thanks.

These things are called variable length array, and MSVC is not the only
one that do not glok vla.

	Subject: Avoid use of variable length array

        Some compilers unfortunately do not understand these constructs.
	In codepaths that are not performance critical, use xmalloc()
        and free() instead.

There is another use of vla; I would suggest squashing the following patch
in.
diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index c433748..5065abd 100644
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
@@ -1599,7 +1599,7 @@ static void *threaded_find_deltas(void *arg)
 static void ll_find_deltas(struct object_entry **list, unsigned list_size,
 			   int window, int depth, unsigned *processed)
 {
-	struct thread_params p[delta_search_threads];
+	struct thread_params *p;
 	int i, ret, active_threads = 0;
 
 	if (delta_search_threads <= 1) {
@@ -1610,6 +1610,8 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size,
 		fprintf(stderr, "Delta compression using up to %d threads.\n",
 				delta_search_threads);
 
+	p = xcalloc(delta_search_threads, sizeof(*p));
+
 	/* Partition the work amongst work threads. */
 	for (i = 0; i < delta_search_threads; i++) {
 		unsigned sub_size = list_size / (delta_search_threads - i);
@@ -1717,6 +1719,8 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size,
 			active_threads--;
 		}
 	}
+
+	free(p);
 }
 
 #else
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help