[前][次][番号順一覧][スレッド一覧]

ruby-changes:6642

From: nobu <ko1@a...>
Date: Tue, 22 Jul 2008 17:53:49 +0900 (JST)
Subject: [ruby-changes:6642] Ruby:r18158 (trunk): * compile.c (insn_data_to_s_detail), file.c (rb_stat_inspect),

nobu	2008-07-22 17:53:34 +0900 (Tue, 22 Jul 2008)

  New Revision: 18158

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18158

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
    trunk/dir.c
    trunk/error.c
    trunk/file.c
    trunk/iseq.c
    trunk/process.c
    trunk/re.c

Index: re.c
===================================================================
--- re.c	(revision 18157)
+++ re.c	(revision 18158)
@@ -1806,9 +1806,7 @@
             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, ":");
         }
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 18157)
+++ ChangeLog	(revision 18158)
@@ -1,3 +1,15 @@
+Tue Jul 22 17:53:32 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* win32/win32.c (init_func): new function to get API's address which
Index: iseq.c
===================================================================
--- iseq.c	(revision 18157)
+++ iseq.c	(revision 18158)
@@ -545,13 +545,10 @@
 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 @@
     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,24 +722,20 @@
 {
     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);
 	VALUE opstr = insn_operand_intern(iseqdat, insn, j, iseq[pos + j + 1],
@@ -762,17 +752,18 @@
 	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 @@
     unsigned long size;
     int i;
     ID *tbl;
-    char buff[0x200];
     enum {header_minlen = 72};
 
     rb_secure(1);
@@ -840,11 +830,10 @@
     }
     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 @@
     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 @@
 	    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 @@
 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;
Index: compile.c
===================================================================
--- compile.c	(revision 18157)
+++ compile.c	(revision 18158)
@@ -4679,10 +4679,8 @@
 	    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;
Index: dir.c
===================================================================
--- dir.c	(revision 18157)
+++ dir.c	(revision 18158)
@@ -477,10 +477,7 @@
     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);
 }
Index: process.c
===================================================================
--- process.c	(revision 18157)
+++ process.c	(revision 18158)
@@ -278,33 +278,29 @@
 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)) {
Index: error.c
===================================================================
--- error.c	(revision 18157)
+++ error.c	(revision 18158)
@@ -621,13 +621,11 @@
 {
     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 @@
 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 @@
 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
Index: file.c
===================================================================
--- file.c	(revision 18157)
+++ file.c	(revision 18158)
@@ -687,16 +687,10 @@
 	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));

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]