[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn commit: rev 3789 - in trunk: . subversion/include subversion/libsvn_subr subversion/tests/libsvn_subr

From: Greg Stein <gstein_at_lyra.org>
Date: 2002-11-15 00:54:01 CET

On Thu, Nov 14, 2002 at 01:10:55PM -0600, cmpilato@tigris.org wrote:
>...
> +++ trunk/subversion/include/svn_io.h Thu Nov 14 13:10:43 2002
> @@ -334,6 +334,11 @@
>
> svn_stream_t *svn_stream_from_stdio (FILE *fp, apr_pool_t *pool);
>
> +/* Return a generic readable stream from a hunk of DATA and its
> + length, LEN. Allocate the stream in POOL. */
> +svn_stream_t *svn_stream_from_string (const char *data,
> + apr_size_t len,
> + apr_pool_t *pool);

You should probably doc that 'data' needs to live as long as the stream
does -- a copy is not made.

Cheers,
-g
> +++ trunk/subversion/libsvn_subr/io.c Thu Nov 14 13:10:43 2002
> @@ -1007,6 +1007,47 @@
>
>
>
> +/* Miscellaneous stream functions. */
> +struct string_stream_baton
> +{
> + const char *data;
> + apr_size_t len;
> + apr_size_t amt_read;
> +};

You could replace the sizes with 'const char *end;' and change:

> +static svn_error_t *
> +read_handler_string (void *baton, char *buffer, apr_size_t *len)
> +{
> + struct string_stream_baton *btn = baton;
> + apr_size_t left_to_read = btn->len - btn->amt_read;
> + *len = (*len > left_to_read) ? left_to_read : *len;
> + memcpy (buffer, btn->data + btn->amt_read, *len);
> + btn->amt_read += *len;
> + return SVN_NO_ERROR;
> +}

{
  struct string_stream_baton *btn = baton;
  const char *last = btn->data + *len;
  
  if (last > btn->end)
    last = btn->end;
  *len = last - btn->data;
  memcpy (buffer, btn->data, *len);
  btn->data = last;
  return SVN_NO_ERROR;
}

and:

> +
> +svn_stream_t *
> +svn_stream_from_string (const char *data,
> + apr_size_t len,
> + apr_pool_t *pool)
> +{
> + svn_stream_t *stream;
> + struct string_stream_baton *baton;
> +
> + if (! (data && len))
> + return svn_stream_empty (pool);
> +
> + baton = apr_palloc (pool, sizeof (*baton));
> + baton->data = data;
> + baton->len = len;
> + baton->amt_read = 0;

baton->end = data + len;

Using an end pointer feels a bit simpler than a length and a remaining
amount to read. Not a lot simpler, but some...

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri Nov 15 01:47:54 2002

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.