ruby-changes:52090
From: k0kubun <ko1@a...>
Date: Sat, 11 Aug 2018 23:05:40 +0900 (JST)
Subject: [ruby-changes:52090] k0kubun:r64298 (trunk): mjit_worker.c: share MJIT warning logic
k0kubun 2018-08-11 23:05:34 +0900 (Sat, 11 Aug 2018) New Revision: 64298 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64298 Log: mjit_worker.c: share MJIT warning logic as mjit_warning(). mjit.c: ditto Modified files: trunk/mjit.c trunk/mjit_worker.c Index: mjit.c =================================================================== --- mjit.c (revision 64297) +++ mjit.c (revision 64298) @@ -319,8 +319,7 @@ mjit_get_iseq_func(struct rb_iseq_consta https://github.com/ruby/ruby/blob/trunk/mjit.c#L319 CRITICAL_SECTION_START(3, "in mjit_get_iseq_func to set jit_func"); body->jit_func = (mjit_func_t)NOT_COMPILED_JIT_ISEQ_FUNC; /* JIT worker seems dead. Give up. */ CRITICAL_SECTION_FINISH(3, "in mjit_get_iseq_func to set jit_func"); - if (mjit_opts.warnings || mjit_opts.verbose) - fprintf(stderr, "MJIT warning: timed out to wait for JIT finish\n"); + mjit_warning("timed out to wait for JIT finish"); break; } Index: mjit_worker.c =================================================================== --- mjit_worker.c (revision 64297) +++ mjit_worker.c (revision 64298) @@ -287,14 +287,28 @@ static const char *const CC_LIBS[] = { https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L287 PRINTF_ARGS(static void, 2, 3) verbose(int level, const char *format, ...) { - va_list args; + if (mjit_opts.verbose >= level) { + va_list args; - va_start(args, format); - if (mjit_opts.verbose >= level) + va_start(args, format); vfprintf(stderr, format, args); - va_end(args); - if (mjit_opts.verbose >= level) + va_end(args); fprintf(stderr, "\n"); + } +} + +PRINTF_ARGS(static void, 1, 2) +mjit_warning(const char *format, ...) +{ + if (mjit_opts.warnings || mjit_opts.verbose) { + va_list args; + + fprintf(stderr, "MJIT warning: "); + va_start(args, format); + vfprintf(stderr, format, args); + va_end(args); + fprintf(stderr, "\n"); + } } /* Allocate struct rb_mjit_unit_node and return it. This MUST NOT be @@ -352,9 +366,8 @@ remove_from_list(struct rb_mjit_unit_nod https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L366 static void remove_file(const char *filename) { - if (remove(filename) && (mjit_opts.warnings || mjit_opts.verbose)) { - fprintf(stderr, "MJIT warning: failed to remove \"%s\": %s\n", - filename, strerror(errno)); + if (remove(filename)) { + mjit_warning("failed to remove \"%s\": %s", filename, strerror(errno)); } } @@ -734,8 +747,7 @@ make_pch(void) https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L747 verbose(2, "Creating precompiled header"); args = form_args(3, CC_COMMON_ARGS, CC_CODEFLAG_ARGS, rest_args); if (args == NULL) { - if (mjit_opts.warnings || mjit_opts.verbose) - fprintf(stderr, "MJIT warning: making precompiled header failed on forming args\n"); + mjit_warning("making precompiled header failed on forming args"); CRITICAL_SECTION_START(3, "in make_pch"); pch_status = PCH_FAILED; CRITICAL_SECTION_FINISH(3, "in make_pch"); @@ -748,9 +760,9 @@ make_pch(void) https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L760 CRITICAL_SECTION_START(3, "in make_pch"); if (exit_code == 0) { pch_status = PCH_SUCCESS; - } else { - if (mjit_opts.warnings || mjit_opts.verbose) - fprintf(stderr, "MJIT warning: Making precompiled header failed on compilation. Stopping MJIT worker...\n"); + } + else { + mjit_warning("Making precompiled header failed on compilation. Stopping MJIT worker..."); pch_status = PCH_FAILED; } /* wakeup `mjit_finish` */ @@ -859,8 +871,7 @@ compact_all_jit_code(void) https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L871 if (success) { void *handle = dlopen(so_file, RTLD_NOW); if (handle == NULL) { - if (mjit_opts.warnings || mjit_opts.verbose) - fprintf(stderr, "MJIT warning: failure in loading code from compacted '%s': %s\n", so_file, dlerror()); + mjit_warning("failure in loading code from compacted '%s': %s", so_file, dlerror()); free(unit); return; } @@ -886,8 +897,7 @@ compact_all_jit_code(void) https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L897 sprintf(funcname, "_mjit%d", node->unit->id); if ((func = dlsym(handle, funcname)) == NULL) { - if (mjit_opts.warnings || mjit_opts.verbose) - fprintf(stderr, "MJIT warning: skipping to reload '%s' from '%s': %s\n", funcname, so_file, dlerror()); + mjit_warning("skipping to reload '%s' from '%s': %s", funcname, so_file, dlerror()); continue; } @@ -915,8 +925,7 @@ load_func_from_so(const char *so_file, c https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L925 handle = dlopen(so_file, RTLD_NOW); if (handle == NULL) { - if (mjit_opts.warnings || mjit_opts.verbose) - fprintf(stderr, "MJIT warning: failure in loading code from '%s': %s\n", so_file, dlerror()); + mjit_warning("failure in loading code from '%s': %s", so_file, dlerror()); return (void *)NOT_ADDED_JIT_ISEQ_FUNC; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/