Attached is a small patch to extend the SVN_ERR macro with another parameter, a cleanup statement, that is executed before the error generated by EXPR (if not SVN_NO_ERROR) is returned. Also attached is a log message.
I plan on using this in a test of svn_subst_translate_string2() in which I need to reset the locale to whatever it was before the test began. See: http://thread.gmane.org/gmane.comp.version-control.subversion.devel/125782
[[[ Extend the SVN_ERR macro with another parameter, a cleanup statement, that is executed before returning in case of error. * subversion/include/svn_error.h (SVN_ERR_EX): New macro. Similar to SVN_ERR, it accepts an additional parameter for a cleanup statement to execute before returning an error. (SVN_ERR): Expand to SVN_ERR_EX with the same expression, and a no-op for the cleanup statement. ]]]
Index: subversion/include/svn_error.h =================================================================== --- subversion/include/svn_error.h (revision 1070074) +++ subversion/include/svn_error.h (working copy) @@ -275,8 +275,8 @@ svn_handle_warning(FILE *stream, /** A statement macro for checking error values. * - * Evaluate @a expr. If it yields an error, return that error from the - * current function. Otherwise, continue. + * Evaluate @a expr. If it yields an error, execute the cleanup statement and + * return that error from the current function. Otherwise, continue. * * The <tt>do { ... } while (0)</tt> wrapper has no semantic effect, * but it makes this macro syntactically equivalent to the expression @@ -284,20 +284,31 @@ svn_handle_warning(FILE *stream, * * @code * if (a) - * SVN_ERR(some operation); + * SVN_ERR_EX(some operation, some statement); * else * foo; * @endcode * * would not mean what they appear to. + * + * @since New in 1.7. */ -#define SVN_ERR(expr) \ +#define SVN_ERR_EX(expr, cleanup_stmt) \ do { \ svn_error_t *svn_err__temp = (expr); \ if (svn_err__temp) \ - return svn_error_return(svn_err__temp); \ + { \ + { cleanup_stmt ; } \ + return svn_error_return(svn_err__temp); \ + } \ } while (0) +/** A statement macro for checking error values. + * + * Similar to SVN_ERR_EX except that the cleanup statement is a no-op. + */ +#define SVN_ERR(expr) SVN_ERR_EX(expr, ((void) 0)) + /** * A statement macro for returning error values. *