git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] read-cache.c: fix a sparse warning

From
Ramsay Jones <ramsay@ramsayjones.plus.com>
Date
Sep 14, 2018, 23:29 UTC
Message-ID
<c92b2f25-315d-141b-8974-dd05d7fd2b9e@ramsayjones.plus.com>

At one time, the POSIX standard required the type used to represent a thread handle (pthread_t) be an arithmetic type. This is no longer the case, probably because different platforms used to regularly ignore that requirement. For example, on cygwin a pthread_t is a pointer to a structure (a quite common choice), whereas on Linux it is defined as an 'unsigned long int'.

On cygwin, but not on Linux, 'sparse' currently complains about an initialiser used on a 'struct load_index_extensions' variable, whose first field may be a pthread handle (if not compiled with NO_PTHREADS set).

In order to fix the warning, move the (conditional) pthread field to the end of the struct and change the initialiser to use a NULL, since the new (unconditional) first field is a pointer type.

Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
---
Hi Ben,

If you need to re-roll your 'bp/read-cache-parallel' branch, could you please squash this into the relevant patch (commit a090af334, "read-cache: load cache extensions on a worker thread", 2018-09-12).

Thanks.

ATB, Ramsay Jones

 read-cache.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index b27dc01696..6254291742 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1908,13 +1908,13 @@ static void write_eoie_extension(struct strbuf *sb, git_hash_ctx *eoie_context,
 
 struct load_index_extensions
 {
-#ifndef NO_PTHREADS
-	pthread_t pthread;
-#endif
 	struct index_state *istate;
 	const char *mmap;
 	size_t mmap_size;
 	unsigned long src_offset;
+#ifndef NO_PTHREADS
+	pthread_t pthread;
+#endif
 };
 
 static void *load_index_extensions(void *data)
@@ -2145,7 +2145,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
 	const struct cache_header *hdr;
 	const char *mmap;
 	size_t mmap_size;
-	struct load_index_extensions p = { 0 };
+	struct load_index_extensions p = { NULL };
 	unsigned long extension_offset = 0;
 #ifndef NO_PTHREADS
 	int cpus, nr_threads;
-- 
2.19.0
Next: Eric Sunshine
Message 1 of 5 in “read-cache.c: fix a sparse warning”
  1. read-cache.c: fix a sparse warningRamsay Jones, Sep 14, 2018
  2. Eric SunshineSep 16, 2018
  3. Ben PeartSep 17, 2018
  4. Ramsay JonesSep 17, 2018
  5. Ramsay JonesSep 17, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.