Author: kotkov
Date: Fri May 6 12:48:27 2016
New Revision: 1742540
URL: http://svn.apache.org/viewvc?rev=1742540&view=rev
Log:
Remove code duplication by factoring out a common macro.
* subversion/include/private/svn_sqlite.h
(SVN_SQLITE__ERR_CLOSE): New, factored out from ...
* subversion/libsvn_subr/sqlite.c
(SVN_ERR_CLOSE): ...here.
(svn_sqlite__open): Use the new macro.
* subversion/libsvn_fs_fs/rep-cache.c
(SVN_ERR_CLOSE): Remove.
(open_rep_cache): Use the new macro.
Modified:
subversion/trunk/subversion/include/private/svn_sqlite.h
subversion/trunk/subversion/libsvn_fs_fs/rep-cache.c
subversion/trunk/subversion/libsvn_subr/sqlite.c
Modified: subversion/trunk/subversion/include/private/svn_sqlite.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/private/svn_sqlite.h?rev=1742540&r1=1742539&r2=1742540&view=diff
==============================================================================
--- subversion/trunk/subversion/include/private/svn_sqlite.h (original)
+++ subversion/trunk/subversion/include/private/svn_sqlite.h Fri May 6 12:48:27 2016
@@ -555,6 +555,15 @@ svn_sqlite__hotcopy(const char *src_path
const char *dst_path,
apr_pool_t *scratch_pool);
+/* Evaluate the expression EXPR. If any error is returned, close
+ * the connection in DB. */
+#define SVN_SQLITE__ERR_CLOSE(expr, db) do \
+{ \
+ svn_error_t *svn__err = (expr); \
+ if (svn__err) \
+ return svn_error_compose_create(svn__err, svn_sqlite__close(db)); \
+} while (0)
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
Modified: subversion/trunk/subversion/libsvn_fs_fs/rep-cache.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_fs_fs/rep-cache.c?rev=1742540&r1=1742539&r2=1742540&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_fs_fs/rep-cache.c (original)
+++ subversion/trunk/subversion/libsvn_fs_fs/rep-cache.c Fri May 6 12:48:27 2016
@@ -51,13 +51,6 @@ path_rep_cache_db(const char *fs_path,
return svn_dirent_join(fs_path, REP_CACHE_DB_NAME, result_pool);
}
-#define SVN_ERR_CLOSE(x, db) do \
-{ \
- svn_error_t *svn__err = (x); \
- if (svn__err) \
- return svn_error_compose_create(svn__err, svn_sqlite__close(db)); \
-} while (0)
-
/** Library-private API's. **/
@@ -107,12 +100,15 @@ open_rep_cache(void *baton,
0, NULL, 0,
fs->pool, pool));
- SVN_ERR_CLOSE(svn_sqlite__read_schema_version(&version, sdb, pool), sdb);
+ SVN_SQLITE__ERR_CLOSE(svn_sqlite__read_schema_version(&version, sdb, pool),
+ sdb);
if (version < REP_CACHE_SCHEMA_FORMAT)
{
/* Must be 0 -- an uninitialized (no schema) database. Create
the schema. Results in schema version of 1. */
- SVN_ERR_CLOSE(svn_sqlite__exec_statements(sdb, STMT_CREATE_SCHEMA), sdb);
+ SVN_SQLITE__ERR_CLOSE(svn_sqlite__exec_statements(sdb,
+ STMT_CREATE_SCHEMA),
+ sdb);
}
/* This is used as a flag that the database is available so don't
Modified: subversion/trunk/subversion/libsvn_subr/sqlite.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/sqlite.c?rev=1742540&r1=1742539&r2=1742540&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/sqlite.c (original)
+++ subversion/trunk/subversion/libsvn_subr/sqlite.c Fri May 6 12:48:27 2016
@@ -213,13 +213,6 @@ struct svn_sqlite__value_t
sqlite_err__temp, msg); \
} while (0)
-#define SVN_ERR_CLOSE(x, db) do \
-{ \
- svn_error_t *svn__err = (x); \
- if (svn__err) \
- return svn_error_compose_create(svn__err, svn_sqlite__close(db)); \
-} while (0)
-
/* Time (in milliseconds) to wait for sqlite locks before giving up. */
#define BUSY_TIMEOUT 10000
@@ -1141,7 +1134,7 @@ svn_sqlite__open(svn_sqlite__db_t **db,
sqlite3_profile((*db)->db3, sqlite_profiler, (*db)->db3);
#endif
- SVN_ERR_CLOSE(exec_sql(*db,
+ SVN_SQLITE__ERR_CLOSE(exec_sql(*db,
/* The default behavior of the LIKE operator is to ignore case
for ASCII characters. Hence, by default 'a' LIKE 'A' is true.
The case_sensitive_like pragma installs a new application-
@@ -1180,8 +1173,8 @@ svn_sqlite__open(svn_sqlite__db_t **db,
/* When running in debug mode, enable the checking of foreign key
constraints. This has possible performance implications, so we don't
bother to do it for production...for now. */
- SVN_ERR_CLOSE(exec_sql(*db, "PRAGMA foreign_keys=ON;"),
- *db);
+ SVN_SQLITE__ERR_CLOSE(exec_sql(*db, "PRAGMA foreign_keys=ON;"),
+ *db);
#endif
#ifdef SVN_SQLITE_REVERSE_UNORDERED_SELECTS
@@ -1189,8 +1182,8 @@ svn_sqlite__open(svn_sqlite__db_t **db,
clause to emit their results in the reverse order of what they normally
would. This can help detecting invalid assumptions about the result
order.*/
- SVN_ERR_CLOSE(exec_sql(*db, "PRAGMA reverse_unordered_selects=ON;"),
- *db);
+ SVN_SQLITE__ERR_CLOSE(exec_sql(*db, "PRAGMA reverse_unordered_selects=ON;"),
+ *db);
#endif
/* Store temporary tables in RAM instead of in temporary files, but don't
|