From 91f5f513c4461871fddf8b86c2cf4125ebab2db1 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sun, 21 May 2023 00:15:30 +0200 Subject: [PATCH] Update macro names Make global logic easier. --- example/exm-header.h | 2 +- example/exm-lib.c | 2 +- example/exn-header.h | 2 +- m-core.h | 19 +++++++++++-------- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/example/exm-header.h b/example/exm-header.h index 03d0b144..10a72611 100644 --- a/example/exm-header.h +++ b/example/exm-header.h @@ -2,7 +2,7 @@ #define MY_HEADER // Request M*LIB to not inline functions if not the library source -#define M_USE_EXTERN_DECL +#define M_USE_DECL #include "m-string.h" #include "m-array.h" diff --git a/example/exm-lib.c b/example/exm-lib.c index d40d8500..d4f6f7b8 100644 --- a/example/exm-lib.c +++ b/example/exm-lib.c @@ -1,5 +1,5 @@ // Request M*LIB to define functions // This include both m-string functions and array_str templated functions // Defining M_USE_EXTERN_DEF override M_USE_EXTERN_DECL definition -#define M_USE_EXTERN_DEF +#define M_USE_DEF #include "exm-header.h" diff --git a/example/exn-header.h b/example/exn-header.h index a444ef96..d293786f 100644 --- a/example/exn-header.h +++ b/example/exn-header.h @@ -2,7 +2,7 @@ #define MY_HEADER // Request M*LIB to not always inline functions -#define M_USE_EXTERN_FINE_GRAINED 1 +#define M_USE_FINE_GRAINED_LINKAGE #include "m-string.h" #include "m-array.h" diff --git a/m-core.h b/m-core.h index 6e6a7688..97b2d9ce 100644 --- a/m-core.h +++ b/m-core.h @@ -273,12 +273,13 @@ M_BEGIN_PROTECTED_CODE - extern inline: externally visible code is emitted, so at most one translation unit can use this. - static inline: No generation of an extern visible function. May inline or may call one static function. */ -/* If the user requests to use only declaration for all M*LIN functions (M_USE_EXTERN_DECL), +/* If the user requests to use only declaration for all M*LIB functions globally (M_USE_DECL), it requests no inlining to the compiler and emits code as weak symbol. - Then at most one translation unit should request the definition of all functions (M_USE_EXTERN_DEF). + Then at most one translation unit should request the definition of all functions (M_USE_DEF). This is only supported by GCC and CLANG. You should also use the options -ffunction-sections -fdata-sections -Wl,--gc-sections Otherwise it would increase the size of the executable. - If M_USE_EXTERN_FINE_GRAINED, then uses a mechanism to decl or def the functions in function of M_USE_EXTERN_FINE_DECL / M_USE_EXTERN_FINE_DEF + If M_USE_FINE_GRAINED_LINKAGE, then the mechanism can be turn on / off dynamically in compilation time + to decl or def the functions in function of M_USE_DECL / M_USE_DEF Otherwise uses the classic "M_INLINE" (inline for C++ or static inline for C) inline in C++ as a weak definition by default, which may reduce code size in executable. */ @@ -287,16 +288,18 @@ M_BEGIN_PROTECTED_CODE #else # define M_INLINE_PRAGMA #endif -#if defined(__GNUC__) && defined(M_USE_EXTERN_DEF) -#define M_INLINE M_INLINE_PRAGMA __attribute__((noinline)) extern -#elif defined(__GNUC__) && defined(M_USE_EXTERN_DECL) -#define M_INLINE M_INLINE_PRAGMA __attribute__((weak, noinline)) extern -#elif defined(__GNUC__) && defined(M_USE_EXTERN_FINE_GRAINED) +#if defined(__GNUC__) && defined(M_USE_FINE_GRAINED_LINKAGE) #define M_INLINE \ M_IF_EMPTY(M_USE_DECL)( \ M_IF_EMPTY(M_USE_DEF)(M_INLINE_PRAGMA __attribute__((noinline)) extern, \ M_INLINE_PRAGMA __attribute__((weak, noinline)) extern), \ static inline) +#elif defined(__GNUC__) && defined(M_USE_DECL) +# ifdef M_USE_DEF +# define M_INLINE M_INLINE_PRAGMA __attribute__((noinline)) extern +# else +# define M_INLINE M_INLINE_PRAGMA __attribute__((weak, noinline)) extern +#endif #elif defined(__cplusplus) #define M_INLINE inline #else