diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-11-09 06:16:58 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-11-09 06:16:58 +0000 |
commit | 671707b5460e4fef2d2a9dd5832fb5a50e5c9178 (patch) | |
tree | f67ede8323ff7ef0ad682fe6f65220c5a3fee310 /ext/objspace | |
parent | 90feeb6ab9c9f02a174ac27a5c3bcee6f23aa463 (diff) | |
download | ruby-671707b5460e4fef2d2a9dd5832fb5a50e5c9178.tar.gz |
objspace_dump.c: fix portability issue
* ext/objspace/objspace_dump.c (dump_output): fix portability issue.
mkstemp() may not be available.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/objspace')
-rw-r--r-- | ext/objspace/extconf.rb | 1 | ||||
-rw-r--r-- | ext/objspace/objspace_dump.c | 13 |
2 files changed, 13 insertions, 1 deletions
diff --git a/ext/objspace/extconf.rb b/ext/objspace/extconf.rb index 23a42c4c20..e48fa8c8bc 100644 --- a/ext/objspace/extconf.rb +++ b/ext/objspace/extconf.rb @@ -1,2 +1,3 @@ $INCFLAGS << " -I$(topdir) -I$(top_srcdir)" +have_func("mkstemp") create_makefile('objspace') diff --git a/ext/objspace/objspace_dump.c b/ext/objspace/objspace_dump.c index f52b194497..99fcd7e0df 100644 --- a/ext/objspace/objspace_dump.c +++ b/ext/objspace/objspace_dump.c @@ -290,8 +290,11 @@ root_obj_i(const char *category, VALUE obj, void *data) 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, VALUE opts, VALUE output, char *filename) 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, VALUE output) 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, VALUE os) 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,}; |