Hey Edmund,
Thanks for stretching your svn coding legs with this one. I've got
some detailed feedback for you below:
On Fri, Apr 10, 2009 at 09:55, Edmund Wong <ed_at_kdtc.net> wrote:
>...
> If len == 0, it doesn't break out of the loop; though
> it should break out the next time it tries to read.
I wouldn't exactly trust a stream that has returned len=0 to be readable.
Now... you said the test suite passed, so apparently none of our
streams have a problem with that. But I wouldn't want to rely on that
:-P ... in my feedback below, I've got a suggestion for this.
> I'll need to read up on the stream_read() function.
> What happens if it reads past? Â It should throw
> an error, no? Â And thusly break.
A stream cannot "read past".
>...
> +++ subversion/libsvn_subr/stream.c   (working copy)
> @@ -210,6 +210,8 @@
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â apr_pool_t *scratch_pool)
> Â {
> Â char *buf = apr_palloc(scratch_pool, SVN__STREAM_CHUNK_SIZE);
> + Â svn_error_t *err = SVN_NO_ERROR;
> + Â svn_error_t *err2 = SVN_NO_ERROR;
>
> Â /* Read and write chunks until we get a short read, indicating the
> Â Â Â end of the stream. Â (We can't get a short write without an
> @@ -218,18 +220,46 @@
> Â Â {
> Â Â Â apr_size_t len = SVN__STREAM_CHUNK_SIZE;
>
> - Â Â Â if (cancel_func)
> - Â Â Â Â SVN_ERR(cancel_func(cancel_baton));
> + Â Â Â if (cancel_func)
> + Â Â Â Â err = cancel_func(cancel_baton);
> +
> + Â Â Â if (err)
> + Â Â Â Â break;
You cancel_func == NULL, then you can avoid the second if, since there
is no way err could get set:
if (cancel_func)
{
err = cancel_func(cancel_baton);
if (err)
break;
}
> + Â Â Â err = svn_stream_read(from, buf, &len);
> + Â Â Â if (err)
> + Â Â Â Â break;
> +
> + Â Â Â if (len > 0)
> + Â Â Â Â {
> + Â Â Â Â Â err = svn_stream_write(to, buf, &len);
>
> - Â Â Â SVN_ERR(svn_stream_read(from, buf, &len));
> - Â Â Â if (len > 0)
> - Â Â Â Â SVN_ERR(svn_stream_write(to, buf, &len));
> - Â Â Â if (len != SVN__STREAM_CHUNK_SIZE)
> - Â Â Â Â break;
> + Â Â Â Â Â if (len != SVN__STREAM_CHUNK_SIZE)
> + Â Â Â Â Â Â Â break;
I'd suggest moving this outside of the len>0 block.
> + Â Â Â Â Â if (err)
> + Â Â Â Â Â Â Â break;
> + Â Â Â Â }
> + Â Â Â else
> + Â Â Â Â {
> + Â Â Â Â Â break;
> + Â Â Â Â }
Skip this else branch, and just do the len test here.
> Â Â }
> +
> + Â Â if (err)
> + Â Â {
> + Â Â Â Â err2 = svn_error_compose_create(svn_stream_close(from),
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â svn_stream_close(to));
> + Â Â }
> + Â Â else
> + Â Â {
> + Â Â Â Â err2 = SVN_NO_ERROR;
> +     err  = svn_error_compose_create(svn_stream_close(from),
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â svn_stream_close(to));
> + Â Â }
You could skip the if/else blocks altogether, and just do:
err2 = svn_error_compose_create(...);
> - Â return svn_error_compose_create(svn_stream_close(from),
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â svn_stream_close(to));
> + Â return svn_error_compose_create(err,err2);
If err==NULL, then it will return whatever err2 is... in this case,
any potential problem with closing the streams.
Style note: there should be a space after that comma.
Cheers,
-g
------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=1627618
Received on 2009-04-10 11:35:12 CEST