diff --git a/extlib/benz/include/picrin.h b/extlib/benz/include/picrin.h index a95a6935..0c2ef296 100644 --- a/extlib/benz/include/picrin.h +++ b/extlib/benz/include/picrin.h @@ -33,13 +33,8 @@ extern "C" { #include #include "picrin/config.h" -#include "picrin/util.h" + #include "picrin/compat.h" - -#if PIC_ENABLE_FLOAT -# include -#endif - #include "picrin/xvect.h" #include "picrin/xhash.h" diff --git a/extlib/benz/include/picrin/compat.h b/extlib/benz/include/picrin/compat.h index cca83d95..24f82691 100644 --- a/extlib/benz/include/picrin/compat.h +++ b/extlib/benz/include/picrin/compat.h @@ -9,6 +9,77 @@ extern "C" { #endif +#if __STDC_VERSION__ >= 199901L +# include +#else +# define bool char +# define true 1 +# define false 0 +#endif + +#if __STDC_VERSION__ >= 199901L +# include +#elif ! defined(offsetof) +# define offsetof(s,m) ((size_t)&(((s *)NULL)->m)) +#endif + +#if __STDC_VERSION__ >= 201112L +# include +# define PIC_NORETURN noreturn +#elif __GNUC__ || __clang__ +# define PIC_NORETURN __attribute__((noreturn)) +#else +# define PIC_NORETURN +#endif + +#if __STDC_VERSION__ >= 199901L +# define PIC_INLINE static inline +#elif __GNUC__ || __clang__ +# define PIC_INLINE static __inline__ +#else +# define PIC_INLINE static +#endif + +#define PIC_FALLTHROUGH ((void)0) + +#if __GNUC__ || __clang__ +# define PIC_UNUSED(v) __attribute__((unused)) v +#else +# define PIC_UNUSED(v) v +#endif + +#define PIC_GENSYM2_(x,y) PIC_G##x##_##y##_ +#define PIC_GENSYM1_(x,y) PIC_GENSYM2_(x,y) +#if defined(__COUNTER__) +# define PIC_GENSYM(x) PIC_GENSYM1_(__COUNTER__,x) +#else +# define PIC_GENSYM(x) PIC_GENSYM1_(__LINE__,x) +#endif + +#if __GNUC__ +# define GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) +#endif +#if GCC_VERSION >= 40500 || __clang__ +# define PIC_UNREACHABLE() (__builtin_unreachable()) +#else +# define PIC_UNREACHABLE() (assert(false)) +#endif +#if __GNUC__ +# undef GCC_VERSION +#endif + +#define PIC_SWAP(type,a,b) \ + PIC_SWAP_HELPER_(type, PIC_GENSYM(tmp), a, b) +#define PIC_SWAP_HELPER_(type,tmp,a,b) \ + do { \ + type tmp = (a); \ + (a) = (b); \ + (b) = tmp; \ + } while (0) + + #if PIC_ENABLE_LIBC #include @@ -134,6 +205,10 @@ strcpy(char *dst, const char *src) #endif +#if PIC_ENABLE_FLOAT +# include +#endif + #if defined(__cplusplus) } #endif diff --git a/extlib/benz/include/picrin/util.h b/extlib/benz/include/picrin/util.h deleted file mode 100644 index ad816c70..00000000 --- a/extlib/benz/include/picrin/util.h +++ /dev/null @@ -1,86 +0,0 @@ -/** - * See Copyright Notice in picrin.h - */ - -#ifndef PICRIN_UTIL_H -#define PICRIN_UTIL_H - -#if defined(__cplusplus) -extern "C" { -#endif - -#if __STDC_VERSION__ >= 199901L -# include -#else -# define bool char -# define true 1 -# define false 0 -#endif - -#if __STDC_VERSION__ >= 199901L -# include -#elif ! defined(offsetof) -# define offsetof(s,m) ((size_t)&(((s *)NULL)->m)) -#endif - -#if __STDC_VERSION__ >= 201112L -# include -# define PIC_NORETURN noreturn -#elif __GNUC__ || __clang__ -# define PIC_NORETURN __attribute__((noreturn)) -#else -# define PIC_NORETURN -#endif - -#if __STDC_VERSION__ >= 199901L -# define PIC_INLINE static inline -#elif __GNUC__ || __clang__ -# define PIC_INLINE static __inline__ -#else -# define PIC_INLINE static -#endif - -#define PIC_FALLTHROUGH ((void)0) - -#if __GNUC__ || __clang__ -# define PIC_UNUSED(v) __attribute__((unused)) v -#else -# define PIC_UNUSED(v) v -#endif - -#define PIC_GENSYM2_(x,y) PIC_G##x##_##y##_ -#define PIC_GENSYM1_(x,y) PIC_GENSYM2_(x,y) -#if defined(__COUNTER__) -# define PIC_GENSYM(x) PIC_GENSYM1_(__COUNTER__,x) -#else -# define PIC_GENSYM(x) PIC_GENSYM1_(__LINE__,x) -#endif - -#if __GNUC__ -# define GCC_VERSION (__GNUC__ * 10000 \ - + __GNUC_MINOR__ * 100 \ - + __GNUC_PATCHLEVEL__) -#endif -#if GCC_VERSION >= 40500 || __clang__ -# define PIC_UNREACHABLE() (__builtin_unreachable()) -#else -# define PIC_UNREACHABLE() (assert(false)) -#endif -#if __GNUC__ -# undef GCC_VERSION -#endif - -#define PIC_SWAP(type,a,b) \ - PIC_SWAP_HELPER_(type, PIC_GENSYM(tmp), a, b) -#define PIC_SWAP_HELPER_(type,tmp,a,b) \ - do { \ - type tmp = (a); \ - (a) = (b); \ - (b) = tmp; \ - } while (0) - -#if defined(__cplusplus) -} -#endif - -#endif