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

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Junio C Hamano
Date: Friday, August 21, 2009 - 1:39 pm

Marius Storm-Olsen <mstormo@gmail.com> writes:


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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 01/14] Fix non-constant array creation, Marius Storm-Olsen, (Fri Aug 21, 6:30 am)
[PATCH 02/14] Avoid declaration after statement, Marius Storm-Olsen, (Fri Aug 21, 6:30 am)
[PATCH 03/14] Define SNPRINTF_SIZE_CORR=1 for Microsoft Vi ..., Marius Storm-Olsen, (Fri Aug 21, 6:30 am)
Re: [PATCH 01/14] Fix non-constant array creation, Erik Faye-Lund, (Fri Aug 21, 6:41 am)
Re: [PATCH 01/14] Fix non-constant array creation, Marius Storm-Olsen, (Fri Aug 21, 6:46 am)
Re: [msysGit] Re: [PATCH 01/14] Fix non-constant array cre ..., Marius Storm-Olsen, (Fri Aug 21, 12:49 pm)
Re: [PATCH 01/14] Fix non-constant array creation, Junio C Hamano, (Fri Aug 21, 1:39 pm)
Re: [PATCH 01/14] Fix non-constant array creation, Junio C Hamano, (Fri Aug 21, 2:04 pm)
Re: [PATCH 03/14] Define SNPRINTF_SIZE_CORR=1 for Microsof ..., Marius Storm-Olsen, (Sat Aug 22, 4:32 am)