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

Re: [PATCH] alloc.c: remove alloc_raw_commit_node() function

From
Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Date
Jun 18, 2014, 22:30 UTC
Message-ID
<53A2131A.30900@ramsay1.demon.co.uk>
In-Reply-To
<20140618200854.GA23098@sigill.intra.peff.net>
On 18/06/14 21:08, Jeff King wrote:
> On Wed, Jun 18, 2014 at 08:52:46PM +0100, Ramsay Jones wrote:
> 
[snip]
Show 7 quoted lines
> Yeah, I noticed it while writing the patch but decided it wasn't worth
> the trouble to deal with (since after all, it's not advertised to any
> callers, the very thing that sparse is complaining about. :) ).
> 
> I don't mind fixing it, though I really don't like repeating the
> contents of DEFINE_ALLOCATOR. I know it hasn't changed in a while, but
> it just feels wrong.

So, the patch below is a slight variation on the original patch. I'm still slightly concerned about portability, but given that it has been at least a decade since I last used a (pre-ANSI) compiler which had a problem with this ...

[I have several versions of the C standard that I can use to check up on the legalise, but I'm not sure I can be bothered! ;-) ]

ATB, Ramsay Jones

-- >8 --
Subject: [PATCH] alloc.c: make alloc_raw_commit_node() a static function

In order to encapsulate the setting of the unique commit index, commit 969eba63 ("commit: push commit_index update into alloc_commit_node", 10-06-2014) introduced a (logically private) intermediary allocator function. However, this function (alloc_raw_commit_node()) was declared as a public function, which undermines its entire purpose.

Add a scope parameter to the DEFINE_ALLOCATOR macro to allow the raw commit allocator definition to include the 'static' qualifier.

Noticed by sparse ("symbol 'alloc_raw_commit_node' was not declared. Should it be static?").

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---
 alloc.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/alloc.c b/alloc.c
index eb22a45..5392d13 100644
--- a/alloc.c
+++ b/alloc.c
@@ -18,9 +18,12 @@
 
 #define BLOCKING 1024
 
-#define DEFINE_ALLOCATOR(name, type)				\
+#define PUBLIC
+#define PRIVATE static
+
+#define DEFINE_ALLOCATOR(scope, name, type)			\
 static unsigned int name##_allocs;				\
-void *alloc_##name##_node(void)					\
+scope void *alloc_##name##_node(void)				\
 {								\
 	static int nr;						\
 	static type *block;					\
@@ -45,11 +48,11 @@ union any_object {
 	struct tag tag;
 };
 
-DEFINE_ALLOCATOR(blob, struct blob)
-DEFINE_ALLOCATOR(tree, struct tree)
-DEFINE_ALLOCATOR(raw_commit, struct commit)
-DEFINE_ALLOCATOR(tag, struct tag)
-DEFINE_ALLOCATOR(object, union any_object)
+DEFINE_ALLOCATOR(PUBLIC, blob, struct blob)
+DEFINE_ALLOCATOR(PUBLIC, tree, struct tree)
+DEFINE_ALLOCATOR(PRIVATE, raw_commit, struct commit)
+DEFINE_ALLOCATOR(PUBLIC, tag, struct tag)
+DEFINE_ALLOCATOR(PUBLIC, object, union any_object)
 
 void *alloc_commit_node(void)
 {
-- 
2.0.0
Previous: Jeff KingNext: Jeff King
Message 3 of 6 in “alloc.c: remove alloc_raw_commit_node() function”
  1. alloc.c: remove alloc_raw_commit_node() functionRamsay Jones, Jun 18, 2014
  2. Jeff KingJun 18, 2014
  3. Ramsay JonesJun 18, 2014
  4. Jeff KingJun 19, 2014
  5. Ramsay JonesJun 19, 2014
  6. Junio C HamanoJun 19, 2014

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.