From 68d6bd0873557c12bec6f8e0f8db622f1499d8a7 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Thu, 29 Apr 2021 14:31:05 +0200 Subject: Fix trivial -Wundef warnings * See [Feature #17752] Co-authored-by: xtkoba (Tee KOBAYASHI) --- builtin.c | 2 +- builtin.h | 2 +- dir.c | 2 +- eval_intern.h | 2 +- gc.c | 2 +- hash.c | 2 +- include/ruby/internal/attr/const.h | 2 +- memory_view.c | 4 ++-- ractor_core.h | 2 +- ruby.c | 2 +- template/sizes.c.tmpl | 2 +- thread_pthread.h | 2 +- tool/mk_builtin_loader.rb | 2 +- vm.c | 2 +- vm_core.h | 8 ++++---- vm_exec.c | 2 ++ 16 files changed, 21 insertions(+), 19 deletions(-) diff --git a/builtin.c b/builtin.c index 7c3653dab7..21fff95650 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 3b2f477654..5b4bda1e99 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/dir.c b/dir.c index 8ff812e8e7..fb31bd4f22 100644 --- a/dir.c +++ b/dir.c @@ -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 3238df1036..475fd4d3cf 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/gc.c b/gc.c index 1507be6642..4eb5488463 100644 --- a/gc.c +++ b/gc.c @@ -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 000e816781..ce0e72a017 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/internal/attr/const.h b/include/ruby/internal/attr/const.h index b1f27e2606..c9e8577693 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/memory_view.c b/memory_view.c index ce2803717b..9609ecae3f 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 fb104cd22c..63279ebb98 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/ruby.c b/ruby.c index 21c2daa977..9ca7c2a2eb 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/template/sizes.c.tmpl b/template/sizes.c.tmpl index 848a29f4be..31060f5fea 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.h b/thread_pthread.h index 1d6ea1385f..8b7583d266 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 c1d2376a8b..309ff615c7 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 8c62d7dd91..ea8b21e7a5 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 f21d85032c..72120d5302 100644 --- a/vm_core.h +++ b/vm_core.h @@ -670,7 +670,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 @@ -870,7 +870,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 @@ -1804,7 +1804,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; @@ -1891,7 +1891,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_exec.c b/vm_exec.c index 7aa56f6ad6..305ff90261 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 -- cgit v1.2.3