* Re: [PATCH] Really *do* nothing in while loop
2005-05-08 9:48 ` Michael Tokarev
@ 2005-05-08 11:18 ` Thomas Glanzmann
2005-05-08 11:20 ` James Purser
2005-05-08 21:43 ` J.A. Magallon
2 siblings, 0 replies; 11+ messages in thread
From: Thomas Glanzmann @ 2005-05-08 11:18 UTC (permalink / raw)
To: LKML, GIT
Hello,
> >- /* nothing */
> >+ /* nothing */;
> Well, the lack of semicolon is wrong really (and funny).
yes, it is but harmless in this envrionment.
> 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
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] Really *do* nothing in while loop
2005-05-08 9:48 ` Michael Tokarev
2005-05-08 11:18 ` Thomas Glanzmann
@ 2005-05-08 11:20 ` James Purser
2005-05-08 11:33 ` jdow
2005-05-08 21:43 ` J.A. Magallon
2 siblings, 1 reply; 11+ messages in thread
From: James Purser @ 2005-05-08 11:20 UTC (permalink / raw)
To: Michael Tokarev; +Cc: Thomas Glanzmann, LKML, GIT
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).
>
> 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
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] Really *do* nothing in while loop
2005-05-08 11:20 ` James Purser
@ 2005-05-08 11:33 ` jdow
2005-05-08 11:40 ` Michael Tokarev
0 siblings, 1 reply; 11+ messages in thread
From: jdow @ 2005-05-08 11:33 UTC (permalink / raw)
To: James Purser, Michael Tokarev; +Cc: Thomas Glanzmann, LKML, GIT
From: "James Purser" <purserj@ksit.dynalias.com>
> 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.
{^_^}
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] Really *do* nothing in while loop
2005-05-08 11:33 ` jdow
@ 2005-05-08 11:40 ` Michael Tokarev
2005-05-08 21:08 ` Junio C Hamano
0 siblings, 1 reply; 11+ messages in thread
From: Michael Tokarev @ 2005-05-08 11:40 UTC (permalink / raw)
To: jdow; +Cc: James Purser, Thomas Glanzmann, LKML, GIT
jdow wrote:
> From: "James Purser" <purserj@ksit.dynalias.com>
>
while (deflate(&stream, 0) == Z_OK)
- /* nothing */
+ /* nothing */;
stream.next_in = buf;
>
> 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
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Really *do* nothing in while loop
2005-05-08 11:40 ` Michael Tokarev
@ 2005-05-08 21:08 ` Junio C Hamano
2005-05-08 21:16 ` Daniel Barkalow
0 siblings, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2005-05-08 21:08 UTC (permalink / raw)
To: Michael Tokarev; +Cc: jdow, James Purser, Thomas Glanzmann, LKML, GIT
>>>>> "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?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Really *do* nothing in while loop
2005-05-08 21:08 ` Junio C Hamano
@ 2005-05-08 21:16 ` Daniel Barkalow
2005-05-08 21:35 ` Junio C Hamano
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Barkalow @ 2005-05-08 21:16 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Michael Tokarev, jdow, James Purser, Thomas Glanzmann, GIT
On Sun, 8 May 2005, Junio C Hamano wrote:
> >>>>> "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*
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Really *do* nothing in while loop
2005-05-08 21:16 ` Daniel Barkalow
@ 2005-05-08 21:35 ` Junio C Hamano
0 siblings, 0 replies; 11+ messages in thread
From: Junio C Hamano @ 2005-05-08 21:35 UTC (permalink / raw)
To: Daniel Barkalow
Cc: Michael Tokarev, jdow, James Purser, Thomas Glanzmann, GIT
>>>>> "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?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Really *do* nothing in while loop
2005-05-08 9:48 ` Michael Tokarev
2005-05-08 11:18 ` Thomas Glanzmann
2005-05-08 11:20 ` James Purser
@ 2005-05-08 21:43 ` J.A. Magallon
2 siblings, 0 replies; 11+ messages in thread
From: J.A. Magallon @ 2005-05-08 21:43 UTC (permalink / raw)
To: linux-kernel
On 05.08, 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).
>
> 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.
>
This changes the code in the corner case when deflate(...) IS NOT Z_OK
in the first iteration.
Old code: next_in is not assigned if deflate(&stream, 0) != Z_OK
New code: next_is is _always_ assigned
Other point is if old code was wrong...hidden bug ?
--
J.A. Magallon <jamagallon()able!es> \ Software is like sex:
werewolf!able!es \ It's better when it's free
Mandriva Linux release 2006.0 (Cooker) for i586
Linux 2.6.11-jam16 (gcc 4.0.0 (4.0.0-3mdk for Mandriva Linux release 2006.0))
^ permalink raw reply [flat|nested] 11+ messages in thread