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

svn_cmdline_init EXC_BAD_ACCESS... and svn_pool_create_ex usage of abort

From: señior ¿tyrtle? <machtyrtle_at_gmail.com>
Date: 2005-04-25 09:15:04 CEST

1. svn_cmdline_init might write to a null file if it fails to open file
descriptors for std[in,out,err].
This patch fixes it.

2. It also contains:

int svn_cmdline_init2 (const char *progname, const char *file_path, int fd);

Similar to svn_cmdline_init(), but can be safely called from code not
compiled with [the same compiler as] libsvn-subr.

If file_path is non-null, write any intialization messages to the file
found or created at this location. Otherwise write to; stdout if fd==1,
stderr if fd==2.

Files will be opened with "a+", to preserve any contents they have before
calling. If initialization was succesfull and the file did not previously
exist, it will be removed.

3. svn_pool_create_ex doesn¹t make so much sense to be registering abort ()
to be called when apr cant alloc any more memory. Subversion is a
library...maybe an app will be using it as such and doesn't want it to tear
everything down when it fails. How about:

apr_pool_t *
svn_pool_create_ex2 (apr_pool_t *parent_pool,
    apr_allocator_t *allocator,
    apr_abortfunc_t abort_fun);

I realize I could use apr_pool_create_ex...but doesn't the existance of
svn_pool_create_ex imply that libsvn might be doing things behind the
scenes. And I'd rather not be learning two API's until I decide to.

4. So I don¹t get burnt: The subversion API is by far the easiest I've ever
used.

--- cmdline.c Mon Apr 25 05:09:25 2005
+++ cmdline.c Mon Apr 25 07:27:41 2005
@@ -76,7 +76,8 @@
         (fstat (1, &st) == -1 && open ("/dev/null", O_WRONLY) == -1) ||
         (fstat (2, &st) == -1 && open ("/dev/null", O_WRONLY) == -1))
       {
- fprintf(error_stream, "%s: error: cannot open '/dev/null'\n",
+ if (error_stream)
+ fprintf(error_stream, "%s: error: cannot open '/dev/null'\n",
                 progname);
         return EXIT_FAILURE;
       }
@@ -227,6 +228,48 @@
   return EXIT_SUCCESS;
 }
 
+int
+svn_cmdline_init2 (const char *progname, const char *file_path, int fd)
+{
+ FILE *error_stream;
+ int rval, existed;
+
+ if (file_path)
+ {
+ existed = access(file_path, F_OK)==0;
+
+ error_stream = fopen(file_path, "a+");
+ if (!error_stream)
+ return EXIT_FAILURE;
+ }
+ else
+ {
+ switch (fd)
+ {
+ case 1:
+ error_stream = stdout;
+ break;
+
+ case 2:
+ error_stream = stderr;
+ break;
+
+ default:
+ error_stream = NULL;
+ }
+ }
+
+ rval = svn__cmdline_init(progname, error_stream);
+
+ if (file_path)
+ {
+ fclose(error_stream);
+ if ( rval==EXIT_SUCCESS && ! existed)
+ unlink(file_path);
+ }
+
+ return rval;
+}
 
 svn_error_t *
 svn_cmdline_cstring_from_utf8 (const char **dest,

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Received on Sun Apr 24 20:00:12 2005

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.