mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Sergey Dmitrouk <sdmitrouk@accesssoftek.com>
To: "musl@lists.openwall.com" <musl@lists.openwall.com>
Subject: Re: [PATCH] Convert some is* macros to inline functions
Date: Tue, 14 Oct 2014 12:01:08 +0300	[thread overview]
Message-ID: <20141014090108.GA2635@zx-spectrum> (raw)
In-Reply-To: <20141013184956.GA4874@port70.net>

[-- Attachment #1: Type: text/plain, Size: 849 bytes --]

On Mon, Oct 13, 2014 at 11:49:56AM -0700, Szabolcs Nagy wrote:
> the c++ standard could be more explicit about this incompatibility
> with c: it states the requirement in a note for the <cname> headers
> and then defines the semantics for the <name.h> headers in terms of
> the <cname> one

Sad, but true.  I wish it was stated better.

 > The only way to achieve equivalent inline behavior in C++ is to
 > provide a definition as an extern inline function.

Seems to be true, so newlib and glibc have checks for __cplusplus define.
Alternative would be to provide 26 fake headers containing #include_next
directive, but it's not very portable solution.

Attached is the patch, which simply adds #ifndef __cplusplus around
macros.  At the end, it seems to be the right thing to do, although the
way it's defined is rather confusing.

Thanks,
Sergey

[-- Attachment #2: musl-hide-is-macros-for-cxx.patch --]
[-- Type: text/plain, Size: 1523 bytes --]

diff --git a/include/ctype.h b/include/ctype.h
index a6f44df..eef574b 100644
--- a/include/ctype.h
+++ b/include/ctype.h
@@ -27,6 +27,7 @@ static __inline int __isspace(int _c)
 	return _c == ' ' || (unsigned)_c-'\t' < 5;
 }
 
+#ifndef __cplusplus
 #define isalpha(a) ((((unsigned)(a)|32)-'a') < 26)
 #define isdigit(a) (((unsigned)(a)-'0') < 10)
 #define islower(a) (((unsigned)(a)-'a') < 26)
@@ -34,6 +35,7 @@ static __inline int __isspace(int _c)
 #define isprint(a) (((unsigned)(a)-0x20) < 0x5f)
 #define isgraph(a) (((unsigned)(a)-0x21) < 0x5e)
 #define isspace(a) __isspace(a)
+#endif
 
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
diff --git a/include/wchar.h b/include/wchar.h
index 9fd967c..8cfb584 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -176,9 +176,12 @@ int       iswctype(wint_t, wctype_t);
 wint_t    towlower(wint_t);
 wint_t    towupper(wint_t);
 wctype_t  wctype(const char *);
+
+#ifndef __cplusplus
 #undef iswdigit
 #define iswdigit(a) ((unsigned)(a)-'0' < 10)
 #endif
+#endif
 
 #ifdef __cplusplus
 }
diff --git a/include/wctype.h b/include/wctype.h
index 3ac24f1..3da1219 100644
--- a/include/wctype.h
+++ b/include/wctype.h
@@ -43,8 +43,10 @@ wint_t    towupper(wint_t);
 wctrans_t wctrans(const char *);
 wctype_t  wctype(const char *);
 
+#ifndef __cplusplus
 #undef iswdigit
 #define iswdigit(a) (((unsigned)(a)-L'0') < 10)
+#endif
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)

  reply	other threads:[~2014-10-14  9:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-13 14:20 Sergey Dmitrouk
2014-10-13 14:35 ` Jens Gustedt
2014-10-13 18:00   ` Sergey Dmitrouk
2014-10-13 18:06     ` Rich Felker
2014-10-13 18:49       ` Szabolcs Nagy
2014-10-14  9:01         ` Sergey Dmitrouk [this message]
2014-10-14 16:34           ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141014090108.GA2635@zx-spectrum \
    --to=sdmitrouk@accesssoftek.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).