On Wed, Oct 7, 2015 at 3:02 PM, Ivan Zhakov <[email protected]> wrote:
> On 7 October 2015 at 15:57, Stefan Fuhrmann
> <[email protected]> wrote:
> > On Wed, Oct 7, 2015 at 2:47 PM, Julian Foad <[email protected]>
> wrote:
> >>
> >> Stefan wrote:
> >> > I guess the correct way of doing this is revert Ivan's
> >> > change and apply something like the attached patch.
> >> Ivan wrote:
> >> > Here is the patch that I wanted commit later. What do you think?
> >>
> >> I am not interested in reviewing any more patches that tweak just one
> >> of the implementations. If you (anybody) want to do something, please
> >> combine the two functions into one implementation, and then I will be
> >> interested in reviewing the (single) implementation.
> >
> >
> > Alright, here you go.
> >
> Hi Stefan,
>
> Are you sure that code in proposed patch compiles at least? :)
>
It does, GCC is quite lenient when it comes to pointer types ;)
But it has caused a few test failures. Here the final version.
If that doesn't work either then I'm done for today.
-- Stefan^2.
Index: subversion/libsvn_subr/stream.c
===================================================================
--- subversion/libsvn_subr/stream.c (revision 1707288)
+++ subversion/libsvn_subr/stream.c (working copy)
@@ -1488,21 +1488,25 @@
{
#define MIN_READ_SIZE 64
- apr_size_t to_read = 0;
+ apr_size_t to_read, gotten;
svn_stringbuf_t *text
- = svn_stringbuf_create_ensure(len_hint + MIN_READ_SIZE,
+ = svn_stringbuf_create_ensure(len_hint ? len_hint : MIN_READ_SIZE,
result_pool);
do
{
to_read = text->blocksize - 1 - text->len;
- SVN_ERR(svn_stream_read_full(stream, text->data + text->len, &to_read));
- text->len += to_read;
+ if (to_read == 0)
+ {
+ svn_stringbuf_ensure(text, text->blocksize * 2);
+ to_read = text->blocksize - 1 - text->len;
+ }
- if (to_read && text->blocksize < text->len + MIN_READ_SIZE)
- svn_stringbuf_ensure(text, text->blocksize * 2);
+ gotten = to_read;
+ SVN_ERR(svn_stream_read_full(stream, text->data + text->len, &gotten));
+ text->len += gotten;
}
- while (to_read);
+ while (gotten == to_read);
text->data[text->len] = '\0';
*str = text;
@@ -1798,27 +1802,11 @@
apr_pool_t *result_pool,
apr_pool_t *scratch_pool)
{
- svn_stringbuf_t *work = svn_stringbuf_create_ensure(SVN__STREAM_CHUNK_SIZE,
- result_pool);
- char *buffer = apr_palloc(scratch_pool, SVN__STREAM_CHUNK_SIZE);
-
- while (1)
- {
- apr_size_t len = SVN__STREAM_CHUNK_SIZE;
-
- SVN_ERR(svn_stream_read_full(stream, buffer, &len));
- svn_stringbuf_appendbytes(work, buffer, len);
-
- if (len < SVN__STREAM_CHUNK_SIZE)
- break;
- }
-
+ svn_stringbuf_t *buffer;
+ SVN_ERR(svn_stringbuf_from_stream(&buffer, stream, 0, scratch_pool));
+ *result = svn_string_ncreate(buffer->data, buffer->len, result_pool);
SVN_ERR(svn_stream_close(stream));
- *result = apr_palloc(result_pool, sizeof(**result));
- (*result)->data = work->data;
- (*result)->len = work->len;
-
return SVN_NO_ERROR;
}