mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
90feeb6ab9
commit
671707b546
2 changed files with 13 additions and 1 deletions
|
@ -1,2 +1,3 @@
|
||||||
$INCFLAGS << " -I$(topdir) -I$(top_srcdir)"
|
$INCFLAGS << " -I$(topdir) -I$(top_srcdir)"
|
||||||
|
have_func("mkstemp")
|
||||||
create_makefile('objspace')
|
create_makefile('objspace')
|
||||||
|
|
|
@ -290,8 +290,11 @@ root_obj_i(const char *category, VALUE obj, void *data)
|
||||||
dc->roots++;
|
dc->roots++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef HAVE_MKSTEMP
|
||||||
|
#define dump_output(dc, opts, output, filename) dump_output(dc, opts, output)
|
||||||
|
#endif
|
||||||
static VALUE
|
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))
|
if (RTEST(opts))
|
||||||
output = rb_hash_aref(opts, sym_output);
|
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;
|
dc->string = Qnil;
|
||||||
}
|
}
|
||||||
else if (output == sym_file) {
|
else if (output == sym_file) {
|
||||||
|
#ifdef HAVE_MKSTEMP
|
||||||
int fd = mkstemp(filename);
|
int fd = mkstemp(filename);
|
||||||
dc->string = rb_filesystem_str_new_cstr(filename);
|
dc->string = rb_filesystem_str_new_cstr(filename);
|
||||||
if (fd == -1) rb_sys_fail_path(dc->string);
|
if (fd == -1) rb_sys_fail_path(dc->string);
|
||||||
dc->stream = fdopen(fd, "w");
|
dc->stream = fdopen(fd, "w");
|
||||||
|
#else
|
||||||
|
rb_raise(rb_eArgError, "output to temprary file is not supported");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else if (output == sym_string) {
|
else if (output == sym_string) {
|
||||||
dc->string = rb_str_new_cstr("");
|
dc->string = rb_str_new_cstr("");
|
||||||
|
@ -347,7 +354,9 @@ dump_result(struct dump_config *dc, VALUE output)
|
||||||
static VALUE
|
static VALUE
|
||||||
objspace_dump(int argc, VALUE *argv, VALUE os)
|
objspace_dump(int argc, VALUE *argv, VALUE os)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_MKSTEMP
|
||||||
char filename[] = "/tmp/rubyobjXXXXXX";
|
char filename[] = "/tmp/rubyobjXXXXXX";
|
||||||
|
#endif
|
||||||
VALUE obj = Qnil, opts = Qnil, output;
|
VALUE obj = Qnil, opts = Qnil, output;
|
||||||
struct dump_config dc = {0,};
|
struct dump_config dc = {0,};
|
||||||
|
|
||||||
|
@ -377,7 +386,9 @@ objspace_dump(int argc, VALUE *argv, VALUE os)
|
||||||
static VALUE
|
static VALUE
|
||||||
objspace_dump_all(int argc, VALUE *argv, VALUE os)
|
objspace_dump_all(int argc, VALUE *argv, VALUE os)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_MKSTEMP
|
||||||
char filename[] = "/tmp/rubyheapXXXXXX";
|
char filename[] = "/tmp/rubyheapXXXXXX";
|
||||||
|
#endif
|
||||||
VALUE opts = Qnil, output;
|
VALUE opts = Qnil, output;
|
||||||
struct dump_config dc = {0,};
|
struct dump_config dc = {0,};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue