threads / patch / 529

patchReally *do* nothing in while loop

Subject: [PATCH] Really *do* nothing in while loop

## tl;dr

9 messages between May 8, 2005 and May 8, 2005. Diffs are folded; open one to read it.

replies: 8people: 6as markdown or json

Thomas Glanzmann· May 8, 2005, 09:34 UTC · lore
[PATCH] Really *do* nothing in while loop
Signed-Off-by: Thomas Glanzmann <sithglan@stud.uni-erlangen.de>
Show changes to sha1_file.c +1 −1
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -335,7 +335,7 @@
 	stream.next_in = hdr;
 	stream.avail_in = hdrlen;
 	while (deflate(&stream, 0) == Z_OK)
-		/* nothing */
+		/* nothing */;
 
 	/* Then the data itself.. */
 	stream.next_in = buf;
Michael Tokarev· May 8, 2005, 09:48 UTC · re: Thomas Glanzmann · lore

Re: [PATCH] Really *do* nothing in while loop

Thomas Glanzmann wrote:
Show 15 quoted lines
> [PATCH] Really *do* nothing in while loop
> 
> Signed-Off-by: Thomas Glanzmann <sithglan@stud.uni-erlangen.de>
> 
> --- a/sha1_file.c
> +++ b/sha1_file.c
> @@ -335,7 +335,7 @@
>  	stream.next_in = hdr;
>  	stream.avail_in = hdrlen;
>  	while (deflate(&stream, 0) == Z_OK)
> -		/* nothing */
> +		/* nothing */;
>  
>  	/* Then the data itself.. */
>  	stream.next_in = buf;
Well, the lack of semicolon is wrong really (and funny).

But is the whole while loop needed at all? deflate() consumes as much input as it can, producing as much output as it can. So without the loop, and without updating the buffer pointers ({next,avail}_{in,out}) it will do just fine without the loop, and will return something != Z_OK on next iteration. If this is to mean to flush output, it should be deflate(&stream, Z_FLUSH) or something.

/mjt
P.S.  What's git@vger.kernel.org for ?
Thomas Glanzmann· May 8, 2005, 11:18 UTC · re: Michael Tokarev · lore

Re: [PATCH] Really *do* nothing in while loop

Hello,
> >-		/* nothing */
> >+		/* nothing */;
> Well, the lack of semicolon is wrong really (and funny).
yes, it is but harmless in this envrionment.
Show 7 quoted lines
> But is the whole while loop needed at all?  deflate()
> consumes as much input as it can, producing as much output
> as it can.  So without the loop, and without updating the
> buffer pointers ({next,avail}_{in,out}) it will do just
> fine without the loop, and will return something != Z_OK
> on next iteration.  If this is to mean to flush output,
> it should be deflate(&stream, Z_FLUSH) or something.
I have no idea.
> P.S.  What's git@vger.kernel.org for ?

It is the list which handles GIT related discussions. Frontend/backend and isn't kernel related.

	Thomas
James Purser· May 8, 2005, 11:20 UTC · re: Michael Tokarev · lore

Re: [PATCH] Really *do* nothing in while loop

On Sun, 2005-05-08 at 19:48, Michael Tokarev wrote:
Show 30 quoted lines
> Thomas Glanzmann wrote:
> > [PATCH] Really *do* nothing in while loop
> > 
> > Signed-Off-by: Thomas Glanzmann <sithglan@stud.uni-erlangen.de>
> > 
> > --- a/sha1_file.c
> > +++ b/sha1_file.c
> > @@ -335,7 +335,7 @@
> >  	stream.next_in = hdr;
> >  	stream.avail_in = hdrlen;
> >  	while (deflate(&stream, 0) == Z_OK)
> > -		/* nothing */
> > +		/* nothing */;
> >  
> >  	/* Then the data itself.. */
> >  	stream.next_in = buf;
> 
> Well, the lack of semicolon is wrong really (and funny).
> 
> But is the whole while loop needed at all?  deflate()
> consumes as much input as it can, producing as much output
> as it can.  So without the loop, and without updating the
> buffer pointers ({next,avail}_{in,out}) it will do just
> fine without the loop, and will return something != Z_OK
> on next iteration.  If this is to mean to flush output,
> it should be deflate(&stream, Z_FLUSH) or something.
> 
> /mjt
> 
> P.S.  What's git@vger.kernel.org for ?
Its the mailing list for git development.
> -
> 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
-- 
James Purser
http://ksit.dynalias.com
jdow· May 8, 2005, 11:33 UTC · re: James Purser · lore

Re: [PATCH] Really *do* nothing in while loop

From: "James Purser" <purserj@ksit.dynalias.com>
Show 19 quoted lines
> On Sun, 2005-05-08 at 19:48, Michael Tokarev wrote:
> > Thomas Glanzmann wrote:
> > > [PATCH] Really *do* nothing in while loop
> > > 
> > > Signed-Off-by: Thomas Glanzmann <sithglan@stud.uni-erlangen.de>
> > > 
> > > --- a/sha1_file.c
> > > +++ b/sha1_file.c
> > > @@ -335,7 +335,7 @@
> > >  stream.next_in = hdr;
> > >  stream.avail_in = hdrlen;
> > >  while (deflate(&stream, 0) == Z_OK)
> > > - /* nothing */
> > > + /* nothing */;
> > >  
> > >  /* Then the data itself.. */
> > >  stream.next_in = buf;
> > 
> > Well, the lack of semicolon is wrong really (and funny).
You guys REALLY do not see the changed semantics here? You are
changing:
  while (deflate(&stream, 0) == Z_OK)
      stream.next_in = buf;
into
  while (deflate(&stream, 0) == Z_OK)
    ;
  /* Then the data itself.. */
  stream.next_in = buf;

I suspect the results of that tiny bit of code would be slightly different, especially if "stream.next_in" is volatile, "buf" is volatile, or if the assignment to next_in has an effect on the "deflate" operation.

{^_^}
Michael Tokarev· May 8, 2005, 11:40 UTC · re: jdow · lore

Re: [PATCH] Really *do* nothing in while loop

jdow wrote:
> From: "James Purser" <purserj@ksit.dynalias.com>
> 
   while (deflate(&stream, 0) == Z_OK)
-  /* nothing */
+  /* nothing */;
  stream.next_in = buf;
Show 17 quoted lines
> 
> You guys REALLY do not see the changed semantics here? You are
> changing:
>   while (deflate(&stream, 0) == Z_OK)
>       stream.next_in = buf;
> 
> into
> 
>   while (deflate(&stream, 0) == Z_OK)
>     ;
>   /* Then the data itself.. */
>   stream.next_in = buf;
> 
> I suspect the results of that tiny bit of code would be slightly
> different, especially if "stream.next_in" is volatile, "buf"
> is volatile, or if the assignment to next_in has an effect on
> the "deflate" operation.

As I already said, deflate() in this case does only ONE iteration. stream.avail_in is NOT changed in the loop (except of the deflate() itself, where it will be set to 0 - provided out buffer have enouth room). So the whole while loop does only ONE iteration, returning Z_NEED_DATA or something the next one. So no, the semantics here (actual semantics) does NOT change.

/mjt
Junio C Hamano· May 8, 2005, 21:08 UTC · re: Michael Tokarev · lore

Re: [PATCH] Really *do* nothing in while loop

>>>>> "MT" == Michael Tokarev <mjt@tls.msk.ru> writes:

MT> As I already said, deflate() in this case does only ONE iteration. MT> stream.avail_in is NOT changed in the loop (except of the deflate() MT> itself, where it will be set to 0 - provided out buffer have enouth MT> room)....

Just a stupid question, but what happens when we do not have enough room in the buffer?

Daniel Barkalow· May 8, 2005, 21:16 UTC · re: Junio C Hamano · lore

Re: [PATCH] Really *do* nothing in while loop

On Sun, 8 May 2005, Junio C Hamano wrote:
Show 9 quoted lines
> >>>>> "MT" == Michael Tokarev <mjt@tls.msk.ru> writes:
> 
> MT> As I already said, deflate() in this case does only ONE iteration.
> MT> stream.avail_in is NOT changed in the loop (except of the deflate()
> MT> itself, where it will be set to 0 - provided out buffer have enouth
> MT> room)....
> 
> Just a stupid question, but what happens when we do not have
> enough room in the buffer?

We must have enough room; we sized the buffer with deflateBound to fit the worst case.

	-Daniel
*This .sig left intentionally blank*
Junio C Hamano· May 8, 2005, 21:35 UTC · re: Daniel Barkalow · lore

Re: [PATCH] Really *do* nothing in while loop

>>>>> "DB" == Daniel Barkalow <barkalow@iabervon.org> writes:
DB> On Sun, 8 May 2005, Junio C Hamano wrote:
>> 

MT> As I already said, deflate() in this case does only ONE iteration. MT> stream.avail_in is NOT changed in the loop (except of the deflate() MT> itself, where it will be set to 0 - provided out buffer have enouth MT> room)....

>> 
>> Just a stupid question, but what happens when we do not have
>> enough room in the buffer?

DB> We must have enough room; we sized the buffer with deflateBound to fit the DB> worst case.

Thanks for the explanation. Then do we still need to express it as a while loop?

← back to recent threads