ruby-changes:52093
From: k0kubun <ko1@a...>
Date: Sat, 11 Aug 2018 23:19:01 +0900 (JST)
Subject: [ruby-changes:52093] k0kubun:r64301 (trunk): mjit_worker.c: don't use ruby_strdup
k0kubun 2018-08-11 23:18:55 +0900 (Sat, 11 Aug 2018) New Revision: 64301 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64301 Log: mjit_worker.c: don't use ruby_strdup on MJIT worker. That may trigger GC. And handled strdup failure instead. mjit_compile.c: update comment about GC Modified files: trunk/mjit_compile.c trunk/mjit_worker.c Index: mjit_worker.c =================================================================== --- mjit_worker.c (revision 64300) +++ mjit_worker.c (revision 64301) @@ -8,7 +8,7 @@ https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L8 /* NOTE: All functions in this file are executed on MJIT worker. So don't call Ruby methods (C functions that may call rb_funcall) or trigger - GC (using xmalloc, ZALLOC, etc.) in this file. */ + GC (using ZALLOC, xmalloc, xfree, etc.) in this file. */ /* We utilize widely used C compilers (GCC and LLVM Clang) to implement MJIT. We feed them a C code generated from ISEQ. The @@ -78,7 +78,6 @@ https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L78 #include "gc.h" #include "ruby_assert.h" #include "ruby/thread.h" -#include "ruby/util.h" #ifdef _WIN32 #include <winsock2.h> @@ -95,9 +94,11 @@ https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L94 #ifdef HAVE_SYS_PARAM_H # include <sys/param.h> #endif - #include "dln.h" +#include "ruby/util.h" +#undef strdup /* ruby_strdup may trigger GC */ + #ifndef MAXPATHLEN # define MAXPATHLEN 1024 #endif @@ -885,6 +886,8 @@ compact_all_jit_code(void) https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L886 if (!mjit_opts.save_temps) { # ifdef _WIN32 unit->so_file = strdup(so_file); /* lazily delete on `clean_object_files()` */ + if (unit->so_file == NULL) + mjit_warning("failed to allocate memory to lazily remove '%s': %s", so_file, strerror(errno)); # else remove_file(so_file); # endif @@ -1085,6 +1088,10 @@ convert_unit_to_func(struct rb_mjit_unit https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L1088 /* Alwasy set o_file for compaction. The value is also used for lazy deletion. */ unit->o_file = strdup(o_file); + if (unit->o_file == NULL) { + mjit_warning("failed to allocate memory to remember '%s' (%s), removing it...", o_file, strerror(errno)); + remove_file(o_file); + } } #endif end_time = real_ms_time(); @@ -1100,6 +1107,8 @@ convert_unit_to_func(struct rb_mjit_unit https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L1107 if (!mjit_opts.save_temps) { #ifdef _WIN32 unit->so_file = strdup(so_file); /* lazily delete on `clean_object_files()` */ + if (unit->so_file == NULL) + mjit_warning("failed to allocate memory to lazily remove '%s': %s", so_file, strerror(errno)); #else remove_file(so_file); #endif Index: mjit_compile.c =================================================================== --- mjit_compile.c (revision 64300) +++ mjit_compile.c (revision 64301) @@ -8,7 +8,7 @@ https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L8 /* NOTE: All functions in this file are executed on MJIT worker. So don't call Ruby methods (C functions that may call rb_funcall) or trigger - GC (using xmalloc, ZALLOC, etc.) in this file. */ + GC (using ZALLOC, xmalloc, xfree, etc.) in this file. */ #include "internal.h" #include "vm_core.h" -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/