diff --git a/builtin.c b/builtin.c index 7c3653dab7e778..21fff95650972e 100644 --- a/builtin.c +++ b/builtin.c @@ -3,7 +3,7 @@ #include "iseq.h" #include "builtin.h" -#if CROSS_COMPILING +#ifdef CROSS_COMPILING #define INCLUDED_BY_BUILTIN_C 1 #include "mini_builtin.c" diff --git a/builtin.h b/builtin.h index 3b2f4776544abf..5b4bda1e99b911 100644 --- a/builtin.h +++ b/builtin.h @@ -65,7 +65,7 @@ PUREFUNC(static inline VALUE rb_vm_lvar(rb_execution_context_t *ec, int index)); static inline VALUE rb_vm_lvar(rb_execution_context_t *ec, int index) { -#if VM_CORE_H_EC_DEFINED +#if defined(VM_CORE_H_EC_DEFINED) && VM_CORE_H_EC_DEFINED return ec->cfp->ep[index]; #else return rb_vm_lvar_exposed(ec, index); diff --git a/configure.ac b/configure.ac index fa62b5fa851daa..6605939eac31fb 100644 --- a/configure.ac +++ b/configure.ac @@ -627,6 +627,7 @@ AS_CASE(["$GCC:${warnflags+set}:${extra_warnflags:+set}:"], -Werror=pointer-arith \ -Werror=shorten-64-to-32 \ -Werror=write-strings \ + -Werror=undef \ -Wimplicit-fallthrough=0 \ -Wmissing-noreturn \ -Wno-cast-function-type \ diff --git a/coroutine/copy/Context.h b/coroutine/copy/Context.h index db13604d3fa067..2cb2bc19c85f8c 100644 --- a/coroutine/copy/Context.h +++ b/coroutine/copy/Context.h @@ -23,9 +23,12 @@ #define COROUTINE __attribute__((noreturn)) void +#ifdef HAVE_STDINT_H +#include #if INTPTR_MAX <= INT32_MAX #define COROUTINE_LIMITED_ADDRESS_SPACE #endif +#endif // This stack copying implementation which uses a private stack for each coroutine, including the main one. #define COROUTINE_PRIVATE_STACK diff --git a/coroutine/ucontext/Context.h b/coroutine/ucontext/Context.h index 797108642b6ce0..39d7ca70cabb49 100644 --- a/coroutine/ucontext/Context.h +++ b/coroutine/ucontext/Context.h @@ -16,9 +16,12 @@ #define COROUTINE __attribute__((noreturn)) void +#ifdef HAVE_STDINT_H +#include #if INTPTR_MAX <= INT32_MAX #define COROUTINE_LIMITED_ADDRESS_SPACE #endif +#endif struct coroutine_context { diff --git a/dir.c b/dir.c index 8ff812e8e7b41c..b122b2cb90d46d 100644 --- a/dir.c +++ b/dir.c @@ -50,13 +50,13 @@ # define dirent direct # define NAMLEN(dirent) (dirent)->d_namlen # define HAVE_DIRENT_NAMLEN 1 -# if HAVE_SYS_NDIR_H +# ifdef HAVE_SYS_NDIR_H # include # endif -# if HAVE_SYS_DIR_H +# ifdef HAVE_SYS_DIR_H # include # endif -# if HAVE_NDIR_H +# ifdef HAVE_NDIR_H # include # endif # ifdef _WIN32 @@ -216,7 +216,7 @@ typedef enum { #else #define FNM_SYSCASE 0 #endif -#if _WIN32 +#ifdef _WIN32 #define FNM_SHORTNAME 0x20 #else #define FNM_SHORTNAME 0 diff --git a/eval_intern.h b/eval_intern.h index 3238df1036a29a..475fd4d3cf0acb 100644 --- a/eval_intern.h +++ b/eval_intern.h @@ -144,7 +144,7 @@ LONG WINAPI rb_w32_stack_overflow_handler(struct _EXCEPTION_POINTERS *); #define EC_REPUSH_TAG() (void)(_ec->tag = &_tag) -#if defined __GNUC__ && __GNUC__ == 4 && (__GNUC_MINOR__ >= 6 && __GNUC_MINOR__ <= 8) || __clang__ +#if defined __GNUC__ && __GNUC__ == 4 && (__GNUC_MINOR__ >= 6 && __GNUC_MINOR__ <= 8) || defined __clang__ /* This macro prevents GCC 4.6--4.8 from emitting maybe-uninitialized warnings. * This macro also prevents Clang from dumping core in EC_EXEC_TAG(). * (I confirmed Clang 4.0.1 and 5.0.0.) diff --git a/ext/bigdecimal/missing.h b/ext/bigdecimal/missing.h index 11b58c099d5471..7969849158d46b 100644 --- a/ext/bigdecimal/missing.h +++ b/ext/bigdecimal/missing.h @@ -45,7 +45,7 @@ extern "C" { # if __has_builtin(__builtin_unreachable) # define UNREACHABLE __builtin_unreachable() -# elif HAVE___ASSUME +# elif defined(HAVE___ASSUME) # define UNREACHABLE __assume(0) # else diff --git a/ext/cgi/escape/escape.c b/ext/cgi/escape/escape.c index 77627e2f03cb58..3a7837e4df963c 100644 --- a/ext/cgi/escape/escape.c +++ b/ext/cgi/escape/escape.c @@ -388,7 +388,7 @@ cgiesc_unescape(int argc, VALUE *argv, VALUE self) void Init_escape(void) { -#if HAVE_RB_EXT_RACTOR_SAFE +#ifdef HAVE_RB_EXT_RACTOR_SAFE rb_ext_ractor_safe(true); #endif diff --git a/ext/monitor/monitor.c b/ext/monitor/monitor.c index 43a18f58af29e2..00d663195f245e 100644 --- a/ext/monitor/monitor.c +++ b/ext/monitor/monitor.c @@ -203,7 +203,7 @@ monitor_synchronize(VALUE monitor) void Init_monitor(void) { -#if HAVE_RB_EXT_RACTOR_SAFE +#ifdef HAVE_RB_EXT_RACTOR_SAFE rb_ext_ractor_safe(true); #endif diff --git a/ext/nkf/nkf-utf8/nkf.h b/ext/nkf/nkf-utf8/nkf.h index cd3037601b35d5..b3a520da54edff 100644 --- a/ext/nkf/nkf-utf8/nkf.h +++ b/ext/nkf/nkf-utf8/nkf.h @@ -16,8 +16,8 @@ #define X0201_DEFAULT TRUE #endif -#if DEFAULT_NEWLINE == 0x0D0A -#elif DEFAULT_NEWLINE == 0x0D +#if defined(DEFAULT_NEWLINE) && DEFAULT_NEWLINE == 0x0D0A +#elif defined(DEFAULT_NEWLINE) && DEFAULT_NEWLINE == 0x0D #else #define DEFAULT_NEWLINE 0x0A #endif diff --git a/ext/openssl/ossl_pkey_ec.c b/ext/openssl/ossl_pkey_ec.c index deca4f43b047af..be9b09cae6680e 100644 --- a/ext/openssl/ossl_pkey_ec.c +++ b/ext/openssl/ossl_pkey_ec.c @@ -1469,7 +1469,7 @@ static VALUE ossl_ec_point_mul(int argc, VALUE *argv, VALUE self) if (EC_POINT_mul(group, point_result, bn_g, point_self, bn, ossl_bn_ctx) != 1) ossl_raise(eEC_POINT, NULL); } else { -#if OPENSSL_VERSION_MAJOR+0 >= 3 || defined(LIBRESSL_VERSION_NUMBER) +#if (defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 3) || defined(LIBRESSL_VERSION_NUMBER) rb_raise(rb_eNotImpError, "calling #mul with arrays is not" \ "supported by this OpenSSL version"); #else diff --git a/ext/psych/yaml/yaml_private.h b/ext/psych/yaml/yaml_private.h index 6c674de147a5c4..266a6bd3a75183 100644 --- a/ext/psych/yaml/yaml_private.h +++ b/ext/psych/yaml/yaml_private.h @@ -2,7 +2,7 @@ #include RUBY_EXTCONF_H #endif -#if HAVE_CONFIG_H +#ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/ext/racc/cparse/cparse.c b/ext/racc/cparse/cparse.c index 8614c10e09099c..f71ed2bba9e5c7 100644 --- a/ext/racc/cparse/cparse.c +++ b/ext/racc/cparse/cparse.c @@ -819,7 +819,7 @@ reduce0(RB_BLOCK_CALL_FUNC_ARGLIST(_, data)) void Init_cparse(void) { -#if HAVE_RB_EXT_RACTOR_SAFE +#ifdef HAVE_RB_EXT_RACTOR_SAFE rb_ext_ractor_safe(true); #endif diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 45919202e4dfd0..4c5349783bd0fb 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -4564,7 +4564,7 @@ zlib_gunzip_run(VALUE arg) void Init_zlib(void) { -#if HAVE_RB_EXT_RACTOR_SAFE +#ifdef HAVE_RB_EXT_RACTOR_SAFE rb_ext_ractor_safe(true); #endif diff --git a/gc.c b/gc.c index 4d78b85543561f..feb3850600e900 100644 --- a/gc.c +++ b/gc.c @@ -45,7 +45,7 @@ #ifdef HAVE_MALLOC_USABLE_SIZE # ifdef RUBY_ALTERNATIVE_MALLOC_HEADER # include RUBY_ALTERNATIVE_MALLOC_HEADER -# elif HAVE_MALLOC_H +# elif defined(HAVE_MALLOC_H) # include # elif defined(HAVE_MALLOC_NP_H) # include @@ -381,7 +381,7 @@ static ruby_gc_params_t gc_params = { #endif #if RGENGC_DEBUG < 0 && !defined(_MSC_VER) # define RGENGC_DEBUG_ENABLED(level) (-(RGENGC_DEBUG) >= (level) && ruby_rgengc_debug >= (level)) -#elif HAVE_VA_ARGS_MACRO +#elif defined(HAVE_VA_ARGS_MACRO) # define RGENGC_DEBUG_ENABLED(level) ((RGENGC_DEBUG) >= (level)) #else # define RGENGC_DEBUG_ENABLED(level) 0 @@ -830,7 +830,7 @@ enum { }; #define HEAP_PAGE_ALIGN (1 << HEAP_PAGE_ALIGN_LOG) #define HEAP_PAGE_SIZE HEAP_PAGE_ALIGN -#if defined(HAVE_MMAP) && (PAGE_SIZE <= HEAP_PAGE_SIZE) +#if defined(HAVE_MMAP) && (!defined(PAGE_SIZE) || PAGE_SIZE <= HEAP_PAGE_SIZE) # define USE_MMAP_ALIGNED_ALLOC 1 #else # define USE_MMAP_ALIGNED_ALLOC 0 diff --git a/hash.c b/hash.c index a36310209b474f..18ce5dc50d43f7 100644 --- a/hash.c +++ b/hash.c @@ -800,7 +800,7 @@ ar_force_convert_table(VALUE hash, const char *file, int line) if (RHASH_AR_TABLE(hash)) { unsigned i, bound = RHASH_AR_TABLE_BOUND(hash); -#if RHASH_CONVERT_TABLE_DEBUG +#if defined(RHASH_CONVERT_TABLE_DEBUG) && RHASH_CONVERT_TABLE_DEBUG rb_obj_info_dump(hash); fprintf(stderr, "force_convert: %s:%d\n", file, line); RB_DEBUG_COUNTER_INC(obj_hash_force_convert); diff --git a/include/ruby/backward/2/attributes.h b/include/ruby/backward/2/attributes.h index eaff9e3381a19b..0389f82190eeaf 100644 --- a/include/ruby/backward/2/attributes.h +++ b/include/ruby/backward/2/attributes.h @@ -90,16 +90,12 @@ #define ERRORFUNC(mesg, x) RBIMPL_ATTR_ERROR(mesg) x #if RBIMPL_HAS_ATTRIBUTE(error) # define HAVE_ATTRIBUTE_ERRORFUNC 1 -#else -# define HAVE_ATTRIBUTE_ERRORFUNC 0 #endif #undef WARNINGFUNC #define WARNINGFUNC(mesg, x) RBIMPL_ATTR_WARNING(mesg) x #if RBIMPL_HAS_ATTRIBUTE(warning) # define HAVE_ATTRIBUTE_WARNINGFUNC 1 -#else -# define HAVE_ATTRIBUTE_WARNINGFUNC 0 #endif /* diff --git a/include/ruby/internal/attr/const.h b/include/ruby/internal/attr/const.h index b1f27e2606787b..c9e8577693d378 100644 --- a/include/ruby/internal/attr/const.h +++ b/include/ruby/internal/attr/const.h @@ -37,7 +37,7 @@ #endif /** Enables #RBIMPL_ATTR_CONST if and only if. ! #RUBY_DEBUG. */ -#if !RUBY_DEBUG +#if !defined(RUBY_DEBUG) || !RUBY_DEBUG # define RBIMPL_ATTR_CONST_UNLESS_DEBUG() RBIMPL_ATTR_CONST() #else # define RBIMPL_ATTR_CONST_UNLESS_DEBUG() /* void */ diff --git a/include/ruby/internal/core/rbasic.h b/include/ruby/internal/core/rbasic.h index a6093c047a9916..aafec2422f7a72 100644 --- a/include/ruby/internal/core/rbasic.h +++ b/include/ruby/internal/core/rbasic.h @@ -37,10 +37,11 @@ /** @cond INTERNAL_MACRO */ #define RBIMPL_EMBED_LEN_MAX_OF(T) \ - RBIMPL_CAST((int)(sizeof(VALUE[RVALUE_EMBED_LEN_MAX]) / (sizeof(T)))) + RBIMPL_CAST((int)(sizeof(VALUE[RBIMPL_RVALUE_EMBED_LEN_MAX]) / (sizeof(T)))) /** @endcond */ -enum ruby_rvalue_flags { RVALUE_EMBED_LEN_MAX = 3 }; +#define RBIMPL_RVALUE_EMBED_LEN_MAX 3 +enum ruby_rvalue_flags { RVALUE_EMBED_LEN_MAX = RBIMPL_RVALUE_EMBED_LEN_MAX }; struct RUBY_ALIGNAS(SIZEOF_VALUE) diff --git a/include/ruby/internal/has/builtin.h b/include/ruby/internal/has/builtin.h index a59f8357551b45..01b1861eef31a1 100644 --- a/include/ruby/internal/has/builtin.h +++ b/include/ruby/internal/has/builtin.h @@ -50,6 +50,7 @@ # define RBIMPL_HAS_BUILTIN___builtin_add_overflow RBIMPL_COMPILER_SINCE(GCC, 5, 1, 0) # define RBIMPL_HAS_BUILTIN___builtin_alloca RBIMPL_COMPILER_SINCE(GCC, 0, 0, 0) # define RBIMPL_HAS_BUILTIN___builtin_alloca_with_align RBIMPL_COMPILER_SINCE(GCC, 6, 1, 0) +# define RBIMPL_HAS_BUILTIN___builtin_assume 0 # /* See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52624 for bswap16. */ # define RBIMPL_HAS_BUILTIN___builtin_bswap16 RBIMPL_COMPILER_SINCE(GCC, 4, 8, 0) # define RBIMPL_HAS_BUILTIN___builtin_bswap32 RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) @@ -67,6 +68,10 @@ # define RBIMPL_HAS_BUILTIN___builtin_popcount RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) # define RBIMPL_HAS_BUILTIN___builtin_popcountl RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) # define RBIMPL_HAS_BUILTIN___builtin_popcountll RBIMPL_COMPILER_SINCE(GCC, 3, 6, 0) +# define RBIMPL_HAS_BUILTIN___builtin_rotateleft32 0 +# define RBIMPL_HAS_BUILTIN___builtin_rotateleft64 0 +# define RBIMPL_HAS_BUILTIN___builtin_rotateright32 0 +# define RBIMPL_HAS_BUILTIN___builtin_rotateright64 0 # define RBIMPL_HAS_BUILTIN___builtin_sub_overflow RBIMPL_COMPILER_SINCE(GCC, 5, 1, 0) # define RBIMPL_HAS_BUILTIN___builtin_unreachable RBIMPL_COMPILER_SINCE(GCC, 4, 5, 0) # /* Note that "0, 0, 0" might be inaccurate. */ @@ -79,7 +84,9 @@ # /* Take config.h definition when available */ # define RBIMPL_HAS_BUILTIN(_) ((RBIMPL_HAS_BUILTIN_ ## _)+0) # define RBIMPL_HAS_BUILTIN___builtin_add_overflow HAVE_BUILTIN___BUILTIN_ADD_OVERFLOW +# define RBIMPL_HAS_BUILTIN___builtin_alloca 0 # define RBIMPL_HAS_BUILTIN___builtin_alloca_with_align HAVE_BUILTIN___BUILTIN_ALLOCA_WITH_ALIGN +# define RBIMPL_HAS_BUILTIN___builtin_assume 0 # define RBIMPL_HAS_BUILTIN___builtin_assume_aligned HAVE_BUILTIN___BUILTIN_ASSUME_ALIGNED # define RBIMPL_HAS_BUILTIN___builtin_bswap16 HAVE_BUILTIN___BUILTIN_BSWAP16 # define RBIMPL_HAS_BUILTIN___builtin_bswap32 HAVE_BUILTIN___BUILTIN_BSWAP32 @@ -89,15 +96,23 @@ # define RBIMPL_HAS_BUILTIN___builtin_clzll HAVE_BUILTIN___BUILTIN_CLZLL # define RBIMPL_HAS_BUILTIN___builtin_constant_p HAVE_BUILTIN___BUILTIN_CONSTANT_P # define RBIMPL_HAS_BUILTIN___builtin_ctz HAVE_BUILTIN___BUILTIN_CTZ +# define RBIMPL_HAS_BUILTIN___builtin_ctzl 0 # define RBIMPL_HAS_BUILTIN___builtin_ctzll HAVE_BUILTIN___BUILTIN_CTZLL # define RBIMPL_HAS_BUILTIN___builtin_expect HAVE_BUILTIN___BUILTIN_EXPECT # define RBIMPL_HAS_BUILTIN___builtin_mul_overflow HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW # define RBIMPL_HAS_BUILTIN___builtin_mul_overflow_p HAVE_BUILTIN___BUILTIN_MUL_OVERFLOW_P # define RBIMPL_HAS_BUILTIN___builtin_popcount HAVE_BUILTIN___BUILTIN_POPCOUNT +# define RBIMPL_HAS_BUILTIN___builtin_popcountl 0 +# define RBIMPL_HAS_BUILTIN___builtin_rotateleft32 0 +# define RBIMPL_HAS_BUILTIN___builtin_rotateleft64 0 +# define RBIMPL_HAS_BUILTIN___builtin_rotateright32 0 +# define RBIMPL_HAS_BUILTIN___builtin_rotateright64 0 # define RBIMPL_HAS_BUILTIN___builtin_popcountll HAVE_BUILTIN___BUILTIN_POPCOUNTLL # define RBIMPL_HAS_BUILTIN___builtin_sub_overflow HAVE_BUILTIN___BUILTIN_SUB_OVERFLOW # if defined(UNREACHABLE) # define RBIMPL_HAS_BUILTIN___builtin_unreachable 1 +# else +# define RBIMPL_HAS_BUILTIN___builtin_unreachable 0 # endif #endif diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index ce5f6c652db157..341a71695395ad 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -72,7 +72,7 @@ VALUE rb_get_path_no_checksafe(VALUE); ((argc) == 0 ? (vargc) <= 1 : /* [ruby-core:85266] [Bug #14425] */ \ (argc) == (vargc)) # if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P) -# if HAVE_ATTRIBUTE_ERRORFUNC +# ifdef HAVE_ATTRIBUTE_ERRORFUNC ERRORFUNC((" argument length doesn't match"), int rb_varargs_bad_length(int,int)); # else # define rb_varargs_bad_length(argc, vargc) \ diff --git a/internal/bignum.h b/internal/bignum.h index aaada45ed87913..9b89e61f28fea1 100644 --- a/internal/bignum.h +++ b/internal/bignum.h @@ -83,8 +83,8 @@ #define BIGNUM_EMBED_LEN_SHIFT \ (FL_USHIFT+3) /* bit offset of BIGNUM_EMBED_LEN_MASK */ #ifndef BIGNUM_EMBED_LEN_MAX -# if (SIZEOF_VALUE*RVALUE_EMBED_LEN_MAX/SIZEOF_ACTUAL_BDIGIT) < (1 << BIGNUM_EMBED_LEN_NUMBITS)-1 -# define BIGNUM_EMBED_LEN_MAX (SIZEOF_VALUE*RVALUE_EMBED_LEN_MAX/SIZEOF_ACTUAL_BDIGIT) +# if (SIZEOF_VALUE*RBIMPL_RVALUE_EMBED_LEN_MAX/SIZEOF_ACTUAL_BDIGIT) < (1 << BIGNUM_EMBED_LEN_NUMBITS)-1 +# define BIGNUM_EMBED_LEN_MAX (SIZEOF_VALUE*RBIMPL_RVALUE_EMBED_LEN_MAX/SIZEOF_ACTUAL_BDIGIT) # else # define BIGNUM_EMBED_LEN_MAX ((1 << BIGNUM_EMBED_LEN_NUMBITS)-1) # endif diff --git a/memory_view.c b/memory_view.c index ce2803717b4125..9609ecae3f89a8 100644 --- a/memory_view.c +++ b/memory_view.c @@ -671,7 +671,7 @@ extract_item_member(const uint8_t *ptr, const rb_memory_view_item_component_t *m return LL2NUM(val.ll); } else { -#if SIZEOF_INT64_t == SIZEOF_LONG +#if SIZEOF_INT64_T == SIZEOF_LONG return LONG2NUM(val.i64); #else return LL2NUM(val.i64); @@ -683,7 +683,7 @@ extract_item_member(const uint8_t *ptr, const rb_memory_view_item_component_t *m return ULL2NUM(val.ull); } else { -#if SIZEOF_UINT64_t == SIZEOF_LONG +#if SIZEOF_UINT64_T == SIZEOF_LONG return ULONG2NUM(val.u64); #else return ULL2NUM(val.u64); diff --git a/ractor_core.h b/ractor_core.h index fb104cd22c78f2..63279ebb989911 100644 --- a/ractor_core.h +++ b/ractor_core.h @@ -261,7 +261,7 @@ static inline void rb_ractor_set_current_ec(rb_ractor_t *cr, rb_execution_context_t *ec) { #ifdef RB_THREAD_LOCAL_SPECIFIER - #if __APPLE__ + #ifdef __APPLE__ rb_current_ec_set(ec); #else ruby_current_ec = ec; diff --git a/random.c b/random.c index eec017cfd5724e..2c9fe0c9065e3e 100644 --- a/random.c +++ b/random.c @@ -428,7 +428,7 @@ random_init(int argc, VALUE *argv, VALUE obj) # define USE_DEV_URANDOM 0 #endif -#if HAVE_GETENTROPY +#ifdef HAVE_GETENTROPY # define MAX_SEED_LEN_PER_READ 256 static int fill_random_bytes_urandom(void *seed, size_t size) diff --git a/ruby.c b/ruby.c index 21c2daa977822e..9ca7c2a2eb8f6a 100644 --- a/ruby.c +++ b/ruby.c @@ -1826,7 +1826,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) opt->script_name = rb_str_new_cstr(opt->script); opt->script = RSTRING_PTR(opt->script_name); -#if _WIN32 +#ifdef _WIN32 translit_char_bin(RSTRING_PTR(opt->script_name), '\\', '/'); #elif defined DOSISH translit_char(RSTRING_PTR(opt->script_name), '\\', '/'); diff --git a/signal.c b/signal.c index 2ebd1196fa3ec3..46ac6c26cc82d8 100644 --- a/signal.c +++ b/signal.c @@ -29,7 +29,7 @@ # include #endif -#if HAVE_PTHREAD_H +#ifdef HAVE_PTHREAD_H # include #endif diff --git a/siphash.c b/siphash.c index ddf8ee245d818c..2c48fa8496428b 100644 --- a/siphash.c +++ b/siphash.c @@ -180,7 +180,7 @@ int_sip_dump(sip_state *state) int v; for (v = 0; v < 4; v++) { -#if HAVE_UINT64_T +#ifdef HAVE_UINT64_T printf("v%d: %" PRIx64 "\n", v, state->v[v]); #else printf("v%d: %" PRIx32 "%.8" PRIx32 "\n", v, state->v[v].hi, state->v[v].lo); @@ -447,7 +447,7 @@ sip_hash13(const uint8_t key[16], const uint8_t *data, size_t len) OR_BYTE(4); case 4: #if BYTE_ORDER == LITTLE_ENDIAN && UNALIGNED_WORD_ACCESS - #if HAVE_UINT64_T + #ifdef HAVE_UINT64_T last |= (uint64_t) ((uint32_t *) end)[0]; #else last.lo |= ((uint32_t *) end)[0]; diff --git a/strftime.c b/strftime.c index c3d600114f0697..a12f0200b48554 100644 --- a/strftime.c +++ b/strftime.c @@ -59,7 +59,7 @@ #endif #if defined(TM_IN_SYS_TIME) || !defined(GAWK) #include -#if HAVE_SYS_TIME_H +#ifdef HAVE_SYS_TIME_H #include #endif #endif diff --git a/template/sizes.c.tmpl b/template/sizes.c.tmpl index 848a29f4beb747..31060f5fea676d 100644 --- a/template/sizes.c.tmpl +++ b/template/sizes.c.tmpl @@ -43,7 +43,7 @@ Init_sizeof(void) % next % end % cond = conditions[type] -#if SIZEOF_<%= type.tr_cpp %> != 0<%= " && #{cond}" if cond %> +#if defined(SIZEOF_<%= type.tr_cpp %>) && SIZEOF_<%= type.tr_cpp %> != 0<%= " && #{cond}" if cond %> DEFINE(<%= type %>, <%= type.tr_cpp %>); #endif % end diff --git a/thread_pthread.c b/thread_pthread.c index 8149ee57f54507..3e0c78b256b2c3 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -20,9 +20,9 @@ #ifdef HAVE_THR_STKSEGMENT #include #endif -#if HAVE_FCNTL_H +#if defined(HAVE_FCNTL_H) #include -#elif HAVE_SYS_FCNTL_H +#elif defined(HAVE_SYS_FCNTL_H) #include #endif #ifdef HAVE_SYS_PRCTL_H diff --git a/thread_pthread.h b/thread_pthread.h index 1d6ea1385fe831..8b7583d2664beb 100644 --- a/thread_pthread.h +++ b/thread_pthread.h @@ -100,7 +100,7 @@ native_tls_set(native_tls_key_t key, void *ptr) RUBY_SYMBOL_EXPORT_BEGIN #ifdef RB_THREAD_LOCAL_SPECIFIER - #if __APPLE__ + #ifdef __APPLE__ // on Darwin, TLS can not be accessed across .so struct rb_execution_context_struct *rb_current_ec(); void rb_current_ec_set(struct rb_execution_context_struct *); diff --git a/tool/mk_builtin_loader.rb b/tool/mk_builtin_loader.rb index c1d2376a8b14f3..309ff615c754d7 100644 --- a/tool/mk_builtin_loader.rb +++ b/tool/mk_builtin_loader.rb @@ -343,7 +343,7 @@ def mk_builtin_header file f.puts f.puts " // arity_check" f.puts "COMPILER_WARNING_PUSH" - f.puts "#if GCC_VERSION_SINCE(5, 1, 0) || __clang__" + f.puts "#if GCC_VERSION_SINCE(5, 1, 0) || defined __clang__" f.puts "COMPILER_WARNING_ERROR(-Wincompatible-pointer-types)" f.puts "#endif" bs.each{|func, (argc, cfunc_name)| diff --git a/vm.c b/vm.c index 8c62d7dd91e50c..ea8b21e7a5f192 100644 --- a/vm.c +++ b/vm.c @@ -3262,7 +3262,7 @@ static VALUE nsdr(VALUE self) { VALUE ary = rb_ary_new(); -#if HAVE_BACKTRACE +#ifdef HAVE_BACKTRACE #include #define MAX_NATIVE_TRACE 1024 static void *trace[MAX_NATIVE_TRACE]; diff --git a/vm_core.h b/vm_core.h index 31ac4ace76991a..56d2f7d8ac96d5 100644 --- a/vm_core.h +++ b/vm_core.h @@ -662,7 +662,7 @@ typedef struct rb_vm_struct { #endif const struct rb_callcache *global_cc_cache_table[VM_GLOBAL_CC_CACHE_TABLE_SIZE]; // vm_eval.c -#if USE_VM_CLOCK +#if defined(USE_VM_CLOCK) && USE_VM_CLOCK uint32_t clock; #endif @@ -862,7 +862,7 @@ struct rb_execution_context_struct { /* interrupt flags */ rb_atomic_t interrupt_flag; rb_atomic_t interrupt_mask; /* size should match flag */ -#if USE_VM_CLOCK +#if defined(USE_VM_CLOCK) && USE_VM_CLOCK uint32_t checked_clock; #endif @@ -1796,7 +1796,7 @@ static inline rb_execution_context_t * rb_current_execution_context(void) { #ifdef RB_THREAD_LOCAL_SPECIFIER - #if __APPLE__ + #ifdef __APPLE__ rb_execution_context_t *ec = rb_current_ec(); #else rb_execution_context_t *ec = ruby_current_ec; @@ -1883,7 +1883,7 @@ enum { static inline bool RUBY_VM_INTERRUPTED_ANY(rb_execution_context_t *ec) { -#if USE_VM_CLOCK +#if defined(USE_VM_CLOCK) && USE_VM_CLOCK uint32_t current_clock = rb_ec_vm_ptr(ec)->clock; if (current_clock != ec->checked_clock) { diff --git a/vm_dump.c b/vm_dump.c index 109757a14e955e..26a2bf3ba4951b 100644 --- a/vm_dump.c +++ b/vm_dump.c @@ -470,6 +470,7 @@ rb_vmdebug_thread_dump_state(VALUE self) #endif #if defined(HAVE_BACKTRACE) +# define USE_BACKTRACE 1 # ifdef HAVE_LIBUNWIND # undef backtrace # define backtrace unw_backtrace @@ -572,14 +573,14 @@ backtrace(void **trace, int size) return n; } # elif defined(BROKEN_BACKTRACE) -# undef HAVE_BACKTRACE -# define HAVE_BACKTRACE 0 +# undef USE_BACKTRACE +# define USE_BACKTRACE 0 # endif #else -# define HAVE_BACKTRACE 0 +# define USE_BACKTRACE 0 #endif -#if HAVE_BACKTRACE +#if USE_BACKTRACE # include #elif defined(_WIN32) # include @@ -752,7 +753,7 @@ dump_thread(void *arg) void rb_print_backtrace(void) { -#if HAVE_BACKTRACE +#if USE_BACKTRACE #define MAX_NATIVE_TRACE 1024 static void *trace[MAX_NATIVE_TRACE]; int n = (int)backtrace(trace, MAX_NATIVE_TRACE); @@ -1034,14 +1035,14 @@ rb_vm_bugreport(const void *ctx) rb_dump_machine_register(ctx); -#if HAVE_BACKTRACE || defined(_WIN32) +#if USE_BACKTRACE || defined(_WIN32) fprintf(stderr, "-- C level backtrace information " "-------------------------------------------\n"); rb_print_backtrace(); fprintf(stderr, "\n"); -#endif /* HAVE_BACKTRACE */ +#endif /* USE_BACKTRACE */ if (other_runtime_info || vm) { fprintf(stderr, "-- Other runtime information " diff --git a/vm_exec.c b/vm_exec.c index 7aa56f6ad620bb..305ff9026101d0 100644 --- a/vm_exec.c +++ b/vm_exec.c @@ -104,6 +104,8 @@ vm_exec_core(rb_execution_context_t *ec, VALUE initial) #else register rb_control_frame_t *reg_cfp; const VALUE *reg_pc; +#define USE_MACHINE_REGS 0 + #endif #if USE_MACHINE_REGS