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

Re: svn commit: r1104124 - in /subversion/trunk/subversion: include/svn_io.h libsvn_subr/deprecated.c libsvn_subr/io.c

From: Daniel Shahaf <d.s_at_daniel.shahaf.name>
Date: Tue, 17 May 2011 15:13:25 +0200

Greg Stein wrote on Tue, May 17, 2011 at 07:12:58 -0400:
> On Tue, May 17, 2011 at 06:55, <danielsh_at_apache.org> wrote:
> >...
> > +++ subversion/trunk/subversion/libsvn_subr/deprecated.c Tue May 17 10:55:51 2011
> > @@ -630,6 +630,17 @@ svn_opt_print_generic_help(const char *h
> >
> >  /*** From io.c ***/
> >  svn_error_t *
> > +svn_io_file_create(const char *file,
> > +                   const char *contents,
> > +                   apr_pool_t *pool)
> > +{
> > +  const svn_string_t *contents_string;
> > +
> > +  contents_string = (contents ? svn_string_create(contents, pool) : NULL);
> > +  return svn_io_file_create2(file, contents_string, pool);
>
> contents_string can go on the stack, rather than allocated:
>
> contents_string.data = contents;
> contents_string.len = strlen(contents);
> return svn_error_return(svn_io_file_create2(file, &contents_string, pool);
>
> ... tho it makes the NULL concept a bit more difficult.
>

I didn't realize that svn_string_*create() didn't do that for me.

The patch seems straightforward,
[[[
Index: subversion/libsvn_subr/deprecated.c
===================================================================
--- subversion/libsvn_subr/deprecated.c (revision 1104124)
+++ subversion/libsvn_subr/deprecated.c (working copy)
@@ -634,10 +634,17 @@ svn_io_file_create(const char *file,
                    const char *contents,
                    apr_pool_t *pool)
 {
- const svn_string_t *contents_string;
+ if (contents && *contents)
+ {
+ const svn_string_t contents_string;
+ contents_string.data = contents;
+ contents_string.len = strlen(contents);
+ return svn_io_file_create2(file, &contents_string, pool);
+ }
+ else
+ {
+ return svn_io_file_create2(file, NULL, pool);
+ }
-
- contents_string = (contents ? svn_string_create(contents, pool) : NULL);
- return svn_io_file_create2(file, contents_string, pool);
 }
 
 svn_error_t *
]]]

but I wonder if we shouldn't be teaching the svn_string_create() API to
optionally return a shallow copy. (which isn't as good as stack, but
still saves the pstrdup())

> >...
>
> Cheers,
> -g
Received on 2011-05-17 14:14:06 CEST

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.