Skip to content

Commit 80429ee

Browse files
committed
* 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
1 parent 2c3cc47 commit 80429ee

File tree

12 files changed

+79
-65
lines changed

12 files changed

+79
-65
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Mon Feb 27 10:50:23 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* io.c, process.c, time.c, ext: use rb_sys_fail_str instead of
4+
rb_sys_fail.
5+
16
Mon Feb 27 10:48:49 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
27

38
* ext/openssl/extconf.rb: suppress useless deprecation warnings

ext/date/date_core.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6587,7 +6587,7 @@ d_lite_hash(VALUE self)
65876587

65886588
#include "date_tmx.h"
65896589
static void set_tmx(VALUE, struct tmx *);
6590-
static VALUE strftimev(const char *, VALUE,
6590+
static VALUE strftimev(VALUE, const char *, VALUE,
65916591
void (*)(VALUE, struct tmx *));
65926592

65936593
/*
@@ -6604,7 +6604,7 @@ static VALUE strftimev(const char *, VALUE,
66046604
static VALUE
66056605
d_lite_to_s(VALUE self)
66066606
{
6607-
return strftimev("%Y-%m-%d", self, set_tmx);
6607+
return strftimev(Qnil, "%Y-%m-%d", self, set_tmx);
66086608
}
66096609

66106610
#ifndef NDEBUG
@@ -6729,7 +6729,7 @@ size_t date_strftime(char *s, size_t maxsize, const char *format,
67296729

67306730
#define SMALLBUF 100
67316731
static size_t
6732-
date_strftime_alloc(char **buf, const char *format,
6732+
date_strftime_alloc(char **buf, VALUE formatv, const char *format,
67336733
struct tmx *tmx)
67346734
{
67356735
size_t size, len, flen;
@@ -6756,6 +6756,7 @@ date_strftime_alloc(char **buf, const char *format,
67566756
if (len > 0) break;
67576757
xfree(*buf);
67586758
if (size >= 1024 * flen) {
6759+
if (!NIL_P(formatv)) rb_sys_fail_str(formatv);
67596760
rb_sys_fail(format);
67606761
break;
67616762
}
@@ -6868,7 +6869,7 @@ date_strftime_internal(int argc, VALUE *argv, VALUE self,
68686869

68696870
str = rb_str_new(0, 0);
68706871
while (p < pe) {
6871-
len = date_strftime_alloc(&buf, p, &tmx);
6872+
len = date_strftime_alloc(&buf, vfmt, p, &tmx);
68726873
rb_str_cat(str, buf, len);
68736874
p += strlen(p);
68746875
if (buf != buffer) {
@@ -6883,7 +6884,7 @@ date_strftime_internal(int argc, VALUE *argv, VALUE self,
68836884
return str;
68846885
}
68856886
else
6886-
len = date_strftime_alloc(&buf, fmt, &tmx);
6887+
len = date_strftime_alloc(&buf, vfmt, fmt, &tmx);
68876888

68886889
str = rb_str_new(buf, len);
68896890
if (buf != buffer) xfree(buf);
@@ -7077,7 +7078,7 @@ d_lite_strftime(int argc, VALUE *argv, VALUE self)
70777078
}
70787079

70797080
static VALUE
7080-
strftimev(const char *fmt, VALUE self,
7081+
strftimev(VALUE vfmt, const char *fmt, VALUE self,
70817082
void (*func)(VALUE, struct tmx *))
70827083
{
70837084
char buffer[SMALLBUF], *buf = buffer;
@@ -7086,7 +7087,7 @@ strftimev(const char *fmt, VALUE self,
70867087
VALUE str;
70877088

70887089
(*func)(self, &tmx);
7089-
len = date_strftime_alloc(&buf, fmt, &tmx);
7090+
len = date_strftime_alloc(&buf, vfmt, fmt, &tmx);
70907091
str = rb_usascii_str_new(buf, len);
70917092
if (buf != buffer) xfree(buf);
70927093
return str;
@@ -7105,7 +7106,7 @@ strftimev(const char *fmt, VALUE self,
71057106
static VALUE
71067107
d_lite_asctime(VALUE self)
71077108
{
7108-
return strftimev("%a %b %e %H:%M:%S %Y", self, set_tmx);
7109+
return strftimev(Qnil, "%a %b %e %H:%M:%S %Y", self, set_tmx);
71097110
}
71107111

71117112
/*
@@ -7118,7 +7119,7 @@ d_lite_asctime(VALUE self)
71187119
static VALUE
71197120
d_lite_iso8601(VALUE self)
71207121
{
7121-
return strftimev("%Y-%m-%d", self, set_tmx);
7122+
return strftimev(Qnil, "%Y-%m-%d", self, set_tmx);
71227123
}
71237124

71247125
/*
@@ -7130,7 +7131,7 @@ d_lite_iso8601(VALUE self)
71307131
static VALUE
71317132
d_lite_rfc3339(VALUE self)
71327133
{
7133-
return strftimev("%Y-%m-%dT%H:%M:%S%:z", self, set_tmx);
7134+
return strftimev(Qnil, "%Y-%m-%dT%H:%M:%S%:z", self, set_tmx);
71347135
}
71357136

71367137
/*
@@ -7143,7 +7144,7 @@ d_lite_rfc3339(VALUE self)
71437144
static VALUE
71447145
d_lite_rfc2822(VALUE self)
71457146
{
7146-
return strftimev("%a, %-d %b %Y %T %z", self, set_tmx);
7147+
return strftimev(Qnil, "%a, %-d %b %Y %T %z", self, set_tmx);
71477148
}
71487149

71497150
/*
@@ -7157,7 +7158,7 @@ static VALUE
71577158
d_lite_httpdate(VALUE self)
71587159
{
71597160
volatile VALUE dup = dup_obj_with_new_offset(self, 0);
7160-
return strftimev("%a, %d %b %Y %T GMT", dup, set_tmx);
7161+
return strftimev(Qnil, "%a, %d %b %Y %T GMT", dup, set_tmx);
71617162
}
71627163

71637164
static VALUE
@@ -7204,7 +7205,7 @@ d_lite_jisx0301(VALUE self)
72047205
get_d1(self);
72057206
s = jisx0301_date(m_real_local_jd(dat),
72067207
m_real_year(dat));
7207-
return strftimev(RSTRING_PTR(s), self, set_tmx);
7208+
return strftimev(s, RSTRING_PTR(s), self, set_tmx);
72087209
}
72097210

72107211
#ifndef NDEBUG
@@ -8294,7 +8295,7 @@ datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
82948295
static VALUE
82958296
dt_lite_to_s(VALUE self)
82968297
{
8297-
return strftimev("%Y-%m-%dT%H:%M:%S%:z", self, set_tmx);
8298+
return strftimev(Qnil, "%Y-%m-%dT%H:%M:%S%:z", self, set_tmx);
82988299
}
82998300

83008301
/*
@@ -8500,7 +8501,7 @@ iso8601_timediv(VALUE self, VALUE n)
85008501
rb_str_append(fmt, rb_f_sprintf(3, argv));
85018502
}
85028503
rb_str_append(fmt, rb_usascii_str_new2("%:z"));
8503-
return strftimev(RSTRING_PTR(fmt), self, set_tmx);
8504+
return strftimev(fmt, RSTRING_PTR(fmt), self, set_tmx);
85048505
}
85058506

85068507
/*
@@ -8526,7 +8527,7 @@ dt_lite_iso8601(int argc, VALUE *argv, VALUE self)
85268527
if (argc < 1)
85278528
n = INT2FIX(0);
85288529

8529-
return f_add(strftimev("%Y-%m-%d", self, set_tmx),
8530+
return f_add(strftimev(Qnil, "%Y-%m-%d", self, set_tmx),
85308531
iso8601_timediv(self, n));
85318532
}
85328533

@@ -8574,7 +8575,7 @@ dt_lite_jisx0301(int argc, VALUE *argv, VALUE self)
85748575
get_d1(self);
85758576
s = jisx0301_date(m_real_local_jd(dat),
85768577
m_real_year(dat));
8577-
return rb_str_append(strftimev(RSTRING_PTR(s), self, set_tmx),
8578+
return rb_str_append(strftimev(s, RSTRING_PTR(s), self, set_tmx),
85788579
iso8601_timediv(self, n));
85798580
}
85808581
}

ext/dbm/dbm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ fdbm_initialize(int argc, VALUE *argv, VALUE obj)
206206

207207
if (!dbm) {
208208
if (mode == -1) return Qnil;
209-
rb_sys_fail(RSTRING_PTR(file));
209+
rb_sys_fail_str(file);
210210
}
211211

212212
dbmp = ALLOC(struct dbmdata);

ext/gdbm/gdbm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ fgdbm_initialize(int argc, VALUE *argv, VALUE obj)
243243
if (gdbm_errno == GDBM_FILE_OPEN_ERROR ||
244244
gdbm_errno == GDBM_CANT_BE_READER ||
245245
gdbm_errno == GDBM_CANT_BE_WRITER)
246-
rb_sys_fail(RSTRING_PTR(file));
246+
rb_sys_fail_str(file);
247247
else
248248
rb_raise(rb_eGDBMError, "%s", gdbm_strerror(gdbm_errno));
249249
}

ext/iconv/iconv.c

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ static VALUE rb_eIconvOutOfRange;
105105
static VALUE rb_eIconvBrokenLibrary;
106106

107107
static ID rb_success, rb_failed;
108-
static VALUE iconv_fail _((VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, const char *mesg));
109-
static VALUE iconv_fail_retry _((VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, const char *mesg));
108+
static VALUE iconv_fail _((VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, VALUE mesg));
109+
static VALUE iconv_fail_retry _((VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, VALUE mesg));
110110
static VALUE iconv_failure_initialize _((VALUE error, VALUE mesg, VALUE success, VALUE failed));
111111
static VALUE iconv_failure_success _((VALUE self));
112112
static VALUE iconv_failure_failed _((VALUE self));
@@ -174,14 +174,23 @@ map_charset(VALUE *code)
174174
return StringValuePtr(*code);
175175
}
176176

177-
NORETURN(static void rb_iconv_sys_fail(const char *s));
177+
NORETURN(static void rb_iconv_sys_fail_str(VALUE msg));
178178
static void
179-
rb_iconv_sys_fail(const char *s)
179+
rb_iconv_sys_fail_str(VALUE msg)
180180
{
181181
if (errno == 0) {
182-
rb_exc_raise(iconv_fail(rb_eIconvBrokenLibrary, Qnil, Qnil, NULL, s));
182+
rb_exc_raise(iconv_fail(rb_eIconvBrokenLibrary, Qnil, Qnil, NULL, msg));
183183
}
184-
rb_sys_fail(s);
184+
rb_sys_fail_str(msg);
185+
}
186+
187+
#define rb_sys_fail_str(s) rb_iconv_sys_fail_str(s)
188+
189+
NORETURN(static void rb_iconv_sys_fail(const char *s));
190+
static void
191+
rb_iconv_sys_fail(const char *s)
192+
{
193+
rb_iconv_sys_fail_str(rb_str_new_cstr(s));
185194
}
186195

187196
#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)
237246
}
238247
{
239248
const char *s = inval ? "invalid encoding " : "iconv";
240-
volatile VALUE msg = rb_str_new(0, strlen(s) + RSTRING_LEN(to) +
241-
RSTRING_LEN(from) + 8);
242-
243-
sprintf(RSTRING_PTR(msg), "%s(\"%s\", \"%s\")",
244-
s, RSTRING_PTR(to), RSTRING_PTR(from));
245-
s = RSTRING_PTR(msg);
246-
rb_str_set_len(msg, strlen(s));
247-
if (!inval) rb_sys_fail(s);
249+
VALUE msg = rb_sprintf("%s(\"%s\", \"%s\")",
250+
s, RSTRING_PTR(to), RSTRING_PTR(from));
251+
if (!inval) rb_sys_fail_str(msg);
248252
rb_exc_raise(iconv_fail(rb_eIconvInvalidEncoding, Qnil,
249-
rb_ary_new3(2, to, from), NULL, s));
253+
rb_ary_new3(2, to, from), NULL, msg));
250254
}
251255
}
252256

@@ -363,12 +367,12 @@ iconv_failure_initialize(VALUE error, VALUE mesg, VALUE success, VALUE failed)
363367
}
364368

365369
static VALUE
366-
iconv_fail(VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, const char *mesg)
370+
iconv_fail(VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, VALUE mesg)
367371
{
368372
VALUE args[3];
369373

370-
if (mesg && *mesg) {
371-
args[0] = rb_str_new2(mesg);
374+
if (!NIL_P(mesg)) {
375+
args[0] = mesg;
372376
}
373377
else if (TYPE(failed) != T_STRING || RSTRING_LEN(failed) < FAILED_MAXLEN) {
374378
args[0] = rb_inspect(failed);
@@ -390,7 +394,7 @@ iconv_fail(VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, co
390394
}
391395

392396
static VALUE
393-
iconv_fail_retry(VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, const char *mesg)
397+
iconv_fail_retry(VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, VALUE mesg)
394398
{
395399
error = iconv_fail(error, success, failed, env, mesg);
396400
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
438442
error = iconv_try(cd, &inptr, &inlen, &outptr, &outlen);
439443
if (RTEST(error)) {
440444
unsigned int i;
441-
rescue = iconv_fail_retry(error, Qnil, Qnil, env, 0);
445+
rescue = iconv_fail_retry(error, Qnil, Qnil, env, Qnil);
442446
if (TYPE(rescue) == T_ARRAY) {
443447
str = RARRAY_LEN(rescue) > 0 ? RARRAY_PTR(rescue)[0] : Qnil;
444448
}
@@ -469,12 +473,11 @@ iconv_convert(iconv_t cd, VALUE str, long start, long length, int toidx, struct
469473
inlen = length;
470474

471475
do {
472-
char errmsg[50];
476+
VALUE errmsg = Qnil;
473477
const char *tmpstart = inptr;
474478
outptr = buffer;
475479
outlen = sizeof(buffer);
476480

477-
errmsg[0] = 0;
478481
error = iconv_try(cd, &inptr, &inlen, &outptr, &outlen);
479482

480483
if (
@@ -511,7 +514,7 @@ iconv_convert(iconv_t cd, VALUE str, long start, long length, int toidx, struct
511514
}
512515
else {
513516
/* Some iconv() have a bug, return *outlen out of range */
514-
sprintf(errmsg, "bug?(output length = %ld)", (long)(sizeof(buffer) - outlen));
517+
errmsg = rb_sprintf("bug?(output length = %ld)", (long)(sizeof(buffer) - outlen));
515518
error = rb_eIconvOutOfRange;
516519
}
517520

ext/sdbm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fsdbm_initialize(int argc, VALUE *argv, VALUE obj)
109109

110110
if (!dbm) {
111111
if (mode == -1) return Qnil;
112-
rb_sys_fail(RSTRING_PTR(file));
112+
rb_sys_fail_str(file);
113113
}
114114

115115
dbmp = ALLOC(struct dbmdata);

ext/socket/basicsocket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ bsock_setsockopt(int argc, VALUE *argv, VALUE sock)
247247
break;
248248
}
249249

250-
#define rb_sys_fail_path(path) rb_sys_fail(NIL_P(path) ? 0 : RSTRING_PTR(path))
250+
#define rb_sys_fail_path(path) rb_sys_fail_str(path)
251251

252252
rb_io_check_closed(fptr);
253253
if (setsockopt(fptr->fd, level, option, v, vlen) < 0)

ext/socket/unixsocket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ rsock_init_unixsock(VALUE sock, VALUE path, int server)
6262

6363
if (status < 0) {
6464
close(fd);
65-
rb_sys_fail(sockaddr.sun_path);
65+
rb_sys_fail_str(path);
6666
}
6767

6868
if (server) {

include/ruby/intern.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ struct rb_exec_arg {
585585
const char *prog;
586586
VALUE options;
587587
VALUE redirect_fds;
588+
VALUE progname;
588589
};
589590
int rb_proc_exec_n(int, VALUE*, const char*);
590591
int rb_proc_exec(const char*);

0 commit comments

Comments
 (0)