From 1d0ade6fa23500ad271cac328cca33aae0ab83cf Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Wed, 30 Jun 2021 20:52:47 -0700 Subject: [PATCH] libc: Remove the duplication lib_xxx macro Signed-off-by: Xiang Xiao Change-Id: I73c876ed40811c013dad83b8b2aeb7bdc3041913 --- include/nuttx/lib/lib.h | 46 +++++++++++++++++++++++++++++++++++++++++ libs/libc/libc.h | 46 ----------------------------------------- libs/libnx/nxcontext.h | 44 +-------------------------------------- libs/libxx/libxx.hxx | 24 +-------------------- 4 files changed, 48 insertions(+), 112 deletions(-) diff --git a/include/nuttx/lib/lib.h b/include/nuttx/lib/lib.h index e4ffbf5202..51c71ec142 100644 --- a/include/nuttx/lib/lib.h +++ b/include/nuttx/lib/lib.h @@ -28,11 +28,57 @@ #include #include +#include /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +/* The NuttX C library can be built in two modes: (1) as a standard, + * C-library that can be used by normal, user-space applications, or + * (2) as a special, kernel-mode C-library only used within the OS. + * If NuttX is not being built as separated kernel- and user-space modules, + * then only the first mode is supported. + */ + +#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) + + /* Domain-specific allocations */ + +# define lib_malloc(s) kmm_malloc(s) +# define lib_zalloc(s) kmm_zalloc(s) +# define lib_realloc(p,s) kmm_realloc(p,s) +# define lib_memalign(p,s) kmm_memalign(p,s) +# define lib_free(p) kmm_free(p) + + /* User-accessible allocations */ + +# define lib_umalloc(s) kumm_malloc(s) +# define lib_uzalloc(s) kumm_zalloc(s) +# define lib_urealloc(p,s) kumm_realloc(p,s) +# define lib_umemalign(p,s) kumm_memalign(p,s) +# define lib_ufree(p) kumm_free(p) + +#else + + /* Domain-specific allocations */ + +# define lib_malloc(s) malloc(s) +# define lib_zalloc(s) zalloc(s) +# define lib_realloc(p,s) realloc(p,s) +# define lib_memalign(p,s) memalign(p,s) +# define lib_free(p) free(p) + + /* User-accessible allocations */ + +# define lib_umalloc(s) malloc(s) +# define lib_uzalloc(s) zalloc(s) +# define lib_urealloc(p,s) realloc(p,s) +# define lib_umemalign(p,s) memalign(p,s) +# define lib_ufree(p) free(p) + +#endif + /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/libs/libc/libc.h b/libs/libc/libc.h index 9b2a230d99..feef666e50 100644 --- a/libs/libc/libc.h +++ b/libs/libc/libc.h @@ -35,7 +35,6 @@ #include #include -#include #include /**************************************************************************** @@ -52,51 +51,6 @@ # define CONFIG_LIB_HOMEDIR "/" #endif -/* The NuttX C library can be built in two modes: (1) as a standard, - * C-library that can be used by normal, user-space applications, or - * (2) as a special, kernel-mode C-library only used within the OS. - * If NuttX is not being built as separated kernel- and user-space modules, - * then only the first mode is supported. - */ - -#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) - - /* Domain-specific allocations */ - -# define lib_malloc(s) kmm_malloc(s) -# define lib_zalloc(s) kmm_zalloc(s) -# define lib_realloc(p,s) kmm_realloc(p,s) -# define lib_memalign(p,s) kmm_memalign(p,s) -# define lib_free(p) kmm_free(p) - - /* User-accessible allocations */ - -# define lib_umalloc(s) kumm_malloc(s) -# define lib_uzalloc(s) kumm_zalloc(s) -# define lib_urealloc(p,s) kumm_realloc(p,s) -# define lib_umemalign(p,s) kumm_memalign(p,s) -# define lib_ufree(p) kumm_free(p) - -#else - - /* Domain-specific allocations */ - -# define lib_malloc(s) malloc(s) -# define lib_zalloc(s) zalloc(s) -# define lib_realloc(p,s) realloc(p,s) -# define lib_memalign(p,s) memalign(p,s) -# define lib_free(p) free(p) - - /* User-accessible allocations */ - -# define lib_umalloc(s) malloc(s) -# define lib_uzalloc(s) zalloc(s) -# define lib_urealloc(p,s) realloc(p,s) -# define lib_umemalign(p,s) memalign(p,s) -# define lib_ufree(p) free(p) - -#endif - #define LIB_BUFLEN_UNKNOWN INT_MAX /**************************************************************************** diff --git a/libs/libnx/nxcontext.h b/libs/libnx/nxcontext.h index 91ab9e36e3..794a2e7f84 100644 --- a/libs/libnx/nxcontext.h +++ b/libs/libnx/nxcontext.h @@ -33,55 +33,13 @@ #include #include -#include +#include #include /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -/* The NuttX NX library can be build in two modes: (1) as a standard, C- - * library that can be used by normal, user-space applications, or (2) as - * a special, kernel-mode NX-library only used within the OS. If NuttX is - * not being built as separated kernel- and user-space modules, then only - * the first mode is supported. - */ - -#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) - - /* Domain-specific allocations */ - -# define lib_malloc(s) kmm_malloc(s) -# define lib_zalloc(s) kmm_zalloc(s) -# define lib_realloc(p,s) kmm_realloc(p,s) -# define lib_memalign(p,s) kmm_memalign(p,s) -# define lib_free(p) kmm_free(p) - - /* User-accessible allocations */ - -# define lib_umalloc(s) kumm_malloc(s) -# define lib_uzalloc(s) kumm_zalloc(s) -# define lib_urealloc(p,s) kumm_realloc(p,s) -# define lib_ufree(p) kumm_free(p) - -#else - - /* Domain-specific allocations */ - -# define lib_malloc(s) malloc(s) -# define lib_zalloc(s) zalloc(s) -# define lib_realloc(p,s) realloc(p,s) -# define lib_free(p) free(p) - - /* User-accessible allocations */ - -# define lib_umalloc(s) malloc(s) -# define lib_uzalloc(s) zalloc(s) -# define lib_urealloc(p,s) realloc(p,s) -# define lib_ufree(p) free(p) - -#endif - /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/libs/libxx/libxx.hxx b/libs/libxx/libxx.hxx index 1cac8a3cf8..d11f7b4299 100644 --- a/libs/libxx/libxx.hxx +++ b/libs/libxx/libxx.hxx @@ -26,29 +26,7 @@ #include -//*************************************************************************** -// Definitions -//*************************************************************************** - -// The NuttX C library an be build in two modes: (1) as a standard, C-libary -// that can be used by normal, user-space applications, or (2) as a special, -// kernel-mode C-library only used within the OS. If NuttX is not being -// built as separated kernel- and user-space modules, then only the first -// mode is supported. - -#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) -# include -# define lib_malloc(s) kmm_malloc(s) -# define lib_zalloc(s) kmm_zalloc(s) -# define lib_realloc(p,s) kmm_realloc(p,s) -# define lib_free(p) kmm_free(p) -#else -# include -# define lib_malloc(s) malloc(s) -# define lib_zalloc(s) zalloc(s) -# define lib_realloc(p,s) realloc(p,s) -# define lib_free(p) free(p) -#endif +#include //*************************************************************************** // Public Types