Author: stefan2
Date: Thu Jun 2 12:33:13 2011
New Revision: 1130522
URL: http://svn.apache.org/viewvc?rev=1130522&view=rev
Log:
Since svn_stream_readline_detect_eol will only work for streams that support
mark & seek, note that in the docstring and move the EOL detecting from the
generic readline() function to svn_stream_readline_detect_eol.
* subversion/include/svn_io.h
(svn_stream_readline_detect_eol): make limitations clear in docstring
* subversion/libsvn_subr/stream.c
(stream_readline_bytewise, stream_readline): remove EOL auto-detection code
(svn_stream_readline_detect_eol): detect EOL here
Modified:
subversion/trunk/subversion/include/svn_io.h
subversion/trunk/subversion/libsvn_subr/stream.c
Modified: subversion/trunk/subversion/include/svn_io.h
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_io.h?rev=1130522&r1=1130521&r2=1130522&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_io.h (original)
+++ subversion/trunk/subversion/include/svn_io.h Thu Jun 2 12:33:13 2011
@@ -1223,6 +1223,9 @@ svn_stream_readline(svn_stream_t *stream
* is returned in @a *eol. If EOF is reached and the stream does not
* end with a newline character, @a *eol will be NULL.
*
+ * @note This function will fail if @a stream does not support mark
+ * and seek (see @ref svn_stream_supports_mark).
+ *
* @since New in 1.7.
*/
svn_error_t *
Modified: subversion/trunk/subversion/libsvn_subr/stream.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/stream.c?rev=1130522&r1=1130521&r2=1130522&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/stream.c (original)
+++ subversion/trunk/subversion/libsvn_subr/stream.c Thu Jun 2 12:33:13 2011
@@ -310,13 +310,11 @@ scan_eol(const char **eol, svn_stream_t
static svn_error_t *
stream_readline_bytewise(svn_stringbuf_t **stringbuf,
svn_boolean_t *eof,
- const char **eol,
+ const char *eol,
svn_stream_t *stream,
- svn_boolean_t detect_eol,
apr_pool_t *pool)
{
svn_stringbuf_t *str;
- const char *eol_str;
apr_size_t numbytes;
const char *match;
char c;
@@ -327,22 +325,8 @@ stream_readline_bytewise(svn_stringbuf_t
80 chars. */
str = svn_stringbuf_create_ensure(LINE_CHUNK_SIZE, pool);
- if (detect_eol)
- {
- SVN_ERR(scan_eol(&eol_str, stream, pool));
- if (eol)
- *eol = eol_str;
- if (! eol_str)
- {
- /* No newline until EOF, EOL_STR can be anything. */
- eol_str = APR_EOL_STR;
- }
- }
- else
- eol_str = *eol;
-
/* Read into STR up to and including the next EOL sequence. */
- match = eol_str;
+ match = eol;
while (*match)
{
numbytes = 1;
@@ -351,8 +335,6 @@ stream_readline_bytewise(svn_stringbuf_t
{
/* a 'short' read means the stream has run out. */
*eof = TRUE;
- if (detect_eol && eol)
- *eol = NULL;
*stringbuf = str;
return SVN_NO_ERROR;
}
@@ -360,13 +342,13 @@ stream_readline_bytewise(svn_stringbuf_t
if (c == *match)
match++;
else
- match = eol_str;
+ match = eol;
svn_stringbuf_appendbyte(str, c);
}
*eof = FALSE;
- svn_stringbuf_chop(str, match - eol_str);
+ svn_stringbuf_chop(str, match - eol);
*stringbuf = str;
return SVN_NO_ERROR;
@@ -476,16 +458,13 @@ stream_readline_chunky(svn_stringbuf_t *
/* Guts of svn_stream_readline() and svn_stream_readline_detect_eol().
* Returns the line read from STREAM in *STRINGBUF, and indicates
- * end-of-file in *EOF. If DETECT_EOL is TRUE, the end-of-line indicator
- * is detected automatically and returned in *EOL.
- * If DETECT_EOL is FALSE, *EOL must point to the desired end-of-line
+ * end-of-file in *EOF. EOL must point to the desired end-of-line
* indicator. STRINGBUF is allocated in POOL. */
static svn_error_t *
stream_readline(svn_stringbuf_t **stringbuf,
svn_boolean_t *eof,
- const char **eol,
+ const char *eol,
svn_stream_t *stream,
- svn_boolean_t detect_eol,
apr_pool_t *pool)
{
*eof = FALSE;
@@ -494,15 +473,14 @@ stream_readline(svn_stringbuf_t **string
* EOL we are looking for. Optimize that common case.
*/
if (svn_stream_supports_mark(stream) &&
- svn_stream_is_buffered(stream) &&
- !detect_eol)
+ svn_stream_is_buffered(stream))
{
/* We can efficiently read chunks speculatively and reposition the
* stream pointer to the end of the line once we found that.
*/
SVN_ERR(stream_readline_chunky(stringbuf,
eof,
- *eol,
+ eol,
stream,
pool));
}
@@ -514,7 +492,6 @@ stream_readline(svn_stringbuf_t **string
eof,
eol,
stream,
- detect_eol,
pool));
}
@@ -528,8 +505,8 @@ svn_stream_readline(svn_stream_t *stream
svn_boolean_t *eof,
apr_pool_t *pool)
{
- return svn_error_return(stream_readline(stringbuf, eof, &eol, stream,
- FALSE, pool));
+ return svn_error_return(stream_readline(stringbuf, eof, eol, stream,
+ pool));
}
svn_error_t *
@@ -539,8 +516,17 @@ svn_stream_readline_detect_eol(svn_strea
svn_boolean_t *eof,
apr_pool_t *pool)
{
- return svn_error_return(stream_readline(stringbuf, eof, eol, stream,
- TRUE, pool));
+ const char *eol_str = NULL;
+ SVN_ERR(scan_eol(&eol_str, stream, pool));
+ if (eol)
+ *eol = eol_str;
+
+ /* If we encountered EOF before EOL, EOL_STR can be anything. */
+ if (! eol_str)
+ eol_str = APR_EOL_STR;
+
+ return svn_error_return(stream_readline(stringbuf, eof, eol_str, stream,
+ pool));
}