Re: [PATCH] extend the SVN_ERR macro with a cleanup statement parameter
Hi Danny, Just thought I would give you a gentle poke and see if you were still pursuing this submission, or not? On 14/02/2011, at 7:37 AM, Branko Čibej wrote: On 13.02.2011 21:28, Bert Huijben wrote: -Original Message- From: Danny Trebbien [mailto:dtrebb...@gmail.com] Sent: zondag 13 februari 2011 21:00 To: Subversion Development Subject: [PATCH] extend the SVN_ERR macro with a cleanup statement parameter 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 It's much easier to use a helper function or (if that is impossible) a goto to get specialized error handling. This macro is in use everywhere inside Subversion and in many third party tools using our libraries so I would recommend to not change it. Another option is a file local macro that performs your specialized cleanup. All those options are used in multiple places in our codebase. Just write your test as a wrapper around the real test functionality, set and reset the locale in the wrapper and pass through whatever error code you receive. Don't change the semantics of a public macro, especialy not in a backwards-incompatible way. -- Brane
Re: [PATCH] extend the SVN_ERR macro with a cleanup statement parameter
On Sun, Feb 27, 2011 at 3:45 AM, Gavin Beau Baumanis gav...@thespidernet.com wrote: Hi Danny, Just thought I would give you a gentle poke and see if you were still pursuing this submission, or not? Oh, no. I ended up using Brane's suggestion of writing a wrapper function (https://github.com/dtrebbien/subversion/commit/edc2dd1e9e94709e179f43e5f0948cb27433a908).
[PATCH] extend the SVN_ERR macro with a cleanup statement parameter
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 ttdo { ... } 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. *
RE: [PATCH] extend the SVN_ERR macro with a cleanup statement parameter
-Original Message- From: Danny Trebbien [mailto:dtrebb...@gmail.com] Sent: zondag 13 februari 2011 21:00 To: Subversion Development Subject: [PATCH] extend the SVN_ERR macro with a cleanup statement parameter 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 It's much easier to use a helper function or (if that is impossible) a goto to get specialized error handling. This macro is in use everywhere inside Subversion and in many third party tools using our libraries so I would recommend to not change it. Another option is a file local macro that performs your specialized cleanup. All those options are used in multiple places in our codebase. Bert
Re: [PATCH] extend the SVN_ERR macro with a cleanup statement parameter
On 13.02.2011 21:28, Bert Huijben wrote: -Original Message- From: Danny Trebbien [mailto:dtrebb...@gmail.com] Sent: zondag 13 februari 2011 21:00 To: Subversion Development Subject: [PATCH] extend the SVN_ERR macro with a cleanup statement parameter 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 It's much easier to use a helper function or (if that is impossible) a goto to get specialized error handling. This macro is in use everywhere inside Subversion and in many third party tools using our libraries so I would recommend to not change it. Another option is a file local macro that performs your specialized cleanup. All those options are used in multiple places in our codebase. Just write your test as a wrapper around the real test functionality, set and reset the locale in the wrapper and pass through whatever error code you receive. Don't change the semantics of a public macro, especialy not in a backwards-incompatible way. -- Brane