Greg Stein wrote on Tue, May 17, 2011 at 07:12:58 -0400:
> On Tue, May 17, 2011 at 06:55,  <danie...@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

Reply via email to