Commit 231ca4fa by lhchavez

Proof-of-concept for a more aggressive GIT_UNUSED()

This adds a `-Wunused-result`-proof `GIT_UNUSED()`, just to demonstrate
that it works. With this, sortedcache.h is now completely
`GIT_WARN_UNUSED_RESULT`-annotated!
parent 9eb17d46
...@@ -43,7 +43,15 @@ ...@@ -43,7 +43,15 @@
# define GIT_ALIGN(x,size) x # define GIT_ALIGN(x,size) x
#endif #endif
#define GIT_UNUSED(x) ((void)(x)) #if defined(__GNUC__)
# define GIT_UNUSED(x) \
do { \
typeof(x) _unused __attribute__((unused)); \
_unused = (x); \
} while (0)
#else
# define GIT_UNUSED(x) ((void)(x))
#endif
/* Define the printf format specifier to use for size_t output */ /* Define the printf format specifier to use for size_t output */
#if defined(_MSC_VER) || defined(__MINGW32__) #if defined(_MSC_VER) || defined(__MINGW32__)
......
...@@ -573,7 +573,7 @@ int git_odb__add_default_backends( ...@@ -573,7 +573,7 @@ int git_odb__add_default_backends(
git_odb *db, const char *objects_dir, git_odb *db, const char *objects_dir,
bool as_alternates, int alternate_depth) bool as_alternates, int alternate_depth)
{ {
size_t i; size_t i = 0;
struct stat st; struct stat st;
ino_t inode; ino_t inode;
git_odb_backend *loose, *packed; git_odb_backend *loose, *packed;
...@@ -582,7 +582,7 @@ int git_odb__add_default_backends( ...@@ -582,7 +582,7 @@ int git_odb__add_default_backends(
* a cross-platform workaround for this */ * a cross-platform workaround for this */
#ifdef GIT_WIN32 #ifdef GIT_WIN32
GIT_UNUSED(i); GIT_UNUSED(i);
GIT_UNUSED(st); GIT_UNUSED(&st);
inode = 0; inode = 0;
#else #else
......
...@@ -122,7 +122,7 @@ static int packed_reload(refdb_fs_backend *backend) ...@@ -122,7 +122,7 @@ static int packed_reload(refdb_fs_backend *backend)
*/ */
if (error <= 0) { if (error <= 0) {
if (error == GIT_ENOTFOUND) { if (error == GIT_ENOTFOUND) {
git_sortedcache_clear(backend->refcache, true); GIT_UNUSED(git_sortedcache_clear(backend->refcache, true));
git_error_clear(); git_error_clear();
error = 0; error = 0;
} }
...@@ -131,7 +131,7 @@ static int packed_reload(refdb_fs_backend *backend) ...@@ -131,7 +131,7 @@ static int packed_reload(refdb_fs_backend *backend)
/* At this point, refresh the packed refs from the loaded buffer. */ /* At this point, refresh the packed refs from the loaded buffer. */
git_sortedcache_clear(backend->refcache, false); GIT_UNUSED(git_sortedcache_clear(backend->refcache, false));
scan = (char *)packedrefs.ptr; scan = (char *)packedrefs.ptr;
eof = scan + packedrefs.size; eof = scan + packedrefs.size;
...@@ -219,7 +219,7 @@ static int packed_reload(refdb_fs_backend *backend) ...@@ -219,7 +219,7 @@ static int packed_reload(refdb_fs_backend *backend)
parse_failed: parse_failed:
git_error_set(GIT_ERROR_REFERENCE, "corrupted packed references file"); git_error_set(GIT_ERROR_REFERENCE, "corrupted packed references file");
git_sortedcache_clear(backend->refcache, false); GIT_UNUSED(git_sortedcache_clear(backend->refcache, false));
git_sortedcache_wunlock(backend->refcache); git_sortedcache_wunlock(backend->refcache);
git_buf_dispose(&packedrefs); git_buf_dispose(&packedrefs);
......
...@@ -133,7 +133,8 @@ void git_sortedcache_updated(git_sortedcache *sc); ...@@ -133,7 +133,8 @@ void git_sortedcache_updated(git_sortedcache *sc);
* If `wlock` is true, grabs write lock and releases when done, otherwise * If `wlock` is true, grabs write lock and releases when done, otherwise
* you should already be holding a write lock when you call this. * you should already be holding a write lock when you call this.
*/ */
int git_sortedcache_clear(git_sortedcache *sc, bool wlock); GIT_WARN_UNUSED_RESULT int git_sortedcache_clear(
git_sortedcache *sc, bool wlock);
/* Find and/or insert item, returning pointer to item data. /* Find and/or insert item, returning pointer to item data.
* You should already be holding the write lock when you call this. * You should already be holding the write lock when you call this.
......
...@@ -52,7 +52,7 @@ void test_core_sha1__detect_collision_attack(void) ...@@ -52,7 +52,7 @@ void test_core_sha1__detect_collision_attack(void)
git_oid oid, expected; git_oid oid, expected;
#ifdef GIT_SHA1_COLLISIONDETECT #ifdef GIT_SHA1_COLLISIONDETECT
GIT_UNUSED(expected); GIT_UNUSED(&expected);
cl_git_fail(sha1_file(&oid, FIXTURE_DIR "/shattered-1.pdf")); cl_git_fail(sha1_file(&oid, FIXTURE_DIR "/shattered-1.pdf"));
cl_assert_equal_s("SHA1 collision attack detected", git_error_last()->message); cl_assert_equal_s("SHA1 collision attack detected", git_error_last()->message);
#else #else
......
...@@ -54,7 +54,7 @@ void test_core_sortedcache__name_only(void) ...@@ -54,7 +54,7 @@ void test_core_sortedcache__name_only(void)
cl_assert_equal_i( cl_assert_equal_i(
GIT_ENOTFOUND, git_sortedcache_lookup_index(&pos, sc, "abc")); GIT_ENOTFOUND, git_sortedcache_lookup_index(&pos, sc, "abc"));
git_sortedcache_clear(sc, true); cl_git_pass(git_sortedcache_clear(sc, true));
cl_assert_equal_sz(0, git_sortedcache_entrycount(sc)); cl_assert_equal_sz(0, git_sortedcache_entrycount(sc));
cl_assert(git_sortedcache_entry(sc, 0) == NULL); cl_assert(git_sortedcache_entry(sc, 0) == NULL);
...@@ -154,7 +154,7 @@ void test_core_sortedcache__in_memory(void) ...@@ -154,7 +154,7 @@ void test_core_sortedcache__in_memory(void)
cl_assert_equal_i(0, free_count); cl_assert_equal_i(0, free_count);
git_sortedcache_clear(sc, true); cl_git_pass(git_sortedcache_clear(sc, true));
cl_assert_equal_i(5, free_count); cl_assert_equal_i(5, free_count);
...@@ -247,7 +247,7 @@ static void sortedcache_test_reload(git_sortedcache *sc) ...@@ -247,7 +247,7 @@ static void sortedcache_test_reload(git_sortedcache *sc)
cl_assert(git_sortedcache_lockandload(sc, &buf) > 0); cl_assert(git_sortedcache_lockandload(sc, &buf) > 0);
git_sortedcache_clear(sc, false); /* clear once we already have lock */ cl_git_pass(git_sortedcache_clear(sc, false)); /* clear once we already have lock */
for (scan = buf.ptr; *scan; scan = after + 1) { for (scan = buf.ptr; *scan; scan = after + 1) {
int val = strtol(scan, &after, 0); int val = strtol(scan, &after, 0);
......
...@@ -318,11 +318,9 @@ void test_index_addall__files_in_folders(void) ...@@ -318,11 +318,9 @@ void test_index_addall__files_in_folders(void)
void test_index_addall__hidden_files(void) void test_index_addall__hidden_files(void)
{ {
#ifdef GIT_WIN32
git_index *index; git_index *index;
GIT_UNUSED(index);
#ifdef GIT_WIN32
addall_create_test_repo(true); addall_create_test_repo(true);
cl_git_pass(git_repository_index(&index, g_repo)); cl_git_pass(git_repository_index(&index, g_repo));
......
...@@ -49,13 +49,10 @@ void test_index_bypath__add_submodule_unregistered(void) ...@@ -49,13 +49,10 @@ void test_index_bypath__add_submodule_unregistered(void)
void test_index_bypath__add_hidden(void) void test_index_bypath__add_hidden(void)
{ {
#ifdef GIT_WIN32
const git_index_entry *entry; const git_index_entry *entry;
bool hidden; bool hidden;
GIT_UNUSED(entry);
GIT_UNUSED(hidden);
#ifdef GIT_WIN32
cl_git_mkfile("submod2/hidden_file", "you can't see me"); cl_git_mkfile("submod2/hidden_file", "you can't see me");
cl_git_pass(git_win32__hidden(&hidden, "submod2/hidden_file")); cl_git_pass(git_win32__hidden(&hidden, "submod2/hidden_file"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment