ruby-changes:31529
From: nobu <ko1@a...>
Date: Sat, 9 Nov 2013 15:17:06 +0900 (JST)
Subject: [ruby-changes:31529] nobu:r43608 (trunk): objspace_dump.c: fix portability issue
nobu 2013-11-09 15:16:58 +0900 (Sat, 09 Nov 2013) New Revision: 43608 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43608 Log: objspace_dump.c: fix portability issue * ext/objspace/objspace_dump.c (dump_output): fix portability issue. mkstemp() may not be available. Modified files: trunk/ext/objspace/extconf.rb trunk/ext/objspace/objspace_dump.c Index: ext/objspace/extconf.rb =================================================================== --- ext/objspace/extconf.rb (revision 43607) +++ ext/objspace/extconf.rb (revision 43608) @@ -1,2 +1,3 @@ https://github.com/ruby/ruby/blob/trunk/ext/objspace/extconf.rb#L1 $INCFLAGS << " -I$(topdir) -I$(top_srcdir)" +have_func("mkstemp") create_makefile('objspace') Index: ext/objspace/objspace_dump.c =================================================================== --- ext/objspace/objspace_dump.c (revision 43607) +++ ext/objspace/objspace_dump.c (revision 43608) @@ -290,8 +290,11 @@ root_obj_i(const char *category, VALUE o https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L290 dc->roots++; } +#ifndef HAVE_MKSTEMP +#define dump_output(dc, opts, output, filename) dump_output(dc, opts, output) +#endif static VALUE -dump_output(struct dump_config *dc, VALUE opts, VALUE output, char *filename) +dump_output(struct dump_config *dc, VALUE opts, VALUE output, const char *filename) { if (RTEST(opts)) output = rb_hash_aref(opts, sym_output); @@ -301,10 +304,14 @@ dump_output(struct dump_config *dc, VALU https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L304 dc->string = Qnil; } else if (output == sym_file) { +#ifdef HAVE_MKSTEMP int fd = mkstemp(filename); dc->string = rb_filesystem_str_new_cstr(filename); if (fd == -1) rb_sys_fail_path(dc->string); dc->stream = fdopen(fd, "w"); +#else + rb_raise(rb_eArgError, "output to temprary file is not supported"); +#endif } else if (output == sym_string) { dc->string = rb_str_new_cstr(""); @@ -347,7 +354,9 @@ dump_result(struct dump_config *dc, VALU https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L354 static VALUE objspace_dump(int argc, VALUE *argv, VALUE os) { +#ifdef HAVE_MKSTEMP char filename[] = "/tmp/rubyobjXXXXXX"; +#endif VALUE obj = Qnil, opts = Qnil, output; struct dump_config dc = {0,}; @@ -377,7 +386,9 @@ objspace_dump(int argc, VALUE *argv, VAL https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L386 static VALUE objspace_dump_all(int argc, VALUE *argv, VALUE os) { +#ifdef HAVE_MKSTEMP char filename[] = "/tmp/rubyheapXXXXXX"; +#endif VALUE opts = Qnil, output; struct dump_config dc = {0,}; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/