Skip to contentSkip to conversation

lib: Make strreplace prototype compatible with C++

PATCH In review Matt Ullman 3 participants 5 messages Jun 17, 2016 1 message not in the archive Generic string library

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CA+55aFy_whqDaO_qOg0sz8+LKNRfj7QcHVQyce4FvF78tcvTkQ@mail.gmail.com

#1 lore raw

PATCH v2 1/1 lib: Make strreplace prototype compatible with C++

Since "new" is a keyword in C++, this breaks compilation when string.h is included in a C++ file. For example, this affects VirtualBox Guest Additions.

https://www.virtualbox.org/pipermail/vbox-dev/2015-August/013368.html

---
Thanks for your feedback and I agree. I've made the requested changes.

 include/linux/string.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/string.h +1 -1
index 26b6f6a..1e5183b 100644
@@ -115,7 +115,7 @@ extern int memcmp(const void *,const void *,__kernel_size_t);
 extern void * memchr(const void *,int,__kernel_size_t);
 #endif
 void *memchr_inv(const void *s, int c, size_t n);
-char *strreplace(char *s, char old, char new);
+char *strreplace(char *, char, char);
 
 extern void kfree_const(const void *x);
 
Signature · 1 line
2.9.0
#2 lore raw
Quoted 9 lines · Matt Ullman

Since "new" is a keyword in C++, this breaks compilation when string.h is included in a C++ file. For example, this affects VirtualBox Guest Additions.

https://www.virtualbox.org/pipermail/vbox-dev/2015-August/013368.html

---
Thanks for your feedback and I agree. I've made the requested changes.

I didn't see and could not find any reply to v1. Who is that comment addressed to? Linus?

fwiw, I prefer v1 of the patch. and so does scripts/kernel-doc.

Quoted 17 lines
 include/linux/string.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/string.h +1 -1
index 26b6f6a..1e5183b 100644
@@ -115,7 +115,7 @@ extern int memcmp(const void *,const void *,__kernel_size_t);
 extern void * memchr(const void *,int,__kernel_size_t);
 #endif
 void *memchr_inv(const void *s, int c, size_t n);
-char *strreplace(char *s, char old, char new);
+char *strreplace(char *, char, char);
 
 extern void kfree_const(const void *x);
 
Signature · 1 line
~Randy
#3 lore raw
Quoted 2 lines · Randy Dunlap

I didn't see and could not find any reply to v1. Who is that comment addressed to? Linus?

Yes, this was addressed to Linus. He CC'd the mailing list, but I could not

Quoted 10 lines · find it either. Here is what he

Please only change the prototype, not the function. Might as well remove the argument names in the prototype.

Let's not make the C code uglier for no reason. The fact that C++ screwed up and thought that "new" can't be used as a variable name is no reason not to do it in C code.

Similarly, we don't make C code use the insane C++ pointer caring rules.

Linus

-- Matt Ullman

#4 lore raw

(Matt, you've got an unusual reply-to header)

Quoted 9 lines · Matt Ullman
Quoted 2 lines · Randy Dunlap

I didn't see and could not find any reply to v1.  Who is that comment addressed to?  Linus?

Yes, this was addressed to Linus. He CC'd the mailing list, but I could not

Quoted 4 lines · find it either. Here is what he

Please only change the prototype, not the function. Might as well remove the argument names in the prototype.

Quoted 8 lines
Quoted 7 lines

Let's not make the C code uglier for no reason. The fact that C++ screwed up and thought that "new" can't be used as a variable name is no reason not to do it in C code.

Similarly, we don't make C code use the insane C++ pointer caring rules.

   Linus

-- Matt Ullman

I think kernel-doc is useful and maybe from/to or find/replace could be used instead of old/new

#5 lore raw
Quoted 2 lines · Joe Perches

(Matt, you've got an unusual reply-to header)

Apologies, I'm using a new mail client and accidently set Reply-To instead of In-Reply-To.

-- Matt Ullman