You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by da...@apache.org on 2012/04/24 11:40:45 UTC

svn commit: r1329609 - in /subversion/trunk/subversion: include/svn_error.h libsvn_fs/fs-loader.c

Author: danielsh
Date: Tue Apr 24 09:40:45 2012
New Revision: 1329609

URL: http://svn.apache.org/viewvc?rev=1329609&view=rev
Log:
Follow-up to r1329601:

* subversion/include/svn_error.h
  (SVN_ERR_ASSERT2): New.

* subversion/libsvn_fs/fs-loader.c
  (svn_fs_commit_txn): Use new macro to not-leak errors upon asserting.

Modified:
    subversion/trunk/subversion/include/svn_error.h
    subversion/trunk/subversion/libsvn_fs/fs-loader.c

Modified: subversion/trunk/subversion/include/svn_error.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_error.h?rev=1329609&r1=1329608&r2=1329609&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_error.h (original)
+++ subversion/trunk/subversion/include/svn_error.h Tue Apr 24 09:40:45 2012
@@ -460,6 +460,29 @@ svn_error_t *svn_error_purge_tracing(svn
     abort();                                                 \
   } while (1)
 
+/** Like SVN_ERR_ASSERT(), but append ERR to the returned error chain.
+ *
+ * If EXPR is true, return a malfunction error whose chain includes ERR.
+ * If EXPR is false, do nothing.  (In particular, this does not clear ERR.)
+ *
+ * @since New in 1.8.
+ */
+#ifdef __clang_analyzer__
+#include <assert.h>
+/* Just ignore ERR.  If the assert triggers, it'll be our least concern. */
+#define SVN_ERR_ASSERT2(expr, err)       assert((expr))
+#else
+#define SVN_ERR_ASSERT2(expr, err)                                      \
+  do {                                                                  \
+    if (!(expr)) {                                                      \
+      return svn_error_compose_create(                                  \
+               svn_error__malfunction(TRUE, __FILE__, __LINE__, #expr), \
+               (err));                                                  \
+    }                                                                   \
+  } while (0)
+#endif
+
+
 /** Check that a condition is true: if not, report an error and possibly
  * terminate the program.
  *

Modified: subversion/trunk/subversion/libsvn_fs/fs-loader.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_fs/fs-loader.c?rev=1329609&r1=1329608&r2=1329609&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_fs/fs-loader.c (original)
+++ subversion/trunk/subversion/libsvn_fs/fs-loader.c Tue Apr 24 09:40:45 2012
@@ -661,12 +661,13 @@ svn_fs_commit_txn(const char **conflict_
 
 #ifdef SVN_DEBUG
   /* Check postconditions. */
-  /* ### TODO: don't leak an error when these trigger */
   if (conflict_p)
     {
-      SVN_ERR_ASSERT(! (SVN_IS_VALID_REVNUM(*new_rev) && *conflict_p != NULL));
-      SVN_ERR_ASSERT((*conflict_p != NULL)
-                     == (err && err->apr_err == SVN_ERR_FS_CONFLICT));
+      SVN_ERR_ASSERT2(! (SVN_IS_VALID_REVNUM(*new_rev) && *conflict_p != NULL),
+                      err);
+      SVN_ERR_ASSERT2((*conflict_p != NULL)
+                      == (err && err->apr_err == SVN_ERR_FS_CONFLICT),
+                      err);
     }
 #endif
 



Re: svn commit: r1329609 - in /subversion/trunk/subversion: include/svn_error.h libsvn_fs/fs-loader.c

Posted by Greg Stein <gs...@gmail.com>.
On Apr 25, 2012 7:40 AM, "Daniel Shahaf" <da...@elego.de> wrote:
>
> Bert Huijben wrote on Wed, Apr 25, 2012 at 12:52:07 +0200:
> >
> >
> > > -----Original Message-----
> > > From: Daniel Shahaf [mailto:danielsh@elego.de]
> > > Sent: woensdag 25 april 2012 11:46
> > > To: Greg Stein
> > > Cc: Hyrum K Wright; dev@subversion.apache.org
> > > Subject: Re: svn commit: r1329609 - in /subversion/trunk/subversion:
> > > include/svn_error.h libsvn_fs/fs-loader.c
> >
> >
> > > if (!(expr)) {
> > >   svn_error_t *e1 = (err), *e2 = svn_error__malfunction();
> > >   return (e1 ? svn_error_compose_create(e2, e1) : e2);
> > > }
> >
> > svn_error_compose_create() has no problems with NULL arguments.
> >
>
> I know, I think Greg's concern was calling it too often (as opposed to
> calling it with NULL)

Yup. Especially after we just got done talking about how these remain in
production code.

Cheers,
-g

Re: svn commit: r1329609 - in /subversion/trunk/subversion: include/svn_error.h libsvn_fs/fs-loader.c

Posted by 'Daniel Shahaf' <da...@elego.de>.
Bert Huijben wrote on Wed, Apr 25, 2012 at 12:52:07 +0200:
> 
> 
> > -----Original Message-----
> > From: Daniel Shahaf [mailto:danielsh@elego.de]
> > Sent: woensdag 25 april 2012 11:46
> > To: Greg Stein
> > Cc: Hyrum K Wright; dev@subversion.apache.org
> > Subject: Re: svn commit: r1329609 - in /subversion/trunk/subversion:
> > include/svn_error.h libsvn_fs/fs-loader.c
> 
> 
> > if (!(expr)) {
> >   svn_error_t *e1 = (err), *e2 = svn_error__malfunction();
> >   return (e1 ? svn_error_compose_create(e2, e1) : e2);
> > }
> 
> svn_error_compose_create() has no problems with NULL arguments.
> 

I know, I think Greg's concern was calling it too often (as opposed to
calling it with NULL)

> 	Bert
> 

RE: svn commit: r1329609 - in /subversion/trunk/subversion: include/svn_error.h libsvn_fs/fs-loader.c

Posted by Bert Huijben <be...@qqmail.nl>.

> -----Original Message-----
> From: Daniel Shahaf [mailto:danielsh@elego.de]
> Sent: woensdag 25 april 2012 11:46
> To: Greg Stein
> Cc: Hyrum K Wright; dev@subversion.apache.org
> Subject: Re: svn commit: r1329609 - in /subversion/trunk/subversion:
> include/svn_error.h libsvn_fs/fs-loader.c


> if (!(expr)) {
>   svn_error_t *e1 = (err), *e2 = svn_error__malfunction();
>   return (e1 ? svn_error_compose_create(e2, e1) : e2);
> }

svn_error_compose_create() has no problems with NULL arguments.

	Bert


Re: svn commit: r1329609 - in /subversion/trunk/subversion: include/svn_error.h libsvn_fs/fs-loader.c

Posted by Daniel Shahaf <da...@elego.de>.
Greg Stein wrote on Wed, Apr 25, 2012 at 04:35:46 -0400:
> On Wed, Apr 25, 2012 at 04:24, Daniel Shahaf <da...@elego.de> wrote:
> >...
> > SVN_ERR_ASSERT(x) === SVN_ERR_ASSERT(x, SVN_NO_ERROR)
> >
> > Still, I would prefer not to deprecate SVN_ERR_ASSERT() because that
> > would kill readability for the 99% common case.  So:
> >
> > - I'll redefine SVN_ERR_ASSERT() as above
> 
> Does that imply a compose_create() call where arg2 is always SVN_NO_ERROR? Ugh.
> 

Yes.  We could restructure things though -- implement
svn_error_compose_create() as a macro, or have SVN_ERR_ASSERT2() (in its
new name) optimize for the case that ERR is NULL:

if (!(expr)) {
  svn_error_t *e1 = (err), *e2 = svn_error__malfunction();
  return (e1 ? svn_error_compose_create(e2, e1) : e2);
}

Re: svn commit: r1329609 - in /subversion/trunk/subversion: include/svn_error.h libsvn_fs/fs-loader.c

Posted by Julian Foad <ju...@btopenworld.com>.
Greg Stein wrote:

> On Wed, Apr 25, 2012 at 04:24, Daniel Shahaf <da...@elego.de> wrote:
>>  - I'll rename SVN_ERR_ASSERT2() to SVN_ERR_ASSERT_CHAIN()
> 
> +1
> 
> (I'd also be +0 for SVN_ERR_ASSERT_C())

+1 on a shorter name, since brevity is one of the important qualities of assertion statements.

SVN_ERR_ASSERT_E for 'with an Error' may be better, as 'C' is often used for 'const' as in APR_UINT64_C and may be more descriptive than 'chain'.

(While in general we should use full words in identifiers, that's more 
important with the many identifiers that a reader may not have seen 
recently, e.g. API functions, and less important with the few ubiquitous
 identifiers such as svn_revnum_t, SVN_ERR, SVN_ERR_W.)

- Julian

Re: svn commit: r1329609 - in /subversion/trunk/subversion: include/svn_error.h libsvn_fs/fs-loader.c

Posted by Greg Stein <gs...@gmail.com>.
On Wed, Apr 25, 2012 at 04:24, Daniel Shahaf <da...@elego.de> wrote:
>...
> SVN_ERR_ASSERT(x) === SVN_ERR_ASSERT(x, SVN_NO_ERROR)
>
> Still, I would prefer not to deprecate SVN_ERR_ASSERT() because that
> would kill readability for the 99% common case.  So:
>
> - I'll redefine SVN_ERR_ASSERT() as above

Does that imply a compose_create() call where arg2 is always SVN_NO_ERROR? Ugh.

> - I'll rename SVN_ERR_ASSERT2() to SVN_ERR_ASSERT_CHAIN()

+1

(I'd also be +0 for SVN_ERR_ASSERT_C())

Cheers,
-g

Re: svn commit: r1329609 - in /subversion/trunk/subversion: include/svn_error.h libsvn_fs/fs-loader.c

Posted by Daniel Shahaf <da...@elego.de>.
Hyrum K Wright wrote on Tue, Apr 24, 2012 at 18:36:28 -0500:
> On Tue, Apr 24, 2012 at 4:40 AM,  <da...@apache.org> wrote:
> > Author: danielsh
> > Date: Tue Apr 24 09:40:45 2012
> > New Revision: 1329609
> >
> > URL: http://svn.apache.org/viewvc?rev=1329609&view=rev
> > Log:
> > Follow-up to r1329601:
> >
> > * subversion/include/svn_error.h
> >  (SVN_ERR_ASSERT2): New.
> 
> Our standard convention is that $SYMBOL(n) deprecates $SYMBOL(n-1).
> Does this deprecate the existing SVN_ERR_ASSERT() macro, or provide
> additional / different functionality?  If the former please note it as
> such, and we should attempt to convert the code to use the new macro.
> If the latter, please rename to something more descriptive.
> 

SVN_ERR_ASSERT(x) === SVN_ERR_ASSERT(x, SVN_NO_ERROR)

Still, I would prefer not to deprecate SVN_ERR_ASSERT() because that
would kill readability for the 99% common case.  So:

- I'll redefine SVN_ERR_ASSERT() as above
- I'll rename SVN_ERR_ASSERT2() to SVN_ERR_ASSERT_CHAIN()


> -Hyrum
> 
> > ...
> 
> 
> 
> -- 
> 
> uberSVN: Apache Subversion Made Easy
> http://www.uberSVN.com/

Re: svn commit: r1329609 - in /subversion/trunk/subversion: include/svn_error.h libsvn_fs/fs-loader.c

Posted by Hyrum K Wright <hy...@wandisco.com>.
On Tue, Apr 24, 2012 at 4:40 AM,  <da...@apache.org> wrote:
> Author: danielsh
> Date: Tue Apr 24 09:40:45 2012
> New Revision: 1329609
>
> URL: http://svn.apache.org/viewvc?rev=1329609&view=rev
> Log:
> Follow-up to r1329601:
>
> * subversion/include/svn_error.h
>  (SVN_ERR_ASSERT2): New.

Our standard convention is that $SYMBOL(n) deprecates $SYMBOL(n-1).
Does this deprecate the existing SVN_ERR_ASSERT() macro, or provide
additional / different functionality?  If the former please note it as
such, and we should attempt to convert the code to use the new macro.
If the latter, please rename to something more descriptive.

-Hyrum

> ...



-- 

uberSVN: Apache Subversion Made Easy
http://www.uberSVN.com/

Re: svn commit: r1329609 - in /subversion/trunk/subversion: include/svn_error.h libsvn_fs/fs-loader.c

Posted by DanielShahaf <da...@elego.de>.
Julian Foad wrote on Tue, Apr 24, 2012 at 16:14:46 +0100:
> danielsh@apache.org wrote:
> > + * If EXPR is true, return a malfunction error whose chain includes ERR.
> > + * If EXPR is false, do nothing.  (In particular, this does not clear ERR.)
> 
> True and false are the wrong way around.

Thanks, r1329796.

Re: svn commit: r1329609 - in /subversion/trunk/subversion: include/svn_error.h libsvn_fs/fs-loader.c

Posted by Julian Foad <ju...@btopenworld.com>.
danielsh@apache.org wrote:

> URL: http://svn.apache.org/viewvc?rev=1329609&view=rev
> Log:
> Follow-up to r1329601:
> 
> * subversion/include/svn_error.h
>   (SVN_ERR_ASSERT2): New.
> 
> * subversion/libsvn_fs/fs-loader.c
>   (svn_fs_commit_txn): Use new macro to not-leak errors upon asserting.
> 
> Modified: subversion/trunk/subversion/include/svn_error.h
> ==============================================================================
> +/** Like SVN_ERR_ASSERT(), but append ERR to the returned error chain.
> + *
> + * If EXPR is true, return a malfunction error whose chain includes ERR.
> + * If EXPR is false, do nothing.  (In particular, this does not clear ERR.)

True and false are the wrong way around.

- Julian


> + *
> + * @since New in 1.8.
> + */
> +#ifdef __clang_analyzer__
> +#include <assert.h>
> +/* Just ignore ERR.  If the assert triggers, it'll be our least concern. */
> +#define SVN_ERR_ASSERT2(expr, err)       assert((expr))
> +#else
> +#define SVN_ERR_ASSERT2(expr, err)                                     \
> +  do {                                                                 \
> +    if (!(expr)) {                                                     \
> +      return svn_error_compose_create(                                 \
> +               svn_error__malfunction(TRUE, __FILE__, __LINE__, #expr), \
> +               (err));                                                  \
> +    }                                                                   \
> +  } while (0)
> +#endif