summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-07-23 01:02:18 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-07-23 01:02:18 +0000
commit6524f34a2688436249d111a3456a097c7111722c (patch)
treef9c83bf95a7873e01e38ff396a8bc5490b61162c /eval.c
parente6a02b93747266925fd536a30715352bf2c60c07 (diff)
* sprintf.c (rb_vsprintf, rb_sprintf): new functions return new String,
using missing/vsnprintf.c. [ruby-dev:26580] * missing/vsnprintf.c: made the output changeable. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8825 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c40
1 files changed, 14 insertions, 26 deletions
diff --git a/eval.c b/eval.c
index 2058ae7b5e..1b4559c67d 100644
--- a/eval.c
+++ b/eval.c
@@ -6120,7 +6120,7 @@ backtrace(lev)
int lev;
{
struct FRAME *frame = ruby_frame;
- char buf[BUFSIZ];
+ VALUE str;
volatile VALUE ary;
NODE *n;
@@ -6131,17 +6131,16 @@ backtrace(lev)
if (lev < 0) {
ruby_set_current_source();
if (frame->this_func) {
- snprintf(buf, BUFSIZ, "%s:%d:in `%s'",
- ruby_sourcefile, ruby_sourceline,
- rb_id2name(frame->this_func));
+ str = rb_sprintf("%s:%d:in `%s'", ruby_sourcefile, ruby_sourceline,
+ rb_id2name(frame->this_func));
}
else if (ruby_sourceline == 0) {
- snprintf(buf, BUFSIZ, "%s", ruby_sourcefile);
+ str = rb_str_new2(ruby_sourcefile);
}
else {
- snprintf(buf, BUFSIZ, "%s:%d", ruby_sourcefile, ruby_sourceline);
+ str = rb_sprintf("%s:%d", ruby_sourcefile, ruby_sourceline);
}
- rb_ary_push(ary, rb_str_new2(buf));
+ rb_ary_push(ary, str);
if (lev < -1) return ary;
}
else {
@@ -6156,14 +6155,13 @@ backtrace(lev)
for (; frame && (n = frame->node); frame = frame->prev) {
if (frame->prev && frame->prev->this_func) {
if (frame->prev->node == n) continue;
- snprintf(buf, BUFSIZ, "%s:%d:in `%s'",
- n->nd_file, nd_line(n),
- rb_id2name(frame->prev->this_func));
+ str = rb_sprintf("%s:%d:in `%s'", n->nd_file, nd_line(n),
+ rb_id2name(frame->prev->this_func));
}
else {
- snprintf(buf, BUFSIZ, "%s:%d", n->nd_file, nd_line(n));
+ str = rb_sprintf("%s:%d", n->nd_file, nd_line(n));
}
- rb_ary_push(ary, rb_str_new2(buf));
+ rb_ary_push(ary, str);
}
return ary;
@@ -8667,23 +8665,16 @@ proc_to_s(self)
NODE *node;
char *cname = rb_obj_classname(self);
const int w = (SIZEOF_LONG * CHAR_BIT) / 4;
- long len = strlen(cname)+6+w; /* 6:tags 16:addr */
VALUE str;
Data_Get_Struct(self, struct BLOCK, data);
if ((node = data->frame.node) || (node = data->body)) {
- len += strlen(node->nd_file) + 2 + (SIZEOF_LONG*CHAR_BIT-NODE_LSHIFT)/3;
- str = rb_str_new(0, len);
- snprintf(RSTRING(str)->ptr, len+1,
- "#<%s:0x%.*lx@%s:%d>", cname, w, (VALUE)data->body,
- node->nd_file, nd_line(node));
+ str = rb_sprintf("#<%s:0x%.*lx@%s:%d>", cname, w, (VALUE)data->body,
+ node->nd_file, nd_line(node));
}
else {
- str = rb_str_new(0, len);
- snprintf(RSTRING(str)->ptr, len+1,
- "#<%s:0x%.*lx>", cname, w, (VALUE)data->body);
+ str = rb_sprintf("#<%s:0x%.*lx>", cname, w, (VALUE)data->body);
}
- RSTRING(str)->len = strlen(RSTRING(str)->ptr);
if (OBJ_TAINTED(self)) OBJ_TAINT(str);
return str;
@@ -12761,11 +12752,8 @@ rb_thread_inspect(thread)
rb_thread_t th = rb_thread_check(thread);
const char *status = thread_status_name(th->status);
VALUE str;
- size_t len = strlen(cname)+7+16+9+1;
- str = rb_str_new(0, len); /* 7:tags 16:addr 9:status 1:nul */
- snprintf(RSTRING(str)->ptr, len, "#<%s:0x%lx %s>", cname, thread, status);
- RSTRING(str)->len = strlen(RSTRING(str)->ptr);
+ str = rb_sprintf("#<%s:0x%lx %s>", cname, thread, status);
OBJ_INFECT(str, thread);
return str;