You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/06/02 15:32:40 UTC
[incubator-nuttx] 01/02: libc: Unify the selection of inline or
macro
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit a7174cee30c85696debacbeef0a7e5a2b111f620
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Tue Jun 2 21:41:13 2020 +0800
libc: Unify the selection of inline or macro
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
Change-Id: I44a26550ff856af07d2d96a6f0a6066f988d6da3
---
include/ctype.h | 37 +++++++++++++++++--------------------
include/stdlib.h | 26 +++++++++++++-------------
include/strings.h | 20 ++++++++++++--------
include/time.h | 4 ++--
4 files changed, 44 insertions(+), 43 deletions(-)
diff --git a/include/ctype.h b/include/ctype.h
index dcf918b..cdba367 100644
--- a/include/ctype.h
+++ b/include/ctype.h
@@ -1,7 +1,8 @@
/****************************************************************************
* include/ctype.h
*
- * Copyright (C) 2007-2009, 2011, 2014, 2016 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2009, 2011, 2014, 2016 Gregory Nutt.
+ * All rights reserved.
* Author: Gregory Nutt <gn...@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -61,7 +62,7 @@
*
****************************************************************************/
-#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus)
+#ifdef CONFIG_HAVE_INLINE
static inline int isspace(int c)
{
return c == ' ' || c == '\t' || c == '\n' || c == '\r' ||
@@ -82,7 +83,7 @@ static inline int isspace(int c)
*
****************************************************************************/
-#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus)
+#ifdef CONFIG_HAVE_INLINE
static inline int isascii(int c)
{
return c >= 0 && c <= 0x7f;
@@ -99,7 +100,7 @@ static inline int isascii(int c)
*
****************************************************************************/
-#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus)
+#ifdef CONFIG_HAVE_INLINE
static inline int isprint(int c)
{
return c >= 0x20 && c < 0x7f;
@@ -116,7 +117,7 @@ static inline int isprint(int c)
*
****************************************************************************/
-#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus)
+#ifdef CONFIG_HAVE_INLINE
static inline int isgraph(int c)
{
return c > 0x20 && c < 0x7f;
@@ -133,7 +134,7 @@ static inline int isgraph(int c)
*
****************************************************************************/
-#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus)
+#ifdef CONFIG_HAVE_INLINE
static inline int iscntrl(int c)
{
return !isprint(c);
@@ -150,7 +151,7 @@ static inline int iscntrl(int c)
*
****************************************************************************/
-#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus)
+#ifdef CONFIG_HAVE_INLINE
static inline int islower(int c)
{
return c >= 'a' && c <= 'z';
@@ -167,7 +168,7 @@ static inline int islower(int c)
*
****************************************************************************/
-#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus)
+#ifdef CONFIG_HAVE_INLINE
static inline int isupper(int c)
{
return c >= 'A' && c <= 'Z';
@@ -184,7 +185,7 @@ static inline int isupper(int c)
*
****************************************************************************/
-#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus)
+#ifdef CONFIG_HAVE_INLINE
static inline int isalpha(int c)
{
return islower(c) || isupper(c);
@@ -201,7 +202,7 @@ static inline int isalpha(int c)
*
****************************************************************************/
-#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus)
+#ifdef CONFIG_HAVE_INLINE
static inline int isblank(int c)
{
return c == ' ' || c == '\t';
@@ -218,7 +219,7 @@ static inline int isblank(int c)
*
****************************************************************************/
-#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus)
+#ifdef CONFIG_HAVE_INLINE
static inline int isdigit(int c)
{
return c >= '0' && c <= '9';
@@ -235,7 +236,7 @@ static inline int isdigit(int c)
*
****************************************************************************/
-#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus)
+#ifdef CONFIG_HAVE_INLINE
static inline int isalnum(int c)
{
return isalpha(c) || isdigit(c);
@@ -253,7 +254,7 @@ static inline int isalnum(int c)
*
****************************************************************************/
-#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus)
+#ifdef CONFIG_HAVE_INLINE
static inline int ispunct(int c)
{
return isgraph(c) && !isalnum(c);
@@ -270,7 +271,7 @@ static inline int ispunct(int c)
*
****************************************************************************/
-#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus)
+#ifdef CONFIG_HAVE_INLINE
static inline int isxdigit(int c)
{
return (c >= '0' && c <= '9') ||
@@ -292,7 +293,7 @@ static inline int isxdigit(int c)
*
****************************************************************************/
-#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus)
+#ifdef CONFIG_HAVE_INLINE
static inline int toupper(int c)
{
return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c;
@@ -310,7 +311,7 @@ static inline int toupper(int c)
*
****************************************************************************/
-#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus)
+#ifdef CONFIG_HAVE_INLINE
static inline int tolower(int c)
{
return (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c;
@@ -324,10 +325,6 @@ static inline int tolower(int c)
* Public Type Definitions
****************************************************************************/
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
diff --git a/include/stdlib.h b/include/stdlib.h
index f25d7f3..811cacd 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -160,8 +160,8 @@ int on_exit(CODE void (*func)(int, FAR void *), FAR void *arg);
void _exit(int status); /* See unistd.h */
-#ifdef __cplusplus
-inline void _Exit(int s)
+#ifdef CONFIG_HAVE_INLINE
+static inline void _Exit(int s)
{
_exit(s);
}
@@ -196,8 +196,8 @@ double strtod(FAR const char *str, FAR char **endptr);
long double strtold(FAR const char *str, FAR char **endptr);
#endif
-#ifdef __cplusplus
-inline int atoi(FAR const char *nptr)
+#ifdef CONFIG_HAVE_INLINE
+static inline int atoi(FAR const char *nptr)
{
return (int)strtol(nptr, NULL, 10);
}
@@ -205,8 +205,8 @@ inline int atoi(FAR const char *nptr)
#define atoi(nptr) ((int)strtol((nptr), NULL, 10))
#endif
-#ifdef __cplusplus
-inline int atol(FAR const char *nptr)
+#ifdef CONFIG_HAVE_INLINE
+static inline int atol(FAR const char *nptr)
{
return strtol(nptr, NULL, 10);
}
@@ -215,8 +215,8 @@ inline int atol(FAR const char *nptr)
#endif
#ifdef CONFIG_HAVE_LONG_LONG
-#ifdef __cplusplus
-inline long long atoll(FAR const char *nptr)
+#ifdef CONFIG_HAVE_INLINE
+static inline long long atoll(FAR const char *nptr)
{
return strtoll(nptr, NULL, 10);
}
@@ -226,8 +226,8 @@ inline long long atoll(FAR const char *nptr)
#endif
#ifdef CONFIG_HAVE_DOUBLE
-#ifdef __cplusplus
-inline double atof(FAR const char *nptr)
+#ifdef CONFIG_HAVE_INLINE
+static inline double atof(FAR const char *nptr)
{
return strtod(nptr, NULL);
}
@@ -259,13 +259,13 @@ FAR void *memalign(size_t, size_t);
FAR void *zalloc(size_t);
FAR void *calloc(size_t, size_t);
-#ifdef __cplusplus
-inline FAR void *aligned_alloc(size_t a, size_t s)
+#ifdef CONFIG_HAVE_INLINE
+static inline FAR void *aligned_alloc(size_t a, size_t s)
{
return memalign(a, s);
}
-inline int posix_memalign(FAR void **m, size_t a, size_t s)
+static inline int posix_memalign(FAR void **m, size_t a, size_t s)
{
return (*m = memalign(a, s)) ? OK : ENOMEM;
}
diff --git a/include/strings.h b/include/strings.h
index 6aa3a71..0386dae 100644
--- a/include/strings.h
+++ b/include/strings.h
@@ -48,11 +48,13 @@
* Pre-processor Definitions
****************************************************************************/
-#if !defined(CONFIG_HAVE_INLINE) && !defined(__cplusplus)
+#ifndef CONFIG_HAVE_INLINE
/* Compatibility definitions
*
- * Marked LEGACY in Open Group Base Specifications Issue 6/IEEE Std 1003.1-2004
- * Removed from Open Group Base Specifications Issue 7/IEEE Std 1003.1-2008
+ * Marked LEGACY in Open Group Base Specifications Issue 6/
+ * IEEE Std 1003.1-2004
+ * Removed from Open Group Base Specifications Issue 7/
+ * IEEE Std 1003.1-2008
*/
# define bcmp(b1,b2,len) memcmp(b1,b2,(size_t)len)
@@ -61,7 +63,7 @@
# define index(s,c) strchr(s,c)
# define rindex(s,c) strrchr(s,c)
-#endif /* !CONFIG_HAVE_INLINE && !__cplusplus */
+#endif /* !CONFIG_HAVE_INLINE */
/****************************************************************************
* Inline Functions
@@ -76,11 +78,13 @@ extern "C"
#define EXTERN extern
#endif
-#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus)
+#ifdef CONFIG_HAVE_INLINE
/* Compatibility inline functions.
*
- * Marked LEGACY in Open Group Base Specifications Issue 6/IEEE Std 1003.1-2004
- * Removed from Open Group Base Specifications Issue 7/IEEE Std 1003.1-2008
+ * Marked LEGACY in Open Group Base Specifications Issue 6/
+ * IEEE Std 1003.1-2004
+ * Removed from Open Group Base Specifications Issue 7/
+ * IEEE Std 1003.1-2008
*/
static inline int bcmp(FAR const void *b1, FAR const void *b2, size_t len)
@@ -107,7 +111,7 @@ static inline FAR char *rindex(FAR const char *s, int c)
{
return strrchr(s, c);
}
-#endif /* CONFIG_HAVE_INLINE || __cplusplus */
+#endif /* CONFIG_HAVE_INLINE */
/****************************************************************************
* Public Function Prototypes
diff --git a/include/time.h b/include/time.h
index eb0f163..846000a 100644
--- a/include/time.h
+++ b/include/time.h
@@ -201,8 +201,8 @@ int clock_settime(clockid_t clockid, FAR const struct timespec *tp);
int clock_gettime(clockid_t clockid, FAR struct timespec *tp);
int clock_getres(clockid_t clockid, FAR struct timespec *res);
-#ifdef __cplusplus
-inline int timespec_get(FAR struct timespec *t, int b)
+#ifdef CONFIG_HAVE_INLINE
+static inline int timespec_get(FAR struct timespec *t, int b)
{
return b == TIME_UTC ? (clock_gettime(CLOCK_REALTIME, t), b) : 0;
}