From: Sergey Dmitrouk <sdmitrouk@accesssoftek.com>
To: <musl@lists.openwall.com>
Subject: [PATCH] Convert some is* macros to inline functions
Date: Mon, 13 Oct 2014 17:20:20 +0300 [thread overview]
Message-ID: <20141013142020.GA26828@zx-spectrum.accesssoftek.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 295 bytes --]
Hello,
eight is* functions of C standard library are also declared in form of
macros in headers provided by musl. Standard doesn't seem to allow them
to be implemented as macros. Please find the attached patch that proposes
replacing these macros with inline functions.
Best regards,
Sergey
[-- Attachment #2: musl-is-macros-to-inline-funcs.patch --]
[-- Type: text/plain, Size: 6375 bytes --]
diff --git a/include/ctype.h b/include/ctype.h
index a6f44df..7f8d98d 100644
--- a/include/ctype.h
+++ b/include/ctype.h
@@ -8,16 +8,9 @@ extern "C" {
#include <features.h>
int isalnum(int);
-int isalpha(int);
int isblank(int);
int iscntrl(int);
-int isdigit(int);
-int isgraph(int);
-int islower(int);
-int isprint(int);
int ispunct(int);
-int isspace(int);
-int isupper(int);
int isxdigit(int);
int tolower(int);
int toupper(int);
@@ -27,14 +20,40 @@ static __inline int __isspace(int _c)
return _c == ' ' || (unsigned)_c-'\t' < 5;
}
-#define isalpha(a) ((((unsigned)(a)|32)-'a') < 26)
-#define isdigit(a) (((unsigned)(a)-'0') < 10)
-#define islower(a) (((unsigned)(a)-'a') < 26)
-#define isupper(a) (((unsigned)(a)-'A') < 26)
-#define isprint(a) (((unsigned)(a)-0x20) < 0x5f)
-#define isgraph(a) (((unsigned)(a)-0x21) < 0x5e)
-#define isspace(a) __isspace(a)
+__inline int isalpha(int _c)
+{
+ return (((unsigned)_c | 32) - 'a') < 26;
+}
+
+__inline int isdigit(int _c)
+{
+ return ((unsigned)_c - '0') < 10;
+}
+__inline int islower(int _c)
+{
+ return ((unsigned)_c - 'a') < 26;
+}
+
+__inline int isupper(int _c)
+{
+ return ((unsigned)_c - 'A') < 26;
+}
+
+__inline int isprint(int _c)
+{
+ return ((unsigned)_c - 0x20) < 0x5f;
+}
+
+__inline int isgraph(int _c)
+{
+ return ((unsigned)_c - 0x21) < 0x5e;
+}
+
+__inline int isspace(int _c)
+{
+ return __isspace(_c);
+}
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
diff --git a/include/wchar.h b/include/wchar.h
index 9fd967c..3033df8 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -138,8 +138,6 @@ wint_t ungetwc (wint_t, FILE *);
struct tm;
size_t wcsftime (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict);
-#undef iswdigit
-
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
FILE *open_wmemstream(wchar_t **, size_t *);
@@ -164,7 +162,6 @@ int iswalnum(wint_t);
int iswalpha(wint_t);
int iswblank(wint_t);
int iswcntrl(wint_t);
-int iswdigit(wint_t);
int iswgraph(wint_t);
int iswlower(wint_t);
int iswprint(wint_t);
@@ -176,8 +173,15 @@ int iswctype(wint_t, wctype_t);
wint_t towlower(wint_t);
wint_t towupper(wint_t);
wctype_t wctype(const char *);
-#undef iswdigit
-#define iswdigit(a) ((unsigned)(a)-'0' < 10)
+
+#ifndef __iswdigit_defined
+#define __iswdigit_defined
+__inline int iswdigit(wint_t _c)
+{
+ return ((unsigned)_c - L'0') < 10;
+}
+#endif
+
#endif
#ifdef __cplusplus
diff --git a/include/wctype.h b/include/wctype.h
index 3ac24f1..3747c87 100644
--- a/include/wctype.h
+++ b/include/wctype.h
@@ -22,13 +22,10 @@ typedef const int * wctrans_t;
#undef WEOF
#define WEOF 0xffffffffU
-#undef iswdigit
-
int iswalnum(wint_t);
int iswalpha(wint_t);
int iswblank(wint_t);
int iswcntrl(wint_t);
-int iswdigit(wint_t);
int iswgraph(wint_t);
int iswlower(wint_t);
int iswprint(wint_t);
@@ -43,8 +40,13 @@ wint_t towupper(wint_t);
wctrans_t wctrans(const char *);
wctype_t wctype(const char *);
-#undef iswdigit
-#define iswdigit(a) (((unsigned)(a)-L'0') < 10)
+#ifndef __iswdigit_defined
+#define __iswdigit_defined
+__inline int iswdigit(wint_t _c)
+{
+ return ((unsigned)_c - L'0') < 10;
+}
+#endif
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
diff --git a/src/ctype/isalpha.c b/src/ctype/isalpha.c
index f155d3a..b5403d6 100644
--- a/src/ctype/isalpha.c
+++ b/src/ctype/isalpha.c
@@ -1,11 +1,7 @@
#include <ctype.h>
#include "libc.h"
-#undef isalpha
-int isalpha(int c)
-{
- return ((unsigned)c|32)-'a' < 26;
-}
+extern inline int isalpha(int);
int __isalpha_l(int c, locale_t l)
{
diff --git a/src/ctype/isdigit.c b/src/ctype/isdigit.c
index 4d8a103..b4e58d2 100644
--- a/src/ctype/isdigit.c
+++ b/src/ctype/isdigit.c
@@ -1,11 +1,7 @@
#include <ctype.h>
#include "libc.h"
-#undef isdigit
-int isdigit(int c)
-{
- return (unsigned)c-'0' < 10;
-}
+extern inline int isdigit(int);
int __isdigit_l(int c, locale_t l)
{
diff --git a/src/ctype/isgraph.c b/src/ctype/isgraph.c
index a0aae08..b831164 100644
--- a/src/ctype/isgraph.c
+++ b/src/ctype/isgraph.c
@@ -1,11 +1,7 @@
#include <ctype.h>
#include "libc.h"
-#undef isgraph
-int isgraph(int c)
-{
- return (unsigned)c-0x21 < 0x5e;
-}
+extern inline int isgraph(int);
int __isgraph_l(int c, locale_t l)
{
diff --git a/src/ctype/islower.c b/src/ctype/islower.c
index 0264021..3e3dde1 100644
--- a/src/ctype/islower.c
+++ b/src/ctype/islower.c
@@ -1,11 +1,7 @@
#include <ctype.h>
#include "libc.h"
-#undef islower
-int islower(int c)
-{
- return (unsigned)c-'a' < 26;
-}
+extern inline int islower(int);
int __islower_l(int c, locale_t l)
{
diff --git a/src/ctype/isprint.c b/src/ctype/isprint.c
index 067275f..25dd9fc 100644
--- a/src/ctype/isprint.c
+++ b/src/ctype/isprint.c
@@ -1,11 +1,7 @@
#include <ctype.h>
#include "libc.h"
-#undef isprint
-int isprint(int c)
-{
- return (unsigned)c-0x20 < 0x5f;
-}
+extern inline int isprint(int);
int __isprint_l(int c, locale_t l)
{
diff --git a/src/ctype/isspace.c b/src/ctype/isspace.c
index 231e907..86614a3 100644
--- a/src/ctype/isspace.c
+++ b/src/ctype/isspace.c
@@ -1,11 +1,7 @@
#include <ctype.h>
#include "libc.h"
-#undef isspace
-int isspace(int c)
-{
- return c == ' ' || (unsigned)c-'\t' < 5;
-}
+extern inline int isspace(int);
int __isspace_l(int c, locale_t l)
{
diff --git a/src/ctype/isupper.c b/src/ctype/isupper.c
index 68c36f4..ef808e4 100644
--- a/src/ctype/isupper.c
+++ b/src/ctype/isupper.c
@@ -1,11 +1,7 @@
#include <ctype.h>
#include "libc.h"
-#undef isupper
-int isupper(int c)
-{
- return (unsigned)c-'A' < 26;
-}
+extern inline int isupper(int);
int __isupper_l(int c, locale_t l)
{
diff --git a/src/ctype/iswdigit.c b/src/ctype/iswdigit.c
index ed9a88e..550d6e1 100644
--- a/src/ctype/iswdigit.c
+++ b/src/ctype/iswdigit.c
@@ -1,12 +1,7 @@
#include <wctype.h>
#include "libc.h"
-#undef iswdigit
-
-int iswdigit(wint_t wc)
-{
- return (unsigned)wc-'0' < 10;
-}
+extern inline int iswdigit(wint_t);
int __iswdigit_l(wint_t c, locale_t l)
{
next reply other threads:[~2014-10-13 14:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-13 14:20 Sergey Dmitrouk [this message]
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
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=20141013142020.GA26828@zx-spectrum.accesssoftek.com \
--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).