Re: [PATCH] This patch is to allow 12 different OS's to compile and run git.
- From
- Boyd Lynn Gerber <gerberb@zenez.com>
- Date
- Jun 6, 2008, 23:23 UTC
- Message-ID
- <Pine.LNX.4.64.0806061718420.18454@xenau.zenez.com>
- In-Reply-To
- <7vmylyrwkg.fsf@gitster.siamese.dyndns.org>
On Fri, 6 Jun 2008, Junio C Hamano wrote:
Show 22 quoted lines
> Boyd Lynn Gerber <gerberb@zenez.com> writes:
> > diff --git a/progress.c b/progress.c
> > index d19f80c..295c4e3 100644
> > --- a/progress.c
> > +++ b/progress.c
> > @@ -241,7 +241,8 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
> > *p_progress = NULL;
> > if (progress->last_value != -1) {
> > /* Force the last update */
> > - char buf[strlen(msg) + 5];
> > + /* char buf[strlen(msg) + 5]; */
> > + char *buf = alloca (strlen(msg) + 5 );
> > struct throughput *tp = progress->throughput;
> > if (tp) {
> > unsigned int rate = !tp->avg_misecs ? 0 :
>
> I do not know the situation over there these days, but I have a distant
> but bitter memory of having to deal with AIX X-<. It insisted that
> inclusion of <alloca.h> to be the very first thing in the source before
> anything else. I would want to keep alloca() out of the codebase without
> very good reason. Not that I care much about portability to AIX, but not
> having to worry about alloca() unless necessary is a good thing.You hit the nail on the head, AIX and any Novell derived Compiler code requires it. Also the SCO OS's
Show 15 quoted lines
> I do not think progress_msg() is a good reason to even worrying about a > dynamically sized array. The function is designed to spit out a single > line of message (so the incoming msg is expected to be shorter than 80 > chars or so). If you "git grep stop_progress_msg", you will see that > there are only two callers of this function, one in progress.c itself that > says "done", and the other one in index-pack.c that gives a string > formatted into 48-byte buffer. > > So we can be lazy and say: > > char buf[128]; > ... > snprintf(buf, sizeof(buf), ", %s.\n", msg) > > and be done with it.
I like the idea.
Show 37 quoted lines
> If you really wanted to be safe and anal, you could do something like
> this, which would be just as efficient and much more straightforward:
>
> progress.c | 11 ++++++++---
> 1 files changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/progress.c b/progress.c
> index d19f80c..55a8687 100644
> --- a/progress.c
> +++ b/progress.c
> @@ -241,16 +241,21 @@ void stop_progress_msg(struct progress **p_progress, const char *msg)
> *p_progress = NULL;
> if (progress->last_value != -1) {
> /* Force the last update */
> - char buf[strlen(msg) + 5];
> + char buf[128], *bufp;
> + size_t len = strlen(msg) + 5;
> struct throughput *tp = progress->throughput;
> +
> + bufp = (len < sizeof(buf)) ? buf : xmalloc(len + 1);
> if (tp) {
> unsigned int rate = !tp->avg_misecs ? 0 :
> tp->avg_bytes / tp->avg_misecs;
> throughput_string(tp, tp->curr_total, rate);
> }
> progress_update = 1;
> - sprintf(buf, ", %s.\n", msg);
> - display(progress, progress->last_value, buf);
> + sprintf(bufp, ", %s.\n", msg);
> + display(progress, progress->last_value, bufp);
> + if (buf != bufp)
> + free(bufp);
> }
> clear_progress_signal();
> free(progress->throughput);
>
> Thanks for the suggestions. I am making changes based on all the feed back. I will remove all the debug junk from the final patch. I am putting options in and out a lot at the moment. Trying to make sure I do not break anything on the 12 OS's. It is a real pain testing all the changes on them to make sure I did not break anything.
Thanks,
-- Boyd Gerber <gerberb@zenez.com> ZENEZ 1042 East Fort Union #135, Midvale Utah 84047