From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/6299 Path: news.gmane.org!not-for-mail From: Sergey Dmitrouk Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] Convert some is* macros to inline functions Date: Mon, 13 Oct 2014 17:20:20 +0300 Message-ID: <20141013142020.GA26828@zx-spectrum.accesssoftek.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="a8Wt8u1KmwUX3Y2C" X-Trace: ger.gmane.org 1413210043 22427 80.91.229.3 (13 Oct 2014 14:20:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 13 Oct 2014 14:20:43 +0000 (UTC) To: Original-X-From: musl-return-6312-gllmg-musl=m.gmane.org@lists.openwall.com Mon Oct 13 16:20:37 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1XdgUF-0008Ea-Rx for gllmg-musl@plane.gmane.org; Mon, 13 Oct 2014 16:20:36 +0200 Original-Received: (qmail 7925 invoked by uid 550); 13 Oct 2014 14:20:34 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 7917 invoked from network); 13 Oct 2014 14:20:33 -0000 Content-Disposition: inline Xref: news.gmane.org gmane.linux.lib.musl.general:6299 Archived-At: --a8Wt8u1KmwUX3Y2C Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline 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 --a8Wt8u1KmwUX3Y2C Content-Type: text/plain; charset="us-ascii" Content-Disposition: attachment; filename="musl-is-macros-to-inline-funcs.patch" 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 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 #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 #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 #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 #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 #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 #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 #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 #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) { --a8Wt8u1KmwUX3Y2C--