Re: [PATCH 1/4] stringbuf: A string buffer implementation

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Matthew Wilcox
Date: Wednesday, October 24, 2007 - 8:23 pm

On Wed, Oct 24, 2007 at 08:07:23PM -0400, Kyle Moffett wrote:

Ah, gotcha.  I don't really like the va_copy idea, and I don't like the idea of having sb_printf call sb_vprintf twice ... how about just doing away with sb_vprintf altogether:

diff --git a/include/linux/stringbuf.h b/include/linux/stringbuf.h
index c030bc6..ae5c02f 100644
--- a/include/linux/stringbuf.h
+++ b/include/linux/stringbuf.h
@@ -57,11 +57,6 @@ static inline void sb_free(struct stringbuf *sb)
 
 extern void sb_printf(struct stringbuf *sb, gfp_t gfp, const char *fmt, ...)
 	__attribute__((format(printf, 3, 4)));
-#if 0
-/* Waiting for a user to show up */
-extern void sb_vprintf(struct stringbuf *sb, gfp_t gfp, const char *fmt,
-			va_list args) __attribute__((format(printf, 3, 0)));
-#endif
 
 /*
  * Convert the stringbuf to a string.  It is the caller's responsibility
diff --git a/lib/stringbuf.c b/lib/stringbuf.c
index b4e59f4..691fcd1 100644
--- a/lib/stringbuf.c
+++ b/lib/stringbuf.c
@@ -22,12 +22,9 @@
 #define INITIAL_SIZE 128
 #define ERR_STRING "out of memory"
 
-/*
- * Not currently used outside this file, but separated from sb_printf
- * for when someone needs it.
- */
-static void sb_vprintf(struct stringbuf *sb, gfp_t gfp, const char *format, va_list args)
+void sb_printf(struct stringbuf *sb, gfp_t gfp, const char *format, ...)
 {
+	va_list args;
 	char *s;
 	int size, newlen;
 
@@ -41,7 +38,9 @@ static void sb_vprintf(struct stringbuf *sb, gfp_t gfp, const char *format, va_l
 	}
 
 	s = sb->buf + sb->len;
+	va_start(args, format);
 	size = vsnprintf(s, sb->alloc - sb->len, format, args);
+	va_end(args);
 
 	sb->len += size;
 	if (likely(sb->len < sb->alloc))
@@ -61,7 +60,9 @@ static void sb_vprintf(struct stringbuf *sb, gfp_t gfp, const char *format, va_l
 
 	/* Point to the end of the old string since we already updated ->len */
 	s += sb->len - size;
+	va_start(args, format);
 	vsprintf(s, format, args);
+	va_end(args);
 	return;
 
  nomem:
@@ -70,16 +71,4 @@ static void sb_vprintf(struct stringbuf *sb, gfp_t gfp, const char *format, va_l
 	sb->len = sizeof(ERR_STRING);
 	sb->alloc = -ENOMEM;
 }
-/* When we get our first modular user, delete this comment
-EXPORT_SYMBOL(sb_vprintf);
-*/
-
-void sb_printf(struct stringbuf *sb, gfp_t gfp, const char *format, ...)
-{
-	va_list args;
-
-	va_start(args, format);
-	sb_vprintf(sb, gfp, format, args);
-	va_end(args);
-}
 EXPORT_SYMBOL(sb_printf);

-- 
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Stringbuf, v2, Matthew Wilcox, (Wed Oct 24, 12:58 pm)
[PATCH 1/4] stringbuf: A string buffer implementation, Matthew Wilcox, (Wed Oct 24, 12:59 pm)
[PATCH 2/4] isdn: Use stringbuf, Matthew Wilcox, (Wed Oct 24, 12:59 pm)
[PATCH 3/4] sound: Use stringbuf, Matthew Wilcox, (Wed Oct 24, 12:59 pm)
[PATCH 4/4] partitions: Fix non-atomic printk, Matthew Wilcox, (Wed Oct 24, 12:59 pm)
Re: Stringbuf, v2, Joe Perches, (Wed Oct 24, 1:51 pm)
Re: Stringbuf, v2, Matthew Wilcox, (Wed Oct 24, 1:57 pm)
Re: Stringbuf, v2, Joe Perches, (Wed Oct 24, 2:06 pm)
Re: [PATCH 1/4] stringbuf: A string buffer implementation, Matthew Wilcox, (Wed Oct 24, 2:21 pm)
Re: Stringbuf, v2, Matthew Wilcox, (Wed Oct 24, 2:34 pm)
Re: [PATCH 1/4] stringbuf: A string buffer implementation, Matthew Wilcox, (Wed Oct 24, 8:23 pm)
Re: [PATCH 1/4] stringbuf: A string buffer implementation, Rusty Russell, (Thu Oct 25, 7:11 pm)
Re: [PATCH 1/4] stringbuf: A string buffer implementation, Matthew Wilcox, (Fri Oct 26, 4:57 am)
Re: [PATCH 1/4] stringbuf: A string buffer implementation, Rusty Russell, (Sat Oct 27, 3:09 am)
Re: [PATCH 1/4] stringbuf: A string buffer implementation, Rusty Russell, (Sat Oct 27, 5:50 am)
Re: [PATCH 1/4] stringbuf: A string buffer implementation, Matthew Wilcox, (Sat Oct 27, 9:48 am)
Re: [PATCH 1/4] stringbuf: A string buffer implementation, Rusty Russell, (Sun Oct 28, 10:38 pm)