ruby-changes:51904
From: shyouhei <ko1@a...>
Date: Mon, 30 Jul 2018 16:07:55 +0900 (JST)
Subject: [ruby-changes:51904] shyouhei:r64118 (trunk): reduce copy & paste
shyouhei 2018-07-30 16:07:48 +0900 (Mon, 30 Jul 2018) New Revision: 64118 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64118 Log: reduce copy & paste We see several occurrence of "diagnostic push/pop" so why not make them macros. Tested on GCC8 / Clang 6. Note that ruby.h is intentionally left untouched because we don't want to introduce new public macros. Modified files: trunk/cont.c trunk/dln.c trunk/eval_intern.h trunk/internal.h trunk/mjit.c trunk/process.c trunk/template/prelude.c.tmpl Index: mjit.c =================================================================== --- mjit.c (revision 64117) +++ mjit.c (revision 64118) @@ -387,14 +387,13 @@ start_process(const char *path, char *co https://github.com/ruby/ruby/blob/trunk/mjit.c#L387 } dev_null = rb_cloexec_open(ruby_null_device, O_WRONLY, 0); + COMPILER_WARNING_PUSH; #ifdef __GNUC__ -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" + COMPILER_WARNING_IGNORED(-Wdeprecated-declarations); #endif if ((pid = vfork()) == 0) { -#ifdef __GNUC__ -# pragma GCC diagnostic pop -#endif + COMPILER_WARNING_POP; + umask(0077); if (mjit_opts.verbose == 0) { /* CC can be started in a thread using a file which has been Index: dln.c =================================================================== --- dln.c (revision 64117) +++ dln.c (revision 64118) @@ -1244,12 +1244,9 @@ rb_w32_check_imported(HMODULE ext, HMODU https://github.com/ruby/ruby/blob/trunk/dln.c#L1244 #endif #ifdef USE_DLN_DLOPEN -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wpedantic" -#elif defined(__GNUC__) && (__GNUC__ >= 5) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wpedantic" +COMPILER_WARNING_PUSH +#if defined(__clang__) || GCC_VERSION_SINCE(4, 2, 0) +COMPILER_WARNING_IGNORED(-Wpedantic) #endif static bool dln_incompatible_library_p(void *handle) @@ -1257,11 +1254,7 @@ dln_incompatible_library_p(void *handle) https://github.com/ruby/ruby/blob/trunk/dln.c#L1254 void *ex = dlsym(handle, EXTERNAL_PREFIX"ruby_xmalloc"); return ex && ex != ruby_xmalloc; } -#ifdef __clang__ -#pragma clang diagnostic pop -#elif defined(__GNUC__) && (__GNUC__ >= 5) -#pragma GCC diagnostic pop -#endif +COMPILER_WARNING_POP #endif void* Index: process.c =================================================================== --- process.c (revision 64117) +++ process.c (revision 64118) @@ -3972,9 +3972,9 @@ retry_fork_async_signal_safe(int *status https://github.com/ruby/ruby/blob/trunk/process.c#L3972 while (1) { prefork(); disable_child_handler_before_fork(&old); + COMPILER_WARNING_PUSH; #ifdef __GNUC__ -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" + COMPILER_WARNING_IGNORED(-Wdeprecated-declarations); #endif #ifdef HAVE_WORKING_VFORK if (!has_privilege()) @@ -3984,9 +3984,7 @@ retry_fork_async_signal_safe(int *status https://github.com/ruby/ruby/blob/trunk/process.c#L3984 #else pid = fork(); #endif -#ifdef __GNUC__ -# pragma GCC diagnostic pop -#endif + COMPILER_WARNING_POP; if (pid == 0) {/* fork succeed, child process */ int ret; close(ep[0]); @@ -4055,13 +4053,13 @@ rb_fork_ruby(int *status) https://github.com/ruby/ruby/blob/trunk/process.c#L4053 prefork(); disable_child_handler_before_fork(&old); before_fork_ruby(); + COMPILER_WARNING_PUSH; #ifdef __GNUC__ -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" + COMPILER_WARNING_IGNORED(-Wdeprecated-declarations); #endif pid = fork(); #ifdef __GNUC__ -# pragma GCC diagnostic pop + COMPILER_WARNING_POP; #endif err = errno; after_fork_ruby(); Index: cont.c =================================================================== --- cont.c (revision 64117) +++ cont.c (revision 64118) @@ -628,9 +628,9 @@ show_vm_pcs(const rb_control_frame_t *cf https://github.com/ruby/ruby/blob/trunk/cont.c#L628 } } #endif +COMPILER_WARNING_PUSH #ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wduplicate-decl-specifier" +COMPILER_WARNING_IGNORED(-Wduplicate-decl-specifier) #endif static VALUE cont_capture(volatile int *volatile stat) @@ -694,9 +694,7 @@ cont_capture(volatile int *volatile stat https://github.com/ruby/ruby/blob/trunk/cont.c#L694 return contval; } } -#ifdef __clang__ -#pragma clang diagnostic pop -#endif +COMPILER_WARNING_POP static inline void fiber_restore_thread(rb_thread_t *th, rb_fiber_t *fib) Index: internal.h =================================================================== --- internal.h (revision 64117) +++ internal.h (revision 64118) @@ -2147,6 +2147,43 @@ rb_obj_builtin_type(VALUE obj) https://github.com/ruby/ruby/blob/trunk/internal.h#L2147 # define BITFIELD(type) unsigned int #endif +#if defined(_MSC_VER) +# define COMPILER_WARNING_PUSH __pragma(warning(push)) +# define COMPILER_WARNING_POP __pragma(warning(pop)) +# define COMPILER_WARNING_ERROR(flag) __pragma(warning(error: flag))) +# define COMPILER_WARNING_IGNORED(flag) __pragma(warning(suppress: flag))) + +#elif defined(__clang__) /* clang 2.6 already had this feature */ +# define COMPILER_WARNING_PUSH _Pragma("clang diagnostic push") +# define COMPILER_WARNING_POP _Pragma("clang diagnostic pop") +# define COMPILER_WARNING_SPECIFIER(kind, msg) \ + clang diagnostic kind # msg +# define COMPILER_WARNING_ERROR(flag) \ + COMPILER_WARNING_PRAGMA(COMPILER_WARNING_SPECIFIER(error, flag)) +# define COMPILER_WARNING_IGNORED(flag) \ + COMPILER_WARNING_PRAGMA(COMPILER_WARNING_SPECIFIER(ignored, flag)) + +#elif GCC_VERSION_SINCE(4, 2, 0) +/* https://gcc.gnu.org/onlinedocs/gcc-4.2.0/gcc/Diagnostic-Pragmas.html */ +# define COMPILER_WARNING_PUSH _Pragma("GCC diagnostic push") +# define COMPILER_WARNING_POP _Pragma("GCC diagnostic pop") +# define COMPILER_WARNING_SPECIFIER(kind, msg) \ + GCC diagnostic kind # msg +# define COMPILER_WARNING_ERROR(flag) \ + COMPILER_WARNING_PRAGMA(COMPILER_WARNING_SPECIFIER(error, flag)) +# define COMPILER_WARNING_IGNORED(flag) \ + COMPILER_WARNING_PRAGMA(COMPILER_WARNING_SPECIFIER(ignored, flag)) + +#else /* other compilers to follow? */ +# define COMPILER_WARNING_PUSH /* nop */ +# define COMPILER_WARNING_POP /* nop */ +# define COMPILER_WARNING_ERROR(cond, flag) /* nop */ +# define COMPILER_WARNING_ignored(cond, flag) /* nop */ +#endif + +#define COMPILER_WARNING_PRAGMA(str) COMPILER_WARNING_PRAGMA_(str) +#define COMPILER_WARNING_PRAGMA_(str) _Pragma(#str) + #if defined(__cplusplus) #if 0 { /* satisfy cc-mode */ Index: template/prelude.c.tmpl =================================================================== --- template/prelude.c.tmpl (revision 64117) +++ template/prelude.c.tmpl (revision 64118) @@ -138,9 +138,9 @@ prelude_prefix_path(VALUE self) https://github.com/ruby/ruby/blob/trunk/template/prelude.c.tmpl#L138 % unless preludes.empty? #define PRELUDE_NAME(n) rb_usascii_str_new_static(prelude_name##n, sizeof(prelude_name##n)-1) #define PRELUDE_CODE(n) rb_usascii_str_new_static(prelude_code##n.L0, sizeof(prelude_code##n)) -#if defined __GNUC__ && __GNUC__ >= 5 -# pragma GCC diagnostic push -# pragma GCC diagnostic error "-Wmissing-field-initializers" +COMPILER_WARNING_PUSH +#if GCC_VERSION_SINCE(4, 2, 0) +COMPILER_WARNING_ERROR(-Wmissing-field-initializers) #endif static void prelude_eval(VALUE code, VALUE name, int line) @@ -168,9 +168,7 @@ prelude_eval(VALUE code, VALUE name, int https://github.com/ruby/ruby/blob/trunk/template/prelude.c.tmpl#L168 NULL, ISEQ_TYPE_TOP, &optimization)); rb_ast_dispose(ast); } -#if defined __GNUC__ && __GNUC__ >= 5 -# pragma GCC diagnostic pop -#endif +COMPILER_WARNING_POP % end % if @have_sublib Index: eval_intern.h =================================================================== --- eval_intern.h (revision 64117) +++ eval_intern.h (revision 64118) @@ -160,10 +160,10 @@ LONG WINAPI rb_w32_stack_overflow_handle https://github.com/ruby/ruby/blob/trunk/eval_intern.h#L160 #if defined(USE_UNALIGNED_MEMBER_ACCESS) && USE_UNALIGNED_MEMBER_ACCESS && \ defined(__clang__) # define UNALIGNED_MEMBER_ACCESS(expr) __extension__({ \ - _Pragma("GCC diagnostic push"); \ - _Pragma("GCC diagnostic ignored \"-Waddress-of-packed-member\""); \ + COMPILER_WARNING_PUSH; \ + COMPILER_WARNING_IGNORED(-Waddress-of-packed-member); \ typeof(expr) unaligned_member_access_result = (expr); \ - _Pragma("GCC diagnostic pop"); \ + COMPILER_WARNING_POP; \ unaligned_member_access_result; \ }) #else -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/