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

ruby-changes:22776

From: nobu <ko1@a...>
Date: Mon, 27 Feb 2012 10:50:44 +0900 (JST)
Subject: [ruby-changes:22776] nobu:r34825 (trunk): * io.c, process.c, time.c, ext: use rb_sys_fail_str instead of

nobu	2012-02-27 10:50:27 +0900 (Mon, 27 Feb 2012)

  New Revision: 34825

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

  Log:
    * io.c, process.c, time.c, ext: use rb_sys_fail_str instead of
      rb_sys_fail.

  Modified files:
    trunk/ChangeLog
    trunk/ext/date/date_core.c
    trunk/ext/dbm/dbm.c
    trunk/ext/gdbm/gdbm.c
    trunk/ext/iconv/iconv.c
    trunk/ext/sdbm/init.c
    trunk/ext/socket/basicsocket.c
    trunk/ext/socket/unixsocket.c
    trunk/include/ruby/intern.h
    trunk/io.c
    trunk/process.c
    trunk/time.c

Index: time.c
===================================================================
--- time.c	(revision 34824)
+++ time.c	(revision 34825)
@@ -4290,7 +4290,7 @@
 
 #define SMALLBUF 100
 static size_t
-rb_strftime_alloc(char **buf, const char *format, rb_encoding *enc,
+rb_strftime_alloc(char **buf, VALUE formatv, const char *format, rb_encoding *enc,
                   struct vtm *vtm, wideval_t timew, int gmt)
 {
     size_t size, len, flen;
@@ -4328,6 +4328,7 @@
 	if (len > 0) break;
 	xfree(*buf);
 	if (size >= 1024 * flen) {
+	    if (!NIL_P(formatv)) rb_sys_fail_str(formatv);
 	    rb_sys_fail(format);
 	    break;
 	}
@@ -4345,7 +4346,7 @@
 
     GetTimeval(time, tobj);
     MAKE_TM(time, tobj);
-    len = rb_strftime_alloc(&buf, fmt, enc, &tobj->vtm, tobj->timew, TIME_UTC_P(tobj));
+    len = rb_strftime_alloc(&buf, Qnil, fmt, enc, &tobj->vtm, tobj->timew, TIME_UTC_P(tobj));
     str = rb_enc_str_new(buf, len, enc);
     if (buf != buffer) xfree(buf);
     return str;
@@ -4563,7 +4564,8 @@
 
 	str = rb_str_new(0, 0);
 	while (p < pe) {
-	    len = rb_strftime_alloc(&buf, p, enc, &tobj->vtm, tobj->timew, TIME_UTC_P(tobj));
+	    len = rb_strftime_alloc(&buf, format, p, enc,
+				    &tobj->vtm, tobj->timew, TIME_UTC_P(tobj));
 	    rb_str_cat(str, buf, len);
 	    p += strlen(p);
 	    if (buf != buffer) {
@@ -4576,7 +4578,7 @@
 	return str;
     }
     else {
-	len = rb_strftime_alloc(&buf, RSTRING_PTR(format), enc,
+	len = rb_strftime_alloc(&buf, format, RSTRING_PTR(format), enc,
 				&tobj->vtm, tobj->timew, TIME_UTC_P(tobj));
     }
     str = rb_enc_str_new(buf, len, enc);
Index: include/ruby/intern.h
===================================================================
--- include/ruby/intern.h	(revision 34824)
+++ include/ruby/intern.h	(revision 34825)
@@ -585,6 +585,7 @@
     const char *prog;
     VALUE options;
     VALUE redirect_fds;
+    VALUE progname;
 };
 int rb_proc_exec_n(int, VALUE*, const char*);
 int rb_proc_exec(const char*);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 34824)
+++ ChangeLog	(revision 34825)
@@ -1,3 +1,8 @@
+Mon Feb 27 10:50:23 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* io.c, process.c, time.c, ext: use rb_sys_fail_str instead of
+	  rb_sys_fail.
+
 Mon Feb 27 10:48:49 2012  Nobuyoshi Nakada  <nobu@r...>
 
 	* ext/openssl/extconf.rb: suppress useless deprecation warnings
Index: io.c
===================================================================
--- io.c	(revision 34824)
+++ io.c	(revision 34825)
@@ -5454,13 +5454,13 @@
     switch (fmode & (FMODE_READABLE|FMODE_WRITABLE)) {
       case FMODE_READABLE|FMODE_WRITABLE:
         if (rb_pipe(arg.write_pair) < 0)
-            rb_sys_fail(cmd);
+            rb_sys_fail_str(prog);
         if (rb_pipe(arg.pair) < 0) {
             int e = errno;
             close(arg.write_pair[0]);
             close(arg.write_pair[1]);
             errno = e;
-            rb_sys_fail(cmd);
+            rb_sys_fail_str(prog);
         }
         if (eargp) {
             rb_exec_arg_addopt(eargp, INT2FIX(0), INT2FIX(arg.write_pair[0]));
@@ -5469,18 +5469,18 @@
 	break;
       case FMODE_READABLE:
         if (rb_pipe(arg.pair) < 0)
-            rb_sys_fail(cmd);
+            rb_sys_fail_str(prog);
         if (eargp)
             rb_exec_arg_addopt(eargp, INT2FIX(1), INT2FIX(arg.pair[1]));
 	break;
       case FMODE_WRITABLE:
         if (rb_pipe(arg.pair) < 0)
-            rb_sys_fail(cmd);
+            rb_sys_fail_str(prog);
         if (eargp)
             rb_exec_arg_addopt(eargp, INT2FIX(0), INT2FIX(arg.pair[0]));
 	break;
       default:
-        rb_sys_fail(cmd);
+        rb_sys_fail_str(prog);
     }
     if (eargp) {
         rb_exec_arg_fixup(arg.execp);
@@ -5509,7 +5509,7 @@
 	errno = e;
         if (errmsg[0])
             rb_sys_fail(errmsg);
-	rb_sys_fail(cmd);
+	rb_sys_fail_str(prog);
     }
     if ((fmode & FMODE_READABLE) && (fmode & FMODE_WRITABLE)) {
         close(arg.pair[1]);
@@ -5542,13 +5542,13 @@
     switch (fmode & (FMODE_READABLE|FMODE_WRITABLE)) {
       case FMODE_READABLE|FMODE_WRITABLE:
         if (rb_pipe(write_pair) < 0)
-            rb_sys_fail(cmd);
+            rb_sys_fail_str(prog);
         if (rb_pipe(pair) < 0) {
             int e = errno;
             close(write_pair[0]);
             close(write_pair[1]);
             errno = e;
-            rb_sys_fail(cmd);
+            rb_sys_fail_str(prog);
         }
         if (eargp) {
             rb_exec_arg_addopt(eargp, INT2FIX(0), INT2FIX(write_pair[0]));
@@ -5557,18 +5557,18 @@
 	break;
       case FMODE_READABLE:
         if (rb_pipe(pair) < 0)
-            rb_sys_fail(cmd);
+            rb_sys_fail_str(prog);
         if (eargp)
             rb_exec_arg_addopt(eargp, INT2FIX(1), INT2FIX(pair[1]));
 	break;
       case FMODE_WRITABLE:
         if (rb_pipe(pair) < 0)
-            rb_sys_fail(cmd);
+            rb_sys_fail_str(prog);
         if (eargp)
             rb_exec_arg_addopt(eargp, INT2FIX(0), INT2FIX(pair[0]));
 	break;
       default:
-        rb_sys_fail(cmd);
+        rb_sys_fail_str(prog);
     }
     if (eargp) {
 	rb_exec_arg_fixup(eargp);
@@ -5597,7 +5597,7 @@
 		    close(write_pair[1]);
 		}
 		errno = e;
-		rb_sys_fail(cmd);
+		rb_sys_fail_str(prog);
 	    }
 	    break;
 	}
@@ -7967,7 +7967,7 @@
     if (rv) {
 	/* posix_fadvise(2) doesn't set errno. On success it returns 0; otherwise
 	   it returns the error code. */
-	rb_syserr_fail(rv, RSTRING_PTR(fptr->pathv));
+	rb_syserr_fail_str(rv, fptr->pathv);
     }
 
     return Qnil;
Index: process.c
===================================================================
--- process.c	(revision 34824)
+++ process.c	(revision 34825)
@@ -1798,6 +1798,7 @@
     e->argc = argc;
     e->argv = argv;
     e->prog = prog ? RSTRING_PTR(prog) : 0;
+    e->progname = prog;
 }
 
 VALUE
@@ -1875,7 +1876,7 @@
     rb_exec_err(&earg, errmsg, sizeof(errmsg));
     if (errmsg[0])
         rb_sys_fail(errmsg);
-    rb_sys_fail(earg.prog);
+    rb_sys_fail_str(earg.progname);
     return Qnil;		/* dummy */
 }
 
@@ -2326,6 +2327,7 @@
         s->prog = NULL;
         s->options = soptions = hide_obj(rb_ary_new());
         s->redirect_fds = Qnil;
+	s->progname = Qnil;
     }
 
 #ifdef HAVE_SETPGID
@@ -3345,8 +3347,8 @@
     pid = rb_spawn_process(&earg, rb_exec_arg_prepare(&earg, argc, argv, TRUE), errmsg, sizeof(errmsg));
     if (pid == -1) {
 	const char *prog = errmsg;
-	if (!prog[0] && !(prog = earg.prog) && earg.argc) {
-	    prog = RSTRING_PTR(earg.argv[0]);
+	if (!prog[0]) {
+	    rb_sys_fail_str(earg.progname);
 	}
 	rb_sys_fail(prog);
     }
Index: ext/sdbm/init.c
===================================================================
--- ext/sdbm/init.c	(revision 34824)
+++ ext/sdbm/init.c	(revision 34825)
@@ -109,7 +109,7 @@
 
     if (!dbm) {
 	if (mode == -1) return Qnil;
-	rb_sys_fail(RSTRING_PTR(file));
+	rb_sys_fail_str(file);
     }
 
     dbmp = ALLOC(struct dbmdata);
Index: ext/date/date_core.c
===================================================================
--- ext/date/date_core.c	(revision 34824)
+++ ext/date/date_core.c	(revision 34825)
@@ -6587,7 +6587,7 @@
 
 #include "date_tmx.h"
 static void set_tmx(VALUE, struct tmx *);
-static VALUE strftimev(const char *, VALUE,
+static VALUE strftimev(VALUE, const char *, VALUE,
 		       void (*)(VALUE, struct tmx *));
 
 /*
@@ -6604,7 +6604,7 @@
 static VALUE
 d_lite_to_s(VALUE self)
 {
-    return strftimev("%Y-%m-%d", self, set_tmx);
+    return strftimev(Qnil, "%Y-%m-%d", self, set_tmx);
 }
 
 #ifndef NDEBUG
@@ -6729,7 +6729,7 @@
 
 #define SMALLBUF 100
 static size_t
-date_strftime_alloc(char **buf, const char *format,
+date_strftime_alloc(char **buf, VALUE formatv, const char *format,
 		    struct tmx *tmx)
 {
     size_t size, len, flen;
@@ -6756,6 +6756,7 @@
 	if (len > 0) break;
 	xfree(*buf);
 	if (size >= 1024 * flen) {
+	    if (!NIL_P(formatv)) rb_sys_fail_str(formatv);
 	    rb_sys_fail(format);
 	    break;
 	}
@@ -6868,7 +6869,7 @@
 
 	str = rb_str_new(0, 0);
 	while (p < pe) {
-	    len = date_strftime_alloc(&buf, p, &tmx);
+	    len = date_strftime_alloc(&buf, vfmt, p, &tmx);
 	    rb_str_cat(str, buf, len);
 	    p += strlen(p);
 	    if (buf != buffer) {
@@ -6883,7 +6884,7 @@
 	return str;
     }
     else
-	len = date_strftime_alloc(&buf, fmt, &tmx);
+	len = date_strftime_alloc(&buf, vfmt, fmt, &tmx);
 
     str = rb_str_new(buf, len);
     if (buf != buffer) xfree(buf);
@@ -7077,7 +7078,7 @@
 }
 
 static VALUE
-strftimev(const char *fmt, VALUE self,
+strftimev(VALUE vfmt, const char *fmt, VALUE self,
 	  void (*func)(VALUE, struct tmx *))
 {
     char buffer[SMALLBUF], *buf = buffer;
@@ -7086,7 +7087,7 @@
     VALUE str;
 
     (*func)(self, &tmx);
-    len = date_strftime_alloc(&buf, fmt, &tmx);
+    len = date_strftime_alloc(&buf, vfmt, fmt, &tmx);
     str = rb_usascii_str_new(buf, len);
     if (buf != buffer) xfree(buf);
     return str;
@@ -7105,7 +7106,7 @@
 static VALUE
 d_lite_asctime(VALUE self)
 {
-    return strftimev("%a %b %e %H:%M:%S %Y", self, set_tmx);
+    return strftimev(Qnil, "%a %b %e %H:%M:%S %Y", self, set_tmx);
 }
 
 /*
@@ -7118,7 +7119,7 @@
 static VALUE
 d_lite_iso8601(VALUE self)
 {
-    return strftimev("%Y-%m-%d", self, set_tmx);
+    return strftimev(Qnil, "%Y-%m-%d", self, set_tmx);
 }
 
 /*
@@ -7130,7 +7131,7 @@
 static VALUE
 d_lite_rfc3339(VALUE self)
 {
-    return strftimev("%Y-%m-%dT%H:%M:%S%:z", self, set_tmx);
+    return strftimev(Qnil, "%Y-%m-%dT%H:%M:%S%:z", self, set_tmx);
 }
 
 /*
@@ -7143,7 +7144,7 @@
 static VALUE
 d_lite_rfc2822(VALUE self)
 {
-    return strftimev("%a, %-d %b %Y %T %z", self, set_tmx);
+    return strftimev(Qnil, "%a, %-d %b %Y %T %z", self, set_tmx);
 }
 
 /*
@@ -7157,7 +7158,7 @@
 d_lite_httpdate(VALUE self)
 {
     volatile VALUE dup = dup_obj_with_new_offset(self, 0);
-    return strftimev("%a, %d %b %Y %T GMT", dup, set_tmx);
+    return strftimev(Qnil, "%a, %d %b %Y %T GMT", dup, set_tmx);
 }
 
 static VALUE
@@ -7204,7 +7205,7 @@
     get_d1(self);
     s = jisx0301_date(m_real_local_jd(dat),
 		      m_real_year(dat));
-    return strftimev(RSTRING_PTR(s), self, set_tmx);
+    return strftimev(s, RSTRING_PTR(s), self, set_tmx);
 }
 
 #ifndef NDEBUG
@@ -8294,7 +8295,7 @@
 static VALUE
 dt_lite_to_s(VALUE self)
 {
-    return strftimev("%Y-%m-%dT%H:%M:%S%:z", self, set_tmx);
+    return strftimev(Qnil, "%Y-%m-%dT%H:%M:%S%:z", self, set_tmx);
 }
 
 /*
@@ -8500,7 +8501,7 @@
 	rb_str_append(fmt, rb_f_sprintf(3, argv));
     }
     rb_str_append(fmt, rb_usascii_str_new2("%:z"));
-    return strftimev(RSTRING_PTR(fmt), self, set_tmx);
+    return strftimev(fmt, RSTRING_PTR(fmt), self, set_tmx);
 }
 
 /*
@@ -8526,7 +8527,7 @@
     if (argc < 1)
 	n = INT2FIX(0);
 
-    return f_add(strftimev("%Y-%m-%d", self, set_tmx),
+    return f_add(strftimev(Qnil, "%Y-%m-%d", self, set_tmx),
 		 iso8601_timediv(self, n));
 }
 
@@ -8574,7 +8575,7 @@
 	get_d1(self);
 	s = jisx0301_date(m_real_local_jd(dat),
 			  m_real_year(dat));
-	return rb_str_append(strftimev(RSTRING_PTR(s), self, set_tmx),
+	return rb_str_append(strftimev(s, RSTRING_PTR(s), self, set_tmx),
 			     iso8601_timediv(self, n));
     }
 }
Index: ext/socket/basicsocket.c
===================================================================
--- ext/socket/basicsocket.c	(revision 34824)
+++ ext/socket/basicsocket.c	(revision 34825)
@@ -247,7 +247,7 @@
 	break;
     }
 
-#define rb_sys_fail_path(path) rb_sys_fail(NIL_P(path) ? 0 : RSTRING_PTR(path))
+#define rb_sys_fail_path(path) rb_sys_fail_str(path)
 
     rb_io_check_closed(fptr);
     if (setsockopt(fptr->fd, level, option, v, vlen) < 0)
Index: ext/socket/unixsocket.c
===================================================================
--- ext/socket/unixsocket.c	(revision 34824)
+++ ext/socket/unixsocket.c	(revision 34825)
@@ -62,7 +62,7 @@
 
     if (status < 0) {
 	close(fd);
-	rb_sys_fail(sockaddr.sun_path);
+	rb_sys_fail_str(path);
     }
 
     if (server) {
Index: ext/dbm/dbm.c
===================================================================
--- ext/dbm/dbm.c	(revision 34824)
+++ ext/dbm/dbm.c	(revision 34825)
@@ -206,7 +206,7 @@
 
     if (!dbm) {
 	if (mode == -1) return Qnil;
-	rb_sys_fail(RSTRING_PTR(file));
+	rb_sys_fail_str(file);
     }
 
     dbmp = ALLOC(struct dbmdata);
Index: ext/gdbm/gdbm.c
===================================================================
--- ext/gdbm/gdbm.c	(revision 34824)
+++ ext/gdbm/gdbm.c	(revision 34825)
@@ -243,7 +243,7 @@
         if (gdbm_errno == GDBM_FILE_OPEN_ERROR ||
             gdbm_errno == GDBM_CANT_BE_READER ||
             gdbm_errno == GDBM_CANT_BE_WRITER)
-            rb_sys_fail(RSTRING_PTR(file));
+            rb_sys_fail_str(file);
         else
             rb_raise(rb_eGDBMError, "%s", gdbm_strerror(gdbm_errno));
     }
Index: ext/iconv/iconv.c
===================================================================
--- ext/iconv/iconv.c	(revision 34824)
+++ ext/iconv/iconv.c	(revision 34825)
@@ -105,8 +105,8 @@
 static VALUE rb_eIconvBrokenLibrary;
 
 static ID rb_success, rb_failed;
-static VALUE iconv_fail _((VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, const char *mesg));
-static VALUE iconv_fail_retry _((VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, const char *mesg));
+static VALUE iconv_fail _((VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, VALUE mesg));
+static VALUE iconv_fail_retry _((VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, VALUE mesg));
 static VALUE iconv_failure_initialize _((VALUE error, VALUE mesg, VALUE success, VALUE failed));
 static VALUE iconv_failure_success _((VALUE self));
 static VALUE iconv_failure_failed _((VALUE self));
@@ -174,16 +174,25 @@
     return StringValuePtr(*code);
 }
 
-NORETURN(static void rb_iconv_sys_fail(const char *s));
+NORETURN(static void rb_iconv_sys_fail_str(VALUE msg));
 static void
-rb_iconv_sys_fail(const char *s)
+rb_iconv_sys_fail_str(VALUE msg)
 {
     if (errno == 0) {
-	rb_exc_raise(iconv_fail(rb_eIconvBrokenLibrary, Qnil, Qnil, NULL, s));
+	rb_exc_raise(iconv_fail(rb_eIconvBrokenLibrary, Qnil, Qnil, NULL, msg));
     }
-    rb_sys_fail(s);
+    rb_sys_fail_str(msg);
 }
 
+#define rb_sys_fail_str(s) rb_iconv_sys_fail_str(s)
+
+NORETURN(static void rb_iconv_sys_fail(const char *s));
+static void
+rb_iconv_sys_fail(const char *s)
+{
+    rb_iconv_sys_fail_str(rb_str_new_cstr(s));
+}
+
 #define rb_sys_fail(s) rb_iconv_sys_fail(s)
 
 static iconv_t
@@ -237,16 +246,11 @@
 	}
 	{
 	    const char *s = inval ? "invalid encoding " : "iconv";
-	    volatile VALUE msg = rb_str_new(0, strlen(s) + RSTRING_LEN(to) +
-					    RSTRING_LEN(from) + 8);
-
-	    sprintf(RSTRING_PTR(msg), "%s(\"%s\", \"%s\")",
-		    s, RSTRING_PTR(to), RSTRING_PTR(from));
-	    s = RSTRING_PTR(msg);
-	    rb_str_set_len(msg, strlen(s));
-	    if (!inval) rb_sys_fail(s);
+	    VALUE msg = rb_sprintf("%s(\"%s\", \"%s\")",
+				   s, RSTRING_PTR(to), RSTRING_PTR(from));
+	    if (!inval) rb_sys_fail_str(msg);
 	    rb_exc_raise(iconv_fail(rb_eIconvInvalidEncoding, Qnil,
-				    rb_ary_new3(2, to, from), NULL, s));
+				    rb_ary_new3(2, to, from), NULL, msg));
 	}
     }
 
@@ -363,12 +367,12 @@
 }
 
 static VALUE
-iconv_fail(VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, const char *mesg)
+iconv_fail(VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, VALUE mesg)
 {
     VALUE args[3];
 
-    if (mesg && *mesg) {
-	args[0] = rb_str_new2(mesg);
+    if (!NIL_P(mesg)) {
+	args[0] = mesg;
     }
     else if (TYPE(failed) != T_STRING || RSTRING_LEN(failed) < FAILED_MAXLEN) {
 	args[0] = rb_inspect(failed);
@@ -390,7 +394,7 @@
 }
 
 static VALUE
-iconv_fail_retry(VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, const char *mesg)
+iconv_fail_retry(VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, VALUE mesg)
 {
     error = iconv_fail(error, success, failed, env, mesg);
     if (!rb_block_given_p()) rb_exc_raise(error);
@@ -438,7 +442,7 @@
 	error = iconv_try(cd, &inptr, &inlen, &outptr, &outlen);
 	if (RTEST(error)) {
 	    unsigned int i;
-	    rescue = iconv_fail_retry(error, Qnil, Qnil, env, 0);
+	    rescue = iconv_fail_retry(error, Qnil, Qnil, env, Qnil);
 	    if (TYPE(rescue) == T_ARRAY) {
 		str = RARRAY_LEN(rescue) > 0 ? RARRAY_PTR(rescue)[0] : Qnil;
 	    }
@@ -469,12 +473,11 @@
     inlen = length;
 
     do {
-	char errmsg[50];
+	VALUE errmsg = Qnil;
 	const char *tmpstart = inptr;
 	outptr = buffer;
 	outlen = sizeof(buffer);
 
-	errmsg[0] = 0;
 	error = iconv_try(cd, &inptr, &inlen, &outptr, &outlen);
 
 	if (
@@ -511,7 +514,7 @@
 	}
 	else {
 	    /* Some iconv() have a bug, return *outlen out of range */
-	    sprintf(errmsg, "bug?(output length = %ld)", (long)(sizeof(buffer) - outlen));
+	    errmsg = rb_sprintf("bug?(output length = %ld)", (long)(sizeof(buffer) - outlen));
 	    error = rb_eIconvOutOfRange;
 	}
 

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

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