1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* compile.c (insn_data_to_s_detail), file.c (rb_stat_inspect),

iseq.c (ruby_iseq_disasm_insn, ruby_iseq_disasm),
  process.c (pst_message), re.c (match_inspect): use rb_str_catf.

* dir.c (dir_inspect), iseq.c (iseq_inspect, insn_operand_intern): use
  rb_sprintf.

* error.c (rb_name_error, rb_raise, rb_loaderror, rb_fatal): use
  rb_vsprintf.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2008-07-22 08:53:34 +00:00
parent ee560dc68f
commit 0acca9a826
8 changed files with 68 additions and 90 deletions

View file

@ -1,3 +1,15 @@
Tue Jul 22 17:53:32 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* compile.c (insn_data_to_s_detail), file.c (rb_stat_inspect),
iseq.c (ruby_iseq_disasm_insn, ruby_iseq_disasm),
process.c (pst_message), re.c (match_inspect): use rb_str_catf.
* dir.c (dir_inspect), iseq.c (iseq_inspect, insn_operand_intern): use
rb_sprintf.
* error.c (rb_name_error, rb_raise, rb_loaderror, rb_fatal): use
rb_vsprintf.
Tue Jul 22 17:20:25 2008 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (init_func): new function to get API's address which

View file

@ -4679,10 +4679,8 @@ insn_data_to_s_detail(INSN *iobj)
switch (type) {
case TS_OFFSET: /* label(destination position) */
{
char buff[0x100];
LABEL *lobj = (LABEL *)OPERAND_AT(iobj, j);
snprintf(buff, sizeof(buff), "<L%03d>", lobj->label_no);
rb_str_concat(str, rb_str_new2(buff));
rb_str_catf(str, "<L%03d>", lobj->label_no);
break;
}
break;

5
dir.c
View file

@ -477,10 +477,7 @@ dir_inspect(VALUE dir)
Data_Get_Struct(dir, struct dir_data, dirp);
if (dirp->path) {
const char *c = rb_obj_classname(dir);
int len = strlen(c) + strlen(dirp->path) + 4;
VALUE s = rb_str_new(0, len);
snprintf(RSTRING_PTR(s), len+1, "#<%s:%s>", c, dirp->path);
return s;
return rb_sprintf("#<%s:%s>", c, dirp->path);
}
return rb_funcall(dir, rb_intern("to_s"), 0, 0);
}

24
error.c
View file

@ -621,13 +621,11 @@ rb_name_error(ID id, const char *fmt, ...)
{
VALUE exc, argv[2];
va_list args;
char buf[BUFSIZ];
va_start(args, fmt);
vsnprintf(buf, BUFSIZ, fmt, args);
argv[0] = rb_vsprintf(fmt, args);
va_end(args);
argv[0] = rb_str_new2(buf);
argv[1] = ID2SYM(id);
exc = rb_class_new_instance(2, argv, rb_eNameError);
rb_exc_raise(exc);
@ -1074,24 +1072,24 @@ void
rb_raise(VALUE exc, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZ];
VALUE mesg;
va_start(args,fmt);
vsnprintf(buf, BUFSIZ, fmt, args);
va_start(args, fmt);
mesg = rb_vsprintf(fmt, args);
va_end(args);
rb_exc_raise(rb_exc_new2(exc, buf));
rb_exc_raise(rb_exc_new3(exc, mesg));
}
void
rb_loaderror(const char *fmt, ...)
{
va_list args;
char buf[BUFSIZ];
VALUE mesg;
va_start(args, fmt);
vsnprintf(buf, BUFSIZ, fmt, args);
mesg = rb_vsprintf(fmt, args);
va_end(args);
rb_exc_raise(rb_exc_new2(rb_eLoadError, buf));
rb_exc_raise(rb_exc_new3(rb_eLoadError, mesg));
}
void
@ -1106,13 +1104,13 @@ void
rb_fatal(const char *fmt, ...)
{
va_list args;
char buf[BUFSIZ];
VALUE mesg;
va_start(args, fmt);
vsnprintf(buf, BUFSIZ, fmt, args);
mesg = rb_vsprintf(fmt, args);
va_end(args);
rb_exc_fatal(rb_exc_new2(rb_eFatal, buf));
rb_exc_fatal(rb_exc_new3(rb_eFatal, mesg));
}
void

10
file.c
View file

@ -687,16 +687,10 @@ rb_stat_inspect(VALUE self)
rb_str_buf_cat2(str, "=");
v = (*member[i].func)(self);
if (i == 2) { /* mode */
char buf[32];
sprintf(buf, "0%lo", NUM2ULONG(v));
rb_str_buf_cat2(str, buf);
rb_str_catf(str, "0%lo", NUM2ULONG(v));
}
else if (i == 0 || i == 6) { /* dev/rdev */
char buf[32];
sprintf(buf, "0x%lx", NUM2ULONG(v));
rb_str_buf_cat2(str, buf);
rb_str_catf(str, "0x%lx", NUM2ULONG(v));
}
else {
rb_str_append(str, rb_inspect(v));

83
iseq.c
View file

@ -545,13 +545,10 @@ iseq_eval(VALUE self)
static VALUE
iseq_inspect(VALUE self)
{
char buff[0x100];
rb_iseq_t *iseq = iseq_check(self);
snprintf(buff, sizeof(buff), "<ISeq:%s@%s>",
RSTRING_PTR(iseq->name), RSTRING_PTR(iseq->filename));
return rb_str_new2(buff);
return rb_sprintf("<ISeq:%s@%s>",
RSTRING_PTR(iseq->name), RSTRING_PTR(iseq->filename));
}
VALUE iseq_data_to_ary(rb_iseq_t *iseq);
@ -622,17 +619,14 @@ insn_operand_intern(rb_iseq_t *iseq,
const char *types = insn_op_types(insn);
char type = types[op_no];
VALUE ret;
char buff[0x100];
switch (type) {
case TS_OFFSET: /* LONG */
snprintf(buff, sizeof(buff), "%ld", pos + len + op);
ret = rb_str_new2(buff);
ret = rb_sprintf("%ld", pos + len + op);
break;
case TS_NUM: /* ULONG */
snprintf(buff, sizeof(buff), "%lu", op);
ret = rb_str_new2(buff);
ret = rb_sprintf("%lu", op);
break;
case TS_LINDEX:
@ -728,23 +722,19 @@ ruby_iseq_disasm_insn(VALUE ret, VALUE *iseq, int pos,
{
int insn = iseq[pos];
int len = insn_len(insn);
int i, j;
int j;
const char *types = insn_op_types(insn);
VALUE str = rb_str_new(0, 0);
char buff[0x100];
char insn_name_buff[0x100];
const char *insn_name_buff;
strcpy(insn_name_buff, insn_name(insn));
if (0) {
for (i = 0; insn_name_buff[i]; i++) {
if (insn_name_buff[i] == '_') {
insn_name_buff[i] = 0;
}
}
insn_name_buff = insn_name(insn);
if (1) {
rb_str_catf(str, "%04d %-16s ", pos, insn_name_buff);
}
else {
rb_str_catf(str, "%04d %-16.*s ", pos,
strcspn(insn_name_buff, "_"), insn_name_buff);
}
snprintf(buff, sizeof(buff), "%04d %-16s ", pos, insn_name_buff);
rb_str_cat2(str, buff);
for (j = 0; types[j]; j++) {
const char *types = insn_op_types(insn);
@ -762,17 +752,18 @@ ruby_iseq_disasm_insn(VALUE ret, VALUE *iseq, int pos,
int line_no = find_line_no(iseqdat, pos);
int prev = find_prev_line_no(iseqdat, pos);
if (line_no && line_no != prev) {
snprintf(buff, sizeof(buff), "%-70s(%4d)", RSTRING_PTR(str),
line_no);
str = rb_str_new2(buff);
long slen = RSTRING_LEN(str);
slen = (slen > 70) ? 0 : (70 - slen);
str = rb_str_catf(str, "%*s(%4d)", (int)slen, "", line_no);
}
}
else {
/* for debug */
struct iseq_insn_info_entry *entry = get_insn_info(iseqdat, pos);
snprintf(buff, sizeof(buff), "%-60s(line: %d, sp: %d)",
RSTRING_PTR(str), entry->line_no, entry->sp);
str = rb_str_new2(buff);
long slen = RSTRING_LEN(str);
slen = (slen > 60) ? 0 : (60 - slen);
str = rb_str_catf(str, "%*s(line: %d, sp: %d)",
(int)slen, "", entry->line_no, entry->sp);
}
if (ret) {
@ -817,7 +808,6 @@ ruby_iseq_disasm(VALUE self)
unsigned long size;
int i;
ID *tbl;
char buff[0x200];
enum {header_minlen = 72};
rb_secure(1);
@ -840,11 +830,10 @@ ruby_iseq_disasm(VALUE self)
}
for (i = 0; i < iseqdat->catch_table_size; i++) {
struct iseq_catch_table_entry *entry = &iseqdat->catch_table[i];
sprintf(buff,
"| catch type: %-6s st: %04d ed: %04d sp: %04d cont: %04d\n",
catch_type((int)entry->type), (int)entry->start,
(int)entry->end, (int)entry->sp, (int)entry->cont);
rb_str_cat2(str, buff);
rb_str_catf(str,
"| catch type: %-6s st: %04d ed: %04d sp: %04d cont: %04d\n",
catch_type((int)entry->type), (int)entry->start,
(int)entry->end, (int)entry->sp, (int)entry->cont);
if (entry->iseq) {
rb_str_concat(str, ruby_iseq_disasm(entry->iseq));
}
@ -858,14 +847,13 @@ ruby_iseq_disasm(VALUE self)
tbl = iseqdat->local_table;
if (tbl) {
snprintf(buff, sizeof(buff),
"local table (size: %d, argc: %d "
"[opts: %d, rest: %d, post: %d, block: %d] s%d)\n",
iseqdat->local_size, iseqdat->argc,
iseqdat->arg_opts, iseqdat->arg_rest,
iseqdat->arg_post_len, iseqdat->arg_block,
iseqdat->arg_simple);
rb_str_cat2(str, buff);
rb_str_catf(str,
"local table (size: %d, argc: %d "
"[opts: %d, rest: %d, post: %d, block: %d] s%d)\n",
iseqdat->local_size, iseqdat->argc,
iseqdat->arg_opts, iseqdat->arg_rest,
iseqdat->arg_post_len, iseqdat->arg_block,
iseqdat->arg_simple);
for (i = 0; i < iseqdat->local_table_size; i++) {
const char *name = rb_id2name(tbl[i]);
@ -893,10 +881,7 @@ ruby_iseq_disasm(VALUE self)
snprintf(info, sizeof(info), "%s%s%s%s", name ? name : "?",
*argi ? "<" : "", argi, *argi ? ">" : "");
snprintf(buff, sizeof(buff), "[%2d] %-11s",
iseqdat->local_size - i, info);
rb_str_cat2(str, buff);
rb_str_catf(str, "[%2d] %-11s", iseqdat->local_size - i, info);
}
rb_str_cat2(str, "\n");
}
@ -954,9 +939,9 @@ static VALUE
register_label(struct st_table *table, int idx)
{
VALUE sym;
char buff[0x20];
char buff[8 + (sizeof(idx) * CHAR_BIT * 32 / 100)];
snprintf(buff, 0x20, "label_%u", idx);
snprintf(buff, sizeof(buff), "label_%u", idx);
sym = ID2SYM(rb_intern(buff));
st_insert(table, idx, sym);
return sym;

View file

@ -278,33 +278,29 @@ static void
pst_message(VALUE str, rb_pid_t pid, int status)
{
char buf[256];
snprintf(buf, sizeof(buf), "pid %ld", (long)pid);
rb_str_cat2(str, buf);
rb_str_catf(str, "pid %ld", (long)pid);
if (WIFSTOPPED(status)) {
int stopsig = WSTOPSIG(status);
const char *signame = ruby_signal_name(stopsig);
if (signame) {
snprintf(buf, sizeof(buf), " stopped SIG%s (signal %d)", signame, stopsig);
rb_str_catf(str, " stopped SIG%s (signal %d)", signame, stopsig);
}
else {
snprintf(buf, sizeof(buf), " stopped signal %d", stopsig);
rb_str_catf(str, " stopped signal %d", stopsig);
}
rb_str_cat2(str, buf);
}
if (WIFSIGNALED(status)) {
int termsig = WTERMSIG(status);
const char *signame = ruby_signal_name(termsig);
if (signame) {
snprintf(buf, sizeof(buf), " SIG%s (signal %d)", signame, termsig);
rb_str_catf(str, " SIG%s (signal %d)", signame, termsig);
}
else {
snprintf(buf, sizeof(buf), " signal %d", termsig);
rb_str_catf(str, " signal %d", termsig);
}
rb_str_cat2(str, buf);
}
if (WIFEXITED(status)) {
snprintf(buf, sizeof(buf), " exit %d", WEXITSTATUS(status));
rb_str_cat2(str, buf);
rb_str_catf(str, " exit %d", WEXITSTATUS(status));
}
#ifdef WCOREDUMP
if (WCOREDUMP(status)) {

4
re.c
View file

@ -1806,9 +1806,7 @@ match_inspect(VALUE match)
if (names[i].name)
rb_str_buf_cat(str, (const char *)names[i].name, names[i].len);
else {
char buf[sizeof(i)*3+1];
snprintf(buf, sizeof(buf), "%d", i);
rb_str_buf_cat2(str, buf);
rb_str_catf(str, "%d", i);
}
rb_str_buf_cat2(str, ":");
}