summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-27 01:50:27 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-27 01:50:27 +0000
commit80429eed638c36baa3574704b1b567aa7acb4fa6 (patch)
tree387905f8803dc1cbf07736ac403351c38caeaeeb /ext
parent2c3cc479a9b7d55e48d50d3c1712f28855faea12 (diff)
* io.c, process.c, time.c, ext: use rb_sys_fail_str instead of
rb_sys_fail. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34825 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/date/date_core.c35
-rw-r--r--ext/dbm/dbm.c2
-rw-r--r--ext/gdbm/gdbm.c2
-rw-r--r--ext/iconv/iconv.c49
-rw-r--r--ext/sdbm/init.c2
-rw-r--r--ext/socket/basicsocket.c2
-rw-r--r--ext/socket/unixsocket.c2
7 files changed, 49 insertions, 45 deletions
diff --git a/ext/date/date_core.c b/ext/date/date_core.c
index 2c72143168..f9b08cb622 100644
--- a/ext/date/date_core.c
+++ b/ext/date/date_core.c
@@ -6587,7 +6587,7 @@ d_lite_hash(VALUE self)
#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 strftimev(const char *, VALUE,
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 @@ size_t date_strftime(char *s, size_t maxsize, const char *format,
#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 @@ date_strftime_alloc(char **buf, const char *format,
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 @@ date_strftime_internal(int argc, VALUE *argv, VALUE self,
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 @@ date_strftime_internal(int argc, VALUE *argv, VALUE self,
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 @@ d_lite_strftime(int argc, VALUE *argv, VALUE self)
}
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 @@ strftimev(const char *fmt, VALUE self,
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 @@ strftimev(const char *fmt, VALUE self,
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 @@ d_lite_asctime(VALUE self)
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 @@ d_lite_iso8601(VALUE self)
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 @@ d_lite_rfc3339(VALUE self)
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 @@ static VALUE
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 @@ d_lite_jisx0301(VALUE self)
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 @@ datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
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 @@ iso8601_timediv(VALUE self, VALUE n)
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 @@ dt_lite_iso8601(int argc, VALUE *argv, VALUE self)
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 @@ dt_lite_jisx0301(int argc, VALUE *argv, VALUE self)
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));
}
}
diff --git a/ext/dbm/dbm.c b/ext/dbm/dbm.c
index dbf1024181..4bc1ce3e40 100644
--- a/ext/dbm/dbm.c
+++ b/ext/dbm/dbm.c
@@ -206,7 +206,7 @@ fdbm_initialize(int argc, VALUE *argv, VALUE obj)
if (!dbm) {
if (mode == -1) return Qnil;
- rb_sys_fail(RSTRING_PTR(file));
+ rb_sys_fail_str(file);
}
dbmp = ALLOC(struct dbmdata);
diff --git a/ext/gdbm/gdbm.c b/ext/gdbm/gdbm.c
index 328feef0e9..9d958d54a2 100644
--- a/ext/gdbm/gdbm.c
+++ b/ext/gdbm/gdbm.c
@@ -243,7 +243,7 @@ fgdbm_initialize(int argc, VALUE *argv, VALUE obj)
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));
}
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index 125e82d624..32d7f92011 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -105,8 +105,8 @@ static VALUE rb_eIconvOutOfRange;
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,14 +174,23 @@ map_charset(VALUE *code)
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)
@@ -237,16 +246,11 @@ iconv_create(VALUE to, VALUE from, struct rb_iconv_opt_t *opt, int *idx)
}
{
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 @@ iconv_failure_initialize(VALUE error, VALUE mesg, VALUE success, VALUE failed)
}
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 @@ iconv_fail(VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, co
}
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 @@ iconv_convert(iconv_t cd, VALUE str, long start, long length, int toidx, struct
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 @@ iconv_convert(iconv_t cd, VALUE str, long start, long length, int toidx, struct
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 @@ iconv_convert(iconv_t cd, VALUE str, long start, long length, int toidx, struct
}
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;
}
diff --git a/ext/sdbm/init.c b/ext/sdbm/init.c
index 7ba59c4e5c..f138d24e23 100644
--- a/ext/sdbm/init.c
+++ b/ext/sdbm/init.c
@@ -109,7 +109,7 @@ fsdbm_initialize(int argc, VALUE *argv, VALUE obj)
if (!dbm) {
if (mode == -1) return Qnil;
- rb_sys_fail(RSTRING_PTR(file));
+ rb_sys_fail_str(file);
}
dbmp = ALLOC(struct dbmdata);
diff --git a/ext/socket/basicsocket.c b/ext/socket/basicsocket.c
index b997043620..c1ae88d80c 100644
--- a/ext/socket/basicsocket.c
+++ b/ext/socket/basicsocket.c
@@ -247,7 +247,7 @@ bsock_setsockopt(int argc, VALUE *argv, VALUE sock)
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)
diff --git a/ext/socket/unixsocket.c b/ext/socket/unixsocket.c
index 2954cef433..afa47d54f6 100644
--- a/ext/socket/unixsocket.c
+++ b/ext/socket/unixsocket.c
@@ -62,7 +62,7 @@ rsock_init_unixsock(VALUE sock, VALUE path, int server)
if (status < 0) {
close(fd);
- rb_sys_fail(sockaddr.sun_path);
+ rb_sys_fail_str(path);
}
if (server) {